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

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`](https://github.com/coder/coder/compare/main...dk/prompt_provenance_poc) branch.
Depends on [coder/aibridge#188](https://github.com/coder/aibridge/pull/188).  
  
Closes https://github.com/coder/internal/issues/1334
This commit is contained in:
Danny Kopping
2026-03-03 21:04:41 +02:00
committed by GitHub
parent c05fbfec6c
commit 1b08bc76a6
20 changed files with 711 additions and 272 deletions
@@ -0,0 +1,12 @@
DROP INDEX IF EXISTS idx_aibridge_tool_usages_provider_tool_call_id;
ALTER TABLE aibridge_tool_usages
DROP COLUMN provider_tool_call_id;
DROP INDEX IF EXISTS idx_aibridge_interceptions_thread_root_id;
DROP INDEX IF EXISTS idx_aibridge_interceptions_thread_parent_id;
ALTER TABLE aibridge_interceptions
DROP COLUMN thread_root_id;
ALTER TABLE aibridge_interceptions
DROP COLUMN thread_parent_id;
@@ -0,0 +1,14 @@
ALTER TABLE aibridge_tool_usages
ADD COLUMN provider_tool_call_id text NULL; -- nullable to allow existing data to be correct
CREATE INDEX idx_aibridge_tool_usages_provider_tool_call_id ON aibridge_tool_usages (provider_tool_call_id);
ALTER TABLE aibridge_interceptions
ADD COLUMN thread_parent_id UUID NULL,
ADD COLUMN thread_root_id UUID NULL;
COMMENT ON COLUMN aibridge_interceptions.thread_parent_id IS 'The interception which directly caused this interception to occur, usually through an agentic loop or threaded conversation.';
COMMENT ON COLUMN aibridge_interceptions.thread_root_id IS 'The root interception of the thread that this interception belongs to.';
CREATE INDEX idx_aibridge_interceptions_thread_parent_id ON aibridge_interceptions (thread_parent_id);
CREATE INDEX idx_aibridge_interceptions_thread_root_id ON aibridge_interceptions (thread_root_id);