Repository navigation
feat(drive): add JSON-structural revision-diff classifier for Drive re-acquisition - #3687
Conversation
Problem: iter_drive_raw_data's live-attachment backfill re-serializes the whole Gemini/AI-Studio JSON document on each re-acquisition pass, so a genuinely-grown conversation is never a byte-prefix superset of its predecessor (confirmed by PR #3656/polylogue-sp72). The existing byte-prefix revision classifier can only ever see this shape as ambiguous. Solution: classify_drive_structural_relation compares two JSON documents structurally -- new dict keys, trailing list growth, and null-to-populated values are treated as growth; any changed/removed existing value is not. Pure function, no SQLite/archive coupling. Ref polylogue-1fijp
Growth cases (trailing list append, dict-key enrichment, null->populated, combinations, and a fixture built through the real production fetch_live_drive_attachment_bytes injector) and ambiguous cases (scalar mutation, removed/reordered elements, unrelated documents, non-JSON bytes). Ref polylogue-1fijp
Problem: _bind_drive_revision_lineage only ever proved lineage via the byte-prefix classifier (classify_raw_revision_cohort_for_live_watch), so a Drive re-acquisition whose bytes structurally grew via the live-attachment backfill's whole-document re-serialization still landed revision_authority='quarantined' with no predecessor_raw_id -- the polylogue-1fijp AC (b) gap PR #3656 deferred. Solution: _drive_structural_growth_predecessor looks for exactly one existing 'full' sibling raw for the logical_source_key that is a JSON- structural predecessor of the new raw's bytes. A unique match is bound directly as a FULL/ASSERTED revision with a real predecessor_raw_id (ASSERTED, not BYTE_PROVEN -- the proof is structural, not byte-level, and that vocabulary distinction is deliberate per raw_admission.py's existing arms). Zero or multiple matches fall through unchanged to the existing byte-prefix quarantine-then-classify path -- strictly additive, no existing behavior narrowed. Updated test_iter_drive_raw_data_two_revision_fixture_gets_real_lineage (polylogue-sp72's own end-to-end fixture through the real _write_session production path) to assert the now-typed predecessor link instead of the documented residual gap it previously proved. Ref polylogue-1fijp
|
Warning Review limit reached
Next review available in: 39 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. 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 (4)
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 |
Summary
Adds a JSON-structural growth classifier for Drive/Gemini re-acquisition bytes and wires it into
_bind_drive_revision_lineageso a genuine Drive re-acquisition growth (the live-attachment-backfill shape, not a byte-append) gets typed, predecessor-linked lineage instead of falling straight through to the byte-prefix classifier's ambiguous/quarantined outcome. This satisfies polylogue-1fijp AC (b) ("drive re-acquire with changed bytes produces typed lineage, not quarantined-unknown"), which PR #3668 explicitly left unattempted and PR #3656 explicitly deferred.Problem
iter_drive_raw_data's live-attachment backfill (_inject_live_drive_attachment_bytes) re-serializes the WHOLE Gemini/AI-Studio JSON document on every re-acquisition pass that resolves a Drive-hosted attachment reference, rather than byte-appending at the document's end. PR #3656 (polylogue-sp72) proved this concretely with a real fixture threaded through the production write path (test_iter_drive_raw_data_two_revision_fixture_gets_real_lineage): the second raw's bytes are not a byte-prefix superset of the first's (not second_bytes.startswith(first_bytes)), so the archive's existing byte-prefix revision classifier (classify_historical_full_revision_streams,archive/revision_authority.py) landsrevision_authority='quarantined'with nopredecessor_raw_idfor this exact, realistic shape — even though the underlying conversation genuinely only grew.Solution
polylogue/sources/drive/structural_diff.py:classify_drive_structural_relation(old_bytes, new_bytes)decodes both payloads as JSON and proves whethernewis a structural extension ofold— every dict key/value and list elementoldasserts is still present, unchanged, innew; new dict keys, new trailing list elements (a conversation growing achunkedPrompt.chunksentry), and null-to-populated values are allowed growth. Any changed or removed existing value breaks the proof and the relation isAMBIGUOUS— the same fail-closed posture as the byte-prefix classifier it complements, proven a different way. Pure function, no SQLite/archive coupling.polylogue/pipeline/services/ingest_batch/_core.py:_bind_drive_revision_lineagenow tries_drive_structural_growth_predecessorfirst — it looks for exactly one existingrevision_kind='full'sibling raw for the logical source key whose bytes are a proven structural predecessor of the new raw's bytes. A unique match is bound directly as aFULL/ASSERTEDrevision with a realpredecessor_raw_idandbaseline_raw_id(ASSERTED, notBYTE_PROVEN— the proof is JSON-structural, not byte-level, and that vocabulary distinction is deliberate:BYTE_PROVENis reserved for thebytes.startswith()relation elsewhere inarchive/revision_authority.py/storage/sqlite/archive_tiers/raw_admission.py). Zero or multiple structural matches fall through unchanged to the existing byte-prefix quarantine-then-classify dance — strictly additive, no existing behavior narrowed.test_iter_drive_raw_data_two_revision_fixture_gets_real_lineage(PR fix(drive): let proven revision lineage bypass Drive freshness tie-break #3656's own end-to-end fixture, through the real_write_sessionproduction path) to assert the now-typed predecessor link instead of the documented residual gap it previously proved.tests/unit/sources/test_drive_structural_diff.py: 15 focused tests on the classifier's semantics directly — trailing-append growth, dict-enrichment growth, combined growth, null→populated growth, new top-level keys, and the ambiguous/rejection cases (scalar mutation, removed/reordered elements, unrelated documents, non-JSON bytes, populated→null regression) — including one fixture built through the real productionfetch_live_drive_attachment_bytesinjector (not a hand-rolled approximation) and a two-generation sequential-fetch fixture.Scope / what's not attempted
Per the bead's own fallback guidance, this is a scoped, real, well-tested slice, not the full raw-admission-chokepoint migration:
_bind_drive_revision_lineageadapter function — it does not touch the shared_classify_raw_revision_cohort/classify_historical_full_revision_streamsbyte-prefix machinery used by every other origin's live-watch/rebuild-repair paths. That shared function's blast radius (every provider, both live-watch and rebuild-repair callers) made it too risky to modify for a Drive-only concern in this pass.admit_raw_observation()(PR feat(storage): add raw-admission chokepoint mechanism + atomic-read contract #3668's chokepoint) — it continues to use thebind_raw_revision/classify_raw_revision_cohort_for_live_watchadapter path, now with the structural pre-check inserted ahead of it. Full chokepoint migration for Drive remains open scope on polylogue-1fijp.aistudio-driveraw pairs mentioned in PR fix(drive): let proven revision lineage bypass Drive freshness tie-break #3656 need a live re-measure/backfill after deploy — not attempted here (retroactive durable-tier cleanup needs its own explicit-consent process per this repo's schema regime).Verification
mypy --strict polylogue/sources/drive/structural_diff.py polylogue/pipeline/services/ingest_batch/_core.py tests/unit/sources/test_drive_structural_diff.py tests/unit/sources/test_drive_ops.py—Success: no issues found in 4 source files.devtools test tests/unit/sources/test_drive_structural_diff.py tests/unit/sources/test_drive_ops.py tests/unit/pipeline/test_ingest_batch.py— 89 passed.devtools test -k "drive or revision_governance or raw_admission"— 308 passed, 1 failed (tests/integration/test_blob_lifecycle_e2e.py::TestOrphanedBlobsCatalogRouting::test_catalog_resolution_drives_end_to_end_cleanup), confirmed pre-existing/unrelated: reproduces identically on a clean checkout with no changes applied (same failure PR fix(drive): let proven revision lineage bypass Drive freshness tie-break #3656 already documented as pre-existing).devtools verify --quick—exit_code: 0.Ref polylogue-1fijp
Co-Authored-By: Claude [email protected]