Repository navigation
fix(installer): cancel jobs during initial persistence - #291
oldwinter53 merged 1 commit into
Conversation
There was a problem hiding this comment.
Approve with nits (1 P3)
Scope: base main, merge base 8d02fe8c; 2 commits, 3 files (apps/linger-installer/AGENTS.md, src/server/jobs.ts, src/server/jobs-start-cancel.test.ts) reviewed at a3dd31d9. Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.
Findings
P3
shutdown() rethrows an initial-write failure that start() already reported (apps/linger-installer/src/server/jobs.ts:565)
- The drain loop deliberately swallows
record.startingrejections ("start() reports a failed initial write to its caller"), butcancel()also awaitsrecord.starting, so the same storage error comes back throughcancellationsandshutdown()throws it at the end. The new testshutdown still cancels and drains other jobs when an initial input save failsasserts this. - Failure scenario: SIGTERM,
/api/stop, or/api/retirearrives while a job's<id>.input.jsonwrite is in flight, and that write fails (disk full or permissions). The HTTP caller ofstart()already gets the error. Thenclose()inserver.ts:656throws atawait jobs.shutdown(), so it skipscloseRuntimeLogins(), thelaunch.html/session.jsoncleanup,lock.close()andresolveClosed(). Because every caller runs it asvoid close(), the process exits on an unhandled rejection instead of shutting down cleanly. The storage failure is the cause, but here it has already been reported once. - Fix: in
shutdown(), ignore a rejected cancellation when its record's start failed. For example, check!this.records.has(record.job.id)after draining, or letcancel()swallowrecord.starting's rejection the same way the drain does. Keep rethrowing persist failures for jobs that still exist. Then update the test to expect a clean shutdown.
Verified as fine
start()setsrecord.startingsynchronously right afterrecords.set, so a concurrentcancel(),busy,shutdown()or deduplicatedstart()always sees it. Noawaitfalls between clearingstartinginfinally, thecancelRequestedcheck, andexecuting = true, so a cancel can't slip in between.- Microtask order:
start()registers onrecord.startingbefore anycancel()orwait(), sorecord.taskis set beforewait()reads it, andcancel()persists afterstart()has decided not to execute. emit()skips persisting whilestartingis set. During that window onlycancel()emits, and it awaitsstartingbefore callingpersist()again. So a failed input write leaves no orphan<id>.json, andpersist()never reads a deleted record. A cancel captured after the first snapshot is saved by the extra persist.- A double cancel during
startingreturns at once, because the job is no longeractive.retry()on a starting job awaits the cancel and then creates a fresh job. The waiting-user replacement path (replacedawaited insidestarting) is unchanged. shutdown()now usesPromise.allSettled, so one failing cancel no longer stops the other jobs from being cancelled and drained.- The six regression tests use real private-file writes and control the storage call with promises. They don't rely on timing sleeps;
setImmediate()is used only as a yield before negative assertions. Putting them in a separate file withvi.mock("./storage.js")keeps the mock away from the existing job tests. - The installer
AGENTS.mdrecords the new invariant. No contract, env or cross-app import changes, and nothing added to the user-message →provider_readypath.
Process notes
a3dd31d9 fix(installer): persist late queued cancellation and drain all shutdown taskspatches code added by5acdc8dein this same PR (await (record.starting ?? this.persist(id))→await record.starting; await this.persist(id), and the sequential shutdown loop). Squash it into the first commit (git rebase -i --autosquash) before the rebase merge.- The branch is up to date with
mainand has no merge commits. Both commits are linked toAfloat16.
CI
All checks that ran pass: check (installer), check (web), changes, repository-gate. The other checks were skipped by path selection. I ran no tests locally; the conclusions above come from reading the code.
Automated review by Claude Code
Automated review of a3dd31d by Claude Code.
There was a problem hiding this comment.
Approve (0 findings)
Scope: follow-up on a3dd31d, reviewing 574f87b against main (merge base 8d02fe8). 3 commits and 3 files reviewed (apps/linger-installer/{AGENTS.md, src/server/jobs.ts, src/server/jobs-start-cancel.test.ts}); the new-change pass covered only a3dd31d..574f87b. Helper skills coderbook, ponytail-review and karpathy-guidelines were not loaded separately; their review criteria were applied from the review procedure. Ran in a separate session.
Previous findings
- P3
jobs.ts:565shutdown rethrows the initial-write failure thatstartalready reported: Resolved.shutdown()(apps/linger-installer/src/server/jobs.ts:566-571) now rethrows a rejected cancellation only when its record is still inthis.records.start()deletes the record when the initial save fails (jobs.ts:354) and rethrows the error to its own caller, so shutdown no longer reports that error a second time andserver.ts:656can continue its cleanup. The test now expectsundefinedin that case (jobs-start-cancel.test.ts, "shutdown drains other jobs without repeating an input error reported by start"). The old code would fail that assertion.
Findings
None.
Verified as fine
- Retained-job failures still propagate. If the final save of a late cancellation fails, the record stays in
this.recordsand shutdown rethrows the error. This is covered by the new test "shutdown still reports a failed cancellation save for a retained job", which also checks that the runner never ran and that a later start recovers. running[index]lines up withcancellationsbecause both arrays come from the samerunninglist. Records are removed only on a failed start, and IDs come fromrandomUUID, so a new record cannot reuse a deleted ID and get its error swallowed by mistake.- Shutdown still waits for every tracked task and for
this.writesbefore it reports anything. The ordering does not change. AGENTS.mdnow states the new invariant: start reports an initial input-save failure, and storage failures for retained jobs still propagate.- No CJK in added lines or commit messages. No merge commits.
Process notes
a3dd31dand574f87bonly patch behaviour that5acdc8dintroduced in this same PR. Becausemaintakes rebase merges, squash them into the first commit (git rebase -i --autosquash) somaingets one coherent fix.- Merge state is BLOCKED while checks are pending.
CI
changes and check (web) pass. check (installer) and repository-gate are still pending, and the other checks are skipped as not applicable. I ran vitest run src/server/jobs-start-cancel.test.ts src/server/jobs.test.ts in apps/linger-installer myself: 2 files, 36 tests, all passed.
Automated review by Claude Code
Automated review of 574f87b by Claude Code.
|
Thanks for the fix and thorough tests! Everything looks good to merge, except there are now merge conflicts with main. Could you please rebase onto the latest main and resolve the conflicts (and squash into a single commit if convenient)? Once CI passes, we'll get this merged. |
There was a problem hiding this comment.
Approve (0 P0, 0 P1, 0 P2, 0 P3)
Scope: follow-up on 574f87b. The head under review is the same commit, 574f87ba7b3f094e31a46a84dbe76cae8eeedd6e. Base main, merge base 8d02fe8c, 3 commits, 3 files (apps/linger-installer/AGENTS.md, src/server/jobs.ts, src/server/jobs-start-cancel.test.ts). Loaded coderbook only; ponytail-review and karpathy-guidelines weren't loaded because no code changed. Ran in a separate session.
Previous findings
The previous review of 574f87b had no findings, so there is nothing to track.
Findings
None. git diff 574f87b..HEAD is empty, so no new code has arrived since the previous review.
Verified as fine
- No code changed since the previously approved review.
- No CJK characters in added lines or in any commit message.
- No merge commits and no fixup or "address review" commits in
8d02fe8c..HEAD. - All three commits link to the GitHub account
Afloat16.
Process notes
- Rebase needed. GitHub reports the merge state as
DIRTY.git merge-treeagainstorigin/mainshows a content conflict inapps/linger-installer/AGENTS.md, caused byc6679e0c fix(installer): cancel pending native sign-in startsonmain, which also adds lines to that file. Rebase ontomain, keep both sets of invariant bullets, and re-runmake check-installer.
CI
All required checks pass: check (installer), check (web), changes, repository-gate. The other checks were skipped by path selection. I ran no tests locally.
Automated review by Claude Code
Automated review of 574f87b by Claude Code.
574f87b to
ecca61c
Compare
There was a problem hiding this comment.
Approve (0 findings)
Scope: follow-up on 574f87b. Base main, merge base 13cb493d (current origin/main tip, so the branch is up to date). 1 commit and 3 files reviewed (apps/linger-installer/AGENTS.md, src/server/jobs.ts, src/server/jobs-start-cancel.test.ts). Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.
Previous findings
The previous review (574f87b) had no findings. Nothing to carry over.
Findings
None.
Verified as fine
- Since the last review, the PR's three commits were squashed into
ecca61cand rebased onto13cb493d.574f87bis no longer an ancestor, so a directgit diff 574f87b..HEADmostly shows unrelatedmainchanges. I compared the PR's own diff against each merge base instead (8d02fe8..574f87bvs13cb493..ecca61c, limited toapps/linger-installer). They match exactly. The only difference is AGENTS.md hunk context: the new paragraph now comes after the runtime-login inspection paragraph thatmainadded in the meantime, and both paragraphs are kept. jobs.tsdoesn't touch the newly merged runtime-login code (runtime-login.ts). The rebase introduces no interaction or conflict.- The earlier analysis still holds:
startingmakes the job count as busy and blocksexecutewhencancelRequestedis set.appendEventdoesn't publish a snapshot before the private input is durable.cancelwaits forstartingand then persists the final state.shutdowncancels and drains both starting and executing jobs. It swallows only an initial-save error for a record thatstart()already removed, and it rethrows persistence failures for retained jobs.waitwaits for bothstartingandtask.
- Commit subject follows the conventional format. No CJK in the added lines or in the commit message.
Process notes
- The fixup commits from the previous round are now squashed into one commit, rebased on the current
main. Nothing to act on.
CI
check (installer), check (web), changes and repository-gate pass. The other checks were skipped because their paths are unaffected. I re-ran no tests, since the installer code is unchanged from the previously reviewed head and CI's installer check covers the test file.
Automated review by Claude Code
Automated review of ecca61c by Claude Code.
oldwinter53
left a comment
There was a problem hiding this comment.
Thanks for rebasing and squashing cleanly onto main! Verified that tracking record.starting, guarding busy/initial persistence cancellation, and draining pending writes in shutdown() close the startup persistence races cleanly with green CI. Adding to the merge queue.
There was a problem hiding this comment.
Approve (0 findings)
Scope: follow-up on ecca61c. The reviewed head is the same commit, so nothing changed since the previous review. Base main, merge base 13cb493d, 1 commit, 3 files (apps/linger-installer/AGENTS.md, src/server/jobs.ts, src/server/jobs-start-cancel.test.ts). Loaded ponytail-review. I did not load coderbook or karpathy-guidelines because there was no new diff to apply them to. The review ran in a separate session.
Previous findings
The previous review of ecca61c approved the PR with no findings, so there is nothing to track.
Findings
None.
Verified as fine
- No code changed since the previous review: the head SHA is
ecca61c4150b2795e4d1f574953992aaf4c3bfa1in both reviews. - I re-read the
jobs.tsdiff:startingis set before the firstawait, sobusy,cancel,shutdownandwaitall see a job whose initial save is still in progress.finallyclearsstarting.- A cancel during the initial save skips
execute(). cancel()waits forstartingbefore the finalpersist, so the canceled state is saved after the input file exists.shutdown()ignores the initial-write error thatstart()already reports to its caller, and still throws cancel failures for jobs it keeps.
- Event persistence is held back while
startingis set, so a failed input write leaves no orphan public job. - The installer
AGENTS.mddocuments the new invariant. - Added lines and the commit message contain no CJK characters.
- There are no merge or fixup commits.
Process notes
- The branch is 1 commit behind
mainand needs a rebase before merge. The newmaincommit isad63af00, which touchespackages/local-installation/src/private-files.ts.git merge-treeshows it merges cleanly.
CI
Passing: check (installer), check (web), changes and repository-gate. The other app checks were skipped because their paths are unaffected. I ran no tests locally because nothing changed since the previous review.
Automated review by Claude Code
Automated review of ecca61c by Claude Code.
What and why
A job becomes visible as
queuedbefore its initial private input and snapshot finish saving. Cancelling in that window marks it canceled, butstart()then launches the installation anyway.shutdown()andwait()also ignored that initial save, so they could return before the queued job started.Cancellation could additionally persist a public job before its private input existed. If the input save failed, this left an incomplete record and raced the persistence queue against deletion of the in-memory job.
Track the initial save as part of the job's lifetime. Treat it as busy, skip execution if cancellation was requested, and drain it during shutdown and wait. Cancellation during that save is included in the initial durable snapshot, after the input file is safely written, with a final save if the first snapshot was captured before cancellation. Shutdown requests cancellation for all tracked jobs and drains them. An initial input-save error already reported by
start()does not interrupt the server's remaining cleanup; persistence failures for retained jobs still propagate. Completed waiting-user jobs keep their existing replacement behavior.How it was verified
Rebased and squashed into one commit on
13cb493d94588151844125a5b2a376f27a21ded9at the maintainer’s request. The conflict was confined to the installer lifecycle notes; both the pending native-sign-in guards and queued-job rules are preserved. The production and regression-test files are byte for byte identical to the previously approved head.The original six real-storage regressions were reproduced on the base and pass with the change:
The review follow-up checks that shutdown then resolves, rather than repeating the initial input error already received by the start caller. That assertion fails on the previous PR head and passes after the correction. A seventh control fails the late canceled-snapshot write after the first snapshot was saved; shutdown still reports that storage error and retains the job record.
make check-installerpasses: typecheck, lint, and 164 tests. Prettier andgit diff --checkpass. The tests pause the initial input or snapshot storage call and use real private-file writes and a controlled installation runner.Boundary
The installer AGENTS.md records the queued-job persistence and shutdown invariant. No API contract changes. This affects installer job lifecycle; it adds no network round trip or file walk to the user-message-to-provider-ready path.