Train AU: bounded shutdown, no writes after it (#664) #669

Closed
kayg wants to merge 0 commits from train/2026-10-22au into dev
Owner

Train AU ran the full suite at 467a35f (run au1): fmt, clippy, workspace tests, the build, svelte-check, every Playwright project: admin 43, cr1440 313, cr390 251+195, wk1440 136+176+1, wk390 147+182+120, small 19. The one failure (pill-room.spec:309 webkit-1440, a web layout test; this train changes no web code) passed 3/3 on rerun.

Contents (#664): shutdown is deterministic and bounded, and nothing writes to a Home after it. One Drain at every way into storage (executor, Notes::enter, Home); idle/half-sent admin and slow HTTP clients bounded by shared graces; cancelled startup scans release their waiters; finished task handles reaped; retired rooms joined; root locks held until process exit; late work refused at every write point; startup waits max grace + drain + settle (40 s, derived in grace.rs), with a clear error if another live server holds the Home.

Independent review: three rounds (do not merge -> do not merge -> merge with fixes -> merge). Final verdict on 690f394: merge. Edit path not slower (p95 0.96 vs 1.57 ms on a 10k-note Home, directional).

Still open on #664: the whole storage_startup test binary occasionally hits WouldBlock (2/40 before, 3/40 after; 0/400 alone) - likely a test-harness race; follow-up.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk

Train AU ran the full suite at 467a35f (run au1): fmt, clippy, workspace tests, the build, svelte-check, every Playwright project: admin 43, cr1440 313, cr390 251+195, wk1440 136+176+1, wk390 147+182+120, small 19. The one failure (pill-room.spec:309 webkit-1440, a web layout test; this train changes no web code) passed 3/3 on rerun. Contents (#664): shutdown is deterministic and bounded, and nothing writes to a Home after it. One Drain at every way into storage (executor, Notes::enter, Home); idle/half-sent admin and slow HTTP clients bounded by shared graces; cancelled startup scans release their waiters; finished task handles reaped; retired rooms joined; root locks held until process exit; late work refused at every write point; startup waits max grace + drain + settle (40 s, derived in grace.rs), with a clear error if another live server holds the Home. Independent review: three rounds (do not merge -> do not merge -> merge with fixes -> merge). Final verdict on 690f394: merge. Edit path not slower (p95 0.96 vs 1.57 ms on a 10k-note Home, directional). Still open on #664: the whole storage_startup test binary occasionally hits WouldBlock (2/40 before, 3/40 after; 0/400 alone) - likely a test-harness race; follow-up. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
# Conflicts:
#	crates/calternal/src/main.rs
Shutdown waits used watch::changed(), which misses a shutdown sent
before the receiver was made, so a late task (a poller set up during
shutdown, a rename queued by the final flush, an admin request accepted
as the stop was sent) waited out its own timer. One helper, stopped(),
now backs every such wait, and the admin socket uses the same rule.

Home shutdown also releases startup-discovery waiters for good
(ScanState::release), so nothing waits on a scan that will never end,
and joins background work again after rooms save, before the writers
close. Finished background handles are reaped through one helper.

Tests: late shutdown waits, released scan waiters, a portable admin
idle-client test, and a wider randomized shutdown property test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
A restart during a long admin request or a stalled download could fail
on the 10 s lock wait while the old server was still inside its 30 s
grace. The graces now live in one place (grace.rs) and the startup wait
is derived from them: the longest grace plus 5 s of closing work. Past
that, a lock still held belongs to a live server and startup fails
clearly as before.

The graces now start together: the admin stop is sent with the HTTP
stop instead of after HTTP drains, and an admin reply written after
shutdown began shares its request's deadline rather than adding 30 s.

Tests (paused clock): a restart during a 12 s admin request starts as
soon as the old server lets go, and a lock held past the wait still
fails with WouldBlock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Review of ce1cf6c: work already running at shutdown could still write
after Notes::shutdown returned and the locks were dropped. A create
paused before its file write landed the file afterwards, and a held
Home opened a new room on request.

Now one rule holds at every entry: work is admitted through a Drain
(calternal-core) that shutdown closes and waits on.
- Engine::execute runs inside the executor's Drain; the detached task
  keeps it open. main closes it at the shutdown signal, within the
  longest grace, so websocket actions axum does not wait for are covered.
- Every Notes operation (and room join) enters through Notes::enter;
  Notes::shutdown first tells Homes to stop (scan waits end), then
  closes the drain (5 s bound), then shuts the Homes.
- A Home refuses new rooms once shutdown takes them, refuses background
  work after its last join, and joins rooms that retired on their own
  but were still saving.

Also: Idle::touch no longer locks or wakes the timer on every lookup,
and the startup error after the full wait says another server is
running rather than the previous one.

Tests: the review's two repros as permanent tests, no background work
after shutdown, the executor drain, and the Drain itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Re-review of d4225a8: work that outlived shutdown's bounded waits
could still write after the locks dropped. A create paused past the
Notes drain landed its file, and an action held past the executor
drain committed to the journal.

- The server no longer releases the root locks itself: they are held
  until the process ends, so the kernel lets go only after every
  thread, the blocking pool included, has stopped. In-process tests use
  shutdown_server_and_release.
- Write points refuse late work as well. A Drain now records when it
  gave up; the executor then refuses to commit (actions and progress
  batches). A Home closes for writes once shutdown has joined everything
  (place_create, room save/trash/rename, Trash file work, bulk removes),
  and the note list stores turn read-only at their final checkpoint.
- STARTUP_LOCK_WAIT now also counts the Notes drain:
  LONGEST + NOTES_DRAIN + SETTLE (40 s), all derived.

Tests: both re-review repros as permanent tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5oTUycqAh7DT72mdSUztk
Merge commit '690f394a5f' into train/2026-10-22au
Some checks failed
CI / server (pull_request) Successful in 37s
CI / web (pull_request) Failing after 53s
CI / rust (pull_request) Failing after 3m42s
467a35f09a
Author
Owner

Closing: this PR's head commit is already in dev (checked 26 Oct, against dev a779a46). The train landed it by merging directly into dev.

Closing: this PR's head commit is already in `dev` (checked 26 Oct, against dev `a779a46`). The train landed it by merging directly into dev.
kayg closed this pull request 2026-10-26 11:18:05 +00:00
Some checks failed
CI / server (pull_request) Successful in 37s
CI / web (pull_request) Failing after 53s
CI / rust (pull_request) Failing after 3m42s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!669
No description provided.