Skip to content

feat: record provider_item_id for tool usage - #26856

Merged
dannykopping merged 2 commits into
mainfrom
dk/tool-usage-provider-item-id
Jul 6, 2026
Merged

feat: record provider_item_id for tool usage#26856
dannykopping merged 2 commits into
mainfrom
dk/tool-usage-provider-item-id

Conversation

@dannykopping

@dannykopping dannykopping commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Plumbs the Responses output item id (added as ToolUsageRecord.ItemID in #26855) through to the database, captured independently of the provider_tool_call_id correlation key. Hosted tools (web_search_call, etc.) only have an item id; agentic tools have both.

provider_item_id is specific to the OpenAI Responses API; it stays empty for chat completions and Anthropic messages, which have no separate item id.

Changes

  • Migration 000534: nullable provider_item_id column on aibridge_tool_usages.
  • Proto: item_id field 11 on RecordToolUsageRequest.
  • Server handler: persists provider_item_id and adds it to structured logging.
  • Translator: maps ToolUsageRecord.ItemID to the proto field.

Tests

  • TestRecordToolUsageProviderItemID: real-database round-trip asserting provider_item_id persists for both hosted and agentic tools, independently of provider_tool_call_id.

Stacked on #26855. Linear: AIGOV-96


This PR was produced by opencode (agent) using the anthropic/claude-opus-4-8 model, under human direction and review.

dannykopping commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

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

@dannykopping dannykopping changed the title feat(coderd/aibridgedserver): record provider_item_id for tool usage feat: record provider_item_id for tool usage Jun 30, 2026
@dannykopping
dannykopping force-pushed the dk/record-all-tool-types branch from d48ce9d to f2e690f Compare June 30, 2026 11:08
@dannykopping
dannykopping force-pushed the dk/tool-usage-provider-item-id branch from 3665432 to 676bc3e Compare June 30, 2026 11:08
@dannykopping
dannykopping force-pushed the dk/record-all-tool-types branch from f2e690f to a876e19 Compare June 30, 2026 12:12
@dannykopping
dannykopping force-pushed the dk/tool-usage-provider-item-id branch from 676bc3e to 114508d Compare June 30, 2026 12:12
@dannykopping
dannykopping requested a review from SasSwart June 30, 2026 12:16
@dannykopping
dannykopping marked this pull request as ready for review June 30, 2026 12:16
@dannykopping
dannykopping requested a review from pawbana July 2, 2026 15:57

// TestRecordToolUsageProviderItemID exercises the RecordToolUsage RPC against a
// real database and confirms that the item_id (the Responses output item's
// unique id) is persisted independently of the tool_call_id correlation key,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not exactly sure what this test checks.
I don't understand why checking for lack of correlation between item_id and tool_call_id is important but maybe I'm missing something.

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.

I clarified the intent a bit. It's just there to show that the two fields can be tracked separately since they serve different purposes.

@dannykopping
dannykopping force-pushed the dk/tool-usage-provider-item-id branch from 114508d to 9493f3a Compare July 6, 2026 06:55
@dannykopping
dannykopping force-pushed the dk/record-all-tool-types branch from a876e19 to 3c594fa Compare July 6, 2026 06:55
@dannykopping
dannykopping force-pushed the dk/tool-usage-provider-item-id branch from 9493f3a to eefaf25 Compare July 6, 2026 07:09
@dannykopping
dannykopping changed the base branch from dk/record-all-tool-types to graphite-base/26856 July 6, 2026 07:10
Plumbs the Responses output item id through to the aibridge tool usage
record so it is captured independently of the tool_call_id correlation
key. Hosted tools (web_search_call, etc.) only have an item id; agentic
tools have both. Conflating them caused data-consistency ambiguity.

- migration 000534: add nullable provider_item_id column
- proto: add item_id field 11 to RecordToolUsageRequest
- server handler: persist item_id and add it to structured logging
- translator: map ToolUsageRecord.ItemID to proto ItemId
- test: real-DB round-trip asserting item_id persists for both hosted
  and agentic tools, independently of provider_tool_call_id
@dannykopping
dannykopping force-pushed the graphite-base/26856 branch from 3c594fa to 08a6359 Compare July 6, 2026 07:10
@dannykopping
dannykopping force-pushed the dk/tool-usage-provider-item-id branch from eefaf25 to 7e89ba2 Compare July 6, 2026 07:10
@graphite-app
graphite-app Bot changed the base branch from graphite-base/26856 to main July 6, 2026 07:11
Signed-off-by: Danny Kopping <danny@coder.com>
@dannykopping
dannykopping force-pushed the dk/tool-usage-provider-item-id branch from 7e89ba2 to 14dcac9 Compare July 6, 2026 07:11
@dannykopping
dannykopping merged commit dd216b9 into main Jul 6, 2026
29 of 30 checks passed

Copy link
Copy Markdown
Contributor Author

Merge activity

@dannykopping
dannykopping deleted the dk/tool-usage-provider-item-id branch July 6, 2026 07:29
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 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.

2 participants