Repository navigation
fix(schemas): batch large journal units - #2971
Merged
Merged
Conversation
A Codex observation can contain hundreds of thousands of samples. Commit inside such a unit in bounded sample-byte batches so one transcript cannot turn the entire private WAL budget into one transaction. Ref polylogue-1xc.14.1.1
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughObservationJournal now inserts samples incrementally using row-count and payload-size thresholds, records pending writes per batch, and preserves final cluster/profile accounting. A regression test verifies partial sample commits during ingestion of a large SchemaUnit. ChangesObservation journal batching
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SchemaUnit
participant ObservationJournal
participant SQLite
SchemaUnit->>ObservationJournal: append_unit with schema_samples
ObservationJournal->>ObservationJournal: buffer canonicalized sample JSON
ObservationJournal->>SQLite: executemany sample batch
SQLite-->>ObservationJournal: commit partial samples
ObservationJournal->>ObservationJournal: record batch pending-write bytes
ObservationJournal->>SQLite: finalize cluster and profile writes
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Sinity
added a commit
that referenced
this pull request
Jul 27, 2026
… equivalence (#3298) ## 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_schema` entrypoint, and shuffled-input-order equivalence for the real `_build_provider_bundle` pipeline. Both run against synthetic/demo data only. ## Problem polylogue-1xc.14.1.1 landed heavy hardening for the `ObservationJournal` full-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: - AC #2/#6 ("cancellation"): `grep -rn cancel polylogue/schemas/generation/observation_journal.py polylogue/schemas/generation/provider_bundle.py` returns 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-level `ObservationJournal.append_unit` call cleans up on SIGTERM — they never exercise the real `generate_provider_schema` entrypoint, 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). - AC #5 ("shuffled input order produces the same schemas, package assignments, profiles, and identities"): `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 real `generate_provider_schema`. With `--pause-after-observe` it installs a `progress_callback` that prints `PAUSED` right after the `observe_and_cluster` phase 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 once `PAUSED` is 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 proves `devtools/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 synthetic `ObservationJournal.append_unit` call. - `test_shuffled_sample_order_yields_identical_schema_and_package_assignment`: feeds an identical `SchemaUnit` multiset through the real `_build_provider_bundle` in two different orders, using the same `iter_schema_units` monkeypatch technique already established by `test_build_provider_bundle_captures_element_windows_and_bundle_scopes` in `test_schema_generation.py`. Asserts schema content (minus the wall-clock `x-polylogue-generated-at` field), 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 custom `observed_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 mentions `list(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 the `bd update` note on polylogue-1xc.14.1.1 (kept open, not closed, because of this gap). ## Verification ``` devtools test tests/unit/core/test_schema_observation_journal.py tests/infra/schema_generation_cancellation_probe.py # 17 passed mypy polylogue # Success: no issues found in 1078 source files ruff check tests/unit/core/test_schema_observation_journal.py tests/infra/schema_generation_cancellation_probe.py ruff format --check tests/unit/core/test_schema_observation_journal.py tests/infra/schema_generation_cancellation_probe.py # All checks passed! / 2 files already formatted devtools render all --check # OK: site sources render and generated local links resolve. (test-only files, no topology drift) ``` `devtools test tests/unit/core/test_schema_generation.py` shows 6 pre-existing `sqlite3.OperationalError: database is locked` setup errors under `-n 2` xdist — 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 --quick` gate (format + lint + mypy + render-all-check) ran automatically on push and passed (exit_code 0). Ref polylogue-1xc.14.1.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Batches sample insertion inside one schema observation unit so an unusually
large Codex transcript cannot create one multi-gigabyte private WAL
transaction.
Problem
Live Codex regeneration established that an individual
SchemaUnitcan carry223,710 samples. The prior transaction repair committed between units, but only
after all samples in a unit had been inserted; that still allowed one giant
unit to exceed the intended journal transaction window.
Solution
Insert sample rows in bounded row/byte batches and account each completed batch
toward the existing private transaction budget. No sample, schema observation,
or generated output is dropped; incomplete journals remain private staging and
are removed on interruption.
Ref polylogue-1xc.14.1.1.
Verification
devtools test tests/unit/core/test_schema_observation_journal.py— 15 passed.devtools verify --quick— all checks passed.Summary by CodeRabbit
Bug Fixes
Tests