Skip to content

fix(acquisition): make live cursors and source freshness content-aware #620

Closed

Description

@Sinity

Scope

Composite issue for live/source acquisition correctness: cursor semantics, source identity, truncation/rewrite handling, Drive diagnostics, and content freshness checks.

Problem

The current live/source freshness model relies too much on file metadata and reparsing whole files:

  • live cursor state records byte size/record count/update time, not byte offset, last complete newline, last record timestamp, or parser/schema fingerprint;
  • watcher ingestion reparses the whole file whenever size changes, then records the full size;
  • same-size rewrites can be skipped, shrink/truncate cases are ambiguous, and partial trailing lines are not handled as tailer state;
  • watcher source identity can come from parent directory names rather than provider names such as claude-code or codex;
  • Drive acquisition does not forward the same observation/progress diagnostics as local/zip streams;
  • source modified-time skips are content-blind and can miss same-mtime changes.

Already completed (#714 / fix(acquisition): harden live freshness and reparse writes)

  • Live cursor rows now store byte_offset, last_complete_newline, parser fingerprint, content fingerprint, source name, and optional last-record timestamp fields.
  • Old size-only cursor rows are migrated in place and reprocessed once to populate content/parser fingerprints.
  • The watcher skips only when byte size, content fingerprint, and parser fingerprint still match.
  • Same-size rewrite, truncate/rewrite, parser-fingerprint change, partial trailing-line cursor offset, append-after-partial-line, and stable watch-source identity are covered in tests/unit/sources/test_live_watcher.py.
  • Watcher source identity now comes from WatchSource.name instead of path.parent.name.
  • Drive raw acquisition now receives observation/progress callbacks through iter_drive_raw_stream() and iter_drive_raw_data().

Remaining acceptance criteria

  1. True incremental tail parsing: resume from the saved byte offset rather than full-file reparse after every size change. The cursor now has the metadata to support this; the watcher still reparses the whole file.
  2. Drive freshness content guards: Drive still skips by mtime only. Needs remote file ID/revision/modifiedTime plus size/hash or conservative fallback.
  3. Daemon/status models: cursor lag, backlog, last ingest, and error facts should be surfaced through daemon status consumable by CLI doctor, TUI, web UI, and browser extension state.
  4. polylogue watch retirement: remove only after polylogued owns equivalent live ingestion behavior and status (feat(surfaces): implement polylogued local reader and query-native CLI UX #717). Do not keep as an alias.
  5. Freshness target: aim for subsecond local ingestion under normal append-only JSONL conditions. Revisit debounce defaults (current 2s is probably too sluggish).

Service boundary

Live ingestion should be treated as daemon-owned infrastructure (polylogued run), not an interactive query CLI mode. The interactive polylogue CLI keeps one-shot archive/query/pipeline operations; long-running live ingestion belongs to the daemon alongside browser receiver and local web/API serving.

Design principle

The cursor invariant is replayability from the last complete, parser-valid boundary. A viable cursor says where ingestion can resume without duplicating, dropping, or accepting partial records, and when parser/schema changes invalidate that position. Size, mtime, and record count are diagnostics, not sufficient cursor identity.

Related

Ref #578

Activity

  1. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Additional integration from the 2026-05-01 audit: Drive acquisition should be part of this same cursor/diagnostics cleanup unless it proves too large.

    Evidence:

    • polylogue/pipeline/services/acquisition_streams.py:111-137 forwards observation_callback and progress_callback only to iter_source_raw_stream() for non-Drive sources.
    • iter_drive_raw_stream() at polylogue/pipeline/services/acquisition_streams.py:76-109 has no observation/progress parameters.
    • polylogue/sources/drive/__init__.py:229-234 also skips Drive files by modified time only.

    Acceptance refinement:

    • Drive acquisition should emit comparable observation/progress diagnostics where applicable, or explicitly document why Drive has a different diagnostic contract.
    • Drive freshness skipping should be reconciled with the size/hash/content-guard decision in this issue.
  2. changed the title [-]fix(live): replace size-cache ingestion with real cursors[/-] [+]fix(acquisition): make live cursors and source freshness content-aware[/+] on May 1, 2026
  3. added
    area:core
    on May 1, 2026
  4. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Cursor implementation guard: this should not become another metadata-only freshness heuristic with more fields.

    The important invariant is replayability from the last complete, parser-valid boundary. A viable cursor needs to say where ingestion can resume without duplicating, dropping, or accepting partial records, and when parser/schema changes invalidate that position. Size, mtime, and record count can remain diagnostics, but they are not sufficient cursor identity.

    Acceptance should include adversarial tests for append-after-partial-line, same-size rewrite, truncate-and-append, parser version/schema fingerprint change, and provider identity derived independently from the watched path. Drive/local/zip sources can have different mechanics, but the freshness decision should be content-aware or explicitly documented as a weaker source contract.

  5. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Implementation anchors and acceptance additions from the 2026-05-01 follow-up audit.

    Code anchors:

    • polylogue/sources/live/cursor.py:15-21: live_cursor stores only source_path, byte_size, record_count, and updated_at.
    • polylogue/sources/live/cursor.py:38-46: get() returns byte size only; set() stores byte size.
    • polylogue/sources/live/watcher.py:118-132: watcher skips when file size equals cursor size, reparses the whole file on growth, then stores the full size; source name is path.parent.name.
    • polylogue/pipeline/services/acquisition_streams.py:76-109: Drive stream has no observation/progress callback parameters.
    • polylogue/pipeline/services/acquisition_streams.py:123-137: non-Drive stream gets callbacks; Drive path does not.
    • polylogue/sources/drive/__init__.py:224-234: Drive freshness skip is modified-time based.

    Acceptance additions:

    • Live cursor stores a line-aligned byte offset, last complete newline offset, last record identity/timestamp where available, parser/schema fingerprint, and enough file identity to detect truncation/rewrite.
    • Watcher source identity is provider/source identity, not a parent-directory accident. For Claude/Codex, persist stable source/provider separately from path.
    • Tests cover partial trailing line, append after partial line, same-size rewrite, truncation/shrink, parser-fingerprint change, and renamed/moved source path.
    • Drive freshness uses remote file ID/revision/modifiedTime plus size/hash or conservative fallback; mtime-only skip is not enough.
    • Drive emits observation/progress diagnostics equivalent to local/zip acquisition, or the issue records a deliberate difference.

    Adjacent cleanup: polylogue/pipeline/watch.py:15-44 still defines WatchRunner, a polling loop around sync_fn() and time.sleep(interval). Either retire/adapt it here as “legacy polling abstraction must obey the live cursor contract,” or keep it linked to a small leaf issue if separate ownership is clearer.

  6. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Opened leaf issue #648 for the legacy polling uncertainty so #620 can keep the main cursor/freshness contract focused while still tracking whether that old abstraction should be retired or adapted.

  7. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Correction to the previous link note: #648 is specifically for the legacy polling WatchRunner abstraction in polylogue/pipeline/watch.py.

  8. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Live ingestion decisions from 2026-05-01 bundle

    Canonical live ingestion should be under ingest:

    polylogue ingest run ...
    polylogue ingest live ...
    polylogue ingest status ...
    

    Do not keep top-level polylogue watch as an alias after the rename.

    Freshness target:

    • Aim for subsecond local ingestion under normal append-only JSONL conditions.
    • Keep visible lag/status because filesystem events and parser backlog exist, but do not treat multi-second lag as acceptable by design.
    • Revisit debounce defaults; a 2s default is probably too sluggish for the desired product feel unless evidence says otherwise.

    Status should expose source/provider identity, source path as provenance, event time, parse time, commit time, event-to-commit lag, cursor offset, last complete newline/record, skipped partial trailing line count, and backlog/error state.

    Drive acquisition should get the same freshness/diagnostics contract now, not as a later optional polish pass.

    Ref #635

  9. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Integrated UX/service-boundary direction from the 2026-05-01 feedback pass.

    Live ingestion should be treated as daemon-owned infrastructure rather than an interactive query CLI mode. Target shape:

    polylogued run
    polylogued status
    

    polylogue watch should not remain the long-term surface once polylogued exists. The interactive polylogue CLI should keep one-shot archive/query/pipeline operations; long-running live ingestion belongs to the daemon alongside browser receiver and local web/API serving.

    Status models from live ingestion should be consumable by polylogue doctor, the local web UI, the TUI/dashboard, extension/popup status where relevant, and tests. Avoid separate semantics for CLI/web/TUI/MCP.

  10. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Integrated Polylogue MK2.zip design context where it affects live ingestion/daemon work.

    Relevant UX/status direction:

    • live ingestion should be a polylogued component, not a long-running interactive polylogue command;
    • daemon status should expose component health consumable by CLI doctor, TUI, web UI, and browser extension state;
    • local web/app status should be a consumer of the same DaemonStatus/component model rather than a separate status vocabulary;
    • cursor/source freshness fixes here should feed status rows that can show source lag, last ingest, cursor health, and FTS/read-model freshness.

    Already-landed context to avoid duplicate implementation:

    • polylogued watch / polylogued run slices have landed or are in flight from the daemon split work; this issue should focus on correctness of cursor/source freshness and status facts, not re-opening the command split.
  11. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Implementation slice opened as PR #714.

    What it covers:

    • live cursor rows now store byte_offset, last_complete_newline, parser fingerprint, content fingerprint, source name, and optional last-record timestamp fields;
    • old size-only cursor rows are migrated in place and reprocessed once to populate content/parser fingerprints;
    • the watcher skips only when byte size, content fingerprint, and parser fingerprint still match;
    • same-size rewrite, truncate/rewrite, parser-fingerprint change, partial trailing-line cursor offset, append-after-partial-line, and stable watch-source identity are covered in tests/unit/sources/test_live_watcher.py;
    • watcher source identity now comes from WatchSource.name instead of path.parent.name;
    • Drive raw acquisition now receives observation/progress callbacks through iter_drive_raw_stream() and iter_drive_raw_data().

    What remains in #620 after this PR:

    • true incremental tail parsing/replay from the saved offset rather than full-file reparse;
    • Drive freshness content guards beyond the existing mtime skip; this PR adds diagnostics but does not solve remote revision/hash freshness;
    • daemon/status models for cursor lag/backlog/last ingest facts.

    Verification recorded in the PR includes focused live/Drive/ingest tests and devtools verify --quick.

  12. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Surface ownership update from #717.

    #620 remains the source of truth for live cursor/source freshness facts: line-aligned offsets, parser/content fingerprints, partial-line handling, Drive diagnostics/freshness, lag/backlog/error facts, and provider/source identity.

    #717 should consume those facts through daemon/API/web/TUI/doctor status instead of redefining live-ingestion semantics. Command removal remains conditional: polylogue watch should disappear only after polylogued owns equivalent live ingestion behavior and status.

    Ref #717

  13. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    Closed by #762. Cursor now stores st_dev/st_ino/mtime_ns stat metadata. Failure quarantine with exponential backoff (max 1h). mark_failed on parse errors, reset_failures on success. 10 adversary tests cover same-size rewrite, truncation, partial-line append, parser fingerprint change, rename detection, and quarantine listing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:pipelinetype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions