Skip to content

fix(daemon): Stop publishing cursor-lag health from a read that failed - #5398

Merged
Sinity merged 1 commit into
masterfrom
fix/budgeted-status-snapshots
Sep 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/budgeted-status-snapshots

Conversation

@Sinity

@Sinity Sinity commented Sep 22, 2026

Copy link
Copy Markdown
Owner

Summary

polylogue-20d.17 AC3/AC9. cursor_lag_summary_info swallowed every sqlite3.Error and returned a bare CursorLagSummary() — byte-identical to a quiet, caught-up archive. Three consumers turned that fabricated zero into a positive health claim.

All four children (20d.17.1–.4) were already satisfied at base; the tracker was stale. Nothing was reimplemented.

The defect — AC9 verbatim

The module comment admitted the swallow and answered it with a log line. But the log is for the operator; the return value is what the surfaces consume:

  • evaluate_cursor_lag derives its family set from the projection. With no families it reported no breach and fired an OK resolution alert — "cursor lag cleared" — for every family that was breaching at the last successful read. Asserted from a read that never happened.
  • _check_cursor_lag's is_ok = not any(severity != OK) then published cursor_lag healthy for a database it could not open.
  • format_daemon_status_lines only prints on a positive count, so an unreadable ledger rendered as no line at all.

CursorLagSummary now carries available / unavailable_reason, following the existing LiveCursorSummary precedent rather than inventing a shape. The marker is deliberately narrow: an absent database or relation is a measured empty ledger; only a read that raised is unavailable.

Both readers now fail closed by raising _CursorLedgerReadError, which also retires their two sqlite_degradation anchors rather than re-anchoring them — the census exempts handlers that raise. The manifest's other route, capture_sqlite_read, was tried and backed out: polylogue/daemon may not import polylogue/storage/tier_access, and adding that edge grew the layering ratchet.

The two unlanded batch commits: superseded, nothing extracted

I asked this lane to salvage two commits from a 09-20 batch that never landed. It diffed both mechanically:

  • 8590e3e91 — 101/101 added lines already present at base, verbatim, including comment text.
  • 0f6603f78 — 81/83 present.

The two absent lines are tier_count_unavailable = any(...) and "ok": _status_ok(...) and not tier_count_unavailable. They are absent because #5353 improved on them: tier_count_unavailable became a module-level function whose result is an operand of the single overall_status_ok producer. That inline composition was precisely the second verdict rule 20d.17.1 exists to eliminate — copying it back would have reintroduced the bug.

They also did not fold unknowns into booleans (planner_stats_present: None if rows is None else rows > 0 is a correct tri-state). They were right-headed; #5353 built on them. Nothing cherry-picked.

Anti-vacuity — five mutations

mutation observed
index read error → bare projection assert True is False … stuck_file_count=0
ops read error → "no evidence" same, no index tier to fall back to
remove the evaluate_cursor_lag guard assert [OK] == [WARNING] — the fabricated resolution returns
_UNMEASURED = CursorLagSummary() assert stale.cursor_lag.available is False → assert True is False
delete the renderer branch assert any("Cursor lag: UNMEASURED") → assert False

Both directions pinned: test_measured_empty_cursor_ledger_stays_available and test_a_readable_recovered_ledger_still_clears_its_alert stay green under every mutation.

One test was refuted and rebuilt: it first failed at its fresh assertion because a lambda **_: double rejected the production spec's positional call — fixed, then it separated red/green on the intended assertion.

Verification

devtools test <7 modules>     exit 0, 231 passed, git_dirty: false
devtools verify --quick       exit 0, 25/25
devtools render all --check   exit 0, 'out of sync' 0
devtools schema closure       all four production files 'out'

Derived identity identical at base and HEAD (INDEX ce86c236…, OPS 86866235…) — the earlier INDEX movement was upstream's. Metadata-only; safe to land during a rebuild.

Residuals

  • open_readonly_connection raises SchemaSkewError, not sqlite3.Error, so a schema-skewed ops tier propagates out to the registry collector. That is a typed refusal reaching the right place, but no test pins it.
  • AC1/AC11 (wholesale daemon/status.py deletion + deletion ledger) stay open on an operator decision — the file has grown, and every landed slice has been additive hardening.
  • Operational: a SIGKILLed devtools test (exit 137, pytest_no_report, pool ~20 deep) strands an index.lock in the worktree gitdir, blocking git add hours later.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy

… no lag

`cursor_lag_summary_info` swallowed every `sqlite3.Error` and returned a bare
`CursorLagSummary()`. That projection is byte-identical to the one a quiet,
fully caught-up archive produces, so a read that failed published "0 stuck,
0 degraded, 0 idle, worst lag 0s" to every consumer. The module's own comment
admitted this and answered it with a log line -- but the log is for the
operator and the *return value* is what the status and health surfaces
consume.

Three consumers turned that fabricated zero into a positive claim:

- `evaluate_cursor_lag` derives its family set from the projection. With no
  families it reported no breach *and* fired an OK resolution alert for every
  family that was breaching at the last successful read -- "cursor lag
  cleared", asserted from a read that never happened. `_check_cursor_lag`'s
  `is_ok = not any(severity != OK)` then published cursor_lag healthy for a
  database it could not open. That is AC9 verbatim.
- `evaluate_cursor_lag_anomaly` fabricated the same resolutions.
- `format_daemon_status_lines` only prints when a count is positive, so an
  unreadable ledger rendered as no line at all -- identical to a quiet one.

`CursorLagSummary` now carries `available` / `unavailable_reason`, the same
pair `LiveCursorSummary` already had, and the marker is narrow: an absent
database or absent relation is a *measured* empty ledger, only a read that
raised is unavailable. `_UNMEASURED_CURSOR_LAG` carries it too, so `_v`'s
stale substitute is no longer indistinguishable from a measured quiet
archive -- the residual #5353 recorded and left open.

Both readers now fail closed by raising `_CursorLedgerReadError` instead of
returning a fabricated projection. That is also what retires their two
`sqlite_degradation` anchors rather than re-anchoring them: the census
exempts handlers that raise, and the baseline drops both in this change as
its manifest instructs. `polylogue.storage.tier_access` was the other route
and is not available -- daemon may not import it, and adding that edge would
grow the layering ratchet.

Anti-vacuity, all five mutations executed and restored:
- index read error -> bare projection: `assert True is False` on `available`
- ops read error -> "no evidence": same, with no index tier to fall back to
- remove the `evaluate_cursor_lag` guard: `[OK] != [WARNING]`, the fabricated
  resolution reappears
- `_UNMEASURED_CURSOR_LAG = CursorLagSummary()`: stale build's `available` is
  True with a measured quiet archive's zeros
- delete the renderer branch: no cursor-lag line for an unreadable ledger
Both directions pinned: a measured empty ledger stays `available`, and a
genuine recovery still clears its alert.

Verification (worktree /realm/worktrees/status-budgets, base bb65bc6):
- devtools test (7 modules) -- 231 passed, 0 failed, exit 0
- devtools verify --quick -- exit 0, 25/25 gates, 0 FAILED
- devtools render all --check -- exit 0, `grep -c "out of sync"` = 0
- devtools schema closure: all four changed production files `out`

Advances polylogue-20d.17 AC3 and AC9.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01ToWqpkXotr573DiQex5vcy
@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 40 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: f0dead29-8a9b-4b0b-a0ac-43d9b714705f

📥 Commits

Reviewing files that changed from the base of the PR and between eb54a24 and 4a0a7da.

📒 Files selected for processing (8)
  • docs/plans/sqlite-degradation-baseline.json
  • polylogue/daemon/cursor_lag_alert.py
  • polylogue/daemon/cursor_lag_anomaly.py
  • polylogue/daemon/cursor_lag_status.py
  • polylogue/daemon/status.py
  • tests/unit/daemon/test_cursor_lag_alert.py
  • tests/unit/daemon/test_cursor_lag_status.py
  • tests/unit/daemon/test_status_unmeasured.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.

@Sinity
Sinity enabled auto-merge (squash) September 22, 2026 06:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T06:59:40.431551Z 4a0a7da PR opened
🔒 Security Review ✅ Completed 2026-09-22T06:57:52.579158Z 4a0a7da PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a0a7da157

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/daemon/status.py Resolved
Comment thread polylogue/daemon/cursor_lag_status.py Resolved
Comment thread polylogue/daemon/cursor_lag_alert.py Resolved
@Sinity
Sinity merged commit a9fa338 into master Sep 22, 2026
3 checks passed
@Sinity
Sinity deleted the fix/budgeted-status-snapshots branch September 22, 2026 07:04
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

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