fix(v5): reject duplicate keys in power-plan JSON specs

Draft
TH
2mo ago
+425-12

Scope — fail closed on ambiguous JSON at the V5 development planning boundary

This DRAFT PR is deliberately stacked on PR #327 (base fix/v5-power-planner-contract-hardening) to isolate a reproduced review finding reported on #327 while its existing Mac checkout is concurrently dirty with someone else's uncommitted numeric-overflow improvements. Nothing from that other worktree was reset, staged, committed, discarded or modified.

Original issue: Python json.loads accepted multiple identical object keys with silent last-wins behavior in the caller-provided V5 planning spec. A synthetic input with three occurrences of primary_non_target_family_size (original 4, then conflicting 1, then 4) returned exit code 0 and PASS_DEVELOPMENT_ONLY_INPUT_CONTRACT. This is a source-review/provenance ambiguity, not proof that the scientific power gate was bypassed; authority flags correctly remained false.

Changes

  • Reject duplicate JSON keys at every nesting depth, after Unicode escape decoding, with an explicit PowerPlanContractError, instead of silently normalizing contradictory inputs.
  • Reject nonstandard Python JSON constants NaN and Infinity, malformed JSON/invalid encoding and non-object root specs before any plan can be written.
  • Add direct subprocess negative tests launched from a foreign working directory with no PYTHONPATH: top-level family count conflicts, nested paired SD conflicts, nested hypothesis ID conflicts, equivalent Unicode-escaped duplicate key, NaN, Infinity, JSON syntax and root type. Keep a positive valid CLI control proving the final-power and confirmatory authority flags stay false.
  • Preserve the original frozen scientific sources/protocol and all development evidence; include transparent, bounded non-clinical provenance rationale.

Model-free qualification and review limits

Mac results at source commit 61231565e3bf79770b79eef334f4225cbf28c05d:

  • Full repo 1,430 tests passed +264 subtests.
  • V5 378 tests passed +86 subtests.
  • Planner 66 tests passed.
  • Frozen original source-hash entries 307/307 PASS.
  • Python compilation, whitespace/diff checks PASS.
  • Alibaba Open Code Review preview lists the changed Python planner as eligible, NOT a real independent model-review verdict.

CI should run the existing exact-head read-only V5 planning-input contract workflow, which already includes this test file. Please record its actual outcome at this head before any promotion.

Scientific/governance hold: Caller-supplied hypothesis family completeness, source-case × stochastic-training-seed covariance, legitimate 90% power at frozen Holm alpha .05/N4096, independent qualified statistical review, cryptographic commit signing, founder approval and confirmatory/reserve authorization all remain OPEN in #326. This fixes only JSON parsing ambiguity. No new model inference, GPU/Kaggle, PHI, paid API or confirmatory/reserve identity materialization, and no claim of clinical readiness, paper publication or final project completion. DCO sign-off alone is not cryptographic signing.

The PR remains DRAFT/UNMERGED. Use normal merge commits only if and when all governance gates have been satisfied; do not force-push/rebase or merge just because CI is green.


Summary by cubic

Fixes the V5 power planner failing closed on ambiguous or degenerate JSON specs so conflicting caller-supplied inputs no longer silently pass, and prevents the CLI from overwriting evidence through its output path. Also aligns the strict-input branch with the exact-head power contracts from PR #327 and the PR #325 statistical reviewer packet while preserving all scientific and confirmatory authority gates.

Python's json.loads previously accepted duplicate keys with last-wins behavior, nonstandard NaN/Infinity literals, and non-object roots. The planner now rejects all of these with explicit PowerPlanContractError failures and produces no plan output. Oversized integers and deeply nested JSON that hit decoder resource limits are also normalized to contract errors. Whitespace-padded metric names are rejected as aliases even when unreferenced. Output files are now created in exclusive mode, so writing over the input source, an existing artifact, or a symlink fails with OUTPUT_ALREADY_EXISTS instead of clobbering evidence. Positive paired SDs whose normal-approximation MDE underflows to exact zero are rejected, and descriptive-metric margins that overflow 2x repeatability are rejected even when unused.

  • Added subprocess negative tests for duplicate top-level, nested, and Unicode-escaped keys, NaN/Infinity, root type, syntax errors, oversized integers, deep nesting, subnormal SD, margin overflow, and padded metric-name aliases.
  • Added no-clobber tests covering self-overwrite, existing evidence, symlinks, and repeated invocations, plus positive CLI controls.
  • Added a scoped provenance/guard note documenting the isolation from PR #327 and the merge alignment with its exact-head contracts and the PR #325 reviewer packet.
  • Pinned the CI checkout action to an immutable revision.