Repository navigation
fix(service-job): kernel shutdown waits for a scheduled run in flight, or settles its row as interrupted - #34331
Conversation
…ttles its row as interrupted IntervalJobAdapter and CronJobAdapter now await the scheduled fire they hold in flight on destroy(), up to a shutdownDrainMs bound (default 10 s, inside the kernel's 60 s shutdownTimeout). DbJobAdapter settles a run that outlives the bound as failed with an interrupted-by-shutdown error while the driver is still up, and starts no new attempt once shutdown began. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
…y, find stays the plain double Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
📓 Docs Drift Check20 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. What this run could not see
Coarse fallback — 3 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin d127470de65bbc20f4b5d5485a2f46796ecb1521 && git checkout d127470de65bbc20f4b5d5485a2f46796ecb1521
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 35c9a305f06a37fe941d424fe0160727e20c0808 7e9abb650ba152eb685bdb9e5de4c881a796e38d && git checkout -B drift-repro 35c9a305f06a37fe941d424fe0160727e20c0808 && git merge --no-ff 7e9abb650ba152eb685bdb9e5de4c881a796e38d
node scripts/docs-audit/affected-docs.mjs --json 35c9a305f06a37fe941d424fe0160727e20c0808 |
…n the engine-double ledger Generated by `node scripts/check-engine-double-contract.mjs --write`: one added row (shutdown-drain-34046.test.ts, update, pinned 1), 0 lost. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kgF3mo9f7LXuv5hac Final head for review · PR #34331 · 2026-11-16T09:58ZArea o1-C (seat repo:objectstack#1) took this PR over from domain:server#5 (takeover claim 6913061905 on #34046). Head-sha: Generated by Claude Code |
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5mww9UksbwbjvM4aYn 席位核对 · PR #34331 · L1-b · 2026-11-16T10:22ZHead-sha: L1 ACCEPT(带一条落地前正文改正)· area o1-C 定稿评论 6913234084 所钉 head。
|
|
repo:objectstack#1 · os-project-manager · session_01FEkQ5kgF3mo9f7LXuv5hac Landing · PR #34331 · 2026-11-16T10:27Z
State change: ready for review + auto-merge (merge queue). On MERGED, Generated by Claude Code |
Requested by Steedos · project thread
Fixes #34046
Clause-②: no
Metadata-protocol: none
维护者速读
sys_job_run行记为failed,错误文案写明「被关停中断」。running,还打两条驱动失败告警。service-job一个包,不新增状态值或元数据键;回滚即 revert 本 PR。packages/services/service-job/src/db-job-adapter.ts的destroy()与wrap()中onAttemptStart两处关停判断;其次scheduled-fire.ts的drainScheduledFires。pnpm --filter @objectstack/service-job exec vitest run src/shutdown-drain-34046.test.ts,预期 8 条全绿。What changes
The kernel destroys plugins in reverse order (
performShutdown()inpackages/core/src/kernel.ts), so the job plugin is destroyed before the driver it writes through.IntervalJobAdapter.destroy()andCronJobAdapter.destroy()cleared their timers and returned at once. A scheduled run still executing then hit the released driver: its row stayedrunningandfinishRun/bumpJoblogged driver failures.scheduled-fire.ts:ScheduledFirenow holds the fire'ssettledpromise next tostartedAt. New helpers:openScheduledFire(),drainScheduledFires(inFlight, boundMs)(waits for every held fire, at mostboundMs, and returns the names still running),drainExpiredMessage(), andDEFAULT_SHUTDOWN_DRAIN_MS = 10_000.IntervalJobAdapterandCronJobAdapter: new constructor optionshutdownDrainMs(default 10000).destroy()stops the timers, clears the registrations, then waits for the fires inscheduledInFlight, up to the bound. If the bound passes, onewarnnames each job left running.IntervalJobAdapter.runScheduled()now skips a tick whose registration is gone (CronJobAdapteralready did), so a tick racingdestroy()starts nothing.DbJobAdapter: newDbJobAdapterOptions.shutdownDrainMs, forwarded to its owninnertimer adapter (the no-cron fallback). A cron adapter you pass in uses its own option. Each scheduled invocation of a wrapped handler is tracked from its first attempt until it settles.destroy()setsshuttingDown, destroysinner, then the cron adapter (both drain), then settles every scheduled run still open:status: 'failed',error= "interrupted by shutdown: …".sys_jobmirrors it like any failed run. This happens while the driver is still up. The existing one-terminal-write latch makes the abandoned handler's own settle a no-op when it finishes later. OnceshuttingDownis set, a scheduled run starts no retry attempt. If shutdown starts while an attempt's row insert is in flight, that row is settled as interrupted and the attempt never starts.failedis reused because the run did not finish, and that is whatfailedalready means. SpecJobExecutionStatus,sys_job_run.statusandsys_job.last_statusare untouched.trigger()/replay()are unchanged. They are not waited for, not settled and not gated, because their callers await them.shutdownTimeout, which every plugin's teardown shares.packages/coreis not touched.Tests
New pin file
packages/services/service-job/src/shutdown-drain-34046.test.ts(8 tests). The harness models a kernel teardown:await db.destroy(), then the engine is "released". After that, every engine write (insert/update) is recorded and throwsNo driver available for object ….findstays the plain double, because every path that settles a run ends in a write. Legs:DbJobAdapterwith no cron adapter (IntervalJobAdapterowns the timer, interval schedule), andDbJobAdapterwith a realCronJobAdapteron a croner expression* * * * * *.destroy()stays pending until the run ends. The row endssuccessand no new fire starts. Zero engine calls after release, and no driver-failure warn.destroy()resolves at exactly the bound. The row isfailedwith the "interrupted by shutdown" error, andsys_jobshowslast_status: failed, failure_count: 1. When the handler finishes later, there are zero engine calls after release and no driver-failure warn.IntervalJobAdapter.destroy()waits for its in-flight fire.CronJobAdapter.destroy()gives up at its bound and names the job.Before reading (main 021abd4)
The adapters' main sources were copied next to a variant of the pin file that only measures. That harness also guarded
find, which is whyfind sys_jobappears. On the run-past-the-bound case, both legs read the same:This is the card's trace: the row is left
running, and both WARNs fire after the driver is gone. The pin file run against main:Tests 6 failed (6)(the six tests that existed then). Each failure wasdestroy()resolving before the in-flight run settled (expected true to be false).Ablations (each negative pin; mutate, run the pin file, restore; `scripts/ablation-replace.mjs`)
Run at
2ad7c43191. The only later change is in the test double:findis no longer guarded. Subjects are imported fromsrcby relative path, so no build was involved. Each restore was proven: blob == HEAD andgit diff HEADempty.IntervalJobAdapter.destroy()drain replaced by an empty list (old non-awaiting destroy). Result:Tests 3 failed | 5 passed (8). Interval leg (1), (2) and the standalone interval test fail withexpected true to be false(destroy resolved early).CronJobAdapter.destroy(). Result:Tests 3 failed | 5 passed (8). Cron leg (1), (2) and the standalone cron test fail.await this.settleInterruptedRuns()removed fromDbJobAdapter.destroy(). Result:Tests 2 failed | 6 passed (8). Both legs of (2) fail withexpected 'running' to be 'failed'.shuttingDowncheck before an attempt removed. Result:Tests 2 failed | 6 passed (8). Both legs of (3) fail withafterRelease=["insert sys_job_run", …].Acceptance notes
CronJobAdapterfire still releases its cluster lock in its ownfinally, after the kernel is gone. The cluster plugin is destroyed after the job plugin, so this can log the existing "cluster lock could not release" warn once. The lease also expires on its TTL. Not changed here: the card's two WARNs are aboutsys_job_run/sys_job.trigger()/replay()runs in flight at shutdown are out of scope by order ("manual trigger semantics unchanged"). They are neither waited for nor settled.JobServicePluginis untouched. Itskernel:readyplaceholder hand-over callsIntervalJobAdapter.destroy(), which now also waits for a placeholder fire in flight (bounded), instead of leaving it running beside the upgraded adapter.Verification
Local runs: head
9993f237ea(origin/main merged at2ad7c43191). The dependents and the derived gate sweep ran at2ad7c43191. The commit after it changes only the pin file's double, and the package suite plus every derived gate that reads test files were re-run at9993f237ea. Dependency closures were rebuilt first:--filter '@objectstack/runtime^...' --filter '@objectstack/service-automation^...' --filter '@objectstack/cli^...' build, exit 0.@objectstack/service-jobat9993f237ea:vitest run:Test Files 13 passed (13) · Tests 163 passed (163).typecheck: exit 0.eslint --no-inline-configon the five touched files: exit 0.@objectstack/runtime, the 7 job files:Tests 142 passed (142).@objectstack/service-automation,wait-node*.test.ts:Tests 40 passed (40).@objectstack/cli,src/utils/schema-migration-plugins.test.ts(integration project):Tests 53 passed (53).@objectstack/service-cluster-redis,redis-outage.real-redis.test.ts:Tests 2 passed (2).node scripts/pm/dispatch-gates.mjs --commandsgives 71 families. All 71 were run at2ad7c43191.--ranreconciliation: 71 derived, 70 run, 1 NOT-MEASURED, 0 UNRUN.check:dual-build-cjs-loadsexit 3 (PREREQUISITE NOT MET: the whole workspace is not built here). NOT MEASURED; CI runs it.check:objectql-double-limitexit 1 at2ad7c43191. The probe threw on the double'sfindguard. Fixed in9993f237ea, and the re-run there exits 0.check:engine-double-contract: the new pin file's double routesupdatethroughassertEngineUpdateDispatch, as required. Its ledger row (scripts/engine-double-contract.pinned.json: file = this test, verbupdate, pinned 1) was added in 312b779 bynode scripts/check-engine-double-contract.mjs --write(area grant, 0 lost); at head 7e9abb6 the gate is judged green by CI (Lint · CI, release & engine gatessuccess). It was red at9993f237ea, before the row.9993f237ea, exit 0:objectql-double-limit,cross-package-test-inputs,test-source-alias,nul-bytes,where-matcher,rest-log-spy-declared,registry-log-declared,swallow-census-controls,tier-file-adoption,issue-citations,doc-authoring,refd-timer-probe,logger-receiver-detach,keyed-text-bounds,query-options-erasure,optional-error-sink.git merge-treeagainst origin/main (10 commits past the merge): clean. None of those commits touchespackages/services/service-job/**or the ledger.Session: https://claude.ai/code/session_01QsR2jTEivi2wogPpeo3xd5
🤖 Generated with Claude Code