Replace the `usageDetails` JSON column with top-level columns on
`agent_execution`:
- `cacheReadTokens` and `cacheWriteTokens` store the prompt-cache tokens
of the `finish` usage. Both are subsets of `promptTokens`.
- `parentExecutionId` and `rootExecutionId` link a delegated run to the
execution that delegated it and to the top of its tree. Both reference
`agent_execution.id` with ON DELETE SET NULL and have an index.
The sub-agent runner sets the links from the parent execution id in the
parent persistence metadata. Background jobs pass it on dispatch. A
resumed child keeps the links of its first execution.
Remove the sub-agent usage roll-up. Each delegated run already records
its own execution, so the system usage route now returns each turn with
its descendants (found through `rootExecutionId`) and their sum.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a nullable `usageDetails` JSON column to `agent_execution`. The
execution recorder now keeps the prompt-cache read and write tokens of the
`finish` usage, and the usage of direct sub-agents from their
`subagent-completed` chunks. The token columns and the thread counters do
not change: they still count the turn's own model calls only.
System agents get a `GET /agents/system/:agentId/chat/:threadId/usage`
route that returns the usage of each turn in a usable thread. Project
agents already return the new column with the thread detail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>