Skip to content

fix(server): end every remote run, and make TUI modes and writes explicit - #205

Merged
sweepies merged 4 commits into
mainfrom
fix/server-cli-state
Nov 9, 2026
Merged

sweepies merged 4 commits into
mainfrom
fix/server-cli-state

Conversation

@sweepies

@sweepies sweepies commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Second PR that replaces implicit state machines with explicit ones (after #204).

Changes

  • Remote runs always finish. The job's outcome was written only after runner.run(...).await returned, so a panic left the job Running forever. That blocked the user with job-running, counted toward MAX_JOBS, and kept the CLI polling with no deadline. The run is now wrapped in catch_unwind, a panic becomes Failed, and finished: Option<i64> is folded into the terminal states, so the two can no longer disagree.
  • Writes are staged. Plan::write writes every new file beside its original, copying permissions and resolving symlinks, before renaming any of them into place. A staging failure leaves the tree untouched. A rename that fails partway returns a WriteError naming the files already written. The TUI used to say "Nothing was written" after a partial write; it now says what happened and refreshes its working-tree view.
  • TUI Mode (Browse, Searching, Help, ConfirmApply, ConfirmCopier(i), Copier(i)) replaces searching, confirming, confirming_template, copier and help. Pick (Open, Selected, Applied) replaces selected + applied.
  • Cron sweep: a token probe that fails after the sweep was queued no longer queues the sweep again 60 s later.
  • /readyz now has a comment explaining why webhooks and remote runs check only accepting: deliveries are queued while the server is unready, because rejecting them would lose them.

Tests

New tests cover a panicking runner (the run fails and the user can start another) and a staged write that can't stage every file (nothing written, no temporary files left behind). The patchula-server and patchula-cli suites pass, and Clippy is clean.

View guided diff Turn on auto-fix

…icit

- A remote run whose runner panicked stayed Running for good: it blocked
  its user with job-running, counted toward the job cap and kept the CLI
  polling. The run's outcome is now recorded on every exit, a panic
  included, and its end time is part of the terminal state.
- Writing updates stages every file beside the original before renaming
  any into place. A staging failure writes nothing; a failed rename names
  the files already written. The TUI no longer says "Nothing was written"
  after a partial write, and refreshes its working-tree view.
- The TUI's search, help, apply and copier prompts are one Mode, and an
  update's selected/applied flags are one Pick, so no two can overlap.
- A failed token probe after the cron sweep was queued no longer queues the
  sweep again a minute later.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 6384610 Commit Preview URL

Branch Preview URL
Nov 08 2026, 09:41 PM

… place

Review findings on #205:
- A start request dropped between recording its job and spawning its task
  left the job Running for good. The task lock is now taken first, so the
  record and the spawn happen with no await between them.
- A runner that panicked while building its future escaped catch_unwind;
  it is now called inside the caught future.
- An engine whose run panicked was reused by later batches and runs; its
  slot is now emptied so the next run builds a fresh one.
- Staging files beside their originals and renaming them changed owners,
  ACLs and hard links, made read-only files writable, failed in read-only
  directories, could leave or clobber temporary files, and collided when two
  paths named one file. Files are now opened for writing first (any refusal
  writes nothing, a second path to the same file is refused) and written in
  place; a failure while writing names the written and partly written files.
- A key pressed while a confirmed copier run waits no longer cancels it.
…s one file

Second-pass review findings on #205:
- Plan::write held every file open until all were written, so a plan
  touching more files than the open-file limit (256 by default on macOS)
  could never be written. Files are now checked by opening and closing
  each, then written one at a time.
- Two hard links to one file were both written, the second erasing the
  first; on Unix the device and inode now decide what is the same file.
- A remote run started as shutdown began could spawn after drain took the
  tasks and escape it; accepting is checked again under the tasks lock.
The write phase reopened each file by path, so a file replaced between
the check and the write (renamed away, swapped for a symlink, a pipe or
another file) was written instead. Each file must be a regular file, and
the reopened file's device and inode must match what was checked, or the
write stops before touching it.
@sweepies
sweepies merged commit 2e9742b into main Nov 9, 2026
11 checks passed
@sweepies
sweepies deleted the fix/server-cli-state branch November 9, 2026 01:01
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 9, 2026
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