instance-ready-before-wake
What production showed
woodstar-community (account bdm, channel edge, exec-backed, hibernating, nested rows) creates an instance through the console API and sends it requests at once. Flagship journal, 2026-11-24, ws-techpreneurs.bdm.oncarlos.com:
13:59:20 provision: minted instance route ws-techpreneurs... (app "woodstar-community" acct "bdm")
13:59:23 agent: ... needs a root pass for 543bc15 (...); asked for one
13:59:23 rollout: ...: install before its wake: materialize ...: its install is relayed to the root pass
13:59:23 activator: wake ...: refusing to wake: no build is installed for this instance yet
... the same pair every ~2s ...
13:59:27 ...: instance directory not made yet; config is written once it is
13:59:40 ...: repointed -> 543bc15 (edge; hibernating — runs it on next wake)
13:59:41 activator: no replica ... — booting fresh; started carlos-instance-gen@...:202.service
13:59:42 activator: generation 202 of 543bc15: ... woke in 1.688s
13:59:44 agent: ...: its instance directory is there now, writing its config
13:59:45 config updated
13:59:54 rollout: swap.started ...: starting build 543bc15 (config change)
14:00:05 rollout: swap.done ...: now serving build 543bc15Two defects, about 45 s from "created" to "serving with its config". Both are still on main at 67a5b32da. This branch fixes the second, which is also #1384 (Slopbox: the unconfigured first boot exits, fails its health check and stops the rollout). The first is analysed below and tracked as #1386; nothing of it is changed here.
Fixed here: the first generation ran without its config
Generation 202 served for about 12 s with no <host>.config.env (for this tenant, no WOODSTAR_WORLD), then was swapped for 203. Requests in between reached a process without its settings.
Cause. A nested row's config file lives in its instance directory. Only the activator's first wake makes that directory (internal/activator/prepare.go:66), so the config pass that ran at 13:59:27 could not write (internal/appconfig/syncexec.go:1514, :661). The agent came back for it once the directory was there (internal/host/agent.go:2850), which is after the spawn had read the file (prepare.go:102). The scheduler then saw a delivery to a running instance and queued a config attempt (internal/rollout/manager.go:1249-1269): the restart. A wake that beats the first config pass to a new route has the same gap, nested or flat.
Fix. The activator asks the agent before it plans a wake: Service.ConfigBeforeWake, step 0.69 of doWakeOnce.
- A route whose file exists costs one
Lstat. One a config pass has already settled with no file (an app with no settings) costs a map read more. - Any other gets one config pass narrowed to that host. It makes the instance directory exactly as
preparewould a moment later (appconfig.MakeInstanceDir:os.MkdirAll, 0700, only when the pass has a file to write; a row with an instance overlay gets its file, and so its directory, even when the render is empty) and writes the bundle through the same renderer andinstancefswriter as every pass. - The planner then snapshots the delivered revision (
rollout/wakeplan.go:423) and the spawn reads the file. The wake's healthy event activates that revision, so nothing is pending and no swap follows. On a box without the scheduler the pass's restart leg answers "delivered on wake" in place of a bounce.
It refuses nothing. A pass that fails, or cannot get the config lock inside 5 s, leaves the wake exactly as it was before, and the config loops deliver and restart as they do today.
How long it can hold a wake. The lock wait and the pass's reads share one 5 s budget. The config ack has 5 s of its own (round 1's P2). With the scheduler armed the ack is deferred and the hook holds a wake 5 s at most; on a box that acks in line the two add up, so the worst case is about 10 s. The bound was left as it is: cutting the total would cut the ack budget the P2 added. The gate that refuses a wake whose config a box cannot provide is still the config guard (#213), at the lease.
The spec's rejected alternative. The exec config delivery design (2026-08-02-exec-config-delivery-design.md §6) turned down fetch-at-spawn: bucket latency and availability in the wake path, no file on disk. This is narrower. The file on disk is still the only thing a spawn reads. The bucket is read inside a wake only while no pass has settled that host's file, which is a new instance's first wake, and a slow or failed read costs that wake nothing but the old behaviour. A host a wake's pass leaves unsettled is not asked about again for 30 s. That window starts only when an attempt ran (the store would not open, or the pass had the config lock). A wake that timed out waiting for the lock starts none, so the next wake asks again: creating an instance starts a config pass at about the time of its first wake, and in the trace above the wake that started came 18 s after the first refused one.
Not covered. A box with host writes on takes doClaimWake before step 0.69 and keeps the old first wake. The ordinary config passes still leave the directory to the activator (TestConfigGenTickWritesANestedRowsConfigOnceItsDirAppears still holds).
One behaviour to know. The directory and the config file can now appear on a box before it holds the instance's lease, where main made the directory under the lease. Config sync already writes config for every route row on a box whatever the lease, so the box was entitled to the bytes; nothing reaps a nested directory on either path.
Files
internal/activator/activator.go,configbeforewake.go: the hook field and its one call.internal/appconfig/syncexec.go:MakeInstanceDir,syncExecHostMaking,ExecSpawned.internal/host/configbeforewake.go: the hook, the settled-hosts memo,passLock(a config lock a wake can stop waiting for);syncExecLockedmoved here fromagent.go..amadan/code-health.tsv: three raises of one or two lines, each for the one call or field, at the same three sites #1290 raised.- Census overlay and card
instance-ready-before-wake.
Tests
Each was watched to fail with its part of the fix disabled.
internal/activator:TestConfigIsAskedForBeforeAWakeIsPlannedOrStarted(order: config, then plan, then the start),TestConfigIsNotAskedForOnAPinnedOrFallbackWake.internal/appconfig:TestSyncExecMakeInstanceDirWritesANestedRowWithNoDirectory,...MakesNothingForAnEmptyBundle.internal/host:TestConfigBeforeWake...(writes a new nested instance's config with an ack that says delivered on wake and no restart; leaves an existing file alone without touching the store or the lock; asks once for an app with no settings; follows what the passes settled; skips routes config sync does not deliver to; gives up when a pass holds the lock; a lock timeout does not stop the next wake from asking (...ALockTimeoutDoesNotStartTheRetryWindow, watched to fail against the hook as it was at ca87c86); does not ask again inside its retry window; still acks a file it wrote when its wake's context ended; needs the armed guard's key).internal/rollout:TestAConfigDeliveredBeforeItsWakeIsPlannedLeavesNoAttemptpins the scheduler behaviour the fix rests on. It passes on main too: the scheduler is not changed.
Review
One round, Opus, independent, given the diff and the invariants: READY AFTER FIXES, no P1.
- P2, fixed: the config ack of a file the wake's pass wrote was written under the wake's 5 s budget, and no later pass acks a file that is up to date, so a cut-off ack was lost for good. It now has a budget of its own, cut loose from the wake's context.
- P3s taken: the hook's scope is config sync's own (
ExecSpawned), so a row no pass would name does not run a pass on every wake; the 30 s retry window;lockContextnever takes the lock on a context already done; the hook's contract and the host-writes gap written down. - P3s left: with the scheduler armed the ack of a delivery made inside a wake says
Restarted, as main's does for any delivery that lands during a wake; after an agent restart each instance of an app with no settings runs one narrowed pass at its first wake until the boot pass has settled it.
Round 2, the census, Fable 5.2 at Paul's direction in place of Astra, at ca87c86: every unit and envelope approved, recorded on #280. No P1 or P2; three P3s, all taken:
- The 30 s retry memo was recorded before the lock was tried, so a lock timeout kept the next wake from asking, in the very case this branch is for. Fixed: the memo is recorded only when an attempt ran (above), with a test.
- The description said the hook holds a wake 5 s at most; it can be about 10 s where acks are written in line. The description and the comment on
configBeforeWakeAckBudgetnow say so; the bound is unchanged. - "Only when there are bytes" was not true of a row with an instance overlay. The
MakeInstanceDircomment and this description now say what happens.
Then origin/main (67a5b32da, with its console-addr-from-install overlay) was merged in and the census regenerated with make census-propose: seal f273b5cb…9a86 to aa953b1a…f121; deliverConfigBeforeWake gains one registry Host site.
Because census-scoped code changed after the verdict, the census reviewer (Fable 5.2 again) checked the delta ca87c86..dcf785e36 inside the same round: READY, every changed unit and re-pinned envelope approved, recorded on #280 at dcf785e36. Not a new round.
Follow-up list (P3s from that check, not taken here, since each would change census-scoped code again):
- A wake that ends while the store is being opened for the first time still starts the 30 s window (
host/configbeforewake.go:300-306). Narrow: the store is cached after the first open. Fix: record there only when the wake's context is still live. - The new test cancels the wake's context before the hook runs, so it takes the lock-timeout branch without ever waiting on the lock; a deadline context would exercise the wait.
- No test of its own for the settled re-check under the lock, or for the window a store failure starts.
- Cost of fix 1 to know: while a long pass holds the lock, every wake of an unsettled host with no file waits up to 5 s, where before only the first in 30 s did.
Gate
CI passed on dcf785e36 (the reviewed tip; it holds the merge of origin/main 67a5b32da). main's own run at 67a5b32da is red on TestBurstSingleKeyFloodBounded (internal/edge, an allocation count); the same test passed in this branch's run, and this branch does not touch internal/edge.
Locally: make code-health passes; natively TestPlan14RootReadCensus, TestCensusScopeIsTheRootBinary, TestPlan14RootInputInventoryCoverage and TestCensusRebaseCarriesDispositions pass at the regenerated seal. On Linux (golang:1.26.10 in a container, tree mounted read-only): go build ./..., go vet with and without the gate's tags, and gofmt -l . clean; internal/appconfig and internal/rollout pass in full; the internal/host config tests pass, the new one included. The container cannot run the two big suites cleanly, for its own reasons: internal/host's claim-serving tests get "operation not supported" from its filesystem and one of them panics, which ends the binary; internal/activator fails TestNextSpawnStrict (no strict cgroup spawn) and, under load, TestSweepBurstOf252MeetsTheDeadline. None touches this change, and CI runs both suites in full. No CLI command, wire shape or root path changes.
Not squashed or force-pushed: AGENTS.md leaves the squash to amadan branch merge -squash. The branch is the two original commits, the merge of main and the P3 commit.
Not fixed here (#1386): about 17 s before a new instance's build is installed
Why it waits for root at all. A managed wake of a row with no installed build runs the adopt pass for that one host (rollout/wakeplan.go:282, release/materialize.go). Every gate passes, and the build is already staged because sibling instances run it, but the last step writes /opt/carlos/live/<host> (release/versions.go:288), and the agent runs under ProtectSystem=strict with only /data and /run/carlos writable (units/carlos-edge.service:48-50). The pass relays to root (release/adopt.go:1886) and the wake is refused until the row is stamped (wakeplan.go:288). That is the privilege split working as designed.
Why root takes 17 s. The ask is prompt: carlos-stage.path starts carlos adopt --stage-only on the first touch. That pass is the whole box's pass, not this host's. In order (host/agent.go:5991 on): startup and unit repair, config sync for every unit route (:6196), the restart pass (:6221), the capability pass (:6242), then release.Pass over every route (:6325), which reads each app's pointer and pipeline from the bucket (release/adopt.go:754, :893) and takes hibernating routes last (:1251). The journal agrees: root's config sync names this host at 13:59:28 and repoints it at 13:59:40. The comment at agent.go:2626 sizes the 15 s re-ask window to outlast "about eight seconds"; the flagship's pass is now about twice that, so a re-ask can land while the pass is still running, and systemd drops a change made mid-run.
What would fix it (root-side, census-gated, and not something to change without timing it on a box):
- First installs first. In
--stage-only, before config sync, onerelease.PassFilternarrowed to adoptable exec-backed hibernating routes with no live link and no installed version. It reads only those apps' pointers and restarts nothing. Estimated 17 s down to the pass's start-up cost. It gives up the sleepers-after-awake-hosts poison ordering for a row that has no previous build to stay on. - Longer term, let a new instance's first wake boot the already staged and verified build before root's link lands, as a held wake already runs a retained copy (
activator.gostep 0.65). That makes the wait zero and touches the installed-means-linked invariant across rollout, activator and release, so it wants a spec. - Size the re-ask window to the pass, or have the pass notice a request that arrived while it ran.
Also seen: the deferred re-ask at 13:59:53 fired after the install had landed at 13:59:40. It starts another full root pass for nothing, and on a box that creates instances on demand that makes "a pass is already running" more likely for the next create.
A new instance's config is in place before its first process starts (no unconfigured first generation, no config-change restart)
Discussions
- No discussions on this branch yet.
Tasks
- No tasks yet.
Activity
- paul@keymail.dev pushed dcf785e36 config before wake: a lock timeout starts no retry window (census review P3s)
- paul@keymail.dev pushed 6e60a51b7 Merge origin/main (67a5b32da) into instance-ready-before-wake
- paul@keymail.dev pushed ca87c8629 config before wake: review round 1 fixes
- paul@keymail.dev pushed 8447b1fcc agent: an instance's config is in place before its first process starts