Skip to content

Run the read action in its own process so a hung imsg-read cannot stall polling (#125 item 2) - #171

Merged
nixfred merged 1 commit into
mainfrom
fix/125-read-action-off-poll-path
Nov 24, 2026
Merged

nixfred merged 1 commit into
mainfrom
fix/125-read-action-off-poll-path

Conversation

@nixfred

@nixfred nixfred commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Refs #125 (item 2). Does not close it: that is the maintainer's call after review.

Problem

collect() called runReadAction (spawnSync, 180 s timeout) inline, at collector.ts 2809 and 2810 on main. One hung imsg-read held the collector process for up to three minutes, and every poll, toast and refresh queued behind it in BarWidget.

Change

  • The due read intent is started by startReadAction in a detached collector.ts --read-worker process, and the poll returns.
  • The collector writes read-action.json first, so only one action runs at a time. That also keeps Messages' process-global selection to one user.
  • The worker only adds done to that file. The collector stays the sole writer of state.json, and folds the result in (settleReadAction) on the poll that started the action or on a later one.
  • The starting poll waits up to BLIP_READ_GRACE_MS (default 5 s), so the common 1 to 3 s action still reports its outcome in the same poll, as before. A hung one now delays one poll by that much instead of three minutes.
  • Kept from the old design: the attempt is persisted BEFORE the action starts, a failed intent is never dropped, an unattempted --all is still never repeated.
  • New: backoff is counted from when the action ended. A worker silent past 190 s counts as a failure and the intent is kept. A result for an intent a newer gesture replaced is ignored.
  • CLAUDE.md invariant amended: "Never detach it" becomes "detached from the poll, never from its acknowledgement", with the reason.

Tests

  • A hung imsg-read no longer holds up polling. Mutation check: restoring the blocking wait makes it fail (the harness kills the run at 10 s).
  • Polls while it hangs start nothing else and keep the intent. The result is picked up by the next poll.
  • A failure that ends after the poll left is kept with its error.
  • Unit cases for settleReadAction and parseReadAction, and for the grace parsing.
  • bun test: 944 pass, 1 fail. The failure is audio-waveform.test.ts, which needs ffmpeg and fails on main too (known exception). The existing 36 read-sync tests pass unchanged.

Not done

  • I did not run the QtTest/Python UI suites or deploy. BarWidget and QML are untouched, so those suites should not be affected, but CI is the check.
  • Not tried against a real gateway Mac. The worker uses the same runReadAction and imsg-read call as before.

Not merged, and not pushed to main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BXN1v5rSKpVomPJvPhZCng

…t stall polling (#125 item 2)

WHAT: collect() used to call runReadAction (spawnSync, 180 s timeout) inline, so
one hung Mac call held the collector process for up to three minutes and every
poll, toast and refresh queued behind it in BarWidget. The due read intent is now
started by startReadAction in a detached `collector.ts --read-worker` process.
The collector writes read-action.json first (one action at a time, which also
keeps Messages' process-global selection to one user), the worker only adds
`done` to it, and the collector stays the SOLE writer of state.json, folding the
result in with settleReadAction on the poll that started it or a later one.
The starting poll waits up to BLIP_READ_GRACE_MS (default 5 s) so the common
1 to 3 s action still reports its outcome in the same poll, as before.

WHY: #125 item 2. The attempt is still persisted BEFORE the action starts, a
failed intent is never dropped, backoff is counted from when the action ended,
a worker silent past 190 s counts as a failure, and a result for an intent a
newer gesture replaced is ignored.

TESTS: a hung imsg-read no longer holds up polling (mutation: restoring the
blocking wait makes it fail), later polls start nothing while it runs, its
result is picked up by the next poll, a failure that ends after the poll left
is kept with its error, settleReadAction unit cases, grace parsing. bun test:
944 pass, 1 fail (audio-waveform, needs ffmpeg, fails on main too).
CLAUDE.md invariant amended: detached from the poll, never from its acknowledgement.

LR-T: blip, read-sync, collector, worker, hung-imsg-read
LR-D: blip
LR-K: issue-125-item-2, read-action-worker, settleReadAction
LR-L: law-9, law-10

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BXN1v5rSKpVomPJvPhZCng
@nixfred
nixfred merged commit 1c7a88b into main Nov 24, 2026
1 check passed
@nixfred
nixfred deleted the fix/125-read-action-off-poll-path branch November 24, 2026 20:54
nixfred added a commit that referenced this pull request Nov 25, 2026
… or suspended worker, one writer per file)

WHAT: Follow-up to #171 from a fresh-context review, before it goes back on main.
- The finished action is settled at the TOP of collect(), and a "*" still running
  is no longer expanded. Reproduced: a mark-all slower than the 5 s grace was
  split into per-chat intents by the next poll, which then ran a --chat for a
  conversation --all had already read, bringing Messages forward on the Mac.
- The marker records the worker's pid and /proc start time. A live worker is
  running however old the clock says it is; a dead one fails on the next poll
  instead of blocking every read action for 190 s (or longer after a clock set
  back).
- One writer per file: the worker reports into read-action.json.<token>.done and
  never rewrites the marker, so an old worker cannot overwrite a newer one.
- A result must match the attempt count as well as unread and seen.
- state.json is saved BEFORE the marker is removed.
- Pin/unpin/mute/unmute are refused at once while a worker runs, instead of
  waiting 60 s on the Mac's Messages lock and then failing.

NOT CHANGED: an intent queued behind a slow action still starts on the next poll
rather than the moment the action ends. Written down in CLAUDE.md.

TESTS: bun test 951 pass, 1 skip, 1 fail (audio-waveform, no ffmpeg here).
Each fix has a test that fails when the fix is removed (4 mutations).
Not tried against a real gateway Mac.

LR-T: blip, read-sync, collector, worker, review-findings
LR-D: blip
LR-K: read-action-worker, expandFailedMarkAll, pid-liveness, issue-125-item-2
LR-L: law-9, law-10

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BXN1v5rSKpVomPJvPhZCng
nixfred added a commit that referenced this pull request Nov 25, 2026
WHAT: Weekly contributor notes for the three changes landed today, with what was
verified, and the open X-handle question for Nick (@k7cfo).

LR-T: blip, weekly-notes, contributors
LR-D: blip
LR-K: w48, k7cfo, ianswope

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BXN1v5rSKpVomPJvPhZCng
@nixfred

nixfred commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

For the record, because this page says "merged" and for a day main did not contain it.

This was merged on 24 Nov at 17:06 UTC. At 20:54 UTC main was force-pushed back to the commit before it. The likely cause is a repository mirror that force-pushes main; the timing and its settings point there, though its logs show nothing for that minute.

It is back on main as of 25 Nov, together with 06334fd, which fixes what an independent review found in this first version:

  • A mark-all still running was treated as a failed one, so the next poll split it into per-chat reads and opened conversations on the Mac that --all had already covered. Reproduced, then fixed.
  • A worker that died blocked every read action for 190 s, longer after a clock change. The marker now records the process, so it is noticed on the next poll, and a suspended machine cannot start a second copy.
  • The worker and the collector each write their own file, so an old result cannot overwrite a newer action.
  • Pin and mute now say the Mac is busy instead of waiting 60 s and failing.

Accepted and not changed: a read queued behind a slow one starts on the next poll. bun test 951 pass, 1 fail (needs ffmpeg locally; CI is green). Each fix has a test that fails without it.


Generated by Claude Code

nixfred added a commit that referenced this pull request Nov 25, 2026
WHAT: GitHub and the Forgejo backup are pushed by hand and compared. The forced
push mirror between them was removed on 2026-11-25 after it erased the #171 merge.

LR-T: blip, remotes, forgejo, mirror
LR-D: blip
LR-K: push-both
LR-L: law-11

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BXN1v5rSKpVomPJvPhZCng
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