Skip to content

Bound JIT proactive provider usage across agent tool rounds - #12817

Merged
Git-on-my-level merged 42 commits into
mainfrom
codex/jit-runtime-bounded-20260905
Sep 6, 2026
Merged

Git-on-my-level merged 42 commits into
mainfrom
codex/jit-runtime-bounded-20260905

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Problem and behavior

JIT proactivity could cross provider retries and agent tool rounds without one durable budget, and its cost evidence was incomplete. This adds a server-advertised jit-cloud-qa-v1 contract carried through Swift, Pi, the desktop relay, and the gateway. The named QA bundle rejects a missing capability before paid admission; ordinary chat retains its existing behavior.

The QA contract reserves a shared owner/run budget in Firestore before each provider call: at most three attempts, 2,048 output tokens per attempt, a conservative 32,768-byte UTF-8 input envelope, and $0.05 estimated spend per run. Unknown usage, interruptions, failed settlement, and concurrent ownership cannot reopen the budget. Qualification requests cannot bypass the gateway through BYOK or a direct route. Null output limits receive the cap; malformed limits are rejected before dispatch. Unsupported image/audio inputs fail before a provider call. Existing daily notification, nano-triage, and full-turn caps remain unchanged.

JIT service turns expose exactly four read-only retrieval tools through the manifest, stdio/Pi transport, and durable run capability. Receipts retain every observed attempt ID, normalized usage, reasoning tokens, rate-card estimate, and explicit unknown cost through SSE and Swift provenance. Streaming remains incremental and preserves provider bytes; a validated receipt is durable before the terminal frame reaches Pi, while early cancellation blocks later rounds. Legacy/nano responses, including errors, retain the backend request ID for exact durable accounting joins without dropping quota or retry headers. The shared full-turn prompt preserves ambient feedback behavior and distinct capture/evaluation timestamps with the authoritative profile timezone.

The named QA backend, desktop backend, and gateway advertise the same capability. QA operation fixes load the existing development encryption secret before seed imports and post-drain verification, check Redis API state without a truncating result limit, and reconcile only the two registered retrieval indexes in based-hardware-dev/jit-qa. Index progress is separated from JSON receipts. Resource validation accepts Cloud Run's omitted protobuf scalar only for an explicitly empty literal, while retaining checks for missing entries, null values, unexpected values, and secret substitutions.

This PR supplies qualification machinery. It does not establish completed live notifications, measured cost reduction, or production rollout readiness.

Validation

  • Root independently ran 325 focused Python gateway/relay/accounting/budget and QA operator tests and a real Firestore emulator proof with two clients: one reservation winner, a three-attempt ceiling, interruption/unknown blocking, and retained overspend.
  • Root independently passed the TypeScript build, 136 extension tests, and 76 adapter/transport tests, including early streaming delivery, terminal cancellation, and unknown-cost propagation. Earlier manifest/capability coverage also passed. The actual four-tool serialized request is 7,479–7,526 UTF-8 bytes under the unchanged envelope.
  • Root ran 64 Swift budget/feedback/delivery tests, including the production shared prompt helper, one evaluation clock read, retained temporal context, and the named QA capability requirement; request-ID error coverage passed 55 focused tests.
  • Root ran 52 QA operator/contract/receipt tests, five index tests exercising real reconciler progress, and 26 resource-contract tests. The real seed import passed in a clean environment. Expanded workflow arguments match all five QA profiles.
  • Full local pre-push, backend typecheck, Swift build, formatting, and generated contracts passed. The patched validator passed against all five deployed baseline QA resources and their admitted digests; HTTP health returned 200 and invalid/absent authorization returned 401. Those baseline resources still require the new budget-enabled deployment and behavioral qualification.

Failure-Class: none

Invariants

  • INV-CUTOVER-1: rollout and account generation remain the admission authority; a QA capability cannot enroll an account.
  • INV-CHAT-1: receipts use the existing shared transport and do not add a transcript writer.
  • INV-AGENT-*: Omi retains run/attempt lifecycle authority. Provider receipt IDs are accounting provenance, not tool authority.

Line-Count-Exception: backend/routers/desktop_chat.py | 1883 -> 1952 | Validate and forward the explicit JIT contract at the existing authenticated relay boundary; budget authority remains in its own module.
Line-Count-Exception: desktop/macos/Desktop/Sources/Chat/AgentBridge.swift | 2206 -> 2211 | Forward five optional receipt fields through the existing bridge response without introducing another transport.
Line-Count-Exception: desktop/macos/Desktop/Sources/Chat/AgentRuntimeProcess.swift | 4386 -> 4390 | Decode four optional usage receipt fields alongside the existing terminal event fields.

Adds a main-only development workflow with immutable API, desktop companion, drain, and sweep images; Cloud Run readback rejects inherited credentials, cache or queue bindings and keeps migration gates closed. Pins Firebase token verification to the auth project while jobs use the dev Firestore ADC data plane.\n\nVerification: actionlint .github/workflows/jit_qa_cloud_run.yml; 30 focused backend tests; python3 backend/scripts/runtime_image_contracts.py check; make preflight; no GCP mutation performed.
…nded-20260905

# Conflicts:
#	desktop/macos/agent/src/adapters/pi-mono.ts
@mintlify

mintlify Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
omi 🟢 Ready View Preview Sep 5, 2026, 11:21 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

Git-on-my-level added a commit that referenced this pull request Sep 5, 2026
The crash-rate date series could omit today's counts when its second clock read was even one millisecond later than its first. Derive the start from the same captured instant as the end so the final UTC bucket is always included.

A deterministic advancing-clock regression fails on the old code and passes with the fix. All 10 focused tests and the admin TypeScript check pass. This was exposed by web CI for #12817.

Failure-Class: new

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 39 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/routers/desktop_chat.py Resolved
Comment thread backend/llm_gateway/gateway/executor.py Resolved
Comment thread backend/tests/unit/test_desktop_chat.py Resolved
Comment thread backend/routers/desktop_chat.py Resolved
@Git-on-my-level
Git-on-my-level merged commit a44ddbd into main Sep 6, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/jit-runtime-bounded-20260905 branch September 6, 2026 03:09
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