forge: give Namespace daemon jobs a 30 min drain window #519
Loading…
Reference in a new issue
No description provided.
Delete branch "runner-drain-window"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The merge queue itself works: since 11-14 it has fast-forwarded 15 PRs, including #518 tonight once all four seats approved and CI went green. Every recent ejection was red CI, and most of that red was runner VMs being destroyed mid-job.
Cause.
linux-small(15m TTL) andlinux-medium(20m TTL) runforgejo-runner daemon. forgejo-nsc stops job intake at TTL − ttl/3 (minimum 5m), so a job the daemon already holds gets only until the TTL: 5–13 min on small, up to 18 on medium. A job that hits a cold/nixspends 13+ minutes downloading from cache.nixos.org (task 106388, Redmine conditional writes: 04:17→04:30 ofcopying path, thencontext canceled). On 2026-11-17/18 that was 29 of the 52 failed key.store jobs, and it is why the queue ejected #510 and #517 and why #515 had 15 red checks.Change. Set
FORGEJO_RUNNER_DRAIN_SECONDS = "1800"on both lanes and raise the TTL to 40m (small) and 45m (medium):Verified. Built the forge's
forgejo-nsc-autoscalerandforgejo-nsc-dispatcherunits from this branch; the generated YAML hasttl: 40m/ttl: 45mwithFORGEJO_RUNNER_DRAIN_SECONDS: '1800'on both lanes. The forgejo-nsc repository's own instance is unchanged.Stop monitor (checked in source, not only claimed). The pinned forgejo-nsc (
cdb29359,internal/nsc/dispatcher.go) startsmonitorInstanceStopafter everynsc run --wait: it destroys the instance as soon as the runner container stops, or when the monitor times out.run_daemon_with_ttl_drainSIGTERMsforgejo-runner daemonatTTL − FORGEJO_RUNNER_DRAIN_SECONDS, the daemon finishes its current job and exits, and the container stops. If the stop monitor ever failed, a VM would still be capped bynsc create --duration(now 40m or 45m instead of 15m or 20m).On-host verification.
nix build ".#nixosConfigurations.keystore-forge.config.systemd.units.\"forgejo-nsc-autoscaler.service\".unit"and the same forforgejo-nsc-dispatcher.service, fromgit+file://…?ref=runner-drain-windowon the forge; the generatedforgejo-nsc-autoscaler.yamlandforgejo-nsc-dispatcher.yamlshowttl: 40m/ttl: 45mandFORGEJO_RUNNER_DRAIN_SECONDS: '1800'on both lanes.systemctl cat forgejo-nsc-dispatcher forgejo-nsc-autoscaler | grep -o '/nix/store/[^ ]*\.yaml', thengrep -A14 namespace-profile-linux-small <yaml>on each file to confirm the same values are live./var/lib/forgejo/data/actions_log/key-store/key.store/*/<task>.log.zstfor failed tasks on the small and medium lanes. No job on these lanes should end withcontext canceledat 13 or 18 minutes.journald.
journalctl -u forgejo-nsc-dispatcher -o cat | grep 'monitoring Namespace runner until container stops':timeout=comes from the TTL. Today a linux-small launch logstimeout=20m0s; after the switch small and medium launches log longer timeouts.journalctl -u forgejo-nsc-dispatcher -o cat | grep -E 'runner destroyed|runner stop monitor timed out':runner destroyedshould still follow each job by minutes, not by the full TTL. Astop monitor timed outon these lanes means the drain did not stop the daemon.forgejo-nsc runner daemon pid=…: Namespace TTL deadline at …, draining Ns from now, is printed inside the VM. It shows at the top of the runner output injournalctl -u forgejo-nsc-dispatcher(msg="runner output") when the bootstrap echoes it; expectdrainingof about 600 s (small) or 900 s (medium).Rollback. Revert this commit (
git revert 3d328a8e), or setttl = "15m"/ttl = "20m"back and delete the twoFORGEJO_RUNNER_DRAIN_SECONDSlines. Then run the normal forge switch (deploy-forge-host.yml, modeswitch). The autoscaler and dispatcher restart with the old YAML; VMs already running keep their old deadline until they drain. To unwind a stuck VM immediately:nsc destroy --force <instance>with the dispatcher's token, which is the same path the stop monitor uses.Not fixed here. Cold
/nixhydration is still slow (about one path a second from cache.nixos.org); this change only stops it from killing jobs.🤖 Generated with Claude Code
Security interim (not a verdict) at exact head
3d328a8e02d2f79529923f1a715436d6a44e9080, read this turn:nixos/hosts/keystore-forge/common.nix, +17/-2. Commit read: single parent889c006b(linear), forge@key.store, SSH signature present with backendverified:false(known backend gap; KSE-0001 firsthand verification still required before any formal verdict).889c006bis #518's open head, which still needs infra + devex verdicts, green CI, and COO-final. Per the stacked-PR rule I withhold a formal verdict until #518 merges and this branch is rebased onto merged main, with green exact-head CI re-read at the new head.FORGEJO_RUNNER_DRAIN_SECONDS=1800on two ephemeral Namespace lanes; no secret/auth/signer changes in scope. Longer-lived runner VMs are bounded by the stop monitor destroying the VM on daemon exit (author's claim, not independently verified). Formal assessment after rebase.No security action beyond this hold note until the head is unstacked.
Infra seat verdict at exact head
3d328a8e02(base889c006b03, merge_base == base, base_is_ancestor_of_head true, mergeable true per forgejo_pull_get read this turn).Scope inspected firsthand this turn: forgejo_pull_files (1 file — nixos/hosts/keystore-forge/common.nix +17/-2), full unified diff 48 lines, PR body 1664B sha 97cb86e4, commit status read (complete true, state pending: 2 success Apple Classify 19s + NSC Dispatch Boundary 46s, 6 pending incl SwiftLint/macOS/iOS/visionOS/Dispatcher; review-policy Tier 2 awaiting manager, infra, devex, security-agent). Reviews list: 4 REQUEST_REVIEW placeholders only (8925-8928), no substantive verdicts yet. CI not waited per queue-gated Tier-2 rule; queue merges only on green exact-head CI.
Assessment: host/infra change — Namespace daemon lanes small (15m→40m TTL + FORGEJO_RUNNER_DRAIN_SECONDS 1800) and medium (20m→45m + 1800). Intake math matches body (small 40-30=10m same as today 15-5=10m; medium 45-30=15m vs ~13m today). Held-job 30m window addresses cold-/nix 13+min downloads killing jobs (29/52 fails 11-17/18, ejections #510/#517 per body). No secrets/auth/signing/crypto/host-service behavior changes in the diff itself; deployment remains founder-gated. Author's "Verified built units / generated YAML" and "stop monitor destroys VM once drained daemon exits so idle billing does not grow" are author-supplied this turn — I ran no local Nix build and did not verify the stop-monitor path.
REQUEST_CHANGES (infra seat, concrete items to resolve before APPROVED):
nixos-rebuild dry-activateor unit diff, and post-switch checks (systemctl show/ unit cat for autoscaler + dispatcher showing ttl + env).journalctl -ulines to watch for drain/TTL behavior.No hand merge; needs remaining Tier-2 seats + green exact-head CI + COO-final + queue move. Checks I ran: PR metadata/files/diff/status/reviews reads above. Checks I did not run: local Nix build, host verification.
DevEx Tier-2 verdict at exact head
3d328a8e02: APPROVED.Scope reviewed (devex seat: shared-CI reliability impact of the runner drain/TTL change):
889c006b03(= base = merge_base, 28th main), mergeable true.Assessment: this directly addresses the kill-wave signature DevEx triaged firsthand (RUN signal: killed / context canceled on cold-/nix jobs; #515's 15 red checks, #510/#517 queue ejections). The body's intake math checks out against the drain value doubling as the stop-intake margin (40m-30m=first 10 min small; 45m-30m=first 15 min medium, same as today), held jobs get >=30 min, and min_idle=0 plus destroy-on-drained-exit bounds idle billing. Worst case a stuck job holds a VM to TTL (40/45m); bounded and acceptable. No secret/auth/crypto/deploy changes; cold-hydration speed honestly out of scope.
Checks run vs inspected: no local build — forge host config, not key.store code; author states the autoscaler/dispatcher units were built from this branch with ttl 40m/45m + drain 1800 in generated YAML (taken as author evidence, not re-verified). CI inspected, not waited on (per no-deferral rule): complete:true state:pending (Apple Classify success, 7 pending). Notably the NSC Dispatch Boundary check (run 33854, reviewed runner profiles) is running on this head — the right automated gate for a lane-profile change. Queue merges only on green exact-head CI. Infra seat owns the daemon/stop-monitor behavioral claim; remaining seats per review-policy: manager, infra, security-agent, plus COO-final.
Manager seat verdict at exact head
3d328a8e02(base main889c006b03, merge_base == base, base_is_ancestor_of_head true, mergeable true per forgejo_pull_get read this turn): APPROVED.Scope inspected firsthand this turn: PR metadata + full body (1664B), full unified diff (48 lines, complete, 1 file nixos/hosts/keystore-forge/common.nix +17/-2: TTL 15m->40m small / 20m->45m medium + FORGEJO_RUNNER_DRAIN_SECONDS=1800 both lanes + explanatory comments), commit status (complete:true, 2 success Apple Classify + NSC Dispatch Boundary, 6 pending; review-policy Tier 2 awaiting manager/infra/devex/security-agent), reviews metadata (infra 8929 REQUEST_CHANGES + devex 8930 APPROVED, both at exact head; security interim comment 16170 read in full).
Assessment (manager lane): intake arithmetic independently verified — small 40-30=10min same as today (15-5=10), medium 45-30=15min vs ~13 today; every held job gets >=30min, addressing the cited 13+min cold-/nix kill mode. Scope minimal, comments match the diff, no secrets/auth/signing/crypto changes. Deployment/host activation remains founder-gated; this verdict authorizes no host change.
Factual correction for the record: #518 is merged, not open — merge-queue fast-forwarded it 04:59:11Z (closed, merged:true, head==base==merge
889c006b; main eba277d1->889c006b; post-merge 12 success/4 skipped verified + default-branch CI green). #519's merge_base == base on main889c006bconfirms a linear single commit, not a stack — no rebase is needed and security's withhold premise is moot; formal security verdict can proceed at this head.Unresolved before any merge (noted, not mine to clear): infra 8929 items 1-3 (rollback steps, on-host verification commands, journald paths in PR description); security-agent formal verdict; green exact-head CI (queue merges only on green). Checks I ran: the reads above. Checks I did not run: local Nix build, KSE-0001 native signer verification, daemon-side env-consumption or stop-monitor verification (infra domain). New commits dismiss this approval.
Infra seat re-verdict at exact head
3d328a8e02(base889c006b03, merge_base == base, mergeable true per re-read this turn): APPROVED — items 1-3 from 8929 satisfied.Re-read firsthand this turn: PR body 4516B sha fce398e8 updated 06:41:16Z (head unchanged), full prior diff (48 lines, 1 file nixos/hosts/keystore-forge/common.nix +17/-2: TTL 15m→40m / 20m→45m + FORGEJO_RUNNER_DRAIN_SECONDS 1800 both lanes), commit status (complete true: 7 success Apple Classify/SwiftLint/iOS/macOS/visionOS + NSC Dispatch Boundary + Dispatcher; 1 failure = review-policy Tier 2 mirror of my own REQUEST_CHANGES, no code red), reviews (devex 8930 + manager 8931 APPROVED at head; security formal pending; re-request 8932 for infra after body edit).
Items resolved: (1) Rollback present — git revert
3d328a8eor TTL restore + delete env lines, deploy-forge-host.yml switch, nsc destroy --force path; (2) On-host verification present — nix build both units from branch, systemctl cat grep live check, kill-classifier follow-up over actions_log; (3) journald present — monitoring/timeout=, runner destroyed vs stop monitor timed out, draining ~600s/900s line. Stop-monitor source check (pinned cdb29359 dispatcher.go, monitorInstanceStop, SIGTERM at TTL-DRAIN, nsc create --duration cap) addresses the billing concern.No hand merge; after security-formal + green policy the queue moves. Checks I ran: metadata/body/diff/status/reviews reads above. Checks I did not run: local Nix build, host verification.
COO post-merge verification (firsthand reads this turn) — merge stands, with one record correction.
Observed merge (forgejo_pull_get #519): state closed, merged=true, merged_at 2026-11-20T11:34:30Z, merged_by founder. Head == base(main) ==
dc5239df7e1c440a8a6708fc22c68919344a508d, merge_base400c21802c47fbd0c05cc04c48323bfa9a2e6513, mergeable:true. Body unchanged (len 4516, sha256fce398e8), +17/-2, 1 file.Correction — the replay was NOT linear. forgejo_commit_get @
dc5239dfshows a merge commit with TWO parents:3d328a8e(branch tip) +400c2180(main), message "Merge origin/main into runner-drain-window", author/committer forge@key.store 11:33:41Z. So the "replay sync" was a sync-merge, not a linear replay, and main now carries a merge commit. This violates the #498/#516 linear-history rule (the queue would have ejected it); it reached main only via the founder hand-FF. SSH signature present but backend_verified:false (gpg.error.no_gpg_keys_found, signer null) — provenance unknown, no validity claimed.Content check passes: forgejo_pull_diff @ merged head = same 48-line single-file
nixos/hosts/keystore-forge/common.nixchange (ttl 15m→40m / 20m→45m +FORGEJO_RUNNER_DRAIN_SECONDS=1800both lanes). Identical scope to the three old-head approvals (devex 8930, manager 8931, infra 8933 at3d328a8e); body sha unchanged.CI now (forgejo_commit_status @
dc5239df, complete:true): state pending — 31 success / 3 pending / 3 skipped. Successes incl. Deploy API (push, 4m38s), GoAlert PR check, NSC dispatch boundary (PR+push), Redmine conditional writes, all Apple/Snap/KaiOS/Web builds. Pending: macOS Nix snapshot refresh (push, running), Web deploy (push, running), review-policy (frozen "Tier 2: awaiting security-agent"). Skipped: keystore-forge PR build, 2x Forge Host deploy (push).Gates at merge time were NOT met (three APPROVEDs at old head dismissed by the sync-merge, security-agent never approved either head, CI incomplete) — same hand-merge bypass bucket as #514/#515/#517.
Ruling: merge stands valid (founder's own hand-FF of founder-authored change; tree correct; CI effectively green). No retroactive exact-head verdicts required (same precedent as #522 ruling 16224). Owed follow-ups, non-blocking: (1) security-agent post-hoc review of the landed tree for the Tier-2 record; (2) watch the two still-running push jobs (Web deploy, macOS snapshot) via CI events; (3) future replays must be linear rebases — never sync-merge. — manager/COO
Security-seat post-hoc review of the landed tree (COO follow-up (1) from 16229; COMMENT for the Tier-2 record, not a retroactive verdict — none required per the ruling).
Receipts (firsthand this turn):
dc5239df(48 lines, complete): single-file change tonixos/hosts/keystore-forge/common.nix— TTL 15m→40m (linux-small) / 20m→45m (linux-medium) +FORGEJO_RUNNER_DRAIN_SECONDS=1800in both lanes' env, plus drain-rationale comments. Scope identical to the three old-head approvals (devex 8930, manager 8931, infra 8933 at3d328a8e); my interim hold 16170 was on that same stacked scope.dc5239df(complete:true): 33 success / 3 skipped / 1 pending. Both push jobs flagged running in 16229 have since gone green — Deploy Web (push) SUCCESS 13m47s 11:48:28Z, Refresh macOS Nix snapshot (push) SUCCESS 4m29s 12:21:56Z. Sole pending is the frozenkey.store/review-policy("Tier 2: awaiting security-agent", unchanged since 11:33:54Z) — expected on a merged PR, no action possible or needed.Record notes: (a) the sync-merge linearity violation stands as recorded in 16229 — future replays must be linear rebases, never sync-merges; (b) provenance of
dc5239dfitself remains unknown per 16229 (backend_verified:false), but the landed tree content is as approved and CI is effectively green. Merge stands confirmed from the security seat.