KB-24B3

C1 Staging Codex R3 Fixes — Fix B: P6 Independent Verification

4 min read Revision 1
c1stagingcodex-r3-fixesready-for-r42026-06-23

04 — FIX B: P6 INDEPENDENT VERIFICATION

sql/p6-evidence-readback.sql (sha256 a021c88b…). The gate runs in ONE txn under LOCK TABLE canonical_operation, c1_test_results IN SHARE MODE; the evidence-ledger row + digest are written only after the gate passes; nothing commits on a RAISE.

P6 no longer merely trusts P3/P4/P5 DONE stamps. It re-derives every PASS fact:

  1. Upstream DONE stamps + sandbox matchc1_vocab_build, c1_verify, c1_bad_input_harness must each exist (RAISE P6_FATAL_MISSING_Pn), and every such stamp's sandbox_id must equal this sandbox's sbx_meta.birth_certificate.sandbox_id (RAISE P6_FATAL_STAMP_SANDBOX_MISMATCH). With Fix A those stamps are provably post-gate.
  2. Exact canonical setcount=3 AND no extra (P6_FATAL_UNEXPECTED_OP) AND no missing (P6_FATAL_MISSING_OP) vs the literal {C1.READ_BALANCE, C1.WRITE_POSTING, C1.VERIFY_DIGEST}. count=3 alone is insufficient — this directly answers Codex's counterexample.
  3. All validatedcount(status='validated')=3 (P6_FATAL_NOT_ALL_VALIDATED).
  4. Field + mode invariants — non-empty title; valid group; status='validated'; required_inputs, expected_outputs, allowed_modes are each non-empty arrays — checked with CASE guards so jsonb_array_length is never evaluated on a non-array (no reliance on undocumented OR short-circuit); every allowed_mode value ∈ c1_allowed_mode (P6_FATAL_FIELD_INVARIANT, P6_FATAL_BAD_MODE).
  5. Bad-input matrix re-derived from P6's OWN oracletotal=9, accepted=0; a 9-row oracle (case_no → expected reject_code/SQLSTATE) is JOINed to c1_test_results; for each case P6 recomputes a verdict from (recorded expect == oracle) AND (actual reject_code/SQLSTATE == expect) AND outcome='rejected'. PASS requires joined_n=9 AND indep_pass=9 AND pass_disagree=0. The stored pass column is not trusted; pass_disagree = count(verdict <> stored_pass) catches tampering (P6_FATAL_ORACLE_JOIN/ORACLE_VERDICT/PASS_TAMPER).
  6. Isolation proof — case 8 rejected with SQLSTATE 42P01, checked directly (not via stored pass) (P6_FATAL_NO_ISOLATION_PROOF).
  7. Zero orphans — every public table/function/trigger ∈ sbx_meta.object_registry (P6_FATAL_ORPHAN).

Read-only validation against live PG16.13 (no sandbox, no DDL/DML — VALUES/constants only)

P6's oracle re-derivation was exercised against one GOOD + six TAMPERED fixtures:

fixture total joined indep_pass disagree gate result
F0 GOOD 9 9 9 0 PASS
F1 case4 accepted (stored pass=true) 9 9 8 1 caught
F2 case4 wrong reject_code (stored pass=true) 9 9 8 1 caught
F3 case7 missing (8 rows) 8 8 8 0 caught (total≠9)
F4 case6 expect tampered ≠ oracle 9 9 8 1 caught
F5 case8 sqlstate ≠ 42P01 (isolation broken) 9 9 8 1 caught
F6 extra 10th row 10 9 9 0 caught (total≠9)

Also proven read-only: exact-set EXCEPT (a count=3 wrong-set flags BOTH extra=C1.WRONG and missing=C1.VERIFY_DIGEST); CASE-guarded invariants do not error on non-array inputs; allowed-mode membership with a non-array row present does not error (WHERE typeof='array' filters before SRF expansion); the whole gate's plpgsql compiles and runs (DO ok, exit 0).

Back to Knowledge Hub knowledge/dev/laws-new/reports/c1-staging-codex-r3-fixes-ready-for-r4/04-fix-p6-independent-verification.md