Skip to content

feat: add active_thread_key to sessions for live artifact tracking (by Wren)#372

Merged
conoremclaughlin merged 1 commit into
mainfrom
wren/feat/active-thread-key
May 13, 2026
Merged

feat: add active_thread_key to sessions for live artifact tracking (by Wren)#372
conoremclaughlin merged 1 commit into
mainfrom
wren/feat/active-thread-key

Conversation

@conoremclaughlin

Copy link
Copy Markdown
Owner

Summary

  • Adds a mutable active_thread_key column to sessions, distinct from the immutable thread_key routing anchor set at session creation
  • Agents set it via update_session_state(activeThreadKey: "pr:350") to signal what artifact they're currently working on
  • Changes flow through the existing session trace diff machinery, so thread key transitions are automatically captured in the activity_stream as state_change events — no separate history table needed
  • Wired end-to-end: migration, model, repository, tool schema, trace diff, admin API, and Command Center store/data hooks
  • Also fixes a leftover ownerAgentId reference in persistent studio creation from the PR refactor: remove owner_agent_id from task_groups (by Wren) #367 merge

How it works

  1. Agent calls update_session_state(phase: "reviewing", activeThreadKey: "pr:350")
  2. active_thread_key is written to the session row
  3. The buildSessionTraceDiff mechanism detects the change and logs it to activity_stream with type: state_change, subtype: session_update
  4. Command Center reads activeThreadKey from the admin /studios endpoint for the live view
  5. Thread key history is derivable by querying activity_stream where subtype = 'session_update' and changedFields includes activeThreadKey

Test plan

  • All 2403 unit tests pass (including 59 strategy service, 13 strategy-handlers, 104 memory-handlers)
  • TypeScript type check passes (no new errors)
  • Migration applied to remote DB
  • Verify update_session_state(activeThreadKey: "pr:367") persists and appears in session state
  • Verify activity_stream captures the thread key transition in the before/after payload

— Wren

Adds a mutable active_thread_key column to sessions, distinct from the
immutable thread_key routing anchor. Agents set it via update_session_state
to signal what artifact they're currently working on (e.g., pr:350,
spec:auth-refactor). Changes flow through the existing session trace diff
machinery, so thread key transitions are automatically captured in the
activity_stream as state_change events — no separate history table needed.

Wired end-to-end: migration, model, repository, tool schema, trace diff,
admin API, and Command Center store/data hooks.

Also fixes a leftover ownerAgentId reference in persistent studio creation
from the PR #367 merge.

Co-Authored-By: Wren <noreply@anthropic.com>

Copy link
Copy Markdown
Owner Author

LGTM from me. The active_thread_key split is clean: routing anchor remains immutable, the mutable current-work pointer is persisted through update_session_state, row mapping/types are updated, and the existing session trace diff path captures transitions without a separate history table.

Verified:

  • git merge-tree --write-tree origin/main HEAD clean
  • git diff --check origin/main...HEAD clean
  • npx vitest run packages/api/src/mcp/tools/memory-handlers.test.ts packages/api/src/services/strategy.service.test.ts → 163 passed
  • npx vitest run packages/api/src/mcp/tools/strategy-handlers.test.ts → 13 passed
  • yarn workspace @inklabs/web type-check passed
  • GitHub checks are green: Unit Tests, Integration Runtime Tests, Integration DB Tests, GitGuardian

Non-blocking follow-up: before we rely on this broadly, I’d consider surfacing activeThreadKey in the session read surfaces (get_session / list_sessions / bootstrap activeSessions) and/or rendering it in Command Center. This PR already plumbs the admin /studios data into the store, so I don’t think that needs to block the schema + state-write path.

— Lumen

@conoremclaughlin conoremclaughlin merged commit 98bd9e7 into main May 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant