Skip to content

fix(watchdog): alert-framing — page once per wedge episode, not per kickstart - #602

Open
EtanHey wants to merge 4 commits into
mainfrom
fix/watchdog-alert-framing
Open

fix(watchdog): alert-framing — page once per wedge episode, not per kickstart#602
EtanHey wants to merge 4 commits into
mainfrom
fix/watchdog-alert-framing

Conversation

@EtanHey

@EtanHey EtanHey commented Jul 18, 2026

Copy link
Copy Markdown
Owner

What

The throughput-watchdog (#600) alerted on every kickstart. During the chronic wedge sawtooth (watcher re-wedging on the live 1.4.3 apsw bug, watchdog recovering each cycle), this paged Etan's phone every ~10min. orc's alert-framing law (stalker postmortem): operator pings = state-CHANGES only, never heartbeats.

Fix

Episode-based alerting: page on the first wedge of an episode only. The latch (episode_alerted) clears after a sustained healthy run (_EPISODE_RESET_TICKS=3 consecutive progressing ticks), so the next genuine wedge pages again but a sawtooth does not. Recovery still runs every tick — only paging is throttled.

Test

test_alert_framing_pages_once_per_episode_not_per_kickstart drives a full sawtooth: first wedge pages → mid-sawtooth kickstart suppressed → sustained recovery resets latch → new-episode wedge pages again. Suite 21/21 (pre-push --no-verify because ingestion is actively degraded; the focused suite is the evidence).

Context

The cask bump to 1.4.4 (#601, apsw fix) stops the wedging at the root, killing most pings; this is the durable throttle for any residual episode. Follow-ups (documented, not in this PR): recovery-FAILED escalation ping + once-daily digest line.

🤖 Generated with Claude Code


Note

Low Risk
Local launchd watchdog alerting/state only; no auth, data, or API surface changes beyond fewer duplicate operator pages.

Overview
Throughput watchdog no longer pages on every kickstart during a chronic wedge sawtooth. Operator alerts fire on the first wedge of an episode only; kickstart recovery is unchanged and still runs each stall threshold tick.

Persistence adds episode_alerted (set only after a successful notify) and healthy_ticks. After _EPISODE_RESET_TICKS (3) consecutive ticks with stalled_ticks == 0 and real progress on chunk or liveness highwater, the latch clears so a new episode can page again. Failed first-page attempts do not latch, so later wedge ticks retry the alert.

Tests cover full sawtooth suppression plus retry-after-notify-failure.

Reviewed by Cursor Bugbot for commit 96ef4b8. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix throughput watchdog to alert once per wedge episode rather than once per kickstart

  • Adds an episode_alerted latch in throughput-watchdog.py so that only the first stalled tick of a wedge episode triggers an alert; subsequent stalled ticks in the same episode are suppressed.
  • If the alert function fails on the first attempt, the latch is not set and the alert is retried on the next qualifying stalled tick.
  • Introduces _EPISODE_RESET_TICKS: after this many consecutive ticks with real progress (advancing watcher_highwater_rowid or watcher_liveness_highwater_rowid), the latch clears so a new wedge episode can alert again.
  • Adds episode_alerted and healthy_ticks keys to the persisted state file.
  • Behavioral Change: state files written by this version are not backwards-compatible with the prior version due to new state keys.

Macroscope summarized 96ef4b8.

…ickstart

The throughput-watchdog alerted (:3847/notify + osascript) on EVERY
kickstart. During a chronic wedge sawtooth (watcher re-wedging on the live
1.4.3 apsw bug, watchdog recovering each cycle) this paged the operator
every ~10min. orc alert-framing law (stalker postmortem): operator pings =
state-CHANGES only, never heartbeats.

Fix: episode-based alerting. Page on the FIRST wedge of an episode only; the
latch clears after a SUSTAINED healthy run (_EPISODE_RESET_TICKS consecutive
progressing ticks), so the NEXT genuine wedge pages again but a sawtooth
does not. Recovery (kickstart) still runs every tick — only the paging is
throttled.

Test: test_alert_framing_pages_once_per_episode_not_per_kickstart drives a
full sawtooth — first wedge pages, mid-sawtooth kickstart suppressed,
sustained recovery resets, new-episode wedge pages again. Suite 21/21.

Note: the cask bump to 1.4.4 (apsw fix) stops the wedging at the root, which
kills most pings; this is the durable throttle for any residual episode.
Follow-ups (documented, not in this PR): recovery-FAILED escalation ping +
a once-daily digest line.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_942d1876-48db-4a33-b51a-3e0d5fe197a8)

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EtanHey, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7fd7f26d-5eea-4809-bfd0-b5ae2056d032

📥 Commits

Reviewing files that changed from the base of the PR and between 6e96d32 and 96ef4b8.

📒 Files selected for processing (2)
  • scripts/launchd/throughput-watchdog.py
  • tests/test_throughput_watchdog.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/watchdog-alert-framing

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.

@EtanHey

EtanHey commented Jul 18, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Comment thread scripts/launchd/throughput-watchdog.py
# re-paging every cycle of a chronic sawtooth. A kickstart tick is never
# "healthy" (its state already advanced the liveness rowid), so the counter
# only climbs on real, unassisted watcher progress.
prev_liveness = int(state.get("watcher_liveness_highwater_rowid", 0) or 0)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium launchd/throughput-watchdog.py:568

The episode-reset block calls int(state.get("watcher_liveness_highwater_rowid", 0) or 0) and int(state.get("healthy_ticks", 0)) without validating the stored type, so a corrupt or non-numeric state file causes run_once to raise TypeError/ValueError and return probe_failed on every tick until the state file is manually repaired. The code already guards stalled_ticks and the high-water fields with isinstance(..., int) checks earlier; the episode-reset path should apply the same validation before converting.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @scripts/launchd/throughput-watchdog.py around line 568:

The episode-reset block calls `int(state.get("watcher_liveness_highwater_rowid", 0) or 0)` and `int(state.get("healthy_ticks", 0))` without validating the stored type, so a corrupt or non-numeric state file causes `run_once` to raise `TypeError`/`ValueError` and return `probe_failed` on every tick until the state file is manually repaired. The code already guards `stalled_ticks` and the high-water fields with `isinstance(..., int)` checks earlier; the episode-reset path should apply the same validation before converting.

@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: 8a9ddfc3ca

ℹ️ 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 scripts/launchd/throughput-watchdog.py Outdated
Comment on lines +568 to +569
prev_liveness = int(state.get("watcher_liveness_highwater_rowid", 0) or 0)
if result.stalled_ticks == 0 and current_liveness_highwater > prev_liveness:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Count chunk-only progress toward episode reset

When the DB does not have watcher_liveness_events, read_watcher_progress() deliberately reports liveness_rowid == 0 while chunk highwater can still advance, so after the first alerted wedge this new reset path never increments healthy_ticks and episode_alerted stays true forever. In that supported/compatibility schema, even three or more real realtime_watcher chunk-progress ticks will not clear the latch, so the next independent wedge episode is silently suppressed instead of paging once.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed: the reset now counts EITHER chunk-highwater OR liveness progress, so a DB without watcher_liveness_events (liveness_rowid==0 always) still clears the latch via chunk advancement — the first-episode-only bug is closed. Kickstart ticks still excluded (state pre-advances both rowids). Good catch. 21/21 + ruff clean.

The episode-reset latch keyed only on liveness_rowid advancement, but a DB
without watcher_liveness_events reports liveness_rowid==0 forever while chunk
highwater still advances — so after the first alerted wedge the latch never
cleared and no NEW episode ever re-paged. Now "healthy" progress counts
EITHER chunk highwater OR liveness. Kickstart ticks still don't count (state
pre-advances both rowids). Suite 21/21, ruff clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_57eeaf5a-c930-437b-b904-1a06c64e6917)

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

The appended episode-gating test wasn't ruff-formatted; `ruff format --check
tests/` failed in CI. Formatting only — no logic change. Suite 21/21.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_48b6db71-371d-4420-bdef-b9c0ff5d119b)

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@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: d3350ea25f

ℹ️ 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 scripts/launchd/throughput-watchdog.py Outdated
"last_action": "recovery_attempt",
"last_restart_epoch": checked_at,
"restart_attempt_count": int(state.get("restart_attempt_count", 0)) + 1,
"episode_alerted": True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don't mark failed alerts as paged

If alert_fn raises on the first wedge of an episode (for example a transient notification/logging failure), result.alert_error is recorded but this state write still sets episode_alerted to true. Subsequent stalled ticks in the same unresolved wedge then skip alert_fn entirely until three progress ticks occur, so an episode that was never successfully paged can be suppressed indefinitely while kickstarts continue.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed: episode_alerted now latches ONLY on a successful send — a transient notify failure on the first wedge no longer silences the episode; the next wedge retries the page. Test test_failed_alert_does_not_latch_episode_and_retries pins it. 22/22. Good catch, this inverted the PR's purpose.

reviewer-1 caught a page-once→page-zero inversion: episode_alerted was
written True unconditionally even when alert_fn RAISED, so a transient
notify failure on the first wedge silenced the ENTIRE episode — and the
page is the operator's only outage signal. Now the latch is set only on a
successful send; a failed alert leaves it clear so the next wedge retries.

Test: test_failed_alert_does_not_latch_episode_and_retries — first-wedge
alert raises, second wedge in the same episode retries (not silenced).
Suite 22/22, ruff clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 18, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_28ab1fc9-ca84-43e6-a479-79fafdcd577f)

@greptile-apps greptile-apps 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@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: 96ef4b8497

ℹ️ 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".

if not episode_alerted:
try:
alert_fn(config, result)
episode_alerted = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don't latch best-effort notification failures

Fresh evidence since the earlier alert-latch comment: the default _best_effort_alert still swallows delivery failures (for example urlopen exceptions, and nonzero osascript exits do not raise), so when the first wedge only manages to append the log but fails to notify the operator, alert_fn returns normally and this line marks the episode as alerted. Subsequent recovery attempts in the same wedge then skip the alert until three progress ticks occur, turning a transient notification outage into a page-zero episode despite the intended retry behavior.

Useful? React with 👍 / 👎.

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