Repository navigation
Attribute Pi main/sub-agent requests with x-awf-caller and preserve caller metadata - #71043
SivaKesava1 with Copilot wants to merge 7 commits into
Conversation
…aller metadata Co-authored-by: SivaKesava1 <[email protected]>
…aller metadata Co-authored-by: SivaKesava1 <[email protected]>
Co-authored-by: SivaKesava1 <[email protected]>
|
We reviewed the caller-attribution changes at
Blocking: unrelated changes. The branch has about 250 changed files beyond the fix. Commit
None of these belong to #70940. The PR touches no compiler code, so after merging Nits
|
Co-authored-by: SivaKesava1 <[email protected]>
…ler-metadata Co-authored-by: SivaKesava1 <[email protected]>
…t_detection record Co-authored-by: SivaKesava1 <[email protected]>
Done in f9cd3c1, the merge 87f10e0, and e0d2c1b:
I couldn't mark the PR ready for review because I don't have a tool for that. Please mark it ready. |
gh-aw never sent AWF's
x-awf-callerheader. Proxy accounting records therefore had no explicit main/sub-agent identity, and the collector also dropped AWF'sagent_name/caller_sourcefields. This PR sends the header where a harness has a real per-caller boundary (currently only Pi), keeps the caller fields in the unified session, and makes audit/logs prefer them over token/model/time correlation.Harnesses
pi_provider.cjssets the header in every Pi process'sbefore_provider_headershook.main.pi_subagent_extension.cjssendssubagent/<name>. The name is passed in that process's environment asGH_AW_PI_SUBAGENT_NAME.^(?:main|subagent/[A-Za-z0-9_.:/-]+)$and the 128-character limit. An invalid value means no header is sent; names are never truncated.models.jsonare unchanged.mainheader would also land on sub-agent requests.Collector and contract
firewall.token_usageandusage.reportnow project:agent_name/agentName→agentNamecaller_source/callerSource→callerSourcepurposewas already projected and is unchanged. AWF's classifier records now also keepcallerSource: awf.unified_session.d.tsand regeneratedunified-session.schema.json.Audit and logs (
pkg/cli)TokenUsageEntrycarriesagent_nameandcaller_source. They are read from the unified session and, when the session has no token-usage events, from rawtoken-usage.jsonl.purposestays unknown.routing_classificationorcallerSource: awf) are never counted as agent requests. Totals are unchanged.Tests
token-usage/v0.28.70records and AWF's producer shapes from feat(api-proxy): attribute requests to the main agent or a sub-agent via x-awf-caller gh-aw-firewall#10222.awf_caller_attribution.test.cjs):pi_main_and_subagent_caller_attribution(spawns a real child process that loadspi_provider.cjs)copilot_sdk_main_and_subagent_caller_attributionunsupported_engine_does_not_mislabel_subagentsinvalid_or_missing_caller_is_absent_and_backward_compatibleawf_owned_purpose_wins_over_callerTestProxyCallerPrecedesCorrelationAndPreservesFallbackTestRawProxyCallerAttributionWithoutUnifiedTokenUsageTestUnsupportedEngineDoesNotMislabelSubagents, which compiles workflows for all five engines and asserts no provider- or process-wide caller header is configured.Expected routed-smoke evidence (
usage/aw_session.jsonl, not yet dispatched on this branch)firewall.token_usageevents should look like this:{"purpose":"agent","callerSource":"caller_header"} {"purpose":"subagent","agentName":"haiku-whoami","callerSource":"caller_header"} {"purpose":"subagent","agentName":"mini-whoami","callerSource":"caller_header"} {"purpose":"routing_classification","callerSource":"awf"}callerSource: awf. Agent requests stay unattributed, so the SDK end-to-end case is unsupported, not passing.Known check failures that also occur on
maingolintflags only files this PR doesn't change:pkg/cli/spec_test.goandpkg/workflow/claude_engine.go.token_usage_subagent_session.go: thedeferat line 172 and the slice indexing at line 1527 (line 1514 onmain).