Skip to content

fix(sources): warn loudly on total ChatGPT bundle shape drift - #3391

Merged
Sinity merged 1 commit into
masterfrom
feature/sources/chatgpt-bundle-shape-drift-warning
Jul 29, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/sources/chatgpt-bundle-shape-drift-warning

Conversation

@Sinity

@Sinity Sinity commented Jul 29, 2026

Copy link
Copy Markdown
Owner

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 into conversations-000.json..conversations-024.json once large enough) was unreferenced by any raw_sessions row. Read-only investigation against the real export and the live archive (/realm/db/polylogue, opened via mode=ro) showed:

  • polylogue import <export.zip> --explain on 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.
  • The live archive already contains 2402 real sessions from this export, acquired between 2026-07-02 and 2026-07-14 (source.db 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).
  • The bead's premise was stale, most likely from an earlier check assuming a literal conversations.json filename 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-free ParsedSessions 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. renaming mapping's node/message shape) would look like, and exactly the kind of silent-drop the bead worried about.

Solution

polylogue/sources/dispatch.py:

  • Added _chatgpt_bundle_record_specs, which filters ChatGPT bundle items through chatgpt.looks_like_fragment before admission (instead of blindly wrapping every list item via the generic _bundle_record_specs).
  • Added _looks_like_chatgpt_mapping_candidate — a "near miss" check (has a non-empty mapping dict) used only to decide whether a zero-match bundle is drift-worth-a-warning or routine metadata-sibling noise. Legitimate siblings never carry a mapping key at all, so they never trigger the warning regardless of list length.
  • _lower_bundle_payload now routes Provider.CHATGPT through the new function; Provider.CLAUDE_AI (the other BUNDLE_PROVIDERS member) is untouched.
  • When ≥5 mapping-bearing candidates all fail shape validation, logger.warning fires with the candidate count — visible in daemon logs without needing to already suspect drift and query raw_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:
    • a real conversation record survives alongside a dropped message_feedback-shaped sibling, with no warning
    • 6 mapping-bearing-but-invalid records trigger the drift warning ("ChatGPT bundle payload" + candidate count in the message)
    • 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_code: 0 (format/lint/mypy/render-all-check), run twice (once manually, once via the pre-push hook)
  • Re-ran polylogue import <real 2026-04-23 export.zip> --explain before and after the change, against a scratch POLYLOGUE_ARCHIVE_ROOT (the real export was only read, never written to) — byte-identical output, confirming no regression against the real corpus shape

Acceptance criteria (polylogue-iwv7)

  1. Cause identified by evidence, not assumed — satisfied. See Problem section above; premise was stale, confirmed via direct archive/export inspection.
  2. The export ingests, sharded exports handled as declared artifact shape in ChatGPT OriginSpec — satisfied as pre-existing behavior. _chatgpt_spec() in polylogue/sources/origin_specs.py declares 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.
  3. Report sessions and date-range added — 2402 real conversation sessions from this export are in the live archive (2421 candidates minus attachment/metadata files that correctly produce no session), acquired 2026-07-02 through 2026-07-14, spanning native create_time 2022-12-12 through 2026-04-23; 373 of those sessions fall specifically in the previously-claimed Oct 2025–Apr 2026 gap.
  4. A future export layout change fails loudly at acquisition rather than being skipped — satisfied by this PR's _chatgpt_bundle_record_specs warning.

Residual risk / follow-ups

  • No live re-acquisition was run as part of this investigation (would mutate the production archive) — none is needed, since the export is already fully ingested.
  • The warning threshold (_CHATGPT_BUNDLE_DRIFT_MIN_CANDIDATES = 5) is a logger.warning, not an alert/metric; it will show up in daemon logs but isn't wired into polylogue ops status aggregation. If stronger guarantees are wanted (e.g. surfaced in daemon status counts), that's separate follow-up work outside this PR's chatgpt.py/dispatch.py scope.
  • source_path/entry-name context isn't threaded down to _lower_bundle_payload today, so the warning identifies the payload only by fallback_id (the zip's stem, shared across all its entries per decoder_zip.process_zip) rather than the specific shard filename. Improving that would require touching decoder_zip.py/emitter.py, which are outside this task's write scope.

Ref polylogue-iwv7

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
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9e681441-05a7-4516-8317-e157319860eb

📥 Commits

Reviewing files that changed from the base of the PR and between 4137244 and 4a190e5.

📒 Files selected for processing (2)
  • polylogue/sources/dispatch.py
  • tests/unit/sources/test_dispatch_payloads.py

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Sinity
Sinity merged commit b64a074 into master Jul 29, 2026
3 checks passed
@Sinity
Sinity deleted the feature/sources/chatgpt-bundle-shape-drift-warning branch July 29, 2026 06:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +729 to +730
if provider is Provider.CHATGPT:
return _chatgpt_bundle_record_specs(payloads, fallback_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread polylogue/sources/dispatch.py Resolved
Sinity added a commit that referenced this pull request Jul 29, 2026
…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]>
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 71.F040 / P2: fixed-already at the checked revision: polylogue/sources/dispatch.py:1393 now recognizes the independent conversation envelope when mapping is absent. The required current_node/create_time/title keys at line 1398 let the drift counter see a renamed tree key without treating unrelated metadata arrays as conversations.

Only the rows listed above are dispositioned. Held findings remain open.

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