Add durable receipt auditing for guarded Antigravity backend dispatch - #1804
Add durable receipt auditing for guarded Antigravity backend dispatch#1804groupthinking with Copilot wants to merge 4 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
…e.total_tokens` in the `input_tokens` field, mislabeling token accounting (input = input+output).
This commit fixes the issue reported at src/youtube_extension/services/agents/adapters/agent_orchestrator.py:522
## Bug
In `execute_antigravity_backend` (`src/youtube_extension/services/agents/adapters/agent_orchestrator.py`, ~line 522), the durable audit-store append was populated as:
```python
total_tokens = receipt.usage.get("total_tokens")
output_tokens = receipt.usage.get("output_tokens")
self._audit_store.append(
...
input_tokens=(int(total_tokens) if isinstance(total_tokens, (int, float)) else None),
output_tokens=(int(output_tokens) if isinstance(output_tokens, (int, float)) else None),
)
```
The `PipelineAuditStore.append` signature (`src/youtube_extension/services/pipeline_audit_store.py`, lines 29-40) records `input_tokens` and `output_tokens` as separate prompt vs. completion counts. The canonical mapping elsewhere (`hybrid_processor_service.py` lines 321-336) derives `input_tokens` from the prompt token count and `output_tokens` from the completion token count.
Here `input_tokens` was fed `usage.get("total_tokens")`, which is the sum input + output. That mislabels the durable receipt: `input_tokens` ends up equal to input+output, corrupting cost/usage accounting derived from the audit trail.
## Trigger
Any completed Antigravity backend dispatch where the provider `usage` dict reports `total_tokens` (e.g. `{"input_tokens": N, "output_tokens": M, "total_tokens": N+M}`): the audit record writes `input_tokens = total_tokens` instead of the real prompt count.
## Fix
Read `usage.get("input_tokens")` (the actual prompt-token key, consistent with the sibling `output_tokens` key already read directly from `usage`) and record that into the audit store's `input_tokens` field:
```python
input_tokens = receipt.usage.get("input_tokens")
output_tokens = receipt.usage.get("output_tokens")
...
input_tokens=(int(input_tokens) if isinstance(input_tokens, (int, float)) else None),
```
`total_tokens` remains used for budget-limit enforcement in `antigravity_backend.py`, which is unaffected. The existing test only sets `usage: {"total_tokens": 321}` and does not assert on recorded token values, so it neither breaks nor catches this — a follow-up test asserting per-direction token recording would be worthwhile.
Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com>
Co-authored-by: groupthinking <garveyht@gmail.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
🔍 PR Validation |
|
Closing as unauthorized adjacent cut. Agent Factory / Antigravity is not the Origin G.A.T.E. cut. CONFLICTING vs rewritten |
Canonical issue
Linked by automation.
Outcome
Adds an optional, guarded Google Antigravity managed backend path in Agent Factory with durable receipt persistence at orchestration time. MCP/tool guardrails remain strict and audit records capture execution metadata without persisting task context.
Scope
AgentOrchestratornow accepts an optionalaudit_storeand records a durable entry onexecute_antigravity_backend.Risk
audit_storehook and associated test.Verification
List exact automated and manual checks, tied to the current head SHA.
Production evidence
Not applicable: backend orchestration/internal audit-path change only; no production surface or deployment behavior change.
Agent handoff