Skip to content

Track agent calls across providers#340

Open
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/subagent-tool-call-tracking
Open

Track agent calls across providers#340
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/subagent-tool-call-tracking

Conversation

@ozymandiashh
Copy link
Copy Markdown
Contributor

@ozymandiashh ozymandiashh commented May 17, 2026

Summary

Addresses #336 by making agent/subagent activity visible at the provider-call level for the providers we can cover safely in one PR: Gemini, Claude, and Codex.

The issue reports two related gaps:

  • Claude CLI subagent activity can be missed depending on where the subagent JSONL files are stored.
  • Gemini usage is too coarse because a full session is treated as one CodeBurn call, so tool usage and token attribution are not granular.

This PR keeps the scope focused on parser/discovery accuracy. It does not add a new provider and does not rely on real local/private usage data.

Why

Before this change, Gemini sessions were collapsed into one aggregate ParsedProviderCall per session. That meant a long Gemini session with multiple assistant messages, tool calls, bash commands, and timestamps looked like one call in CodeBurn. The total usage could be present, but the shape was not useful for understanding what happened inside the session.

For Claude, CodeBurn already handled the nested subagent layout, but not the direct project-level subagents/*.jsonl shape reported by users. Those files could be on disk and still never enter the parser.

For Codex, the provider already maps agent tool calls such as spawn_agent, wait_agent, and close_agent to the canonical Agent tool. This PR adds regression coverage so that behavior remains protected while we fix the broader agent-tracking issue.

What changed

Gemini

  • Emit one provider call per Gemini assistant message that has token usage, instead of one aggregate call per session.
  • Keep per-message model, timestamp, token counts, tools, bash commands, and nearest preceding user prompt.
  • Preserve token totals when splitting a session into multiple calls.
  • Clamp fresh input tokens to avoid negative input when upstream cached tokens exceed input tokens.
  • Use deterministic fallback dedup keys for Gemini messages without IDs.
  • Skip invalid timestamps without poisoning the parser's seenKeys set.

This makes Gemini tool/call reporting more granular. Per-tool counts can increase compared with the old aggregate behavior because repeated tools are now attributed to the specific Gemini message that used them instead of being deduped across the whole session.

Gemini Cache Migration

Existing session-cache entries can contain the old aggregate key shape:

gemini:<sessionId>

When CodeBurn sees that legacy shape for an unchanged Gemini session file, it reparses that file and rewrites the cache with the new granular keys:

gemini:<sessionId>:<messageId>
gemini:<sessionId>:idx-<n>

That avoids leaving existing users stuck with the old one-call-per-session view until the source file changes.

Claude

  • Continue scanning normal project JSONL files.
  • Continue scanning the existing nested subagent layout.
  • Add direct project-level subagents/*.jsonl discovery.
  • Use a Set during discovery so overlapping discovery paths cannot double-count the same file.

Codex

  • Add regression coverage that spawn_agent, wait_agent, and close_agent normalize to Agent.
  • No Codex parser behavior change was needed for this PR.

Validation

  • npx vitest run tests/providers/gemini.test.ts tests/providers/codex.test.ts tests/parser-large-session.test.ts tests/parser-gemini-cache.test.ts tests/provider-registry.test.ts - 37/37 tests passed.
  • npm run build - passed.
  • git diff --check - passed.
  • Claude Opus 4.7 effort max review - PASS.
  • Gemini 3.1 Pro Preview review - PASS.
  • GitHub checks - PASS (check, assess, semgrep).

Notes

I did not validate against a real Fedora reporter environment or real local subagent history. The coverage here uses synthetic fixtures and existing parser behavior, so no local project names, prompts, paths, session IDs, usage values, or private product details are included.

@ozymandiashh ozymandiashh marked this pull request as ready for review May 17, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant