Skip to content

fix(session): preserve tool metadata across pending→running transition#20187

Closed
rmk40 wants to merge 1 commit intoanomalyco:devfrom
rmk40:fix/subagent-click-metadata-race
Closed

fix(session): preserve tool metadata across pending→running transition#20187
rmk40 wants to merge 1 commit intoanomalyco:devfrom
rmk40:fix/subagent-click-metadata-race

Conversation

@rmk40
Copy link
Copy Markdown
Contributor

@rmk40 rmk40 commented Mar 31, 2026

Summary

Regression from c5442d4 (effectify SessionPrompt): clicking a running subagent
in the TUI does nothing because state.metadata.sessionId is never populated
while the tool is running.

Root Cause

ctx.metadata({sessionId}) fires while the part is still pending. The
processor's tool-call handler then transitions the part to running with a
fresh state object — clobbering the metadata. The TUI reads
state.metadata.sessionId for click navigation, so it's always empty.

Fix

Synchronous side-channel (toolMetadata map) on the processor context:

  • setToolMetadata() writes immediately when the metadata callback fires
  • tool-call handler merges title/metadata from the map into the running state
  • Entries cleaned up in tool-result and tool-error

Uses an in-memory side-channel rather than a DB read, so the metadata is
guaranteed to be available regardless of async scheduling.

@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

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

The following comment was made by an LLM, it may be inaccurate:

Related PR Found

PR #20183: #20183

  • Title: fix(session): preserve metadata in tool-call handler for subagent click navigation
  • Relationship: This is already marked as "Related" in the current PR description. Both PRs address the same underlying issue with preserving session metadata in the tool-call handler for subagent navigation in the TUI.

The current PR (#20187) appears to be a refined or follow-up fix to #20183, addressing the regression from the SessionPrompt effectify commit.

@rmk40 rmk40 force-pushed the fix/subagent-click-metadata-race branch 3 times, most recently from 058d701 to 0f8d2b9 Compare March 31, 2026 05:36
The effectify refactor (c5442d4) introduced a race where ctx.metadata()
fires before the processor's tool-call event transitions the part from
pending to running. The tool-call handler constructs a fresh state without
metadata, clobbering the sessionId the task tool just wrote. This made
subagent sessions unclickable in the TUI while running.

- Add toolMetadata side-channel on processor context
- Metadata callback writes synchronously to the side-channel
- tool-call handler merges pending metadata into running state
- Clean up toolMetadata entries in tool-result and tool-error
@rmk40 rmk40 force-pushed the fix/subagent-click-metadata-race branch from 0f8d2b9 to 00739a8 Compare March 31, 2026 05:41
@rmk40
Copy link
Copy Markdown
Contributor Author

rmk40 commented Mar 31, 2026

Superseded by a new PR that includes both the fix and an E2E regression test.

@rmk40 rmk40 closed this Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor needs:compliance This means the issue will auto-close after 2 hours.

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