Skip to content

fix(qsearch): hold live v2 receipts until provider usage is final (accounting gate) - #54

Merged
AetherAI3 merged 4 commits into
claude/qcomms-j6-nanofrom
claude/qcomms-j-settled-usage
Oct 31, 2026
Merged

AetherAI3 merged 4 commits into
claude/qcomms-j6-nanofrom
claude/qcomms-j-settled-usage

Conversation

@AetherAI3

@AetherAI3 AetherAI3 commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Closes the "Remaining accounting blocker" promotion gate (PREDATOR_QCOMMS_J_FOLLOW_THROUGH_V1 §2) with the spec's option "defer final receipt completion until accounting is final". Clients now receive final usage and never a receipt sealed with pending usage. Circuit results are untouched and nothing is resubmitted.

  • Held results: a live v2 request whose ATLAS result is DONE or FAILED but whose usage is missing or zero stays ACCEPTED. It answers 503 ACCOUNTING_PENDING, which becomes ACCOUNTING_TIMEOUT after NANO_QSEARCH_ACCOUNTING_WINDOW_S (default 900 s). The request is still held after the timeout: never sealed pending, never NOT_RUN.
  • Settlement: each repeat or restart drives ATLAS recover_qsearch_submission's accounting read. Nano merges the ledger row's settled usage into the stored ATLAS receipt (same provider job, positive usage only) and then seals OK or FAILED once, with usage_pending: false. A zero is never finalized as a free run.
  • Old stores: a DONE receipt sealed with pending usage is never served as final. It is re-derived from the settled row, and the results must be identical (compare-and-swap; the replaced seal and usage are kept in record_json["reseals"]). Until then it answers 503, or RESEAL_MISMATCH if the results would differ.
  • Unchanged: FakeFez dry runs, and v1 receipts (they carry no usage field).
  • ATLAS helper (commit 8c7c865): recovery now reads settled usage through ATLAS #184's qsearch_receipt_with_settled_usage (b66fd91), and only for the same provider job. The row-usage merge remains as a fallback only for ATLAS pins without the helper. The sealed usage keys stay exactly {quantum_seconds, usage_pending, provider_sub_jobs, provider_metrics}; ATLAS's usage_settled_at and provider_usage_at_receipt are not mapped into the receipt. This branch now merges claude/qcomms-j6-nano, which contains fix(qsearch): keep unknown submission outcomes pending through ledger failures #53.

Review fixes (commit b209605):

  • Terminal outcomes are reported while held: a cancelled, errored or max-time job whose usage stays 0 is still never sealed with final usage. Every 503 now carries job_id, result, provider_status, terminal, usage_pending: true and (for FAILED) reason, under ACCOUNTING_PENDING_TERMINAL. A DONE job gets ACCOUNTING_PENDING, and ACCOUNTING_TIMEOUT applies after the window. A submitted request whose outcome is not known yet answers SUBMITTED_PENDING with the job id when ATLAS names it. The reviewer's reproduction (cancelled job, usage 0, four POSTs) is tested with stand-ins and with real ATLAS.
  • Settled rows need no live context: every recovery first reads ATLAS's ledger-only qsearch_receipt_with_settled_usage, so a settled row, including a historical re-seal, completes without GO or LIVE (no provider context is resolved). Only an unsettled row goes on to provider recovery; without the flags it answers ACCOUNTING_NEEDS_LIVE_CONTEXT.
  • Usage note: record_json explains that usage.provider_metrics is the provider's read at job completion (it may show 0) while quantum_seconds is the settled usage, and it keeps ATLAS's provider_usage_at_receipt.
  • Reruns at ATLAS 81b23df (#184 merged): accounting tests 13 passed; real-ATLAS tests 11 passed; accounting plus Predator parity at f3eade02 21 passed; full suite 1674 passed, 6 skipped, and 7 failures, all of them the test_provenance.py failures that also fail on the base.

Tests:

  • 11 in test_qsearch_accounting.py with stand-in delegates: pending to final, restart, repeated retrieval, terminal failure with late usage, concurrent duplicates submitting once, window, dry and already-settled results sealed at once, re-seal and refusals for old receipts, the merge rule, and Predator parity (settled and re-sealed receipts verify with usage_pending false and quantum_seconds set, against Predator f3eade02).
  • Real ATLAS (b66fd91, helper present) with a fake provider: zero usage is held until ATLAS's accounting read settles the row, then sealed once; repeated retrieval returns the same receipt; the ledger settles exactly once (finalized_seconds 2.0, one row).
  • Full suite: 1670 passed, 6 skipped, and 7 failures, all of them the test_provenance.py failures that also fail on the base.

No QPU run happened.

🤖 Generated with Claude Code

…counting promotion gate)

PREDATOR_QCOMMS_J_FOLLOW_THROUGH_V1 section 2, "Remaining accounting blocker",
option "defer final receipt completion until accounting is final". A live
(non-dry) v2 request whose ATLAS result is DONE or FAILED but whose usage is
missing or zero is held ACCEPTED: 503 ACCOUNTING_PENDING (ACCOUNTING_TIMEOUT after
NANO_QSEARCH_ACCOUNTING_WINDOW_S, default 900 s; still held, never sealed pending,
never NOT_RUN), nothing resubmitted. Each repeat or restart drives ATLAS
recover_qsearch_submission's accounting read; the stored ATLAS receipt is merged
with the ledger row's settled usage (same provider job, positive usage only) and
the OK / FAILED receipt is sealed once with usage_pending false. A DONE receipt an
older Nano sealed while usage was pending is never served as final: it is
re-derived from the settled row with identical results (compare-and-swap; the
replaced seal and usage kept in record_json["reseals"]) or answered 503
(RESEAL_MISMATCH if results would differ). FakeFez dry runs and v1 receipts
(no usage field) are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AetherAI3
AetherAI3 changed the base branch from codex/qcomms-j-pending-ledger to claude/qcomms-j6-nano October 31, 2026 22:35
AetherAI3 and others added 3 commits October 31, 2026 18:37
…ettled_usage

Recovery now takes the client view of the stored receipt from ATLAS #184's
qsearch_receipt_with_settled_usage(ledger, request_id) (the stored DONE/FAILED
receipt completed once, durably, with the row's settled usage), used only for the
same provider job; otherwise the recovered receipt stands and stays held. The
row-usage merge remains only as the fallback for ATLAS pins without the helper.
The sealed v2 usage keys stay exactly {quantum_seconds, usage_pending,
provider_sub_jobs, provider_metrics}: ATLAS's usage_settled_at and
provider_usage_at_receipt are not mapped into the receipt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…edger alone (#54 review)

Review MEDIUM 1: a FAILED (cancelled / errored / max-time) job whose usage stays 0
is still held, never sealed with final usage, but every 503 now carries what the
client can record: job_id, result, provider_status, terminal, usage_pending and
(for FAILED) reason, under ACCOUNTING_PENDING_TERMINAL (ACCOUNTING_PENDING for a
DONE job, ACCOUNTING_TIMEOUT after the window). A submitted request whose outcome
is not known yet answers SUBMITTED_PENDING with the job id when ATLAS names it.

Review MEDIUM 2: recovery first reads ATLAS's ledger-only
qsearch_receipt_with_settled_usage (no provider call, no live context, no flags),
so a settled row, including a historical re-seal, completes without GO / LIVE.
Only an unsettled row goes on to provider recovery; without the flags it answers
ACCOUNTING_NEEDS_LIVE_CONTEXT instead of ACCOUNTING_PENDING.

Also: record_json notes that usage.provider_metrics is the provider's read at job
completion (may show 0) while quantum_seconds is the settled usage, and keeps
ATLAS's provider_usage_at_receipt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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