Skip to content

fix(qsearch): Python lifecycle client parity with wire contract v1 (26 → 0 discrepancies) - #102

Merged
AetherAI3 merged 3 commits into
mainfrom
claude/nano86-python-parity-json
Nov 8, 2026
Merged

AetherAI3 merged 3 commits into
mainfrom
claude/nano86-python-parity-json

Conversation

@AetherAI3

Copy link
Copy Markdown
Owner

Summary

The Python LifecycleClient accepted responses that wire contract v1 (#86) requires clients to refuse. The gaps were recorded as 26 strict-xfail compatibility tests, and this closes all of them, so Python and the TypeScript client (#93) now accept and reject the same bytes. The change only makes the client refuse more. Fuzzing and a differential test show it still accepts every envelope the real server can produce. Follow-up to #86.

Key Changes

  • Strict JSON on every body — Success and error bodies must be strict UTF-8, with no number above 2^53-1, no nesting deeper than 64, and no duplicate members.
  • Closed-envelope validation — A new stdlib-only validator enforces job-state.v1.schema.json (members, types, enums, patterns, nullability, invariants I1–I8) on every 2xx.
  • No leak via exception chaining — Errors carry no __context__ and no frame locals that could expose the response body, URL or transport error.
  • Contract §4 now says "none remain" — A new test fails if any fixture regresses to "accepts" without an explicit entry in the discrepancy table.

Verification

  • xfails 26 → 20 → 0, each commit red first. Client + wire-contract files: 334 passed, 0 xfailed. Lifecycle group: 451 passed, 1 skipped (no aether_atlas).
  • Validator vs jsonschema: about 47k mutated envelopes, zero disagreements. 4,000 fuzzed job_state() outputs were all accepted.
  • feat(conformance): offline release-conformance harness and evidence schema #99 conformance tests: all six required test IDs are present, unrenamed and passing. regen.py --check passes.
  • Full suite (agent run, per file, on base 4b57316): 3346 passed, 18 skipped, 3 failed. The 3 failures also fail on base (j6_a2 ×2, quantum_prepare).
  • Independent review: no CRITICAL or HIGH findings. All MEDIUM and LOW findings are fixed in the third commit.

Risk / Follow-ups

  • Hosts that injected malformed or inconsistent envelopes through a custom transport now get INVALID_RESPONSE. The default HTTP transport is unaffected for any real server output.

🤖 Generated with Claude Code

AetherAI3 and others added 3 commits November 8, 2026 00:11
LifecycleClient now parses success and error bodies with the section 2.1
rules of protocol/qsearch-lifecycle/v1: bytes are decoded strictly as UTF-8
before json.loads (a BOM, UTF-16 or UTF-32 body and encoded surrogates are
refused), every number must have magnitude <= 2^53-1 and nesting is limited
to 64 containers with the top-level value counted as 1. Refusals are
INVALID_RESPONSE / MANUAL_RECONCILIATION with http_status set, including
for non-2xx bodies. Injected text and decoded mappings pass the same rules.

Flips six recorded xfails (encoding_utf8_bom, encoding_utf16_le,
encoding_utf32_be, unsafe_integer, error_body_unsafe_integer,
error_body_depth_exceeds_64); fixtures and SHA256SUMS regenerated and
CONTRACT.md section 4 updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lient

After the existing schema-id, digest-binding and next_action checks, every
2xx lifecycle body (status, cancel, refresh, replace) must now satisfy
protocol/qsearch-lifecycle/v1/job-state.v1.schema.json in full: closed
objects with exact member sets, member types, enums, patterns (fullmatch,
so no trailing newline), nullability, amounts as finite non-bool numbers in
0..2^53-1, booleans strictly bool, and invariants I1-I8. The validator is a
private stdlib module (nano_qsearch/_job_state_v1.py); the runtime stays
free of jsonschema.

Tests: a differential test compares client accept/reject with jsonschema
over every single-member mutation of the 15 golden histories and I1-I8
cross-products (~47k distinct payloads); a seeded fuzz drives
lifecycle.job_state over 4000 random records/receipts/clocks and asserts the
client accepts every projected envelope. Flips the remaining 20 recorded
xfails; fixtures and SHA256SUMS regenerated, CONTRACT.md section 4 now lists
no Python discrepancies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Independent review (no CRITICAL/HIGH) follow-ups, each reproduced by a
failing test first:
- A decoded mapping from an injected transport is canonicalised and parsed
  on the strict byte path, so nested Mapping types are normalised instead of
  refused (regression vs the documented 'decoded mapping' transport).
- A str body is capped by its UTF-8 byte length, not characters.
- The job-state validator no longer raises OverflowError on huge ints.
- Client errors are re-raised with no __context__/__cause__ chain and a fresh
  traceback: 'raise ... from None' only hid the chain, while __context__ (a
  JSONDecodeError whose .doc is the full body) and frame locals stayed
  reachable from the public error.
- Validator refuses a trailing newline in all six patterned fields.
- CONTRACT section 4 wording and the documented jsonschema exclusions.

Refs #86

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AetherAI3
AetherAI3 merged commit 5d83c92 into main Nov 8, 2026
7 of 9 checks passed
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