Skip to content

fix(server): seed standby engines with provider auth and stop re-seeds from forcing rollovers - #4373

Merged
yomgui merged 2 commits into
devfrom
fix/engine-rollover-fingerprint
Sep 3, 2026
Merged

yomgui merged 2 commits into
devfrom
fix/engine-rollover-fingerprint

Conversation

@yomgui

@yomgui yomgui commented Sep 3, 2026

Copy link
Copy Markdown
Member

Why

Engine churn, not token rotation. A spawned engine's environment carries no provider keys (engineEnv in embedded.ts); credentials reach it only through PUT /auth from syncManagedProviderAuth. 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 new generation: scope, re-delivered the same key, reported it as authChanged, and called reloadEngine({ 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

  • engine-pool — new optional prepareStandby(config, { workspace, generationId, baseUrl, username, password }) hook, run after the standby is healthy and before the flip. A throwing seed logs Engine standby preparation failed; flipping anyway. and still flips; the primary is never stranded.
  • managed-provider-auth — syncManagedProviderAuth accepts an explicit standby target that uses the same generation scope the promoted primary will resolve, so the post-flip sync finds its fingerprints applied. The result now reports rotated (value changed since the last delivery anywhere) separately from delivered.
  • cloud-provider-sync — 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).
  • server — 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 uniform engine_reload.

Not changed on purpose: forceStandby on 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).

pnpm evals:pr specs/engine-rollover-auth-reseed.test.ts
  ✓ an engine rollover seeds the standby and re-seeding never forces another rollover  (1 passed, 0 failed, 0 skipped) exit 0

Wraps three focused witnesses:

  • engine-pool.test.ts › seeds the healthy standby before flipping and flips anyway when seeding fails — prepareStandby runs 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, unchanged after 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 keep reloads at 1; a rotated key reloads once more. Fails on the previous code: Expected: 1, Received: 2.
pnpm --filter openwork-server test src/managed-provider-auth.test.ts src/engine-pool.test.ts src/cloud-provider-sync.e2e.test.ts src/server-logger.test.ts   53 pass / 0 fail
pnpm --filter openwork-server typecheck   exit 0

Verdict: Passed.

Related: #4371 (persisted server log), #4372 (headless engine isolation). Follow-up: engine-stall UX.

…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).
@vercel

vercel Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 3, 2026 11:47pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
openwork-den Ignored Ignored Preview Sep 3, 2026 11:47pm UTC
openwork-diagnostics Ignored Ignored Preview Sep 3, 2026 11:47pm UTC
openwork-landing Ignored Ignored Preview Sep 3, 2026 11:47pm UTC

@yomgui

yomgui commented Sep 3, 2026 •

Copy link
Copy Markdown
Member Author

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 primary

prepareStandby 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.

  • ✅ PASS The pool seeds a healthy standby before it becomes primary — prepareStandby 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 use

After the flip the primary-scoped sync reports the provider unchanged with no further PUT /auth; the total stays at two deliveries.

  • ✅ PASS Seeding uses the same generation scope the promoted primary will use — After 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 reload

With 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).

  • ✅ PASS Re-delivering an unchanged key to a replaced engine does not reload — With 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: evals/results/test-runs/2026-09-03T23-47-31-667Z-an-engine-rollover-seeds-the-standby-and-re-seeding-never-forces-another-rollove/test-run.json · Repro: pnpm --dir evals artifacts:publish -- --pr 4373 --test-run 2026-09-03T23-47-31-667Z-an-engine-rollover-seeds-the-standby-and-re-seeding-never-forces-another-rollove

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@yomgui

yomgui commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Red openwork-tests is pre-existing on dev, not this PR.

Both runners fail the same two governance specs that reference a file this PR does not touch:

  • spec-impact.test.ts › every E2E spec is mapped… → evals/specs/cross-server-handoff-atomic-commit.e2e.test.ts has no contract
  • spec-quarantine.test.ts › the enabled E2E set equals the evidence-backed inventory → 38 vs 37

Control on a clean origin/dev checkout (3e425fa, which merged #4054 after this branch was cut):

git checkout --detach origin/dev && pnpm evals:pr specs/spec-impact.test.ts specs/spec-quarantine.test.ts
  × the enabled E2E set equals the evidence-backed inventory  → expected [ …(38) ] to deeply equal [ …(37) ]
  × every E2E spec is mapped to an implementation contract or explicitly allowlisted
      → E2E specs missing a contract or unmapped reason: evals/specs/cross-server-handoff-atomic-commit.e2e.test.ts

Fix for dev: #4375 registers the spec (2 files, +3 lines). Once it lands, this PR's check goes green on re-run; the PR's own witnesses are unaffected (see the test-evidence comment above).

@yomgui

yomgui commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

Updated onto current dev (3296327) without force-push. The stale governance failures are fixed on dev by #4375. Final-head proof: 53/53 focused server tests, server typecheck exit 0, and 1/1 testkit rollover-auth witness; evidence republished above.

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@yomgui
yomgui merged commit a4cc254 into dev Sep 3, 2026
26 checks passed

This branch was successfully deployed

4 active (3 outdated) deployments
Preview – openwork-app — 32963279 Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-landing — 5310c682 Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-den — 5310c682 Deployed Sep 3, 2026 by vercel[bot]
Preview – openwork-diagnostics — 5310c682 Deployed Sep 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant