Repository navigation
fix: prefer unified sessions for subagent attribution - #66746
Conversation
Preserve Copilot subagent metadata and per-agent accounting snapshots in unified sessions. Read structured attribution before legacy logs and limit heuristic parsing to CLI dispatch lines. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reuse the embedded session-parser harness to verify native, bootstrap, and structured-log reconstruction through unified artifacts into audit attribution. Cover nested agent metadata, exact accounting snapshots, missing accounting, main-only sessions, and legacy dispatch fallback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.
|
|
✅ PR Code Quality Reviewer completed the code quality review. Testing safeoutputs availability for required completion signaling.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff
|
|
✅ Ponytail Reviewer completed successfully! Lean already. Ship.
|
|
🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills... |
🏗️ Design Decision Gate: ADR RequiredThis PR triggers ADR enforcement, and no Architecture Decision Record was found. Why enforcement applies
ADR search results
Action taken A draft ADR has been committed to this branch:
It records the decision inferred from the diff: treat structured unified sessions ( Evidence used:
Next action for the author Review the draft ADR, correct anything the gate inferred incorrectly (especially the decider list and the rejected alternatives), and change Status from
|
There was a problem hiding this comment.
🟡 Changes recommended
Retry attempts can leak stale subagent attribution into the final attempt’s token summary.
1 open finding
What changed in this PR
Prioritizes structured unified sessions for accurate Copilot subagent attribution while retaining legacy log fallback.
Changes:
- Derives subagent models and request counts from session lifecycle/accounting data.
- Preserves attribution metadata and updates schemas/documentation.
- Adds Go and JavaScript integration coverage.
| File | Description |
|---|---|
pkg/cli/token_usage_subagent.go |
Prefers structured attribution and narrows fallback matching. |
pkg/cli/token_usage_subagent_session.go |
Parses session lifecycle and accounting data. |
pkg/cli/token_usage_subagent_session_test.go |
Tests structured attribution behavior. |
pkg/cli/session_parser_test.go |
Adds end-to-end Copilot session coverage. |
docs/src/content/docs/specs/unified-agent-session-specification.md |
Documents retained subagent evidence. |
docs/public/schemas/unified-session.schema.json |
Extends unified session schema. |
docs/public/schemas/agent-session.schema.json |
Adds reasoning effort and agent metrics. |
actions/setup/js/unified_session_payload.test.cjs |
Updates payload normalization expectations. |
actions/setup/js/unified_session_payload.cjs |
Retains attribution and correlation fields. |
actions/setup/js/types/unified_session.d.ts |
Extends unified session types. |
actions/setup/js/types/agent_session.d.ts |
Extends canonical session types. |
actions/setup/js/copilot_workflow_events.cjs |
Retains additional lifecycle metadata. |
actions/setup/js/copilot_session.cjs |
Projects per-agent accounting snapshots. |
actions/setup/js/copilot_dynamic_workflow.test.cjs |
Tests Copilot metadata projection. |
.changeset/patch-unified-subagent-sessions.md |
Records the patch release change. |
🧠 Review effort: Balanced
Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Request changes
The new structured attribution path is close, but there are still blocking correctness gaps in how it falls through sources and publishes repeated subagent requests.
Blocking themes
- A malformed preferred artifact currently short-circuits before
agent-session.jsonl, so we can still regress to the lossy stdio heuristic even when valid structured evidence is present. - The structured path emits one row per agent id instead of aggregating identical logical subagent requests, which changes the public
subagent_model_requestsshape compared with the legacy path.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt54 · 63.7 AIC · ⌖ 5.89 AIC · ⊞ 19.8K
Comment /review to run again
|
@copilot address the following outstanding work in one pass:
Push the necessary fixes, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved. Use the pr-finisher skill and stop when only human review or CI remains; do not trigger CI. Sous-chef head: ca4eddc
|
…gent-sessions Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…ns' into pelikhan-unified-subagent-sessions
Preserve retry source scopes in structured attribution and publish subagent hierarchy, model configuration, requests, tokens, and credits in session step summaries. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |

Copilot subagent attribution currently guesses
name(model)pairs from stdout, which can turn startup logs and printed code into fake agents while missing current CLI dispatch formats. This change makes structured unified sessions the primary source and keeps legacy logs as a backward-compatible fallback.Approach
usage/aw_session.jsonlfirst, then the canonicalagent-session.jsonltrace. Structured sessions without subagents suppress heuristic attribution; malformed structured evidence emits a warning before fallback.session.result.agentMetricswithout adding them to aggregate session usage.Integration coverage
Reuse the existing embedded session-parser harness to exercise Copilot native events, bootstrap traces, and structured logs through unified serialization into audit attribution. Cover nested agents, exact token and credit snapshots, snapshot deduplication, missing accounting, main-only sessions, and both legacy dispatch formats.
Validation
Scope
Addresses the session-source and persistence portions of #66740. Per-request proxy joins, routing-cost splits, and new per-agent reporting tables remain outside this change.