Skip to content

feat(trace): trace ordinary tool calls - #147

Open
rgao-coreweave wants to merge 4 commits into
mainfrom
109-11-tool-spans
Open

feat(trace): trace ordinary tool calls#147
rgao-coreweave wants to merge 4 commits into
mainfrom
109-11-tool-spans

Conversation

@rgao-coreweave

@rgao-coreweave rgao-coreweave commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Trace ordinary tool calls as children of their owning turn.

  • ToolLifecycle correlates exact tool_use_id values, ignores duplicate terminal hooks, recovers restart-first results, and closes tool spans before their parent turn.
  • HookHandler handles ordinary pre- and post-tool hooks.
  • Session keeps turns open while their tool children are active.
  • Restart-first tool hooks recover their owning transcript turn by exact tool_use_id; completed historical turns are bounded so later responses cannot leak into them.

The special Agent tool remains deferred to its dedicated lifecycle.

Validation

  • npm run check
  • 88 tests pass

Comment thread src/daemon.ts Outdated
if (session.calls.byToolUseId.has(input.tool_use_id)
|| session.calls.toolUseTombstones.has(input.tool_use_id)) return;

const turn = this.ensureTurn(session, input.prompt_id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after a daemon restart, could this create an empty turn and miss the prompt and the model response that triggered the tool?

For example, if the transcript already has one response, responseOffset will be 1 and userText will be undefined, so the recovered turn will miss both the prompt and that response, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Matching SessionEnd currently repairs the turn, but Stop, a subsequent prompt, or shutdown can finalize it first. I’ll recover the owning transcript turn by exact tool_use_id, retain the fail-closed fallback when no match exists, and add regression coverage.

@rgao-coreweave rgao-coreweave changed the title feat(daemon): trace ordinary tool calls feat(trace): trace ordinary tool lifecycles Jul 23, 2026
@rgao-coreweave rgao-coreweave changed the title feat(trace): trace ordinary tool lifecycles feat(trace): trace ordinary tool calls Aug 4, 2026
@rgao-coreweave
rgao-coreweave requested a review from ro31337 August 6, 2026 23:03
Base automatically changed from 109-14-chat-tool-spans to main August 7, 2026 19:24
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.

2 participants