Skip to content

Commons news outlives a crash: the cursor moves once subscribers hold it - #592

Merged
lydakis merged 1 commit into
mainfrom
claude/project-thread-0nccgi
Nov 1, 2026
Merged

lydakis merged 1 commit into
mainfrom
claude/project-thread-0nccgi

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Fixes the first item of #589 (from the #585 review, r4434606869): commons::news advanced read.json before the events it read reached any subscriber's held file (STORE.sources/.held/BOT.json), so a crash in between lost those posts.

What changes

  • commons::news returns a News (its lines plus the cursor it would write) and no longer writes the cursor. News::mark_read writes it with replace_mode (fsynced, atomic).
  • The commons source (sources::own) sends the lines, then sends Said::Kept(oneshot) and marks the news read only when the lookout answers yes. The source channel now carries Said::{Event, Kept}.
  • The lookout (Service::said) handles Kept by flushing every lookout's held file at once (not on the next tick) and answering through held::then once the writer thread is done.
  • The held writer keeps writes that failed and retries them with the next batch, unless a newer body replaced them. then answers false while any file is unwritten, so the cursor stays put during a disk failure.
  • Lookout::heard_from skips an event whose source and id it already holds (waiting, resent or on its way), so news read again after a crash is held once. Delivery is at least once. A duplicate can only happen if the process dies in the moment between the held write and the cursor write, after a note has already gone out.

Tests

  • commons_news_outlives_a_crash_at_every_step re-runs the test binary as a child (commons_crash_child), which runs the real commons source and Service::said, and calls std::process::abort() at four steps: read, in memory, on disk before the cursor, after the cursor. The parent then restarts a lookout from disk, reads the commons again and checks that each post is held exactly once. I checked that it fails on the old order: with the cursor written right after reading, the heard step loses both posts.
  • a_source_waits_for_what_lookouts_hold_to_be_written covers the answer, the dedupe, and a failed write answering false and then succeeding on retry.
  • news_not_marked_read_is_read_again is the commons-level unit test.
  • cargo test -p sonny: 851 + 2 + 24 passed. cargo clippy -p sonny --all-targets is clean and cargo fmt --check passes.

The docs (LOOKOUT.md, the commons paragraph) and the FEATURES.md sources row are updated. The protocol and schema are unchanged. The remaining #589 items (example scoping, shape writes off the runtime, exact integers) follow in a second PR.

The commons source advanced read.json before the events it read reached
any subscriber's held file, so a crash in between lost those posts
(#589, from the #585 review). news() now returns the lines and the
cursor it would write; the source sends them, asks the lookout whether
every subscriber holds them on disk, and marks them read only on yes.
The lookout writes what it holds at once for the question and answers
when the writer is done; the writer keeps failed writes and tries them
again, answering no while any is unwritten. Read again after a crash,
an event a subscriber already holds is not held twice.

Crash-injection tests abort a child process at four steps (read, in
memory, on disk before the cursor, after the cursor) and check that a
restarted lookout holds each post exactly once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGG8Kwbo2wyYcT9yURQ
@lydakis lydakis self-assigned this Nov 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 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-11-01T07:19:57.315542Z 763b1ee PR opened
🔒 Security Review ✅ Completed 2026-11-01T07:19:04.553356Z 763b1ee 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.

@lydakis
lydakis merged commit 471c416 into main Nov 1, 2026
10 checks passed
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.

2 participants