Skip to content

fix(pipeline): route ingest_record through binary-capable Hermes SQLite detection - #3247

Merged
Sinity merged 1 commit into
masterfrom
fix/pipeline/binary-payload-parse-parity
Jul 21, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/pipeline/binary-payload-parse-parity

Conversation

@Sinity

@Sinity Sinity commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

ingest_record (the live daemon's per-raw ingest worker) previously decoded
every raw as text/JSON before any provider dispatch, so Hermes raws whose
payload is SQLite database bytes failed to parse -- while the rebuild path
(historical backfill / census / replay) parsed the identical bytes fine. This
PR routes ingest_record's decode step through the same binary-capable
detection the rebuild path uses, and fixes two related parse-route divergences
found while proving parity.

Problem

Live failure (2026-07-21, discovered during a targeted Hermes reprocess):
parse_from_raw -> process_ingest_batch -> ingest_record
(polylogue/pipeline/services/ingest_worker.py) fails all 3 Hermes
verification raws (source_path ~/.hermes/verification_evidence.db, SQLite
database bytes) with:

decode: str is not valid UTF-8: surrogates not allowed: line 1 column 1

The REBUILD path (sources.revision_backfill._parse_retained_raw /
_parse_one) parses these same raws fine -- the v42 walk materialized
verification sessions from them via looks_like_sqlite_bytes + the parser
modules' own looks_like_*_path structural probes, bypassing
build_raw_payload_envelope/classify_artifact entirely.

Root cause is two-layered:

  1. polylogue/archive/raw_payload/decode.py: build_raw_payload_envelope
    (the function ingest_record calls to decode every raw) only special-cased
    state.db via _looks_like_hermes_state_db -- verification_evidence.db
    had no equivalent marker branch, so it fell through to the generic
    JSON/JSONL decode path and was rejected as invalid UTF-8.
  2. polylogue/archive/artifact_taxonomy/runtime.py: even after building
    the correct marker payload, classify_artifact() consulted the path-only
    classify_artifact_path() first. That function's "Hermes SQLite evidence
    sidecar" filename rule for verification_evidence.db unconditionally
    returns parse_as_session=False (intended for pre-decode, path-only
    callers like schema sampling) -- and since classify_artifact() returns
    early on a non-None path classification, it shadowed the marker payload's
    positive session classification for the identical filename.

Solution

  • polylogue/archive/raw_payload/decode.py: generalized the state.db-only
    _looks_like_hermes_state_db branch into _hermes_sqlite_marker_payload,
    which now recognizes both state.db and verification_evidence.db by
    calling hermes_state.marker_payload() / hermes_verification.marker_payload()
    directly (previously the state.db marker dict was hand-built inline,
    duplicating what hermes_state.marker_payload already does). Binary-capable
    detection now runs before any text decode, in the same order the rebuild
    path's _parse_one already uses (looks_like_sqlite_bytes -> per-artifact
    looks_like_*_path probes).
  • polylogue/archive/artifact_taxonomy/runtime.py: extracted the two
    Hermes SQLite marker checks (state.db / verification_evidence.db) out of
    _classify_dict into a shared _classify_hermes_sqlite_marker helper, and
    call it from classify_artifact() before consulting
    classify_artifact_path(). The raw *.db path itself still classifies as a
    non-session sidecar when passed alone (schema sampling and other path-only
    callers are unaffected); only a decoded marker payload now wins over the
    path-only sidecar rule.
  • polylogue/sources/revision_backfill.py: while building the parity
    test, found _parse_one's verification_evidence.db branch omitted
    profile_root= (unlike the adjacent state.db branch, which already passes
    profile_root=Path(source_path).parent). This meant the rebuild route
    produced an unqualified verification:<raw_id> session id while the fixed
    ingest route (via dispatch, which already threads profile_root from
    spec.source_path) produces a profile-qualified id -- a second, narrower
    parse-route disagreement in the exact same area. Fixed to match.

Ownership note: polylogue/sources/dispatch.py is owned by a concurrent
lane (OriginSpec work). This PR does not touch it -- the marker-payload
dispatch route (detect_provider / _lower_payload_specs /
_parse_lowered_spec) already fully supported verification_evidence.db
markers; the gap was entirely upstream of dispatch, in the envelope decode and
artifact classification steps.

Other binary-payload providers (AC #4)

Grepped every parser module under polylogue/sources/parsers/ for direct
sqlite3 reads. Only hermes_state.py (state.db) and
hermes_verification.py (verification_evidence.db) read raw SQLite bytes;
both are covered by the new parity test. Antigravity's "brain-metadata"
artifact (looks_like_brain_metadata) is JSON, not binary -- not exposed to
this bug class. No other provider needs coverage.

Acceptance-criteria matrix

# AC Status
1 Diagnose exact divergence point; reuse the rebuild path's helper instead of forking logic Satisfied -- _hermes_sqlite_marker_payload calls the same hermes_state/hermes_verification looks_like_*_path/marker_payload functions _parse_one uses
2 Fix lives in pipeline/services/ingest_worker.py and/or sources/decoders.py; dispatch.py untouched or minimally flagged Satisfied -- fix lives in archive/raw_payload/decode.py (the module ingest_record calls into) and archive/artifact_taxonomy/runtime.py; dispatch.py not touched at all
3 Contract test: raw parseable via rebuild route also parseable via ingest_record, comparing session native ids; anti-vacuity stated Satisfied -- tests/unit/pipeline/test_binary_payload_parse_parity.py, two tests (verification_evidence.db + state.db regression guard); anti-vacuity verified live (see Verification)
4 Check other binary-payload providers Satisfied -- only Hermes exposed; documented above

Verification

devtools test tests/unit/pipeline/test_binary_payload_parse_parity.py \
  tests/unit/pipeline/test_ingest_worker_assembly.py \
  tests/unit/sources/parsers/test_hermes_verification.py \
  tests/unit/sources/parsers/test_hermes_state.py \
  tests/unit/sources/test_revision_backfill.py \
  tests/unit/core/test_raw_payload_decode.py tests/unit/core/test_models.py \
  tests/unit/sources/test_parsers_local_agent.py tests/unit/sources/test_artifact_taxonomy.py

-> 270 passed, 1 pre-existing failure unrelated to this change
(test_build_raw_payload_envelope_prefers_claude_subagent_path_over_codex_like_shape,
reproduces identically against unmodified master -- Claude Code subagent
JSONL classification, no file this PR touches is involved).

mypy --strict polylogue/archive/raw_payload/decode.py \
  polylogue/archive/artifact_taxonomy/runtime.py \
  polylogue/sources/revision_backfill.py \
  polylogue/pipeline/services/ingest_worker.py

-> Success: no issues found in 4 source files

devtools verify --quick

-> all 16 steps ok, exit 0.

Anti-vacuity: stashed the decode.py routing change and re-ran the new
parity test -- it fails with the exact live error string:
decode: str is not valid UTF-8: surrogates not allowed: line 1 column 1.

Ref polylogue-zoc3

…te detection

Problem: ingest_record (pipeline/services/ingest_worker.py) decoded every
raw as text/JSON before any provider dispatch, so Hermes raws whose
payload is SQLite database bytes (verification_evidence.db) failed with
"decode: str is not valid UTF-8: surrogates not allowed" -- even though
the rebuild path (sources.revision_backfill._parse_one) parses the
identical raw bytes fine via looks_like_sqlite_bytes plus structural
looks_like_*_path probes. Only state.db had a matching marker-payload
branch in build_raw_payload_envelope; verification_evidence.db did not.

Solution:
- polylogue/archive/raw_payload/decode.py: generalize the state.db-only
  `_looks_like_hermes_state_db` marker branch into
  `_hermes_sqlite_marker_payload`, which now also recognizes
  verification_evidence.db (calling hermes_state.marker_payload /
  hermes_verification.marker_payload directly instead of duplicating the
  dict construction inline). Binary-capable detection now runs before any
  text decode, matching the rebuild path's ordering.
- polylogue/archive/artifact_taxonomy/runtime.py: classify_artifact() was
  consulting the path-only classify_artifact_path() first, whose
  "Hermes SQLite evidence sidecar" filename rule for verification_evidence.db
  always returned parse_as_session=False -- shadowing the marker payload's
  positive session classification for the *same* filename. Extracted the
  two Hermes SQLite marker checks (state.db / verification_evidence.db)
  into `_classify_hermes_sqlite_marker`, now consulted before the path-only
  rule so a synthesized marker payload wins over the raw-path sidecar rule.
- polylogue/sources/revision_backfill.py: `_parse_one`'s verification_evidence.db
  branch omitted `profile_root=` (unlike the adjacent state.db branch),
  so the rebuild route produced an unqualified `verification:<raw_id>`
  session id while the ingest route (via dispatch, once fixed) produces a
  profile-qualified id -- a second, narrower parse-route disagreement in
  the same area. Passed `profile_root=Path(source_path).parent` to match.

Other binary-payload providers: grepped every parser module for direct
`sqlite3` reads. Only hermes_state.py (state.db) and hermes_verification.py
(verification_evidence.db) read raw SQLite bytes; Antigravity's
"brain-metadata" artifact is JSON, not binary. No other provider is exposed
to this class of bug.

Verification:
- devtools test tests/unit/pipeline/test_binary_payload_parse_parity.py
  tests/unit/pipeline/test_ingest_worker_assembly.py
  tests/unit/sources/parsers/test_hermes_verification.py
  tests/unit/sources/parsers/test_hermes_state.py
  tests/unit/sources/test_revision_backfill.py
  tests/unit/core/test_raw_payload_decode.py tests/unit/core/test_models.py
  tests/unit/sources/test_parsers_local_agent.py tests/unit/sources/test_artifact_taxonomy.py
  -> 270 passed, 1 pre-existing unrelated failure
     (test_build_raw_payload_envelope_prefers_claude_subagent_path_over_codex_like_shape,
     reproduces identically on unmodified master, Claude Code subagent
     JSONL classification, untouched by this change).
- mypy --strict on all 4 touched modules: Success, no issues.
- Anti-vacuity: reverting the decode.py routing change reproduces the
  exact live error string in the new parity test.

Ref polylogue-zoc3
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 21, 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: 48 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

Run ID: 1e658248-4ac2-4e6a-ba27-67b03a4af6c0

📥 Commits

Reviewing files that changed from the base of the PR and between b903024 and 940832f.

📒 Files selected for processing (4)
  • polylogue/archive/artifact_taxonomy/runtime.py
  • polylogue/archive/raw_payload/decode.py
  • polylogue/sources/revision_backfill.py
  • tests/unit/pipeline/test_binary_payload_parse_parity.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pipeline/binary-payload-parse-parity

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 a4760e9 into master Jul 21, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/pipeline/binary-payload-parse-parity branch July 21, 2026 16:34
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