8000 feat: store tool call IDs to determine interception lineage by dannykopping · Pull Request #22246 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: store tool call IDs to determine interception lineage#22246

Merged
dannykopping merged 18 commits intomainfrom
dk/tool-call-id-correlation
Mar 3, 2026
Merged

feat: store tool call IDs to determine interception lineage#22246
dannykopping merged 18 commits intomainfrom
dk/tool-call-id-correlation

Conversation

@dannykopping
Copy link
Contributor
@dannykopping dannykopping commented Feb 23, 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 branch.
Depends on coder/aibridge#188.

Closes coder/internal#1334

Copy link
Contributor Author
dannykopping commented Feb 23, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@dannykopping dannykopping force-pushed the dk/tool-call-id-correlation branch 2 times, most recently from 7aec92f to 6d4111f Compare February 23, 2026 10:02
@dannykopping dannykopping changed the title feat: store and correlate tool call IDs for interception lineage feat: add database column to store and correlate tool call IDs for interception lineage Feb 23, 2026
@dannykopping dannykopping changed the title feat: add database column to store and correlate tool call IDs for interception lineage feat: store and correlate tool call IDs for interception lineage Feb 23, 2026
@dannykopping dannykopping force-pushed the dk/tool-call-id-correlation branch 2 times, most recently from 93873fb to 668fb26 Compare February 23, 2026 13:29
@dannykopping dannykopping changed the title feat: store and correlate tool call IDs for interception lineage feat: store tool call IDs to determine interception lineage Feb 24, 2026
@dannykopping dannykopping force-pushed the dk/tool-call-id-correlation branch 2 times, most recently from 67f72a7 to b9689c6 Compare February 24, 2026 13:15
@dannykopping dannykopping marked this pull request as ready for review February 24, 2026 13:16
@dannykopping dannykopping requested a review from pawbana February 24, 2026 13:16
Copy link
Contributor
@pawbana pawbana left a comment

Choose a reason for hiding this comment

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

Generally ok, few nits / small improvements.
Would be nice to have proper end to end test. May wait for sessions to be finished.

Copy link
Contributor Author

@pawbana I had another PR stacked on top of this to handle the threads, but after a while I just collapsed those changes into here since it replaced some of the original implementations (like SQL queries). I also added an integration test: TestInferredThreadsByToolCalls`` `` Can you have another look pls?

@dannykopping dannykopping requested a review from pawbana February 27, 2026 14:25
@dannykopping dannykopping force-pushed the dk/tool-call-id-correlation branch from a45d054 to 94aabd6 Compare March 2, 2026 09:53
dannykopping added a commit to coder/aibridge that referenced this pull request Mar 2, 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`](main...prompt_provenance_poc) branch.
Downstream: [coder/coder#22246](coder/coder#22246).

Closes #165
dannykopping and others added 6 commits March 2, 2026 18:07
Adds database columns (provider_tool_call_id on aibridge_tool_usages,
parent_id on aibridge_interceptions) and the plumbing to populate them.
When an interception ends with a correlating tool call ID, the server
looks up which interception issued that tool call and sets parent_id.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add test cases for parent interception correlation in
TestRecordInterceptionEnded (ok_with_parent_correlation and
ok_no_parent_found) and ToolCallId assertion in TestRecordToolUsage.

Update aibridge dependency to include extracted scan methods and tests.

Fix dbauthz authorization for GetAIBridgeInterceptionByToolCallID to
use proper RBAC check instead of comment-only justification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Danny Kopping <danny@coder.com>
The hand-written ListAuthorizedAIBridgeInterceptions in modelqueries.go
was missing the new thread_parent_id column in its Scan call, causing
"expected 14 destination arguments in Scan, not 13" errors.

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>
dannykopping and others added 11 commits March 2, 2026 18:07
Signed-off-by: Danny Kopping <danny@coder.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Same fix as downstack but for the additional thread_root_id column.

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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
8000
Signed-off-by: Danny Kopping <danny@coder.com>
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>
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping force-pushed the dk/tool-call-id-correlation branch from 94aabd6 to 958a7e5 Compare March 2, 2026 16:08
Copy link
Contributor
@pawbana pawbana left a comment

Choose a reason for hiding this comment

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

Generally ok.

I think it would be nice to have parentID and rootID logged otherwise just edge case tests and nits.

Graphite ate my comments : (

// tool call IDs correctly propagates thread_parent_id and thread_root_id.
//
// The chain is: A → B → C
// - A is the root (no parent, no root)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Is there a reason for A having no root?
With rootID := A.ID (self reference) there would be distinction between old entires with no root set and new first/root entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're suggesting that we should always set the root ID to discriminate new entries from previous ones (before this change)?
Only interceptions with prompts can classify as thread roots, though.
A thread is a prompt (root) plus an optional agentic loop that follows (children all pointing to their own parent and the original root).
Does that answer your question?

Copy link
Contributor

Choose a reason for hiding this comment

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

always set the root ID to discriminate new entries from previous ones (before this change)?
Yes, it was more of a open question, I don't have strong opinion on NULL vs set to self since I don't have clear idea why this distinction would be needed.

I've asked since we could add it for "free" in case it would be helpful (and I missed some use case).

Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping dannykopping merged commit 9b5573d into main Mar 3, 2026
24 checks passed
@dannykopping dannykopping deleted the dk/tool-call-id-correlation branch March 3, 2026 19:07
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Store tool call ID and infer interception relationships

2 participants

0