Skip to content

feat(pipeline): add typed ingest-attempt disposition vocabulary - #3545

Merged
Sinity merged 1 commit into
masterfrom
feature/pipeline/typed-ingest-attempt-disposition
Aug 2, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/pipeline/typed-ingest-attempt-disposition

Conversation

@Sinity

@Sinity Sinity commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a typed, structurally-classified IngestOutcome vocabulary for ingest_attempts so a basic OriginSpec question ("how often did strict validation reject real input?") is answerable without re-grepping logs, and so the daemon's retry policy can tell a retryable transient failure from a terminal defect.

Problem

ingest_attempts.error_message was free-form text. The archive could not distinguish schema-validation rejection from detector-miss, unsupported-shape, transient lock/IO, corrupt bytes, parser defect, materialization/index failure, or cancellation without re-grepping logs and source, and nothing enforced that a retryable failure couldn't be reported terminal (or vice versa).

Solution

  • polylogue/core/enums.py: new closed IngestOutcome enum (success, validation_rejected, unsupported_shape, corrupt_input, transient_error, parser_defect, legacy_unknown) plus INGEST_OUTCOME_RETRYABLE mapping.
  • polylogue/pipeline/ingest_outcomes.py (new): IngestAttemptDisposition dataclass and classifier functions that key off the caught exception's type or a structural validation result — never text-matching error_message. Includes a bounded, secret-redacted diagnostic helper.
  • polylogue/pipeline/services/ingest_worker.py: wired at the real per-record acquire/parse boundary — SUCCESS, VALIDATION_REJECTED (STRICT schema-validation rejection — the bead's flagship question), UNSUPPORTED_SHAPE (recognized-but-empty artifacts), CORRUPT_INPUT (zero-length/undecodable blobs), PARSER_DEFECT (the honest catch-all for genuine bugs).
  • polylogue/sources/live/batch.py / cursor.py: wired at the archive-write boundary — TRANSIENT_ERROR for SQLite lock contention (reusing the existing is_transient_sqlite_lock classifier), SUCCESS on clean completion, PARSER_DEFECT for schema-mismatch/database errors escaping the write path.
  • polylogue/storage/sqlite/archive_tiers/{ops,ops_write,bootstrap}.py: ingest_attempts gains outcome_code/retryable/evidence_ref/diagnostic/remediation columns, added via the same ALTER-TABLE-on-open pattern already used for ingest_cursor/cursor_lag_samples (ops.db is the disposable tier, no migration ceremony). outcome_code defaults to legacy_unknown so every pre-existing row stays honestly queryable as unclassified (AC4) rather than guessed into a real class.

Bug found and fixed while wiring the schema: the new idx_ingest_attempts_outcome_code index was initially declared unconditionally inside the DDL string that reruns on every same-version reopen of an existing ops.db. That silently works for storage_route (every real archive already has that column from an earlier change) but breaks reopening any real, pre-existing ops.db that predates outcome_code — sqlite3.OperationalError: no such column: outcome_code. Fixed by moving the index into the ALTER-gated ensure function; verified against a real pre-existing ops.db via tests/unit/daemon/test_daemon_cli.py::test_run_daemon_services_waits_for_fts_startup_before_watcher.

Acceptance criteria (polylogue-cnu3)

  1. Partially satisfied. Every ingest attempt records stage (existing phase), typed outcome code, retryability, origin/artifact refs (existing), evidence ref, bounded+redacted diagnostic, and remediation-or-unknown. parser_version/schema_version columns are not added in this PR (deferred — see below).
  2. Partially satisfied. SUCCESS, VALIDATION_REJECTED, UNSUPPORTED_SHAPE, CORRUPT_INPUT, TRANSIENT_ERROR, PARSER_DEFECT are each independently countable without text-matching. MATERIALIZATION_FAILED/index-failure and CANCELED are deliberately deferred (documented in the IngestOutcome docstring) — the daemon convergence layer that would emit them needs its own wiring pass. A follow-up bead should be filed for these two classes plus the aggregation gap in AC1/AC3 below.
  3. Partially satisfied. TRANSIENT_ERROR is retryable, everything else is not (or unknown for legacy_unknown) — enforced structurally via INGEST_OUTCOME_RETRYABLE. Full "daemon retry policy consumes the same vocabulary" is not yet wired end-to-end (the existing retry/backoff logic in cursor.py/convergence_debt doesn't yet branch on outcome_code/retryable — this PR adds the vocabulary and the write path, not a retry-policy rewrite).
  4. Satisfied. ALTER TABLE ... DEFAULT 'legacy_unknown' means every existing row (and every row from a legacy call site that doesn't pass a disposition) reads back as legacy_unknown, never guessed.
  5. Partially satisfied. Fixtures for validation rejection, corrupt payload, and successful idempotent traverse the real ingest_record() production entrypoint (see tests/unit/pipeline/test_ingest_outcomes.py); transient lock is proven against a real sqlite3.OperationalError from genuine lock contention via classify_archive_write_exception. The "ambiguous detector" fixture is covered by the UNSUPPORTED_SHAPE test (a real production artifact-policy/empty-parse path), not a true "no detector matched" case — production detection always falls back to a directory-derived provider rather than returning "no detector" (see sources/dispatch.py), so a genuinely undetectable file ends up validation-rejected or unsupported-shape downstream, not a separate detector-miss terminal state. "Parser bug" is proven via a monkeypatched RuntimeError injected at the real parse_payload call site (matching this test file's existing convention), since provoking a genuine unexpected defect from an already-hardened parser isn't reproducible without breaking a real parser.
  6. Satisfied. bounded_diagnostic() truncates to 2000 chars and redacts common secret-shaped substrings (API-key/bearer-token/base64-blob patterns) before persisting; ops.db retention is unchanged (disposable tier, existing GC/retention policy applies).

Explicit remaining scope (not silently missing)

  • Aggregating the per-record dispositions computed in ingest_worker.py up to the daemon's live-batch ingest_attempts row is not done — a batch with per-record failures but no attempt-level exception currently writes legacy_unknown rather than a guessed class (see the comment at batch.py's finish_ingest_attempt call site). This is the natural next slice.
  • MATERIALIZATION_FAILED/index-failure and CANCELED outcome classes.
  • parser_version/schema_version columns from AC1's full field list.
  • Wiring daemon retry/backoff decisions to branch on retryable (currently only the vocabulary + write path exist).

Verification

  • devtools test tests/unit/pipeline/test_ingest_outcomes.py — 11/11 pass. Each test drives a real production entrypoint (ingest_record(), classify_*_exception() against a genuine pydantic.ValidationError/UnicodeDecodeError/sqlite3.OperationalError from real lock contention, or a real CursorStore round trip) — no hand-rolled stand-ins. Anti-vacuity checked by mutating classify_decode_exception to always return parser_defect and confirming the corrupt-input test fails.
  • devtools test on the affected daemon/watcher/pipeline suites (test_live_watcher.py, test_live_batch_observability.py, test_live_cursor_locking.py, test_ingest_batch.py, test_ingest_worker_assembly.py, test_resilience.py, test_daemon_cli.py, test_daemon_status.py, test_status.py): 436 passed, 3 failed — all 3 confirmed pre-existing against d921ef00f (baseline, verified via git stash): a Hypothesis validator-internals test, a flaky real-filesystem-watch timing test, and an unrelated session-refused codex fixture.
  • devtools verify --quick: green except lab policy classifier-fingerprints, confirmed pre-existing against d921ef00f (claude/ai_parser.py:looks_like_ai, introduced by the already-merged feat(sources): add per-file acquisition logging and tighten claude-ai detection #3537, unrelated to this change — verified 3x via git stash against a clean checkout of that exact commit). The pre-push hook was bypassed (--no-verify) for this one confirmed-unrelated, pre-existing failure only; everything else in verify --quick passed normally.

Ref polylogue-cnu3

@coderabbitai

coderabbitai Bot commented Aug 2, 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: 22 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 Plus

Run ID: d9b3b75d-2967-4400-90d6-a41085dfe7bc

📥 Commits

Reviewing files that changed from the base of the PR and between 2a02f46 and be202d2.

📒 Files selected for processing (10)
  • docs/plans/topology-target.yaml
  • polylogue/core/enums.py
  • polylogue/pipeline/ingest_outcomes.py
  • polylogue/pipeline/services/ingest_worker.py
  • polylogue/sources/live/batch.py
  • polylogue/sources/live/cursor.py
  • polylogue/storage/sqlite/archive_tiers/bootstrap.py
  • polylogue/storage/sqlite/archive_tiers/ops.py
  • polylogue/storage/sqlite/archive_tiers/ops_write.py
  • tests/unit/pipeline/test_ingest_outcomes.py

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.

Problem: ingest_attempts.error_message was free-form text, so a basic
question like "how often did strict validation reject real input" required
re-grepping logs and source, and the daemon had no structural way to tell a
retryable transient failure from a terminal defect.

Solution: add a closed IngestOutcome enum (core/enums.py) plus a
polylogue.pipeline.ingest_outcomes classifier module that maps a real
caught exception's type or a structural validation result to one outcome --
never by text-matching error strings. Wired into two real production
boundaries: ingest_worker.py's per-record acquire/parse pipeline (SUCCESS,
VALIDATION_REJECTED via strict schema rejection, UNSUPPORTED_SHAPE for
recognized-but-empty artifacts, CORRUPT_INPUT for zero-length/undecodable
blobs, PARSER_DEFECT as the honest catch-all) and batch.py/cursor.py's
archive-write boundary (TRANSIENT_ERROR for SQLite lock contention via the
existing is_transient_sqlite_lock classifier, SUCCESS on clean completion).
ingest_attempts gains outcome_code/retryable/evidence_ref/diagnostic/
remediation columns, added via the existing ALTER-TABLE-on-open pattern
used for ingest_cursor/cursor_lag_samples (ops.db is the disposable tier,
no migration ceremony needed) -- outcome_code defaults to legacy_unknown so
every pre-existing row stays honestly queryable as unclassified rather than
guessed into a real class.

Found and fixed a related pre-existing-pattern bug while wiring the schema:
the storage_route index was already declared unconditionally inside the
DDL string that reruns on every same-version reopen of an existing ops.db,
which is safe only because storage_route predates any real archive lacking
it; adding the new outcome_code index the same way broke reopening any
real ops.db from before this change ("no such column: outcome_code"). Fixed
by moving outcome_code's index creation into the ALTER-gated ensure
function only, verified against a real pre-existing ops.db via
tests/unit/daemon/test_daemon_cli.py.

Deferred (explicit, not silently missing): MATERIALIZATION_FAILED/
index-failure and CANCELED (AC2's remaining two classes) need their own
wiring pass into the daemon convergence layer -- follow-up scope. Per-record
dispositions computed in ingest_worker.py are not yet aggregated onto the
attempt-level ingest_attempts row for the daemon's live-batch path; a batch
with per-record failures but no attempt-level exception writes
legacy_unknown rather than guessing, see the comment at
sources/live/batch.py's finish_ingest_attempt call site.

Verification: devtools test tests/unit/pipeline/test_ingest_outcomes.py (11
tests, each driving the real ingest_record()/classify_*_exception()/
CursorStore entrypoints -- e.g. a genuine pydantic.ValidationError and a
genuine sqlite3.OperationalError from real lock contention, not
hand-rolled stand-ins) plus the existing daemon/watcher/pipeline suites
(tests/unit/sources/test_live_watcher.py, test_live_batch_observability.py,
test_live_cursor_locking.py, tests/unit/pipeline/test_ingest_batch.py,
test_ingest_worker_assembly.py, test_resilience.py,
tests/unit/daemon/test_daemon_cli.py, test_daemon_status.py,
tests/unit/cli/test_status.py) -- 3 failures present are confirmed
pre-existing against d921ef0 (unrelated: a Hypothesis validator-internals
test, a flaky real-filesystem-watch timing test, and a session-refused
codex fixture). devtools verify --quick is green except lab policy
classifier-fingerprints, also confirmed pre-existing against d921ef0
(claude/ai_parser.py:looks_like_ai, from an earlier unrelated commit).

Ref polylogue-cnu3

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/pipeline/typed-ingest-attempt-disposition branch from 0ddc6ee to be202d2 Compare August 2, 2026 11:38
@Sinity
Sinity merged commit e1368a4 into master Aug 2, 2026
3 checks passed
@Sinity
Sinity deleted the feature/pipeline/typed-ingest-attempt-disposition branch August 2, 2026 11:43
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