Skip to content

fix(session): preserve metadata in tool-call handler for subagent click navigation#20183

Closed
altendky wants to merge 2 commits intoanomalyco:devfrom
altendky:fix/subagent-click-navigation-debug
Closed

fix(session): preserve metadata in tool-call handler for subagent click navigation#20183
altendky wants to merge 2 commits intoanomalyco:devfrom
altendky:fix/subagent-click-navigation-debug

Conversation

@altendky
Copy link
Copy Markdown
Contributor

@altendky altendky commented Mar 31, 2026

Issue for this PR

Closes #20184

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Clicking on subagent labels in the TUI no longer navigated to the subagent session view after the effectify refactor. The issue was a race condition introduced by the queue-based LLM layer.

Root cause: The queue decouples event processing from tool execution. When a tool's execute callback runs and calls ctx.metadata() (to set the subagent's sessionId), the processor hasn't yet consumed the tool-call event from the queue — so the part is still in "pending" state. The metadata callback had a guard if (status !== "running") return which silently dropped the metadata.

Additionally, even when metadata was successfully written to the DB, the processor's tool-call handler would overwrite it using stale in-memory state (ctx.toolcalls).

Fix (two parts):

  1. prompt.ts - Allow metadata updates for pending parts (only skip completed/error)
  2. processor.ts - Read current DB state before updating and preserve any existing title/metadata

How did you verify your code works?

  1. Added diagnostic logging at all key points (llm queue push, processor tool-input-start/tool-call/tool-result, metadata callbacks)
  2. Reproduced with "launch 3 subagents each sleeping for 60 seconds"
  3. Confirmed logs showed matchStatus=pending when ctx.metadata() was called
  4. Applied fix, confirmed clicking on subagent labels now navigates to subagent view

Screenshots / recordings

N/A (behavioral fix, no UI changes)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ition

This commit contains:
1. Fix for metadata callback to accept pending state (not just running)
2. Fix for processor.tool-call to preserve existing metadata from DB
3. Comprehensive diagnostic logging at all key points:
   - llm.ts: llm.queue.push for tool events
   - processor.ts: tool-input-start, tool-call, tool-call.existing, tool-result
   - prompt.ts: resolveTools.metadata, handleSubtask.metadata
   - task.ts: task.metadata.call

The race condition: queue-based LLM layer decouples event processing from
tool execution, causing ctx.metadata() to run before processor.tool-call
transitions the part from pending to running. The fix reads current DB
state in tool-call handler and preserves any existing metadata.

Subagent click navigation now works. Separate issue observed: doom_loop
permission triggered for task tool (needs investigation).
…ck navigation

The queue-based LLM layer introduced a race condition: tool execute callbacks
(which call ctx.metadata()) run before the processor's tool-call event handler
transitions the part from pending to running. This caused metadata (including
sessionId for subagents) to be silently dropped.

Two fixes:
1. metadata callback now accepts pending state (not just running)
2. processor tool-call handler reads current DB state and preserves any
   existing title/metadata set by ctx.metadata()

Fixes regression from c5442d4 (effectify SessionPrompt service).
@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking on subagent labels in TUI does not navigate to subagent session

1 participant