Repository navigation
test(schemas): prove schema-generation cancellation and shuffle-order equivalence - #3298
Conversation
… equivalence Problem: polylogue-1xc.14.1.1 hardened schema-generation memory bounds (#2968/#2971/#2973) but left two AC items unproven: no test exercised "cancellation equivalence" (only raw ObservationJournal cleanup-on-SIGTERM was covered, not the full generate_provider_schema entrypoint), and no test proved shuffled input order produces identical output -- grep confirmed zero "shuffle" hits anywhere in tests/unit/ for schema generation and zero cancellation-equivalence coverage in observation_journal.py/provider_bundle.py. What changed: - tests/infra/schema_generation_cancellation_probe.py: new subprocess target that writes a small deterministic synthetic ChatGPT archive once, runs generate_provider_schema, and optionally pauses right after the observe_and_cluster phase starts so the parent can SIGTERM mid-run. - tests/unit/core/test_schema_observation_journal.py: - test_generation_cancellation_restarts_from_scratch_and_matches_uninterrupted_run proves devtools/schema_generate.py's own "restart_from_acquisition" resume claim empirically: killing a run mid-observation and rerunning against the same archive produces the same schema as an uninterrupted reference run, and the journal directory is empty afterward. - test_shuffled_sample_order_yields_identical_schema_and_package_assignment feeds the same SchemaUnit multiset through the real _build_provider_bundle in two different orders (monkeypatching iter_schema_units, the same technique already used by test_build_provider_bundle_captures_element_windows_and_bundle_scopes) and asserts schema content, package identity, and cluster-manifest identities are order-invariant. Both tests run against synthetic/demo data only -- no live archive corpus. Verification: devtools test tests/unit/core/test_schema_observation_journal.py tests/infra/schema_generation_cancellation_probe.py -> 17 passed; mypy polylogue (strict) -> Success: no issues found in 1078 source files; ruff check + format --check -> clean; devtools render all --check -> OK (no topology drift, these are test-only files). Ref polylogue-1xc.14.1.1 Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds the two production-route tests needed to close the remaining proof gap on polylogue-1xc.14.1.1 ("Make schema inference replayable and memory-bounded"): cancellation equivalence for the real
generate_provider_schemaentrypoint, and shuffled-input-order equivalence for the real_build_provider_bundlepipeline. Both run against synthetic/demo data only.Problem
polylogue-1xc.14.1.1 landed heavy hardening for the
ObservationJournalfull-corpus pipeline (#2968, #2971, #2973: bounded batch commits, selective-membership replay, Hermes terminal-ledger accounting) with a 1x/10x memory-bound proof already in place. Two AC items were still unproven going into this pass:grep -rn cancel polylogue/schemas/generation/observation_journal.py polylogue/schemas/generation/provider_bundle.pyreturns zero hits. The existing tests (test_journal_cleanup_runs_for_sigterm,test_journal_cleanup_runs_for_real_terminated_process) only prove that a raw, low-levelObservationJournal.append_unitcall cleans up on SIGTERM — they never exercise the realgenerate_provider_schemaentrypoint, and none of them prove a killed-then-restarted run produces the same output as an uninterrupted run (the actual "equivalence" claim in the bead's own notes: "cancellation proof" listed as remaining scope).grep -rl shuffle tests/unit/returns nothing anywhere under the schema test tree. This clause was simply untested.Solution
tests/infra/schema_generation_cancellation_probe.py(new): a subprocess target that writes a small deterministic synthetic ChatGPT archive once (idempotent across repeated invocations against the same--archive-root, so it can be reused for the reference and restarted runs without re-seeding), then calls the realgenerate_provider_schema. With--pause-after-observeit installs aprogress_callbackthat printsPAUSEDright after theobserve_and_clusterphase starts and sleeps, giving the parent a deterministic, non-flaky window to send SIGTERM mid-run.tests/unit/core/test_schema_observation_journal.py:test_generation_cancellation_restarts_from_scratch_and_matches_uninterrupted_run: runs the probe to completion once (reference), then runs it again with--pause-after-observe, SIGTERMs it oncePAUSEDis observed, asserts the journal directory is empty afterward (same contract as the existing terminated-process test, now through the real generation entrypoint), then reruns to completion and asserts the resulting schema/sample_count/default_version are identical to the reference run. This empirically provesdevtools/schema_generate.py's own resume-receipt claim ("the private observation journal is intentionally removed after interruption" /restart_from_acquisition) actually holds for real generation, not just for a syntheticObservationJournal.append_unitcall.test_shuffled_sample_order_yields_identical_schema_and_package_assignment: feeds an identicalSchemaUnitmultiset through the real_build_provider_bundlein two different orders, using the sameiter_schema_unitsmonkeypatch technique already established bytest_build_provider_bundle_captures_element_windows_and_bundle_scopesintest_schema_generation.py. Asserts schema content (minus the wall-clockx-polylogue-generated-atfield), package identity (anchor_profile_family_id,profile_family_ids,sample_count,bundle_scope_count,first_seen/last_seen), catalog version selection, and cluster-manifest identities (exact_structure_ids,bundle_scope_count) are all order-invariant.Not addressed in this PR
AC #5 also contains a separate clause: "Small known-answer provider bundles are byte/content equivalent to the reference algorithm except for newly declared profile metadata." I looked for what "the reference algorithm" refers to and could not find an unambiguous, non-fabricated interpretation:
generate_schema_from_samples(the older genson-based helper) uses a structurally different shape-inference algorithm than_generate_cluster_schema(the production path's customobserved_structure_schema/merge_observed_structure_schemas), so comparing them would not be a meaningful equivalence proof — it would just assert two different algorithms disagree. The other candidate reading (the bead's own description mentionslist(iter_schema_units(...))as the naive/eager alternative to the journal-backed streaming path) would require building a full parallel non-journal reference pipeline for cluster/package/catalog assembly purely for this test — a nontrivial, test-only duplicate implementation that risks becoming exactly the kind of toy replica the project's testing conventions reject. I left this alone rather than fabricate a shaky test; it's called out explicitly in thebd updatenote on polylogue-1xc.14.1.1 (kept open, not closed, because of this gap).Verification
devtools test tests/unit/core/test_schema_generation.pyshows 6 pre-existingsqlite3.OperationalError: database is lockedsetup errors under-n 2xdist — reproduced identically on an unmodified checkout of this file before any of my changes, so it is pre-existing environment flakiness unrelated to this diff (not caused or fixed here).The pre-push
devtools verify --quickgate (format + lint + mypy + render-all-check) ran automatically on push and passed (exit_code 0).Ref polylogue-1xc.14.1.1