Skip to content

Add durable receipt auditing for guarded Antigravity backend dispatch - #1804

Closed
groupthinking with Copilot wants to merge 4 commits into
mainfrom
copilot/add-guarded-antigravity-backend
Closed

Add durable receipt auditing for guarded Antigravity backend dispatch#1804
groupthinking with Copilot wants to merge 4 commits into
mainfrom
copilot/add-guarded-antigravity-backend

Conversation

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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

  • Included:
    • Orchestrator durability hook: AgentOrchestrator now accepts an optional audit_store and records a durable entry on execute_antigravity_backend.
    • Receipt-focused audit payload: persists provider/agent/status, receipt/request hash, interaction/environment IDs, budget flag, policy, and token fields.
    • Context redaction guarantee: audit details intentionally exclude execution context payloads.
    • Targeted regression coverage: added a unit test that verifies durable recording semantics and no context leakage.
    • Minimal hygiene in touched files: import-order/type-import cleanup needed by lint in modified files.
  • Explicitly excluded:
    • No change to provider transport wiring, live-call approval policy, or MCP allowlist semantics.
    • No new API endpoints, storage schema changes, or UI updates.

Risk

  • Risk level: low
  • Failure mode: audit store append failures could drop receipt persistence while managed execution still completes.
  • Rollback: revert orchestrator audit_store hook and associated test.

Verification

List exact automated and manual checks, tied to the current head SHA.

  • Focused tests
  • Required CI
  • Review threads resolved

Production evidence

Not applicable: backend orchestration/internal audit-path change only; no production surface or deployment behavior change.

Agent handoff

  • One canonical issue is linked
  • No competing PR implements the same issue
  • Acceptance criteria are satisfied
  • Required checks pass on the current head
  • Human decision is requested only for product, security, irreversible infrastructure, or production approval
# New orchestration durability path (simplified)
orchestrator = AgentOrchestrator(audit_store=audit_store)
receipt = await orchestrator.execute_antigravity_backend(
    backend=backend,
    task="review",
    context={"video_pack_id": "pack-3"},
)
# audit_store receives receipt metadata, not raw context

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
v0-uvai Ready Ready Preview, v0 Sep 12, 2026 9:06am UTC

Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Comment thread src/youtube_extension/services/agents/adapters/agent_orchestrator.py Outdated
Co-authored-by: groupthinking <154503486+groupthinking@users.noreply.github.com>
Copilot AI changed the title [WIP] Add guarded Antigravity backend to Agent Factory Add durable receipt auditing for guarded Antigravity backend dispatch Sep 8, 2026
Copilot AI requested a review from groupthinking September 8, 2026 23:04
…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>
@coderabbitai

coderabbitai Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: e10f3fdd-1542-439b-801b-dc9c7bed8001

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Snapshot Warnings

⚠️: No snapshots were found for the head SHA ab25fe1.
Ensure 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 Files

None

@github-actions

Copy link
Copy Markdown
Contributor

🔍 PR Validation

⚠️ PR title should follow conventional commits format

@groupthinking
groupthinking marked this pull request as ready for review September 12, 2026 10:06
@groupthinking groupthinking added the bug Something isn't working label Sep 12, 2026
@cursor

cursor Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Closing as unauthorized adjacent cut. Agent Factory / Antigravity is not the Origin G.A.T.E. cut. CONFLICTING vs rewritten main. #1651 stays open with that blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working python

Projects

None yet

2 participants