feat: attribute AI Gateway usage to workspaces (#29235)

- Adds nullable `workspace_id` to AI Gateway interceptions without a
foreign key or index.
- Derives direct attribution from strictly parsed server-minted workspace
session-token names, excluding user-created tokens and validating the
embedded owner.
- Derives delegated Coder Agents attribution from the persisted chat
workspace ID.
- Records `workspace_id` through the additive v1.3 gateway protocol and
structured interception logs.
- Exposes attribution in session details through
`interception_attributions`, including tool-less interceptions and null
values for unknown attribution.

Closes AIGOV-637

Generated by Coder Agents.
This commit is contained in:
Cian Johnston authored and GitHub committed 2026-09-18 15:22:02 +01:00
1 parent 621cbf681e
commit 19076beb8d
33 files changed
+1530 -416

No files matched your search

+4 -1
View File
@@ -1674,7 +1674,8 @@ CREATE TABLE aibridge_interceptions (
agent_firewall_session_id uuid,
agent_firewall_sequence_number integer,
error_type aibridge_interception_error_type,
error_message character varying(1024)
error_message character varying(1024),
workspace_id uuid
);
COMMENT ON TABLE aibridge_interceptions IS 'Audit log of requests intercepted by AI Bridge';
@@ -1703,6 +1704,8 @@ COMMENT ON COLUMN aibridge_interceptions.error_type IS 'Categorised terminal ups
COMMENT ON COLUMN aibridge_interceptions.error_message IS 'Raw terminal upstream error message for a failed interception; NULL when the interception succeeded.';
COMMENT ON COLUMN aibridge_interceptions.workspace_id IS 'The workspace in which the agent ran. NULL when no workspace context is available.';
CREATE TABLE aibridge_model_thoughts (
interception_id uuid NOT NULL,
content text NOT NULL,