Skip to content

fix(sources): account one-pass parser payloads as they are pulled - #4375

Merged
Sinity merged 1 commit into
masterfrom
worktree-agent-a49c709fbe3815545
Aug 28, 2026
Merged

Sinity merged 1 commit into
masterfrom
worktree-agent-a49c709fbe3815545

Conversation

@Sinity

@Sinity Sinity commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

parse_stream(iter(items), ...) no longer equals parse_code(items, ...); this restores the invariant in the production path.

Problem

tests/unit/sources/test_parsers_base.py::test_parse_code_stream_matches_list_parse fails on master. The two ParsedSession values differ in exactly one field, unit_accounting:

  • list: expected={OUTER_RECORD: 2}, two MATERIALIZED outcomes
  • stream: expected={OUTER_RECORD: 1}, one MATERIALIZED outcome

parse_code and parse_code_stream are literally the same function, so the divergence comes from the @parser_admission boundary (polylogue/sources/parsers/base_support.py, added in #4184). It reads args[0] after the parser has run and rebuilds the ledger from it. For a Sequence that works; for a one-pass iterator the object is exhausted, is not a Sequence, and hits the [payload] fallback — so the iterator object itself is counted as a single record. Every streamed session was accounted as one outer record regardless of length, and unknown wire types past the first were never synthesized into *_unknown_input session events.

Solution

Classify each record while the parser pulls it. When the payload is an Iterator, the boundary wraps it in a pass-through generator that records each record's wire type; the Sequence/Mapping path is unchanged. Constant memory, and streaming and list parse now produce identical accounting.

Added test_parse_code_stream_admission_accounts_unknown_records: a two-record stream whose second record is future_record must account expected == 2 with MATERIALIZED + TYPED_UNKNOWN, and equal the list parse. Reverting the generator wrapping makes it red (expected == 1, one outcome).

Verification

  • devtools test tests/unit/sources/test_parsers_base.py — 83 passed
  • devtools test tests/unit/sources — 9 failed, 2602 passed; all 9 reproduce identically on stashed-clean master (6 in test_browser_capture.py, 2 in test_live_batch_support.py, 1 in test_codex_event_stream_contract.py) and belong to other families of polylogue-g8rdy
  • devtools verify --quick — clean, no out of sync

Residual risk

If a stream parser stops consuming early, expected now counts only the records it pulled rather than the whole file. That is honest one-pass truth and conservation still holds; the previous behavior reported a constant 1.

🤖 Generated with Claude Code

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

The admission boundary re-read its payload after the parser returned. A
one-pass iterator is exhausted by then, so it fell through to the
single-item fallback: every streamed session was accounted as one outer
record, and unknown wire types past the first were never surfaced as
session events. Classify each record as the parser pulls it instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3d8a1d04-3fbf-4a04-a683-ef32e09d4c57


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.

@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: 813c6a1e7b

ℹ️ 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".

@Sinity
Sinity merged commit 38c60e6 into master Aug 28, 2026
3 checks passed
@Sinity
Sinity deleted the worktree-agent-a49c709fbe3815545 branch August 28, 2026 02:51
Sinity added a commit that referenced this pull request Aug 28, 2026
)

## Summary

`parse_stream(iter(items), ...)` no longer equals `parse_code(items,
...)`; this restores the invariant in the production path.

## Problem


`tests/unit/sources/test_parsers_base.py::test_parse_code_stream_matches_list_parse`
fails on master. The two `ParsedSession` values differ in exactly one
field, `unit_accounting`:

- list: `expected={OUTER_RECORD: 2}`, two MATERIALIZED outcomes
- stream: `expected={OUTER_RECORD: 1}`, one MATERIALIZED outcome

`parse_code` and `parse_code_stream` are literally the same function, so
the divergence comes from the `@parser_admission` boundary
(`polylogue/sources/parsers/base_support.py`, added in #4184). It reads
`args[0]` *after* the parser has run and rebuilds the ledger from it.
For a Sequence that works; for a one-pass iterator the object is
exhausted, is not a `Sequence`, and hits the `[payload]` fallback — so
the iterator object itself is counted as a single record. Every streamed
session was accounted as one outer record regardless of length, and
unknown wire types past the first were never synthesized into
`*_unknown_input` session events.

## Solution

Classify each record while the parser pulls it. When the payload is an
`Iterator`, the boundary wraps it in a pass-through generator that
records each record's wire type; the Sequence/Mapping path is unchanged.
Constant memory, and streaming and list parse now produce identical
accounting.

Added `test_parse_code_stream_admission_accounts_unknown_records`: a
two-record stream whose second record is `future_record` must account
`expected == 2` with MATERIALIZED + TYPED_UNKNOWN, and equal the list
parse. Reverting the generator wrapping makes it red (`expected == 1`,
one outcome).

## Verification

- `devtools test tests/unit/sources/test_parsers_base.py` — 83 passed
- `devtools test tests/unit/sources` — 9 failed, 2602 passed; all 9
reproduce identically on stashed-clean master (6 in
`test_browser_capture.py`, 2 in `test_live_batch_support.py`, 1 in
`test_codex_event_stream_contract.py`) and belong to other families of
polylogue-g8rdy
- `devtools verify --quick` — clean, no `out of sync`

## Residual risk

If a stream parser stops consuming early, `expected` now counts only the
records it pulled rather than the whole file. That is honest one-pass
truth and conservation still holds; the previous behavior reported a
constant 1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Aug 29, 2026
…es (#4399)

## Summary

Repair four red families across the `cli` and `sources` selections:
browser-capture synthetic-ID normalization, Hermes named-SQLite
admission, Codex unknown response-item preservation, and
`MessageQueryRowPayload` repo parity. Regenerated declarations ship with
them.

## Problem

`legacy_browser_capture_native_id`, its `_UUID_PATTERN`, its `__all__`
entry, and its call site were deleted by #4337 — a two-lane batch
assembly about contract JSON and deployment smoke coverage, unrelated to
browser capture — while all six of its contract tests were left in
place. That is what turned them red (`git show 97cddc4 --
polylogue/browser_capture/identity.py`).

The other three were independent gaps: an uncheckpointed Hermes WAL row
lost at acquisition, a Codex unclassified response item double-counted
by the conservation boundary because it declared no `wire_type`, and
`repo` populated on the substrate row but dropped at the surface because
`_from_row_generic` copies by field name only.

## Solution

Restore the deleted normalization (byte-identical to the deleted body,
minus a redundant wrapper); hoist `hermes_owned_sqlite_name` above the
recognizer guard for `source_only` acquisition; carry the raw provider
token on the unclassified Codex event via `_record_type`, a structural
`record.get("type")` read with no inference; declare `repo` on
`MessageQueryRowPayload`.

## Verification

Each fix was reverted in isolation and the covering test run:

- browser-capture: 6 failed, 44 passed
- Hermes: 2 failed, 141 passed
- Codex: 1 failed, with `assert ['codex_unclassified_response_item'] ==
[...]` naming the mechanism
- repo parity:
`test_generic_row_declarations_have_explicit_field_parity[MessageQueryRowPayload]`
failed, 20 passed

`devtools verify --quick` → exit 0, all 18 gates. `devtools render all
--check` → exit 0, no `out of sync`. `devtools test tests/unit/sources
tests/unit/surfaces` → 2734 passed, 0 failed.

## Residual risk

`native_id` derivation for browser captures reverts to the pre-#4337
rule, which collapses `chatgpt:<uuid>:<hash>` to `<uuid>`. That collapse
is deliberate convergence from #2345 — the extension minted a fresh
synthetic ID per capture, fragmenting one conversation into many
sessions. Blast radius on real data is zero:
`/realm/state/polylogue/source.db` was last written 2026-08-16, before
the regression window opened on 2026-08-27, so no capture was ingested
un-normalized and nothing is re-identified on reindex. Normalization
happens at parse, not in storage, so replay re-derives the same ID from
the same blob.

The Hermes exemption is scoped to `source_only` acquisition of two
filenames and does not relax parser admission; the recognizer still
gates `source_parsing.parse_one_source_path`. Consequence: a named
Hermes SQLite whose schema the recognizer cannot classify is now
acquired as a Hermes raw and may later fail parse with a typed refusal.

The comment at `polylogue/sources/live/batch.py:1972-1975` ("Only the
OriginSpec recognizer may admit a candidate") now sits above a guard
carrying an exemption; filed separately rather than edited here.

Pre-existing and not introduced: the 3-colon-part branch at
`identity.py:27-29` returns `parts[1]` for any `provider:X:Y` where `X`
has no `/`, without requiring `X` to look like a UUID. Shipped since
#2345.

The bead stays open. Its "35 red / 25 remaining" figures are stale — the
five families it names as still red are green on current master (#4371,
#4368, #4375, and the CLI pair), so the remainder must be re-enumerated
rather than restated.
Sinity added a commit that referenced this pull request Sep 1, 2026
)

## Summary

`parse_stream(iter(items), ...)` no longer equals `parse_code(items,
...)`; this restores the invariant in the production path.

## Problem


`tests/unit/sources/test_parsers_base.py::test_parse_code_stream_matches_list_parse`
fails on master. The two `ParsedSession` values differ in exactly one
field, `unit_accounting`:

- list: `expected={OUTER_RECORD: 2}`, two MATERIALIZED outcomes
- stream: `expected={OUTER_RECORD: 1}`, one MATERIALIZED outcome

`parse_code` and `parse_code_stream` are literally the same function, so
the divergence comes from the `@parser_admission` boundary
(`polylogue/sources/parsers/base_support.py`, added in #4184). It reads
`args[0]` *after* the parser has run and rebuilds the ledger from it.
For a Sequence that works; for a one-pass iterator the object is
exhausted, is not a `Sequence`, and hits the `[payload]` fallback — so
the iterator object itself is counted as a single record. Every streamed
session was accounted as one outer record regardless of length, and
unknown wire types past the first were never synthesized into
`*_unknown_input` session events.

## Solution

Classify each record while the parser pulls it. When the payload is an
`Iterator`, the boundary wraps it in a pass-through generator that
records each record's wire type; the Sequence/Mapping path is unchanged.
Constant memory, and streaming and list parse now produce identical
accounting.

Added `test_parse_code_stream_admission_accounts_unknown_records`: a
two-record stream whose second record is `future_record` must account
`expected == 2` with MATERIALIZED + TYPED_UNKNOWN, and equal the list
parse. Reverting the generator wrapping makes it red (`expected == 1`,
one outcome).

## Verification

- `devtools test tests/unit/sources/test_parsers_base.py` — 83 passed
- `devtools test tests/unit/sources` — 9 failed, 2602 passed; all 9
reproduce identically on stashed-clean master (6 in
`test_browser_capture.py`, 2 in `test_live_batch_support.py`, 1 in
`test_codex_event_stream_contract.py`) and belong to other families of
polylogue-g8rdy
- `devtools verify --quick` — clean, no `out of sync`

## Residual risk

If a stream parser stops consuming early, `expected` now counts only the
records it pulled rather than the whole file. That is honest one-pass
truth and conservation still holds; the previous behavior reported a
constant 1.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_014BQsaB1NBY8mTR6yZByfMA

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Sinity added a commit that referenced this pull request Sep 1, 2026
…es (#4399)

## Summary

Repair four red families across the `cli` and `sources` selections:
browser-capture synthetic-ID normalization, Hermes named-SQLite
admission, Codex unknown response-item preservation, and
`MessageQueryRowPayload` repo parity. Regenerated declarations ship with
them.

## Problem

`legacy_browser_capture_native_id`, its `_UUID_PATTERN`, its `__all__`
entry, and its call site were deleted by #4337 — a two-lane batch
assembly about contract JSON and deployment smoke coverage, unrelated to
browser capture — while all six of its contract tests were left in
place. That is what turned them red (`git show 97cddc4 --
polylogue/browser_capture/identity.py`).

The other three were independent gaps: an uncheckpointed Hermes WAL row
lost at acquisition, a Codex unclassified response item double-counted
by the conservation boundary because it declared no `wire_type`, and
`repo` populated on the substrate row but dropped at the surface because
`_from_row_generic` copies by field name only.

## Solution

Restore the deleted normalization (byte-identical to the deleted body,
minus a redundant wrapper); hoist `hermes_owned_sqlite_name` above the
recognizer guard for `source_only` acquisition; carry the raw provider
token on the unclassified Codex event via `_record_type`, a structural
`record.get("type")` read with no inference; declare `repo` on
`MessageQueryRowPayload`.

## Verification

Each fix was reverted in isolation and the covering test run:

- browser-capture: 6 failed, 44 passed
- Hermes: 2 failed, 141 passed
- Codex: 1 failed, with `assert ['codex_unclassified_response_item'] ==
[...]` naming the mechanism
- repo parity:
`test_generic_row_declarations_have_explicit_field_parity[MessageQueryRowPayload]`
failed, 20 passed

`devtools verify --quick` → exit 0, all 18 gates. `devtools render all
--check` → exit 0, no `out of sync`. `devtools test tests/unit/sources
tests/unit/surfaces` → 2734 passed, 0 failed.

## Residual risk

`native_id` derivation for browser captures reverts to the pre-#4337
rule, which collapses `chatgpt:<uuid>:<hash>` to `<uuid>`. That collapse
is deliberate convergence from #2345 — the extension minted a fresh
synthetic ID per capture, fragmenting one conversation into many
sessions. Blast radius on real data is zero:
`/realm/state/polylogue/source.db` was last written 2026-08-16, before
the regression window opened on 2026-08-27, so no capture was ingested
un-normalized and nothing is re-identified on reindex. Normalization
happens at parse, not in storage, so replay re-derives the same ID from
the same blob.

The Hermes exemption is scoped to `source_only` acquisition of two
filenames and does not relax parser admission; the recognizer still
gates `source_parsing.parse_one_source_path`. Consequence: a named
Hermes SQLite whose schema the recognizer cannot classify is now
acquired as a Hermes raw and may later fail parse with a typed refusal.

The comment at `polylogue/sources/live/batch.py:1972-1975` ("Only the
OriginSpec recognizer may admit a candidate") now sits above a guard
carrying an exemption; filed separately rather than edited here.

Pre-existing and not introduced: the 3-colon-part branch at
`identity.py:27-29` returns `parts[1]` for any `provider:X:Y` where `X`
has no `/`, without requiring `X` to look like a UUID. Shipped since
#2345.

The bead stays open. Its "35 red / 25 remaining" figures are stale — the
five families it names as still red are green on current master (#4371,
#4368, #4375, and the CLI pair), so the remainder must be re-enumerated
rather than restated.
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay 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