Skip to content

spike(okf): result-bound receipt for a caller-delegated Attested Computation - #479

Merged
haiyuan-eng-google merged 10 commits into
mainfrom
spike/okf-result-bound-receipt-20260905
Sep 6, 2026
Merged

haiyuan-eng-google merged 10 commits into
mainfrom
spike/okf-result-bound-receipt-20260905

Conversation

@caohy1988

Copy link
Copy Markdown
Collaborator

Spike: OKF result-bound receipt (caller-delegated §10 Attested Computation)

Spike / example-only / SYNTHETIC fixture. Merge gate: @caohy1988. No SDK API change; examples/okf_bqaa_adapter (PR #474 observer) is untouched.

Adds examples/okf_attested_computation/: a trusted session broker approves a typed request against a pinned, digest-checked derived publication of the Acme gross-margin-period computation; the caller's own BigQuery delegation submits one GoogleSQL SELECT (typed DATE bindings, cache off, dry-run-bounded bytes, broker job id); an independent verifier re-reads jobs.get + jobs.getQueryResults and compares owner, literal SQL, bindings, dialect, cache, statement type, referenced tables and the one-cell NUMERIC result (Decimal, no epsilon); a private SQLite registry + HMAC-SHA256 receipts (separate commit/integrity keys, 0600) and a deterministic consumer release the value once, or nothing.

Verdict (live, 2026-09-05, test-project-0728-467323)

Row Case Outcome Released
R1 approved January, user-owned job, fresh-process verifier rerun MATCH / VERIFIED → Gross margin: $400.00 USD · VERIFIED once
R2 product-cost-only formula (real job = 600) MISMATCH / REJECTED sql_mismatch no
R3 period_end → 2026-02-28 (real job = 515) MISMATCH / REJECTED parameter_mismatch no
R4 claim 600 / wrong field / wrong unit MATCH / REJECTED display_mismatch no
R5 invented job; metadata-only verifier UNVERIFIABLE (job_missing, result_unavailable) no
R6 sealed receipt mutated REJECTED receipt_integrity_failed no
R7 same receipt twice second REJECTED request_consumed once
R8 SA-owned job carrying a user label MISMATCH / REJECTED owner_mismatch no
R9 restricted SA: verified, then dataset grant revoked; SA reading the user's job REJECTED access_denied / job_read_denied, no cached release no

Full detail, identity topology, per-job bytes/slot-ms, blockers and cleanup plan: examples/okf_attested_computation/evidence/receipt/report.md. This is MODERATE delivery for receipts only; nothing is labelled ATTESTED, and it does not stand in for the graph spike.

Tests

python -m pytest tests/examples/test_okf_attested_computation.py tests/examples/test_okf_bqaa_adapter.py -q   # 112 passed
OKF_SPIKE_LIVE=1 GOOGLE_CLOUD_PROJECT=test-project-0728-467323 python -m pytest tests/integration/test_okf_attested_computation_live.py -q   # 7 passed (skips safely without env)
python examples/okf_attested_computation/run.py --case approved|sql-substitution|parameter-substitution|display-substitution|missing-evidence|tamper|replay [--live]

Known limitations

  • Verifier is code/process-independent, not a different BigQuery principal (spec §3).
  • Local MAC custody only; no rotation, no portable signature.
  • Full-repo pytest in the author's environment hits a pre-existing google.adk / opentelemetry-semconv import mismatch in three unrelated modules; CI is authoritative.

Plans: Ship/rfc/2026-09-05-spike-receipt-{intent,spec,plan}.md (vault). Governing decision: JOINT_final.md (parallel-spike, receipts-gated).

Pin the Acme gross-margin source (catalog 31da799) with attribution,
add the SYNTHETIC fixture SQL for okf_receipt_spike_20260905, and record
the Day-1 live evidence probe (user-owned jobs, cache disabled, typed
DATE params, jobs.get + getQueryResults read independently).
contracts.py restricts the PR 474 canonical CBOR domain (pinned vectors),
publication.py pins source bytes and compiles only allowlisted table
identifiers, broker.py approves typed DATE requests from a broker-created
session, receipt_store.py adds the private SQLite registry with atomic
consume_once and 0600 MAC key custody. 21 hermetic tests.
…, consumer

execute.py submits the approved SQL with typed DATE bindings, cache off
and a dry-run-derived byte cap under a broker job id; verify.py re-reads
jobs.get/getQueryResults through a confined evidence client and compares
owner, literal SQL, bindings, dialect, cache, statement type, referenced
tables and the one-cell NUMERIC result; consume.py checks the MAC/key,
re-verifies, probes current access, consumes the nonce atomically and
renders only the authoritative value. hermetic.py emulates API resources
for the synthetic fixture; attacks.py is the controlled adversarial
executor. 94 hermetic tests incl. R1-R11 rows and the CLI cases.
tests/integration/test_okf_attested_computation_live.py (opt-in via
OKF_SPIKE_LIVE=1 + GOOGLE_CLOUD_PROJECT) covers R1 with a fresh-process
verifier rerun, R2-R5, and R8/R9 under a real restricted service account
with dataset grant and revocation. evidence/receipt/{report.md,
cases.json, live_cases.json} record the 2026-09-05 live run: approved
January verifies MATCH/VERIFIED and releases 400.00 USD once; the
product-cost-only (600) and period (515) substitutions, display
substitution, identity spoof, revocation, tamper and replay are blocked;
missing evidence stays UNVERIFIABLE. Verbatim Acme attester copy kept
byte-exact as .py.txt; repo autoformat applied.
@caohy1988

Copy link
Copy Markdown
Collaborator Author

Verdict summary (spike, 2026-09-05): receipt slice = credible isolated pass (Y).

  • R1 approved January: real user-owned job, verifier MATCH/VERIFIED from jobs.get + jobs.getQueryResults, second fresh-process verifier agreed (same result_commitment), consumer released Gross margin: $400.00 USD · VERIFIED exactly once.
  • Substitutions FAIL: product-cost-only formula (real job = 600) → REJECTED sql_mismatch; period → 2026-02-28 (real job = 515) → REJECTED parameter_mismatch; claim 600 / wrong field / wrong unit → REJECTED display_mismatch.
  • Identity/access: SA-owned job with user label → REJECTED owner_mismatch; restricted SA verified then revoked → REJECTED access_denied (no cached release); SA reading the user's job → REJECTED job_read_denied.
  • Missing evidence stays UNVERIFIABLE (invented job, metadata-only verifier). Tamper and replay REJECTED.
  • Hermetic: 94 tests + 18 observer tests pass, order-independent. Live: 7/7. Evidence: examples/okf_attested_computation/evidence/receipt/report.md.

Scope earned: MODERATE delivery for receipts only. Not ATTESTED, not combined-runtime. Do not merge without @caohy1988 review.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Opus review — receipt spike (COMMENT-only; Haiyuan is the merge gate)

Reviewed 67889b0 against the JOINT receipt-acceptance list. All ten acceptance bullets are met with live evidence, and the negatives are genuinely adversarial — R2/R3 submit real jobs that really return 600 and 515, rather than fabricated fixtures. Trusted-path discipline is strong: no free-form SQL input (execute.py), requester from tokeninfo rather than an argument (broker.py:107-125), publication re-compiled from pinned bytes inside the verifier (verify.py:85-102), executor value never reaching the verdict. Reproduced 112 passed locally; adapter untouched; 474 merge confirmed an ancestor.

Three findings that don't hold as written. None were exercised by the live suite, so the recorded evidence stands.

1. A wrong claim destroys a sealed VERIFIED receipt and bricks the release (medium). verify() re-seals into the same receipt id (verify.py:434) over INSERT OR REPLACE (receipt_store.py:122-130), and consume() verifies before evaluating the claim. Reproduced at head:

verify#1: VERIFIED                stored: VERIFIED
consume(value=600): REJECTED display_mismatch    stored now: REJECTED
consume(value=400): REJECTED display_mismatch    released: False   consumed? False

The nonce is never consumed, so the request is neither released nor retired, and the authentic record of the good verification is gone. Any party who can present a claim can do this once per request. Suggest sealing each verification under a fresh receipt id / append-only attempts table.

2. A pending handle is consumable (medium). spec.md and the README trust-boundary table say a pending handle cannot be consumed; consume.py:101 merely skips the receipt checks and proceeds to release. The CLI approved case (run.py:131-143) takes exactly that path, so the flagship demo issues and consumes in one process. Release is still gated on fresh evidence + probe + nonce, so the security claim survives — the stated two-step separation does not, and nothing tests it. Enforce it or drop the claim.

3. "Decimal, no epsilon" fails for large NUMERIC (medium). contracts.py:203-207 and :230 use the default decimal context (prec=28) against 38-digit NUMERIC:

decimal_string("…5678.91") -> …5679
decimal_string("…5678.94") -> …5679      # distinct values, identical canonical form
decimal_string("99999999999999999999999999999.999999999") -> InvalidOperation

So a false display claim can bind at that magnitude; and InvalidOperation is an ArithmeticError, not ContractError, so it escapes verify.py:252-255 and the except _Outcome — the verifier raises instead of returning UNVERIFIABLE, and the money_display variant raises after consume_once burns the nonce (consume.py:279-293). Unreachable for this fixture. Fix is localcontext(prec=60) plus catching ArithmeticError at both sites.

Minor: BigQueryEvidenceClient says "no query methods are exposed" (verify.py:452-453) but probe_sources calls client.query (verify.py:490-502); assert (… or True) is tautological at tests/examples/test_okf_attested_computation.py:1132; committed evidence carries personal identifiers in a public repo and the live suite rewrites the tracked live_cases.json (tests/integration/…:79-95), so each run re-injects whichever principal ran it — placeholders + an ignored write path would fix both.

Credit where due: reporting R9b (restricted SA denied reading the user's job) rather than burying it is the right call, and it's the clearest evidence that separate-principal verification isn't yet a usable path.

Recommendation: receipt-slice pass under JOINT §4 — MODERATE for receipts only, no combined-runtime upgrade, which the PR body already states. Ask for (1) and (3) before anything builds on this code, and settle (2) before the trust-boundary table is quoted elsewhere. Full review with repro details: /tmp/okf-spikes/opus-review-479/REVIEW.md.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Astra review of 67889b0: changes requested before an unconditional JOINT receipt-slice pass. Seven concrete findings; local reproductions and an independent Opus pass support the review.

  1. P1 — deleted receipt version bypasses tamper rejection: consume.py:101 treats a sealed receipt with receipt_version removed as pending. With job ID and MAC also corrupted, consumption reissues the receipt and releases VERIFIED. Fresh evidence still controls the value, but R6's tamper-rejection contract fails.
  2. P2 — exact NUMERIC binding rounds: contracts.py:203 uses context-sensitive Decimal.normalize(). Distinct legal NUMERIC values beyond 28 significant digits compare equal and pass VERIFIED.
  3. P2 — agreed cost bound absent: execute.py:81 scales the cap without a hard ceiling; a 2 GiB estimate permits 8 GiB, contrary to the plan's 1 GiB limit.
  4. P2 — live coverage label overstated: README.md:26 marks transient API errors live-pass; those cases are hermetic.
  5. P2 — stale expiry time: run.py:123 captures time before approval and reuses it through consumption. Reproduced both false request_expired and release after expiry.
  6. P2 — failed claim overwrites proof: verify.py:434 stores REJECTED over the valid receipt, blocking a corrected retry. The live R4 loop (test_okf_attested_computation_live.py:307) consequently short-circuits wrong-field/unit rows on the first rejection.
  7. P2 — formatting fails after consumption: consume.py:291 formats after spending the nonce. A legal 27-digit NUMERIC raises InvalidOperation; retry is then request_consumed despite no value having been released.

Evidence credited: independent GET-only readback of the original R1–R4 jobs confirmed approved SQL/400, substituted SQL/600, and changed bindings/515 through jobs.get + getQueryResults. SA-job readback returned Forbidden to the review credentials; historical R8/R9 were inspected, not independently rerun. The SA+user-label rejection is implemented through authoritative owner comparison. Adapter UNVERIFIABLE defaults and SDK source are unchanged.

Checks: 112 passed, 7 live tests skipped; PR CI green across Python 3.10–3.14. Local full suite encounters the reported ADK/OpenTelemetry collection failures. No credential/key material found in committed artifacts, but real personal emails and unused identities remain in the public evidence; use aliases and retain exact topology privately.

Full review and reproductions were written to the requested local/vault paths. No merge or approval performed; Haiyuan remains the merge gate.

P1: a sealed receipt with receipt_version removed is no longer treated as
pending; only the exact executor handle is pending and it is not
consumable (receipt_not_verified). Any other shape fails integrity
(receipt_integrity_failed) and a tampered record is never reissued.
P2: exact NUMERIC via a 120-digit local decimal context with every
ArithmeticError mapped to ContractError; hard 1 GiB maximum_bytes_billed
ceiling; README live labels corrected; CLI reads the clock fresh per
step; a failed display claim never overwrites an authentic VERIFIED
receipt (verifier seals the evidence verdict, claim bound at consume);
render before consume_once so a render failure keeps the nonce.
Committed evidence uses principal aliases. 7 new hermetic tests (101
receipt + 18 observer pass); live suite rerun 7/7 and CLI live cases
regenerated.
@caohy1988

Copy link
Copy Markdown
Collaborator Author

Fix pass for Astra's review, pushed as 05fc445. Every finding is addressed with a new hermetic test; live suite rerun 7/7; CLI live cases regenerated.

  1. P1 deleted receipt_version — only the exact executor handle {receipt_id, request_id, status: pending} is pending, and a pending handle is not consumable (receipt_not_verified). Any other shape goes through the integrity check and fails receipt_integrity_failed; a tampered record is never overwritten or reissued. Tests: test_p1_deleted_receipt_version_is_rejected_not_reissued, test_pending_handle_is_not_consumable. This also settles Opus Revamp README, enhance documentation navigation, and fix CI #2: the two-step verifier → consumer separation is now enforced, and the CLI/live paths use it.
  2. P2 exact NUMERIC — 120-digit local decimal context, 76-digit cap, every ArithmeticError mapped to ContractError in both decimal_string and money_display. Test: test_decimal_string_is_exact_for_38_digit_numeric (the two 38-digit values from the review now stay distinct).
  3. P2 cost ceiling — HARD_MAX_BYTES_BILLED = 1 GiB; dry run above it refuses submission; cap is min(1 GiB, max(100 MiB, 4×dry-run)). Test: test_executor_enforces_hard_cost_ceiling.
  4. P2 README labels — transient-API, R6 field matrix / key lifecycle and R7 concurrency / expiry rows now marked hermetic only.
  5. P2 stale clock — run.py reads the clock fresh at each verify/consume step.
  6. P2 failed claim overwrites proof — the sealed receipt records the evidence verdict only; the claim is bound at return/consume. An authentic VERIFIED receipt is never downgraded, UNVERIFIABLE may be upgraded, a record failing integrity is kept as evidence. Tests: test_wrong_claim_does_not_overwrite_verified_receipt, test_verify_can_upgrade_unverifiable_but_never_downgrade_verified. Live R4 now runs all three wrong claims against one sealed receipt, checks the proof is unchanged, then releases the honest claim.
  7. P2 render after consume — render first; a render failure returns UNVERIFIABLE render_failed with the nonce intact. Test: test_render_failure_does_not_spend_nonce.

Also: committed evidence uses user:owner / sa:okf-receipt-restricted aliases and the live suite redacts on write; verifier docstring corrected. Details in evidence/receipt/report.md → Review fix pass (2026-09-06). One live rerun hit a transient BigQuery reservation error on three jobs with no reservation present in the project; the immediate rerun passed and it is recorded in the report.

Not merged; @caohy1988 remains the merge gate.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Astra re-review of 05fc445: six prior findings fixed; changes still requested for P2 #5.

Closed: deleted-version tamper bypass, exact NUMERIC binding, hard ≤1 GiB cost ceiling, live-coverage labels, preservation of sealed VERIFIED receipts/R4 wrong-field and unit coverage, and rendering before nonce consumption.

P2 #5 is only partially fixed. Fresh timestamps at the two CLI call sites fix the pre-approval snapshot, but examples/okf_attested_computation/consume.py:141 checks expiry using the entry timestamp, passes it into fresh verification, and reaches examples/okf_attested_computation/consume.py:305 without another clock check after API/access reads and rendering. consume_once does not enforce expiry.

Reproduced through the actual consumer and run._issue_then_consume: receipt expires at 1300, consumption enters at 1299, result read completes at 1301, yet the outcome is VERIFIED with value released and nonce consumed. Recheck both deadlines with a trusted fresh clock at the atomic consumption gate. Add a clock-advance regression requiring REJECTED request_expired, no value/display, and an unspent nonce. The evidence report's “all fixed” claim should follow that fix.

Validation: 119 passed, 7 live tests skipped locally; current-head CI green across Python 3.10–3.14. Independent GET-only jobs.get + getQueryResults readback confirms the new approved/substituted/changed-binding jobs return 400 / 600 / 515. R8/R9 reads were Forbidden to review credentials; those live IAM scenarios were inspected, not independently rerun. Example-only scope and adapter UNVERIFIABLE defaults remain intact.

No credential/key material found. Nonblocking privacy caveat: tests/integration/test_okf_attested_computation_live.py:81 still commits a personal email in a fixed alias map, which also misses other operators' identities.

Full review and reproductions saved to the requested local/vault paths. No GitHub approval or merge; Haiyuan remains the merge gate.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Opus re-review of 05fc445 (COMMENT-only; Haiyuan is the merge gate)

Astra's P1 and all six P2s are closed, my three findings are closed, and nothing in the JOINT receipt acceptance regressed. I re-ran every original reproduction against the new head rather than reading the diff for intent — each now behaves correctly.

Finding Closed at Confirmed by
P1 stripped receipt_version reissued receipt_store.py:277-286, consume.py:100-112, receipt_store.py:290-300 stripped version + forged job_id + zeroed MAC → REJECTED ['receipt_integrity_failed']; corrupted record kept verbatim as tamper evidence
P2 NUMERIC rounding contracts.py:67-70, :189-221, :239-251 …5678.91/…5678.94 no longer collide; NUMERIC max and 76-digit BIGNUMERIC round-trip exactly; junk raises ContractError, not ArithmeticError
P2 cost bound execute.py:36, :82-88 refusal above 1 GiB happens before submission
P2 README live labels README.md:28-31 rows now match what the live suite runs
P2 stale clock run.py:120-152 no residual now binding in run_case
P2 failed claim overwrote proof verify.py:379-404, :407-420, :457-458 wrong claim leaves the sealed receipt byte-identical; the honest claim afterwards still releases
P2 render after consume_once consume.py:288-303 render failure → UNVERIFIABLE render_failed, nonce intact

No JOINT regression: all seven CLI cases behave (approved → exit 0; six attacks → exit 2 with the right reason code, no number on stdout), 119 passed offline, and the live suite was genuinely re-run — every live_cases.json row carries a fresh 2026-09-06T00:30–00:31Z timestamp. Live R4 is now the stronger test: seal, three wrong claims, assert the receipt is unchanged after each, then release honestly. Redaction landed and is enforced on write (tests/integration/…:81-97), so future runs can't reintroduce the personal addresses.

Worth flagging for readers, and correctly documented in README.md:12-14: a sealed receipt now attests execution and result, not the display claim. Better decomposition, but a stored VERIFIED receipt no longer means "the number shown was right".

Four low items came out of the fix pass; only the first is worth acting on.

N1 — verify() returns VERIFIED plus the cleartext value over a record it has just judged tampered. _may_store (verify.py:407-420) computes that integrity verdict and uses it only as a storage policy, not as a gate on the return:

forge stored receipt job_id -> okf_rcpt_forged
verify -> verdict=VERIFIED, value=400   (stored record still forged)
consume -> REJECTED ['receipt_integrity_failed']    # gate holds

Release is correctly blocked, so this is not an acceptance regression. It matters because verify.py is a trusted component in the README table, and an integrator wiring its return to a surface — which the CLI now effectively does via diag["issue_out"] — would print 400 over a forged proof. Visible in committed evidence: the blocked tamper case carries "value": "400" at cases.json → issue.issue_out.value in both hermetic and live rows, where no other blocked case does. Either gate the returned value/field/unit on the same check, or strip them from diag["issue_*"] as diag["output"] already does.

N2 — the decimal fix widened the domain, so money_display("99999999999999999999999999999.999999999") now renders $100,000,000,000,000,000,000,000,000,000.00 under a · VERIFIED banner while the receipt binds the exact value; the new test asserts only the prefix. N3 — because a record failing integrity is never replaced, a receipt id is permanently unconsumable after key erasure + rotation even when a fresh verify succeeds (REJECTED ['receipt_key_unknown']); consistent with the documented erasure stance, worth one line in limitations. N4 — carried over and still open: the tautological assert (… or True) at tests/examples/test_okf_attested_computation.py:1146, and the publication.py:20-22 docstring claim about comments/quoted literals.

No changes-requested items remain from me: receipt-slice pass, MODERATE for receipts only under JOINT §4, no combined-runtime upgrade. Full re-review with reproductions: /tmp/okf-spikes/opus-review-479/REVIEW.md.

contracts.trusted_clock gives the verifier and consumer an injectable,
entry-relative, never-backwards clock. verify() re-checks the request
deadline after the result read; consume() re-checks after reads, access
probes and rendering; Registry.try_consume enforces the deadline inside
the BEGIN IMMEDIATE transaction and returns 'expired' without inserting.
Seven boundary tests (expiry crossed during result read / source probe /
output probe, verifier re-check, transactional deadline, default clock,
just-inside-deadline release). Hermetic 126 pass; live 7/7 rerun.
@caohy1988

Copy link
Copy Markdown
Collaborator Author

Residual Astra P2 #5 closed in 6407dcf.

  • contracts.trusted_clock: injectable, entry-relative, never-backwards clock (default measures elapsed wall time from the caller's now).
  • verify() re-checks the request deadline after getQueryResults; consume() re-checks after reads, access probes and rendering.
  • Registry.try_consume enforces the deadline inside the BEGIN IMMEDIATE transaction and returns expired without inserting, so a lock wait cannot carry a request across expiry. consume_once is unchanged for callers.
  • Tests: expiry crossed during result read / source probe / output probe → REJECTED request_expired, no value, nonce unconsumed; verifier re-check; transactional deadline; default clock; just-inside-deadline still releases. Astra's probes.py prior_5 now records REJECTED / no value / nonce unconsumed.
  • Hermetic: 126 passed (+18 observer). Live suite rerun 2026-09-06: 7/7. Report updated.

Not merged; @caohy1988 remains the merge gate.

…ids)

CI Python 3.13 on 6407dcf hit the pre-existing flaky check: the consumer
output carries random hex request/receipt ids that can contain the digit
runs 600/400 by chance. Assert on the governed-value surface only.
@caohy1988

Copy link
Copy Markdown
Collaborator Author

Follow-up 0a13be0: CI Python 3.13 on 6407dcf failed on a pre-existing flaky assertion in my own test (test_consumer_output_never_contains_rejected_numbers searched the whole JSON, including random hex request/receipt ids, for the digit runs 600/400). The assertion now checks the governed-value surface only. No behavior change; 108 receipt tests pass deterministically across repeated runs. Not merged.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Astra re-review of 0a13be0: CHANGES REQUESTED — residual P2 #5 is not fully closed.

The original 1299→1301 reproduction now rejects, and I verified that a real SQLite write-lock wait crossing the deadline returns expired without consuming the nonce. The other six prior findings remain fixed. The deflake change is sound.

Remaining P2: examples/okf_attested_computation/contracts.py:208 computes int(now) + int(time.time() - start), losing fractional alignment with the absolute deadline. Reproduced through the actual CLI _issue_then_consume: entry wall time 1299.75 (now=1299), deadline 1300, result read finishes at 1300.25; the default clock still returns 1299, so the consumer releases VERIFIED and spends the nonce. Source/output probes and rendering reproduce the same failure.

Keep the new post-read/transactional checks, but fix the default clock to honor the actual absolute deadline. Add a default-clock CLI regression at that fractional boundary requiring REJECTED request_expired, no value/display and no nonce consumption. The current integer-clock tests miss it.

Evidence follow-up: examples/okf_attested_computation/evidence/receipt/report.md:29 claims CLI reruns after each pass, but committed cases.json is unchanged from 05fc445 and carries the old attester hash. Regenerate it or label the earlier-head evidence accurately; the refreshed live_cases.json is separate.

Local validation: 126 passed (108 receipt + 18 adapter), 7 live tests skipped. Reproductions and full review are in /tmp/okf-spikes/astra-review-479/; durable review/learning note: Ship/rfc/2026-09-06-spike-receipt-astra-rereview-p25.md. No new cloud queries or IAM mutations in this re-review.

CI at the reviewed head is green: formatting, Python 3.10–3.14, browser smoke, package build, security scan and CLA. Conditional scan steps are skipped. CI run.

Comment only; no GitHub approval or merge. Haiyuan remains the merge gate.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Opus re-review of 0a13be0 — P2 #5 close + deflake (COMMENT-only; Haiyuan is the merge gate)

P2 #5 is genuinely closed, the deflake is correct, and nothing regressed.

First, a correction to my own last pass: I marked P2 #5 closed at 05fc445 because run.py reads fresh clocks. That was the literal finding but not its full extent — consume() still judged expiry against its entry timestamp after the remote reads. Astra's re-review caught the residual and was right to reopen it.

The fix works in three layers: contracts.py:190-211 (injectable, entry-relative, never-backwards clock), verify.py:369-370 (re-check after the result read, before VERIFIED), and consume.py:312-346 + receipt_store.py:145-177 (re-check after reads/probes/rendering, then the deadline re-sampled inside BEGIN IMMEDIATE so a lock wait can't carry a request across expiry). The three-valued try_consume is the right shape — it distinguishes replay from expiry instead of collapsing both into a false request_consumed.

The new tests all inject _FakeClock, so I confirmed the fix on the production path instead: TTL shortened to 3 s, receipt sealed, consume entered while valid, getQueryResults taking 5 s —

OLD 05fc445 : VERIFIED []                  released: True   nonce spent: True
NEW 0a13be0 : REJECTED ['request_expired'] released: False  nonce spent: False

The unspent nonce matters as much as the block: the request stays available rather than being burned by its own expiry. Boundary coverage is real rather than asserted — expiry crossed during the result read, source probe and output probe are each parametrized, and test_p2_5_release_still_works_just_inside_deadline pins the negative, without which "reject everything" would also have passed.

Deflake: correctly diagnosed. I measured the old assertion's failure rate over the two random hex ids at 2.04% per run — about one red CI in ten per push across five Python versions, consistent with 3.13 failing on 6407dcf. The replacement keeps the value/display absence check, which is what the test was actually about; no other assertion in the file has the pattern, and the CLI stdout check is safe because the BLOCKED line carries no ids. Note the substring half is now thin (three fields on the rejected path); the absence check carries it.

No regression: 126 passed offline, all seven CLI cases correct (approved → exit 0; six attacks → exit 2 with the right reason code), and every previously closed finding re-verified at this head — P1 stripped receipt_version, pending handle, wrong-claim-then-honest-claim, the NUMERIC collision. The live suite was re-run again after the change (all rows now 2026-09-06T00:49–00:50Z), which is the right instinct after touching the consumption gate. PR scope still example + tests only.

Three low notes, none blocking. R1 — elapsed time uses time.time() rather than time.monotonic() (contracts.py:204); the max() clamp makes it fail-closed either way, but monotonic would remove the reasoning step. R2 — the clock is anchored to the caller's now, so a caller can hold time still; the exposure is bounded by request_is_expired's lower bound (now = issued_at - 1000 → REJECTED; now = issued_at → releases), i.e. at most one TTL. Worth a line in limitations. Carried over, still open: N1 re-confirmed here — verify() returns VERIFIED with value=400 over a record it has just judged tamper-failing, while consume correctly rejects; plus the money_display rounding, key-erasure stranding, the or True at tests/examples/test_okf_attested_computation.py:1152, and the publication.py:20-22 docstring.

No changes-requested items remain from me: receipt-slice pass, MODERATE for receipts only under JOINT §4. Full re-review with reproductions: /tmp/okf-spikes/opus-review-479/REVIEW.md.

The default trusted_clock computed int(now) + int(elapsed), so an entry at
wall 1299.75 (now 1299) whose read ended at 1300.25 still read 1299 and
released after the absolute deadline 1300. The default clock is now
fractional and wall-aligned: it anchors now to the whole second of entry
and adds the exact wall time elapsed since that boundary, never running
backwards; Registry.try_consume compares the fractional sample without an
integer cast. Injected clocks are unchanged.

Regressions on the production clock path (time.time patched, no injected
clock): deadline crossed during result read / source probe / output
probe / render, and through the actual CLI helper -> REJECTED
request_expired, no value, nonce intact; a fractional just-inside case
still releases. Hermetic 133 pass; live suite 7/7 and the seven live CLI
cases rerun; cases.json regenerated at this head.
@caohy1988

Copy link
Copy Markdown
Collaborator Author

Residual Astra P2 #5b closed in 72f798e.

  • Default contracts.trusted_clock is now fractional and wall-aligned: it anchors the caller's integer now to the whole second of entry and adds the exact wall time elapsed since that boundary (never backwards). Astra's boundary (entry wall 1299.75, now 1299, read ends 1300.25, deadline 1300) now reads 1300.25 → REJECTED request_expired. Registry.try_consume compares the fractional sample with the deadline without an integer cast. Injected clocks unchanged.
  • Regressions on the production clock path (time.time patched, no injected clock): deadline crossed during result read / source probe / output probe / render, and through the actual run._issue_then_consume helper → REJECTED, no value/display, nonce intact; fractional just-inside case (1299.10 → 1299.60) still releases; wall-aligned/never-backwards clock unit test. Astra's rereview-0a13be0/probes.py fractional stages now all record REJECTED / no value / nonce unconsumed.
  • Evidence: cases.json regenerated at this head (all 14 hermetic + live CLI records carry the current attester hash); live_cases.json rerun; report row P2 #5b added and the CLI-rerun claim corrected.
  • Hermetic 133 passed (+18 observer). Live suite rerun 2026-09-06: 7/7; seven live CLI cases: approved releases, six attacks blocked.

Not merged; @caohy1988 remains the merge gate.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Astra re-review of 72f798e: original P2 #5b reproduction and stale CLI evidence are fixed; CHANGES REQUESTED for one remaining P2 expiry race.

The 1299.75→1300.25 cases now reject correctly through the default clock and actual CLI helper, with no value or nonce consumption. All six earlier fixes remain intact. All 14 regenerated CLI records match the current attester hash.

Remaining P2: examples/okf_attested_computation/contracts.py:208 combines the caller's earlier integer now with a separately sampled entry_second. If construction crosses into the next second, examples/okf_attested_computation/contracts.py:214 offsets every subsequent gate one second behind wall time.

Reproduced through actual run._issue_then_consume: consumer _now() samples 1299.9995 (now=1299); a 1 ms scheduling pause puts construction at 1300.0005 (entry_second=1300); the result read completes at 1300.25 against deadline 1300. The clock reports 1299.25, and the consumer returns VERIFIED with a value and consumed nonce.

Use an absolute current clock for the production default; keep synthetic time in explicit clock injection. Add a regression crossing the boundary between the CLI timestamp sample and clock construction. Keep the new post-read and transactional checks—they work with a correct clock.

Validation: 133 passed total (115 receipt + 18 adapter), 7 live tests skipped locally; CI green. Independent jobs.get + getQueryResults reads of the new jobs confirm 400 / 600 / 515; R8/R9 reads remain Forbidden to review credentials. No new query jobs or IAM mutations.

Full review, reproductions and learning note saved to the requested paths, including Ship/rfc/2026-09-06-spike-receipt-astra-rereview-p25b.md. Comment only; no GitHub approval or merge. Haiyuan remains the merge gate.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Opus re-review of 72f798e — P2 #5b (COMMENT-only; Haiyuan is the merge gate)

P2 #5b is closed, confirmed on the production clock path, and nothing regressed. 133 hermetic tests, all seven CLI cases correct, live suite re-run again (01:09–01:10Z), 11/11 CI green, scope still example + tests.

First, my own miss: I saw the int(time.time() - start) truncation at 0a13be0, noted it as "~1 s of slack biased toward allowing", and judged it too trivial to raise. That was the wrong call to make silently — the slack lands entirely on the release side of an absolute deadline, and at the boundary it is a full second.

The fix makes the default clock fractional and wall-aligned (contracts.py:190-217): anchor now to the whole second of entry, add the exact wall time since that boundary, keep the backwards clamp. receipt_store.py:164-166 drops the integer cast inside BEGIN IMMEDIATE. Injected clocks are untouched, and the signature widening to Callable[[], float] is the honest typing.

Independent before/after — approve at wall 1000.0 (deadline 1300), enter consume at 1299.75 (now 1299), result read ends at 1300.25, no injected clock:

PREV 0a13be0 : VERIFIED []                  released: True   nonce spent: True
NEW  72f798e : REJECTED ['request_expired'] released: False  nonce spent: False

Clock semantics checked directly, each line matching the docstring: 1299.75 → 1299.75; wall to 1300.25 → 1300.25; wall stepped back to 1200.0 → 1300.25 (clamped); synthetic now=1299 while wall is 5000.9 → 1299.9, i.e. at most one second stricter, never looser — so no existing hermetic test can be loosened by the change. The new tests cover all four crossing stages (result read, source probe, output probe, render) on the production clock, drive Astra's actual run._issue_then_consume helper, and pin liveness at 1299.10 → 1299.60, without which "reject everything" would also pass.

Since a float now flows through the gates I audited for leaks: clock() is used only in comparisons, every persisted timestamp stays an int (issued_at, consumed_at, probed_at), and contracts.cbor rejects floats outright — a leak into a receipt would fail loudly as receipt_seal_failed, not silently change a digest.

cases.json was regenerated with issue_out reduced to {execution_match, verdict}, which removes what I flagged last pass: the blocked tamper case no longer carries "value": "400", and no case in the file carries a governed value. The record still shows tamper → issue_out.verdict = VERIFIED — N1's signature as a verdict rather than a number, which is the honest way to leave it.

Regression sweep at this head: P1 stripped receipt_version → receipt_integrity_failed; pending handle → receipt_not_verified; wrong-claim-then-honest-claim → REJECTED then released; NUMERIC collision closed; and P2 #5's whole-second case still blocks (5 s read on a 3 s TTL → request_expired, nonce unspent).

Retracting my prior R1. I suggested time.monotonic() for the elapsed measure. That is wrong for this design — the deadlines are absolute wall-clock seconds and the fix's point is anchoring to that frame; a monotonic elapsed measure would reintroduce the drift it removes. The backward-step clamp is the right answer to the NTP concern, and it is tested.

Still open (none blocking): N1 — verify() returns VERIFIED with the value over a record it has just judged tamper-failing, while consume correctly rejects; now purely a code concern since the evidence half is fixed. Plus the money_display rounding, key-erasure stranding, the or True at tests/examples/test_okf_attested_computation.py:1152, and the publication.py:20-22 docstring.

No changes-requested items remain from me: receipt-slice pass, MODERATE for receipts only under JOINT §4. Full re-review with reproductions: /tmp/okf-spikes/opus-review-479/REVIEW.md.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Implemented the residual P2 #5c in c121c44; refreshed evidence is pushed in 6719eb5. The default clock now samples fractional absolute wall time without rebasing to the caller's earlier now. The backward-clock clamp and injected test clocks are preserved.

The new CLI regression failed on 72f798e with an expired release. It now crosses 1299.9995 → 1300.0005 during construction, then rejects at 1300.25 with request_expired, no value/display, and the nonce intact. A rollover before expiry still releases.

Validation: 137 hermetic tests passed; 7/7 live acceptance passed (68.12 s, exit=0); all 14 CLI cases rerun with expected outcomes and the current attester hash. Formatting checks passed. Code/test commit was pushed before the live pass; final worktree is clean. Scope remains the receipt example, its tests and evidence. No SDK/adapter changes. Haiyuan remains the merge gate; not merged.

@caohy1988

Copy link
Copy Markdown
Collaborator Author

Astra re-review of 6719eb5: APPROVE. P2 #5c is closed; no remaining P0/P1/P2 finding in this re-review. COMMENT only; Haiyuan remains the merge gate.

Astra authored the fix. This verdict comes from fresh inspection and separate reproductions, including an old-clock mutation control; it does not claim independent authorship.

  1. Absolute production clock confirmed. contracts.py:202 initializes from time.time() and re-samples max(latest, time.time()), with no rebasing to caller now or integer truncation. Stale/future caller timestamps do not shift it; the backward-step clamp remains.
  2. Injection preserved. An explicit clock is returned by identity without reading wall time and is propagated into verification and consumption. Synthetic fixture helpers explicitly inject time; production-path regressions use the actual CLI/consumer.
  3. The exact 1 ms rollover now blocks. A separate probe leaves run._now() unmodified: consumer sample 1299.9995, construction 1300.0005, result read 1300.25, deadline 1300. Restoring the exact old 72f798e clock in memory yields VERIFIED, released value and spent nonce. HEAD yields REJECTED request_expired, no value/display, nonce intact. Before-deadline rollover still releases. The committed regression fails under the old clock and passes under HEAD. Exact-deadline equality, a multi-second pause and an actual SQLite write-lock wait also reject without spending the nonce.
  4. Scope/API checks pass. Entire PR remains receipt-example/tests only against 22d44db; SDK, okf_bqaa_adapter, workflows and package configuration are unchanged. All 18 adapter tests and seven actual hermetic CLI cases pass their expected behavior/exits.

Fresh focused pytest: 137 passed, 7 skipped (119 receipt + 18 adapter). Exact local/PR HEAD is 6719eb535667963fa640dd4535e508b550eb6cb1; CI is green for Python 3.10-3.14, formatting, browser smoke and package build. Diff check passes; worktree clean.

I inspected the prior 7/7 live log with exit=0, seven refreshed acceptance records and fourteen CLI summaries matching the current attester hash. Live tests were skipped locally; this is not a new independent live run. Previously documented nonblocking demo/privacy limitations remain outside this clock delta.

Full review: /tmp/okf-spikes/astra-review-479/REVIEW.md; reproductions/results: /tmp/okf-spikes/astra-review-479/rereview-6719eb5/; vault: Ship/rfc/2026-09-06-spike-receipt-astra-rereview-6719eb5.md.

Actionable findings: none. No merge performed.

@haiyuan-eng-google
haiyuan-eng-google merged commit 120da78 into main Sep 6, 2026
15 checks passed
caohy1988 added a commit that referenced this pull request Sep 21, 2026
…ap, dashboards extras

Version bump 0.5.2 -> 0.5.3 and the changelog cut for everything merged
since v0.5.2 (2026-09-05), 6 commits. No public API is removed or renamed.

In the wheel: EventsTableNotFoundError, a NotFound subclass raised by
get_trace() / list_traces() reads against a missing events table, naming
the table, the location and the Client() arguments to check (#485, #486);
the extractor-compilation smoke gate applies memory_limit_mb as headroom
above the child's post-import address space instead of an absolute
RLIMIT_AS (#480); new streamlit / dashboards extras, with all now including
dashboards (#480); the package quick-start docstring (#484). Repo side: the
Streamlit agent analytics dashboard (#480), grafana/ moved to
dashboards/grafana/ (#481), ANALYST_TIMEOUT_S and the removal of the
pre-#395 engine compat scaffolding in the skill-evolution job (#483), the
OKF Attested Computation receipt spike (#479), and the README onboarding
fixes (#484, #485).

Entries the Unreleased section lacked are added in this cut: #479, #480,
Deploy section, since deploy/ and scripts/ are not in the wheel. The #486
bullet is carried verbatim.
haiyuan-eng-google pushed a commit that referenced this pull request Sep 21, 2026
…ap, dashboards extras (#487)

Version bump 0.5.2 -> 0.5.3 and the changelog cut for everything merged
since v0.5.2 (2026-09-05), 6 commits. No public API is removed or renamed.

In the wheel: EventsTableNotFoundError, a NotFound subclass raised by
get_trace() / list_traces() reads against a missing events table, naming
the table, the location and the Client() arguments to check (#485, #486);
the extractor-compilation smoke gate applies memory_limit_mb as headroom
above the child's post-import address space instead of an absolute
RLIMIT_AS (#480); new streamlit / dashboards extras, with all now including
dashboards (#480); the package quick-start docstring (#484). Repo side: the
Streamlit agent analytics dashboard (#480), grafana/ moved to
dashboards/grafana/ (#481), ANALYST_TIMEOUT_S and the removal of the
pre-#395 engine compat scaffolding in the skill-evolution job (#483), the
OKF Attested Computation receipt spike (#479), and the README onboarding
fixes (#484, #485).

Entries the Unreleased section lacked are added in this cut: #479, #480,
Deploy section, since deploy/ and scripts/ are not in the wheel. The #486
bullet is carried verbatim.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants