Repository navigation
fix(sources): refuse to session-parse unrecognized SQLite databases - #3576
Conversation
|
Warning Review limit reached
Next review available in: 19 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 (17)
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 |
Live-archive sweep results (full run, read-only)The full read-only sweep against
This confirms the fix works exactly as intended: Codex's own state databases (which have no dedicated session parser — Follow-up for the operator: run |
Ref polylogue-hbtj2 Co-Authored-By: Claude <[email protected]>
Ref polylogue-hbtj2 Co-Authored-By: Claude <[email protected]>
860b4f9 to
1efa47a
Compare
Problem: the 2026-08-02 authority-dataflow audit found ~450MB of SQLite databases (Hermes state.db x2 at 135MB, verification_evidence.db, Codex state_5.sqlite) sitting in raw_sessions and misread as "genuinely diverged" session revisions by a byte-diff classifier that was never designed to reason about opaque binary snapshots. Two concrete detection gaps let this happen: batch_support.py's _parse_payload_as_session_artifact accepted ANY .db/.sqlite/.sqlite3 file under a Hermes-tagged source by bare extension match, never checking content; and no shared chokepoint positively refused an unrecognized binary payload before a JSON/JSONL decode was even attempted, relying on incidental JSONDecodeError instead. What changed: - polylogue/core/binary_signatures.py: single shared, provider-agnostic magic-byte registry (SQLite/PNG/gzip/JPEG/PDF; ZIP deliberately excluded since GDPR export bundles are legitimately zip-shaped sessions). - sources/live/batch_support.py: _parse_payload_as_session_artifact now requires the same content-verified Hermes state.db/verification_evidence.db schema check its path-based sibling already uses, instead of a bare extension match. - sources/dispatch.py: detect_provider_from_raw_bytes_evidence positively refuses a recognized binary signature at the single shared raw-bytes detection chokepoint (used by production per-file acquisition and the unclaimed-file sweep), before any JSON decode attempt. - archive/raw_payload/decode.py: build_raw_payload_envelope (the "every raw, including binary ones" chokepoint per its own docstring) now classifies an unrecognized binary-shaped payload as ArtifactKind BINARY_DATABASE/BINARY_DOCUMENT (parse_as_session=False) instead of falling through to a JSON decode failure. - storage/binary_artifact_sweep.py + two devtools commands (`workspace binary-artifact-sweep`, `workspace binary-artifact-reclassify-apply`): read-only classifier over raw_sessions plus a separate --apply-gated actuator that persists raw_artifacts rows via the existing materialize_artifact_observations machinery, mirroring the raw-live-source-reconciliation report/apply split. Never touches revision_authority. Explicitly out of scope: Hermes state.db/verification_evidence.db already have a dedicated, content-verified, tested session parser (fs1.14 ATIF/ ATOF/verification-ledger topology) that intentionally represents their derived facts as sessions. This bead tightens the *detection boundary* (no dedicated parser claims a shape -> refuse) without reversing that existing feature; whether that feature itself should stop representing Hermes SQLite content as sessions is a separate, larger architectural question flagged in the PR body for an explicit operator decision. Verification: devtools test on the touched modules (3 pre-existing, unrelated failures confirmed via git stash to already fail on master); devtools verify --quick green (ruff format/check, mypy, render all, topology, layering, classifier-fingerprints with an explicit acknowledged-safe entry for sqlite_snapshot.looks_like_sqlite_bytes' behavior-preserving delegation). Ref polylogue-hbtj2 Co-Authored-By: Claude <[email protected]>
1efa47a to
8144716
Compare
…sions Problem Every antigravity-session row in the live archive (116/116, measured 2026-07-31) is a 1-message fragment materialized from a per-artifact ~/.gemini/antigravity/brain/<uuid>/*.md.metadata.json sidecar -- metadata, not conversation content. Real conversation content lives in conversations/*.pb trajectories; acquiring those was already fixed by PR #3441 (merged), which also stopped classifying future metadata sidecars as sessions. That fix is forward-only: the 116 already-materialized phantom sessions and their unclassified raw rows are untouched by it. This closes the retroactive half of polylogue-eo81/polylogue-msia (the two beads describe the same finding). Solution - polylogue/storage/antigravity_phantom_sweep.py: read-only scan_antigravity_phantom_sessions() joins sessions to session_tags on the existing degraded:brain-metadata-fragment auto-tag (written at ingest time by PR #1856) -- precise, already-present evidence, no new content classification needed. Cross-checks each candidate's raw_id against source.db's raw_sessions row when a source connection is given, and reports (rather than assumes) when that raw row is already missing. - polylogue/storage/artifacts/persistence.py: adds materialize_artifact_observations_for_raw_ids(), a scoped sibling of the existing materialize_artifact_observations() full census, so an actuator that already knows exactly which raw ids it touched doesn't have to pay for a 43k-row census just to classify a handful of rows. - devtools/antigravity_phantom_sweep_report.py: read-only report CLI. - devtools/antigravity_phantom_purge_apply.py: --apply-gated actuator. Dry-run by default; --apply calls ArchiveStore.delete_sessions() on the flagged session ids (the same primitive CLI delete / MCP write(operation='delete_session') already reach -- rebuild-safe, since PR #3441's ingest-side classifier already refuses *.md.metadata.json as session content) and materialize_artifact_observations_for_raw_ids() on their raw ids (persists an explicit AGENT_SIDECAR_META classification). - Registered both as `devtools workspace antigravity-phantom-sweep` / `antigravity-phantom-purge-apply`, mirroring the binary-artifact-sweep pattern from polylogue-hbtj2 (PR #3576). Real .pb conversation acquisition: out of scope here, already done. PR #3441 (merged 2026-07-31) already built acquisition for conversations/*.pb -- not a raw protobuf parser, but calling Antigravity's own local language-server RPC (ConvertTrajectoryToMarkdown) to export each cascade to markdown, verified against 44 real files on the live machine (2,162 real messages, blob sizes matching on-disk .pb sizes). No new protobuf-format work was needed or attempted in this change; the only remaining step is operational (sinnix redeploy + reingest), not code. Verification devtools test tests/unit/storage/test_antigravity_phantom_sweep.py -> 5 passed (real parse_brain_metadata/parse_markdown_export fixtures, real ArchiveStore.write_raw_and_parsed writer; dry-run leaves the session untouched; --apply deletes only the tagged phantom and leaves a co-located real antigravity session and its raw row alone) devtools test tests/unit/devtools/test_command_catalog.py \ tests/unit/devtools/test_render_devtools_reference.py \ tests/unit/devtools/test_devtools_main.py -> 17 passed devtools verify --quick -> exit_code 0 (ruff format/check, mypy --strict, render all --check, topology, layering, closure-matrix, schema/manifest/policy lab checks) Not run: devtools verify --all (no seeded testmon db in this worktree; --quick plus the two focused pytest runs above are the verification evidence for this PR, per repo convention for a worktree without a pre-seeded testmon cache). Ref polylogue-eo81, polylogue-msia Co-Authored-By: Claude <[email protected]>
…sions (#3581) ## Summary Retroactive half of the antigravity-inversion finding (polylogue-eo81 / polylogue-msia, the same finding described in two beads): adds a read-only sweep and an `--apply`-gated actuator that delete the 116 already-materialized brain-metadata phantom sessions in the live archive and persist an explicit non-session classification for their raw rows. ## Problem Every `antigravity-session` row in the live archive (116/116, measured 2026-07-31) is a 1-message fragment materialized from a per-artifact `~/.gemini/antigravity/brain/<uuid>/*.md.metadata.json` sidecar -- metadata, not conversation content. Real conversation content lives in `conversations/*.pb` trajectories. Acquiring those `.pb` conversations was already fixed by PR #3441 (merged 2026-07-31): it calls Antigravity's own local language-server RPC (`ConvertTrajectoryToMarkdown`) to export each cascade to markdown -- not a raw protobuf parser, since the language server already exposes trajectory content over RPC -- and verified against all 44 real files on this machine (2,162 real messages, blob sizes matching on-disk `.pb` sizes). That PR also stopped classifying *future* metadata sidecars as sessions (`AGENT_SIDECAR_META`). That fix is forward-only. The 116 already-materialized phantom sessions, and their still-unclassified raw rows in `source.db`, are untouched by it -- PR #3441's own notes call this out explicitly as deliberately out of scope, deferred to a follow-up. This PR is that follow-up. ## Solution - `polylogue/storage/antigravity_phantom_sweep.py`: read-only `scan_antigravity_phantom_sessions()`. Joins `sessions` to `session_tags` on the existing `degraded:brain-metadata-fragment` auto-tag (written at ingest time by PR #1856) -- precise, already-present evidence, no new content classification needed. Cross-checks each candidate's `raw_id` against `source.db`'s `raw_sessions` row when a source connection is given, and reports (rather than assumes) when that raw row is already missing. - `polylogue/storage/artifacts/persistence.py`: adds `materialize_artifact_observations_for_raw_ids()`, a scoped sibling of the existing `materialize_artifact_observations()` full census (from polylogue-hbtj2 / PR #3576), so an actuator that already knows exactly which raw ids it touched doesn't pay for a 43k-row census just to classify a handful of rows. (Also fixes a latent bug in the new function: the connection needs `row_factory = sqlite3.Row` set before `_row_to_raw_session` can read columns by name -- caught by this PR's own test.) - `devtools/antigravity_phantom_sweep_report.py`: read-only report CLI (text or `--json`). - `devtools/antigravity_phantom_purge_apply.py`: `--apply`-gated actuator. Dry-run by default; `--apply` calls `ArchiveStore.delete_sessions()` on the flagged session ids (the same primitive CLI `delete` / MCP `write(operation='delete_session')` already reach -- rebuild-safe, since PR #3441's ingest-side classifier already refuses `*.md.metadata.json` as session content and won't resurrect them on re-ingest) and `materialize_artifact_observations_for_raw_ids()` on their raw ids (persists an explicit `AGENT_SIDECAR_META` classification). - Registered both as `devtools workspace antigravity-phantom-sweep` / `antigravity-phantom-purge-apply`, mirroring the binary-artifact-sweep pattern from polylogue-hbtj2. ## Real `.pb` conversation acquisition: already done, not attempted here Item 2 of both beads' AC ("decide and, if tractable, implement real `.pb` conversation acquisition") was already resolved by PR #3441 before this session started. No protobuf reverse-engineering was needed: the fix routes through Antigravity's own local language-server export RPC rather than parsing the wire format directly. The only remaining step is operational (Sinnix redeploy of the daemon + a reingest pass to acquire the 44 real conversations), not code -- confirmed still pending as of this PR (`raw_sessions` has zero rows referencing `antigravity/conversations` in the live archive checked during this session). ## Verification ``` devtools test tests/unit/storage/test_antigravity_phantom_sweep.py -> 5 passed ``` Builds the phantom shape through the real production parser (`parse_brain_metadata`) and the real archive writer (`ArchiveStore.write_raw_and_parsed`), plus a co-located real antigravity session (`parse_markdown_export`, no degraded flag) to prove the sweep and purge never touch it. Confirms: dry-run mutates nothing; `--apply` deletes only the tagged phantom, leaves the real session and its raw row alone, and writes exactly one `raw_artifacts` row with `artifact_kind = AGENT_SIDECAR_META` for the purged raw id. ``` devtools test tests/unit/devtools/test_command_catalog.py tests/unit/devtools/test_render_devtools_reference.py tests/unit/devtools/test_devtools_main.py -> 17 passed ``` ``` devtools verify --quick -> exit_code 0 (ruff format/check, mypy --strict, render all --check, topology, layering, closure-matrix, schema/manifest/policy lab checks) ``` Not run: `devtools verify --all` (no seeded testmon db in this worktree). `--quick` plus the two focused pytest runs above are the verification evidence for this PR. Manual, read-only cross-check against the live archive (`/realm/db/polylogue`, no writes): confirmed the exact shape both beads describe -- 116 `antigravity-session` rows, all `message_count=1`, all tagged `degraded:brain-metadata-fragment`, all `raw_sessions.source_path` ending `.md.metadata.json`, zero existing `raw_artifacts` rows for any of them, and zero `raw_sessions` rows referencing `antigravity/conversations` (the redeploy+reingest for PR #3441's fix has not happened yet). This PR's actuator was not run against the live archive -- per instruction, only built and tested against fixtures. Ref polylogue-eo81, polylogue-msia
Summary
Tightens the detection boundary so binary SQLite databases can never reach a session parser opportunistically. Adds a shared, magic-byte-based binary-format detector, fixes one extension-only detection bug, adds an explicit refusal at the single shared raw-bytes detection chokepoint, and ships a read-only sweep plus a separate
--apply-gated actuator to classify already-ingested miscaptures.Problem
The 2026-08-02 authority-dataflow audit (
/realm/data/derived/reports/polylogue-authority-dataflow-2026-08-02.html, "the residue, dissected") found ~450MB of SQLite databases sitting inraw_sessionsand misread as "genuinely diverged" session revisions by a byte-diff classifier that was never designed to reason about opaque binary snapshots: two Hermesstate.dbcopies (135MB each), oneverification_evidence.db, and Codexstate_5.sqlite(40MB). Operator directive: "we should be strict. don't try to opportunistically parse any file as session. ofc these should be handled, but these are not sessions."Live-archive verification against
/realm/db/polylogue(read-only) confirmed the exact rows the audit named: all sit atrevision_kind='unknown'/revision_authority='quarantined', meaning they were written by a path that never entered the governance vocabulary rather than a considered decision.Two concrete detection gaps caused this:
sources/live/batch_support.py's_parse_payload_as_session_artifactaccepted any.db/.sqlite/.sqlite3file under a Hermes-tagged source by bare extension match, never checking the actual bytes or schema — its path-based sibling function already did the correct content-verified check, this one didn't.JSONDecodeErrora binary blob happens to raise, with no explicit classification.Solution
polylogue/core/binary_signatures.py(new): single shared, provider-agnostic magic-byte registry (SQLite/PNG/gzip/JPEG/PDF). ZIP is deliberately excluded — ChatGPT/Claude-ai GDPR export bundles are legitimately zip-shaped sessions — but still detectable vialooks_like_zip_bytesfor reporting.sources/live/batch_support.py:_parse_payload_as_session_artifactnow requires the same content-verified Hermesstate.db/verification_evidence.dbschema check (looks_like_state_db_path/looks_like_verification_evidence_db_path, a real read-onlysqlite3connection + required-table check) its path-based sibling already uses, instead of a bare extension match.sources/dispatch.py:detect_provider_from_raw_bytes_evidence(the documented single shared raw-bytes detection chokepoint, used by production per-file acquisition and the unclaimed-file sweep) now positively refuses a recognized binary signature with explicit evidence, before any JSON decode attempt.archive/raw_payload/decode.py:build_raw_payload_envelope(its own docstring: "ingest_record calls this for every raw, including binary ones") now classifies an unrecognized binary-shaped payload asArtifactKind.BINARY_DATABASE/BINARY_DOCUMENT(parse_as_session=False,schema_eligible=False) with an explicit reason, instead of falling through to an incidental decode failure. This runs after the existing Hermes-marker check, so a genuine, content-verified Hermes state.db still wins.polylogue/storage/binary_artifact_sweep.py+devtools workspace binary-artifact-sweep(read-only) +devtools workspace binary-artifact-reclassify-apply(--apply-gated): mirrors theraw-live-source-reconciliationreport/apply split. The read-only report reusesinspect_raw_artifactas a pure function (no persistence) to classify everyraw_sessionsrow by content; the apply step calls the existing, testedmaterialize_artifact_observationsto persistraw_artifactsrows. Neither touchesrevision_authorityor deletes anything — see Verification below for what the apply step would do if run.Explicitly out of scope (flagged for an operator decision)
Hermes
state.db/verification_evidence.dbalready have a dedicated, content-verified, extensively tested session parser (sources/parsers/hermes_state.py/hermes_verification.py) whose output backs a real, shipped feature (fs1.14: ATIF/ATOF trajectory + verification-ledger topology projection,insights/hermes_topology_projection.py,insights/hermes_verification_coverage.py). Confirmed live: the two 135MBstate.dbraw rows and theverification_evidence.dbrow the audit found do haveparsed_at_msset, meaning this dedicated parser already ran on them and materialized derived "sessions" — this is the deliberate, working feature, not the miscapture.This PR tightens the detection boundary (no dedicated, content-verified parser claims a shape → refuse, classify as a binary artifact) without reversing that existing feature. It does not decide whether Hermes SQLite content should stop being represented as sessions at all (a literal reading of I11 in the audit report — "sessions hold conversations" — would require it, but reversing an entire shipped, cross-wired subsystem is a materially larger and riskier change than this bead's detection-strictness scope). That is a separate architectural question for the operator; the sweep below reports these rows informationally (
recognized_session_candidates) so the decision has the data behind it.Verification
devtools test tests/unit/core/test_binary_signatures.py tests/unit/core/test_raw_payload_decode.py tests/unit/sources/test_dispatch_evidence.py tests/unit/sources/test_live_batch_support.py— new regression tests pass (magic-byte refusal for both Hermes-tagged and Codex-tagged unrecognized SQLite payloads, plus a regression guard proving a genuine Hermes state.db still classifiesparse_as_session=True). 3 pre-existing failures intest_live_batch_support.py/test_dispatch_payloads.pyconfirmed unrelated viagit stash(fail identically on master).devtools verify --quick— green (ruff format/check, mypy, render all, topology, layering, classifier-fingerprints). One classifier-fingerprint drift was expected and explicitly acknowledged (devtools lab policy classifier-fingerprints --ack ... --reason ...):sqlite_snapshot.looks_like_sqlite_bytesnow delegates to the shared detector, byte-for-byte identical behavior, no semantic reparse.POLYLOGUE_ARCHIVE_ROOT=/realm/db/polylogue devtools workspace binary-artifact-sweep --json), run against the real archive at/realm/db/polylogue, strictly read-only: full-archive run (43,124 rows) is still completing in the background at PR-open time due to per-row SQLite-connect overhead; a manual SQL check againstraw_sessionsconfirmed the exact rows the audit named (2x Hermesstate.dbat 135,237,632 bytes each, 1xverification_evidence.db, Codexstate_5.sqlite/goals_1.sqlite/memories_1.sqlite, allrevision_kind='unknown'). The full sweep's aggregate counts/samples will be appended to this PR and to beadpolylogue-hbtj2's notes once it completes — the operator should use that output to decide whether/when to run--apply.Follow-ups
devtools workspace binary-artifact-reclassify-apply --applyagainst the live archive once the read-only sweep's findings are reviewed.Ref polylogue-hbtj2