Bind direct tool-call metadata to invocation outputs (#45185)

## Why

Direct tool-call records need to stay associated with the invocation that produced each output, including when call IDs are reused. Completeness must describe the recorded call inventory, independently of tool success.

## What changed

- Attach direct-call records to outputs before they enter history, and set `tool_calls_complete` when the invocation's arguments are fully recorded.
- Bound pending recordings and retained metadata, release reservations on completion or cancellation, and invalidate pending records when capture is disabled.
- Apply request budgets to direct metadata and strip it from inference and compaction inputs when capture is disabled.
- Remove executed-call metadata from app-server raw response notifications and exclude its size from Guardian history retention budgets.
- Track call IDs that bypass dispatch so their reuse cannot incorrectly establish Code Mode completeness.

## Testing

Add regression coverage for direct-call attribution, malformed calls, metadata budgets, cancellation, configuration changes, compaction, notification filtering, and Guardian context isolation.

GitOrigin-RevId: 2ebd39c7f141d04788736491495109841656b4c0
This commit is contained in:
ningyi-oai authored and copyberry committed 2026-09-13 06:53:20 +00:00
1 parent e61f381900
commit 1715e55076
24 files changed
+1760 -297

No files matched your search

@@ -1152,7 +1152,9 @@ pub(crate) async fn apply_bespoke_event_handling(
.send_server_notification(ServerNotification::HookCompleted(notification))
.await;
}
EventMsg::RawResponseItem(raw_response_item_event) => {
EventMsg::RawResponseItem(mut raw_response_item_event) => {
// Keep warehouse metadata out of app-server notifications.
raw_response_item_event.item.clear_executed_tool_calls();
let mut notification = ServerNotification::RawResponseItemCompleted(
RawResponseItemCompletedNotification {
thread_id: conversation_id.to_string(),
@@ -3164,6 +3166,7 @@ mod tests {
})
);
}
Ok(())
}