Repository navigation
fix(sources): warn loudly on total ChatGPT bundle shape drift - #3391
Conversation
Problem: polylogue-iwv7 reported the 2026-04-23 ChatGPT export (sharded into conversations-000.json..conversations-024.json once OpenAI's export grew large enough) as unreferenced by any raw_sessions row, implying six months of history were silently dropped. Investigation via `polylogue import --explain` against the real export (read-only, via POLYLOGUE_ARCHIVE_ROOT pointed at a scratch dir) showed current master already parses every shard correctly -- detection is shape-based (chatgpt.looks_like_fragment), not filename-based, so the numbered shards were never actually a blind spot for the parser. Cross-checking the live archive (source.db/index.db, read-only) confirmed the export had in fact already been fully acquired and indexed between 2026-07-02 and 2026-07-14 (2402 real conversation sessions, 373 of them dated in the claimed Oct 2025-Apr 2026 gap, all with real message/word counts) -- before the bead was even filed on 2026-07-29. The bead's premise was stale, most likely from an earlier check that assumed a literal "conversations.json" filename and missed the shard-suffixed paths. What changed: the diagnosis surfaced a real residual gap instead -- `_lower_bundle_payload`'s ChatGPT branch admitted every list item in a bundle-shaped JSON array unconditionally (message_feedback.json, shared_conversations.json, user_settings.json parse into empty, content-free ParsedSessions rather than being recognized as non-conversation shape), and there was no signal to distinguish "this zero-yield array is a routine metadata sibling" from "every real conversation record in this shard failed to match the expected shape", which is exactly what a future OpenAI export format change (e.g. renaming `mapping`'s node/message shape) would look like. Added `_chatgpt_bundle_record_specs`, which filters bundle items through `chatgpt.looks_like_fragment` before admission, and warns loudly via `logger.warning` when a non-trivial number of `mapping`-bearing "near miss" records (candidates that got as far as carrying a `mapping` dict but failed node-shape validation) all fail to match -- while never warning on legitimate metadata siblings, which never carry a `mapping` key at all regardless of list length. Verification: - `devtools test tests/unit/sources/test_dispatch_payloads.py` -- 13 passed, including 3 new tests: a real conversation survives alongside a dropped metadata sibling with no warning; 6 mapping-shaped-but- invalid records trigger the drift warning; a 25-item metadata-only array (no mapping key) never warns. - `devtools test tests/unit/sources/test_parsers_chatgpt.py` -- 101 passed (no regression in existing ChatGPT parser behavior). - `devtools verify --quick` -- exit 0 (format/lint/mypy/render-all-check). - Re-ran `polylogue import <export.zip> --explain` against the real 2026-04-23 export before and after the change (scratch POLYLOGUE_ARCHIVE_ROOT, read-only source) -- byte-identical output, confirming no regression against the real corpus shape. Ref polylogue-iwv7
|
Warning Review limit reached
Next review available in: 47 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)
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a190e5d8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if provider is Provider.CHATGPT: | ||
| return _chatgpt_bundle_record_specs(payloads, fallback_id) |
There was a problem hiding this comment.
Run the drift check before ZIP bundles are split
When the daemon ingests a real ChatGPT ZIP, this branch is bypassed: iter_entry_payloads uses _iter_json_stream with its default unpack_lists=True, iter_zip_entry_raw_data serializes the resulting individual records, and ingest_worker later calls parse_payload with one dict at a time. Each dict therefore falls through to _single_record_spec, so a shard of malformed mapping records can still produce empty sessions without this warning; only callers that retain the whole list, such as the explain/direct parsing path, receive the new signal. Run the drift check while iterating the ZIP entry or otherwise preserve bundle-level context through acquisition.
AGENTS.md reference: AGENTS.md:L129-L132
Useful? React with 👍 / 👎.
…y promotion Problem: the 2026-07-29 structural-merge promotion (c53ad94) regenerated every provider schema and dropped the x-polylogue-semantic-role overlay for codex/claude-code/claude-ai, so SyntheticCorpus filled role-discriminator fields with opaque `synthetic-<n>` placeholders instead of real user/ assistant values (polylogue-c66i). This normalized every generated message to Role.UNKNOWN and broke property tests, plus regressed 3 stale test contracts elsewhere on this branch's schema/parser lanes. What changed: - devtools/inject_semantic_annotations.py: re-ran the sanctioned re- annotation tool, then fixed 3 real gaps it hit against the promoted schema shape (not just re-running it blindly): - claude-code/codex message_body: the promotion flattened these fields from an anyOf-of-type-variants union to `type: [array, string]` with `items` present directly; the injector's anyOf:array DSL step no longer matched anything. Updated both paths. - claude-code message_container: this entry was simply missing from the ANNOTATION_MAP (not a promotion regression) — added `properties.message`. - claude-code message.role and codex flat properties.role: the promotion also unioned in a second legitimate codex record shape (flat `{"type": "message", "role": ...}`, no `payload` wrapper — the real parser already accepts this, sources/parsers/codex.py) and claude-code's `message.role` mirrors top-level `type` but was never itself annotated. Added both so synthetic generation never leaves a role field unannotated regardless of which record shape it produces. - polylogue/schemas/synthetic/build_batch.py: `_record_role` now checks both codex record shapes (payload.role and flat role) so tool-heavy-style synthetic generation places its tool_use/tool_result blocks after an assistant turn regardless of which shape got generated (test_generation_plants_independent_wire_facts_before_ingest was asserting non-empty tool_use_ids and getting `()` from the untouched flat-shape record). - Removed the test-layer workaround this regression required (tests/infra/strategies/providers.py:repair_role_discriminators and its tests/conftest.py:synthetic_source repair loop): empirically confirmed zero placeholder-triggered records across 60 seeds x 2 providers with the schema fix in place, so the workaround is now dead weight. - tests/unit/sources/test_live_cursor_persistence.py, tests/unit/sources/test_source_laws.py: updated two test doubles whose monkeypatched signatures had drifted from their real counterparts (`_write_parsed_precedence_result` gained `defer_fts_rebuild`; `claude.parse_code` gained `tool_result_sidecars`) and one bundle-item fixture that no longer satisfies chatgpt.looks_like_fragment after #3391 tightened bundle-item shape validation. - tests/unit/sources/test_live_watcher.py: rewrote the ambiguous-membership regression test to the contract PR #3282 (4120c40) deliberately shipped — a decided ambiguous/deferred membership conflict is now preserved as durable authority debt and NOT retried as a file failure, superseding the narrower fail-closed-as-failure framing PR #3193 (f6cc1dd) shipped earlier for the same injection point. The still-fail-closed classify_raw_revision_cohort injection point (empty accepted cohort) is untouched and still covered by test_rewrite_plus_growth_before_planning_fails_closed_to_full_route et al. - docs/plans/demo-corpus-construct-audit.md: regenerated (`devtools render demo-corpus-datasheet`) — the schema fix also repaired real demo-corpus embedding-candidate detection (verifier result flipped failed -> ok; synthetic_message_embedding_rows/embedding_status_rows went from `missing` (0) to `ok` (1)), confirming this is a genuine parser- facing improvement, not just a test-fixture patch. Verification: - python3 devtools/inject_semantic_annotations.py --dry-run -> 0 annotations would be injected (idempotent). - devtools test tests/unit/core/test_synthetic_semantic_wiring.py tests/unit/core/test_synthetic_semantics.py tests/unit/sources/test_parsers_props.py tests/unit/sources/test_null_guard_properties.py -> 238 passed. - devtools test tests/unit/sources/test_live_watcher.py tests/unit/sources/test_live_cursor_persistence.py tests/unit/sources/test_source_laws.py -> 216 passed. - devtools verify --quick -> exit 0 (ruff format/check, mypy --strict, render all --check, all lab/policy gates). - Not run: the full non-integration suite (in progress in parallel). Ref polylogue-c66i Co-Authored-By: Claude <[email protected]>
|
Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.
Only the rows listed above are dispositioned. Held findings remain open. |
Summary
Investigated polylogue-iwv7 (ChatGPT export from 2026-04-23 reported as not ingested, six months of history reportedly absent). Root cause turned out to be a stale bead premise, not a live bug — but the investigation surfaced a real gap in silent-failure observability, which this PR fixes.
Problem
The bead claimed
chatgpt-data-2026-04-23-20-21-52.zip(OpenAI's export sharded intoconversations-000.json..conversations-024.jsononce large enough) was unreferenced by anyraw_sessionsrow. Read-only investigation against the real export and the live archive (/realm/db/polylogue, opened viamode=ro) showed:polylogue import <export.zip> --explainon current master already parses every shard correctly (2421 candidate conversation sessions) — ChatGPT detection is shape-based (chatgpt.looks_like_fragment), not filename-based, so numbered shards were never actually a parser blind spot.raw_sessions.acquired_at_ms) — before the bead was filed on 2026-07-29. 373 of those sessions fall in the claimed Oct 2025–Apr 2026 gap, all with real message/word counts and titles (e.g. "Declarative NixOS setup", 4 messages, 2416 words).conversations.jsonfilename that missed the shard-suffixed paths.What the investigation did surface as a real, still-open gap:
_lower_bundle_payload's ChatGPT branch admitted every item in a bundle-shaped JSON array unconditionally, including legitimate non-conversation siblings (message_feedback.json,shared_conversations.json,user_settings.json), which parse into empty, content-freeParsedSessions rather than being recognized by shape. There was no signal distinguishing "this zero-yield array is a routine metadata sibling" from "every real conversation record in this shard failed to match the expected shape" — exactly what a future OpenAI export format change (e.g. renamingmapping's node/message shape) would look like, and exactly the kind of silent-drop the bead worried about.Solution
polylogue/sources/dispatch.py:_chatgpt_bundle_record_specs, which filters ChatGPT bundle items throughchatgpt.looks_like_fragmentbefore admission (instead of blindly wrapping every list item via the generic_bundle_record_specs)._looks_like_chatgpt_mapping_candidate— a "near miss" check (has a non-emptymappingdict) used only to decide whether a zero-match bundle is drift-worth-a-warning or routine metadata-sibling noise. Legitimate siblings never carry amappingkey at all, so they never trigger the warning regardless of list length._lower_bundle_payloadnow routesProvider.CHATGPTthrough the new function;Provider.CLAUDE_AI(the otherBUNDLE_PROVIDERSmember) is untouched.logger.warningfires with the candidate count — visible in daemon logs without needing to already suspect drift and queryraw_sessions.detection_warnings_json.No schema change; no change to acquisition-tier durable data.
Verification
devtools test tests/unit/sources/test_dispatch_payloads.py— 13 passed, including 3 new tests:message_feedback-shaped sibling, with no warningmapping-bearing-but-invalid records trigger the drift warning ("ChatGPT bundle payload"+ candidate count in the message)mappingkey) never warnsdevtools test tests/unit/sources/test_parsers_chatgpt.py— 101 passed (no regression in existing ChatGPT parser behavior)devtools verify --quick—exit_code: 0(format/lint/mypy/render-all-check), run twice (once manually, once via the pre-push hook)polylogue import <real 2026-04-23 export.zip> --explainbefore and after the change, against a scratchPOLYLOGUE_ARCHIVE_ROOT(the real export was only read, never written to) — byte-identical output, confirming no regression against the real corpus shapeAcceptance criteria (polylogue-iwv7)
_chatgpt_spec()inpolylogue/sources/origin_specs.pydeclares no filename-based artifact rules for ChatGPT; detection was already shape-based and already handles the shard layout. No OriginSpec change was needed or made.create_time2022-12-12 through 2026-04-23; 373 of those sessions fall specifically in the previously-claimed Oct 2025–Apr 2026 gap._chatgpt_bundle_record_specswarning.Residual risk / follow-ups
_CHATGPT_BUNDLE_DRIFT_MIN_CANDIDATES = 5) is alogger.warning, not an alert/metric; it will show up in daemon logs but isn't wired intopolylogue ops statusaggregation. If stronger guarantees are wanted (e.g. surfaced in daemon status counts), that's separate follow-up work outside this PR'schatgpt.py/dispatch.pyscope.source_path/entry-name context isn't threaded down to_lower_bundle_payloadtoday, so the warning identifies the payload only byfallback_id(the zip's stem, shared across all its entries perdecoder_zip.process_zip) rather than the specific shard filename. Improving that would require touchingdecoder_zip.py/emitter.py, which are outside this task's write scope.Ref polylogue-iwv7