Repository navigation
fix(pipeline): route ingest_record through binary-capable Hermes SQLite detection - #3247
Conversation
…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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 48 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 Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 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 |
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01QUsH3Rhq6oAZpYPWcsZqnZ
Summary
ingest_record(the live daemon's per-raw ingest worker) previously decodedevery 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 Hermesverification raws (
source_path ~/.hermes/verification_evidence.db, SQLitedatabase bytes) with:
The REBUILD path (
sources.revision_backfill._parse_retained_raw/_parse_one) parses these same raws fine -- the v42 walk materializedverification sessions from them via
looks_like_sqlite_bytes+ the parsermodules' own
looks_like_*_pathstructural probes, bypassingbuild_raw_payload_envelope/classify_artifactentirely.Root cause is two-layered:
polylogue/archive/raw_payload/decode.py:build_raw_payload_envelope(the function
ingest_recordcalls to decode every raw) only special-casedstate.dbvia_looks_like_hermes_state_db--verification_evidence.dbhad no equivalent marker branch, so it fell through to the generic
JSON/JSONL decode path and was rejected as invalid UTF-8.
polylogue/archive/artifact_taxonomy/runtime.py: even after buildingthe correct marker payload,
classify_artifact()consulted the path-onlyclassify_artifact_path()first. That function's "Hermes SQLite evidencesidecar" filename rule for
verification_evidence.dbunconditionallyreturns
parse_as_session=False(intended for pre-decode, path-onlycallers like schema sampling) -- and since
classify_artifact()returnsearly on a non-
Nonepath classification, it shadowed the marker payload'spositive session classification for the identical filename.
Solution
polylogue/archive/raw_payload/decode.py: generalized the state.db-only_looks_like_hermes_state_dbbranch into_hermes_sqlite_marker_payload,which now recognizes both
state.dbandverification_evidence.dbbycalling
hermes_state.marker_payload()/hermes_verification.marker_payload()directly (previously the state.db marker dict was hand-built inline,
duplicating what
hermes_state.marker_payloadalready does). Binary-capabledetection now runs before any text decode, in the same order the rebuild
path's
_parse_onealready uses (looks_like_sqlite_bytes-> per-artifactlooks_like_*_pathprobes).polylogue/archive/artifact_taxonomy/runtime.py: extracted the twoHermes SQLite marker checks (state.db / verification_evidence.db) out of
_classify_dictinto a shared_classify_hermes_sqlite_markerhelper, andcall it from
classify_artifact()before consultingclassify_artifact_path(). The raw*.dbpath itself still classifies as anon-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 paritytest, found
_parse_one'sverification_evidence.dbbranch omittedprofile_root=(unlike the adjacentstate.dbbranch, which already passesprofile_root=Path(source_path).parent). This meant the rebuild routeproduced an unqualified
verification:<raw_id>session id while the fixedingest route (via dispatch, which already threads
profile_rootfromspec.source_path) produces a profile-qualified id -- a second, narrowerparse-route disagreement in the exact same area. Fixed to match.
Ownership note:
polylogue/sources/dispatch.pyis owned by a concurrentlane (OriginSpec work). This PR does not touch it -- the marker-payload
dispatch route (
detect_provider/_lower_payload_specs/_parse_lowered_spec) already fully supportedverification_evidence.dbmarkers; 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 directsqlite3reads. Onlyhermes_state.py(state.db) andhermes_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 tothis bug class. No other provider needs coverage.
Acceptance-criteria matrix
_hermes_sqlite_marker_payloadcalls the samehermes_state/hermes_verificationlooks_like_*_path/marker_payloadfunctions_parse_oneusespipeline/services/ingest_worker.pyand/orsources/decoders.py;dispatch.pyuntouched or minimally flaggedarchive/raw_payload/decode.py(the moduleingest_recordcalls into) andarchive/artifact_taxonomy/runtime.py;dispatch.pynot touched at allingest_record, comparing session native ids; anti-vacuity statedtests/unit/pipeline/test_binary_payload_parse_parity.py, two tests (verification_evidence.db + state.db regression guard); anti-vacuity verified live (see Verification)Verification
-> 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 subagentJSONL classification, no file this PR touches is involved).
->
Success: no issues found in 4 source files-> all 16 steps
ok, exit 0.Anti-vacuity: stashed the
decode.pyrouting change and re-ran the newparity 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