Repository navigation
fix(server): seed standby engines with provider auth and stop re-seeds from forcing rollovers - #4373
Conversation
…s from forcing rollovers
A spawned engine gets no provider keys in its environment; credentials reach
it only through PUT /auth from the managed-provider sync. The pool never
seeded a standby, so the first sync pass after every flip found a new
generation scope, re-delivered the same key, counted it as a credential
change, and called reloadEngine({ forceStandby: true }): one fresh 1+ GB
engine per sync pass (5-minute interval or any gesture), bounded only by the
30 s spawn floor. On the reporting machine this produced eight engines in 25
minutes, two generations resident at ~2.7 GB, and the request timeouts that
surfaced as "OpenCode unavailable".
- engine-pool: new prepareStandby hook runs after the standby is healthy and
before the flip; a failed seed logs and flips anyway.
- managed-provider-auth: syncManagedProviderAuth accepts an explicit standby
target using the same generation scope the promoted primary will resolve,
and reports rotated (value changed) separately from delivered.
- cloud-provider-sync: only rotated or removed credentials count as
authChanged; re-seeding a replaced engine no longer reloads.
- server: envServiceForConfig exposes the running env store to the pool
hook; every reload caller now passes a distinct rollover reason
(cloud_provider_sync, managed_provider_reload, operation_route,
workspace_bootstrap) so the persisted log names the trigger.
The new cloud-provider-sync case fails on the previous authChanged
definition (Expected reloads 1, Received 2).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
3 Skipped Deployments
|
Test evidence — an-engine-rollover-seeds-the-standby-and-re-seeding-never-forces-another-rollove — ✅ passed✅ passed · 3 expectations passed · 0 failed · 0 pending verdict passed · 0 user observations · 0 probes · steps 0/0 ℹ️ ASSERTION — 1. The pool seeds a healthy standby before it becomes primaryprepareStandby runs once per rollover with the standby's own URL and basic-auth while the old engine is still primary; a throwing seed still flips.
ℹ️ ASSERTION — 2. Seeding uses the same generation scope the promoted primary will useAfter the flip the primary-scoped sync reports the provider unchanged with no further PUT /auth; the total stays at two deliveries.
ℹ️ ASSERTION — 3. Re-delivering an unchanged key to a replaced engine does not reloadWith a fake pool whose generation changes on every reload, the second and third sync passes deliver but keep reloads at 1; a rotated key reloads exactly once more. The same test fails on the previous authChanged definition (Expected 1, Received 2).
Test run created 2026-09-03T23:47:31.667Z · Source: |
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (5310c68289773feafa6a17ad119fe143dfd34e1b). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
|
Red Both runners fail the same two governance specs that reference a file this PR does not touch:
Control on a clean Fix for |
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (32963279a66ebb5d243f8108132a6e73c477c1bc). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
Why
Engine churn, not token rotation. A spawned engine's environment carries no provider keys (
engineEnvinembedded.ts); credentials reach it only throughPUT /authfromsyncManagedProviderAuth. The pool never seeded a standby, so after every rollover the next provider-sync pass (5-minute interval or any gesture such as New task) resolved a newgeneration:scope, re-delivered the same key, reported it asauthChanged, and calledreloadEngine({ forceStandby: true })— one fresh engine per pass, bounded only by the 30 s spawn floor. On the reporting machine: 8 engines in 25 minutes, two generations resident at ~2.7 GB, and the 10 s request timeouts that surfaced as "OpenCode unavailable — Request timed out". The loop only stopped there by accident when #4281 renamed the provider env var (no_stored_credential).What
prepareStandby(config, { workspace, generationId, baseUrl, username, password })hook, run after the standby is healthy and before the flip. A throwing seed logsEngine standby preparation failed; flipping anyway.and still flips; the primary is never stranded.syncManagedProviderAuthaccepts an explicit standbytargetthat uses the same generation scope the promoted primary will resolve, so the post-flip sync finds its fingerprints applied. The result now reportsrotated(value changed since the last delivery anywhere) separately fromdelivered.authChanged = rotated || removed. Re-seeding a replaced engine with an unchanged key is delivered but can no longer force a standby. Genuine rotation still reloads exactly once (SDK clients cache config+auth together).envServiceForConfig()exposes the running env store to the pool hook; every reload caller passes a distinct rollover reason (cloud_provider_sync,managed_provider_reload,operation_route,workspace_bootstrap) so the persisted log from feat(server): persist openwork-server logs to a rotating file #4371 names the trigger instead of a uniformengine_reload.Not changed on purpose:
forceStandbyon the provider-sync path (provider config is global; an in-place dispose refreshes one workspace instance only) and the 15-minute drain inactivity window (long silent tool calls such as 4-minute test runs must not be aborted).Verification
Lane: local (server-only witnesses; no Daytona prerequisite applies).
Wraps three focused witnesses:
engine-pool.test.ts› seeds the healthy standby before flipping and flips anyway when seeding fails —prepareStandbyruns once with the standby's URL + basic-auth while the old engine is still primary; a throwing seed still rolls over.managed-provider-auth.test.ts› seeding a standby generation leaves the promoted primary unchanged on the next sync · re-seeding a replaced engine with the same key is delivered but not rotated — 2 PUTs total,unchangedafter the flip; rotation →rotated.cloud-provider-sync.e2e.test.ts› re-seeding an unchanged credential to a replaced engine generation does not reload again — fake pool changes generation on every reload; passes 2 and 3 deliver but keepreloadsat 1; a rotated key reloads once more. Fails on the previous code:Expected: 1, Received: 2.Verdict: Passed.
Related: #4371 (persisted server log), #4372 (headless engine isolation). Follow-up: engine-stall UX.