Skip to content

feat: record and correlate tool call IDs across interceptions#188

Merged
dannykopping merged 9 commits intomainfrom
dk/tool-call-id-correlation
Mar 2, 2026
Merged

feat: record and correlate tool call IDs across interceptions#188
dannykopping merged 9 commits intomainfrom
dk/tool-call-id-correlation

Conversation

@dannykopping
Copy link
Collaborator

@dannykopping dannykopping commented Feb 23, 2026

Track provider-supplied tool call IDs with each tool use response.

Add CorrelatingToolCallID to the Interceptor interface for interception lineage tracking. Each interceptor scans backward through request messages to find the most recent tool call result, identifying the parent interception that triggered the current one.

Adapted from the aibridge prompt_provenance_poc branch.
Downstream: coder/coder#22246.

Closes #165

Copy link
Collaborator Author

dannykopping commented Feb 23, 2026

@dannykopping dannykopping changed the title fix: Use requests byte payload in messages interceptor (#185) feat: record and correlate tool call IDs across interceptions Feb 23, 2026
@dannykopping dannykopping marked this pull request as ready for review February 24, 2026 12:02
@dannykopping dannykopping requested a review from pawbana February 24, 2026 12:02
@dannykopping dannykopping force-pushed the dk/tool-call-id-correlation branch from cf82329 to c91de99 Compare February 25, 2026 14:17
@dannykopping dannykopping requested a review from pawbana February 26, 2026 12:41
dannykopping and others added 9 commits March 2, 2026 10:21
Add CorrelatingToolCallID to the Interceptor interface, enabling
interception lineage tracking. Each interceptor now scans backward
through request messages/input to find the most recent tool call result,
correctly identifying the parent interception that triggered the current
one.

Also record ToolCallID in non-injected tool usage for the responses API,
which was previously missing and prevented lineage queries from finding
parent interceptions.

Changes:
- Add CorrelatingToolCallID() to Interceptor interface
- Add correlatingToolCallID field to all interceptor base types
- Add backward scan loops in chatcompletions, messages, responses
- Add scanForCorrelatingToolCallID() for responses API
- Record ToolCallID in both injected and non-injected tool usage
- Add CorrelatingToolCallID to InterceptionRecordEnded
- Add ToolCallID to ToolUsageRecord
- Pass CorrelatingToolCallID when ending interceptions in bridge.go
- Update tests and integration test expectations

Signed-off-by: Danny Kopping <danny@coder.com>
Extract scanForCorrelatingToolCallID() into methods on the base structs
for chatcompletions and messages interceptors, matching the existing
pattern in responses. Add TestScanForCorrelatingToolCallID table-driven
tests for all three interceptors.

Update MockRecorder to store full InterceptionRecordEnded structs
instead of just timestamps, enabling richer test assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Danny Kopping <danny@coder.com>
The scan must happen once on the original request messages, not on
every loop iteration. Inside the loop, appended injected tool results
would be picked up instead of the original correlating tool call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Signed-off-by: Danny Kopping <danny@coder.com>
Move CorrelatingToolCallID from InterceptionRecordEnded to
InterceptionRecord so that the parent correlation is passed at
interception start time, when it is already known from the incoming
request's input messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator Author

dannykopping commented Mar 2, 2026

Merge activity

  • Mar 2, 10:27 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Mar 2, 10:28 AM UTC: @dannykopping merged this pull request with Graphite.

@dannykopping dannykopping merged commit 498272d into main Mar 2, 2026
5 checks passed
dannykopping added a commit to coder/coder that referenced this pull request Mar 3, 2026
Adds database columns and server-side logic to track interception lineage via tool call IDs. When an interception ends, the server resolves the correlating tool call ID to find the parent interception and links them via `parent_id`.

New `provider_tool_call_id` column on `aibridge_tool_usages` and `parent_id` column on `aibridge_interceptions`, with indexes for lookup. `findParentInterceptionID` queries by tool call ID and filters out the current interception to find the parent.

Adapted from the [coder/coder `dk/prompt_provenance_poc`](main...dk/prompt_provenance_poc) branch.
Depends on [coder/aibridge#188](coder/aibridge#188).  
  
Closes coder/internal#1334
pull bot pushed a commit to PterX/coder that referenced this pull request Mar 3, 2026
)

Adds database columns and server-side logic to track interception lineage via tool call IDs. When an interception ends, the server resolves the correlating tool call ID to find the parent interception and links them via `parent_id`.

New `provider_tool_call_id` column on `aibridge_tool_usages` and `parent_id` column on `aibridge_interceptions`, with indexes for lookup. `findParentInterceptionID` queries by tool call ID and filters out the current interception to find the parent.

Adapted from the [coder/coder `dk/prompt_provenance_poc`](coder/coder@main...dk/prompt_provenance_poc) branch.
Depends on [coder/aibridge#188](coder/aibridge#188).  
  
Closes coder/internal#1334
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.

Record tool call ID

2 participants