Skip to content

fix(server): make provider-sync reloads truthful about applied engine state - #4880

Merged
reachjalil merged 3 commits into
devfrom
fix/provider-sync-reliability
Sep 11, 2026
Merged

reachjalil merged 3 commits into
devfrom
fix/provider-sync-reliability

Conversation

@benjaminshafii

@benjaminshafii benjaminshafii commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Problem

After a managed provider's API key was rotated, the server could report the reload as done while the engine kept serving with the previous key. Every following run failed with an auth error from the provider while the sync status said applied and reloadPending: false.

Root cause: the engine pool decides whether a reload is needed from a fingerprint of the config bytes, binary, and models URL. Credentials are not part of that fingerprint, so a key-only change looked like "nothing changed" and the rollover was skipped. Callers then cleared their pending state without checking what the pool actually did.

Fix

One behaviour, applied consistently: a reload is only reported as applied when the engine actually read the new config and credentials.

  • EnginePool.requestRollover honours forceStandby even when the fingerprint is unchanged, since the caller knows an input the fingerprint cannot see has changed.
  • reloadOpencodeEngine returns the RolloverOutcome instead of void; cloud sync clears reloadPending only on rolled_over / reloaded_in_place, keeps it owed and retries on coalesced, and fails the run and retries on skipped.
  • A request coalesced into an in-flight rollover now settles with the queued rollover's outcome instead of returning coalesced immediately.
  • A standby that fails or hangs while receiving its credentials is closed and the rollover rejected; the live primary keeps serving. Auth PUT/DELETE get a 10 s budget (OPENWORK_PROVIDER_AUTH_TIMEOUT_MS), standby preparation a 30 s budget (OPENWORK_ENGINE_STANDBY_PREPARE_TIMEOUT_MS).
  • The local PUT /env route (applyManagedProviderReload) had the same gap: it requested an unforced rollover and answered reloaded. It now forces the standby path and reports deferred (with the reload kept pending for the sync retry) when the pool did not apply the change.
  • cloud-provider-sync-contract.e2e terminal predicate no longer requires a provider the journey deletes.

Proof (head of this PR, rebased on dev f128bff74)

Check Result
pnpm evals:pr specs/managed-provider-env-delivery-reload.test.ts 2 passed. Red first on unfixed server.ts: :455 expected [ {…}, {…} ] to deeply equal [] (two kind: "error" witness requests after the PUT /env rotation, engine still sent the revoked key)
pnpm evals:pr specs/opencode-v2-provider-hot-inject.test.ts 1 passed
bun test src/engine-pool.test.ts 31 pass
bun test src/managed-provider-auth.test.ts 18 pass
bun test src/cloud-provider-sync-reload-guard.test.ts 9 pass
bun test src/cloud-provider-sync-drain-defer.test.ts 5 pass
bun test src/cloud-provider-sync.e2e.test.ts 20 pass
pnpm --filter openwork-server typecheck 0 errors

The key-rotation journey runs a real managed v1 engine against an mcpMock provider witness that accepts exactly one bearer key at a time. It rotates the key twice with identical provider config bytes: once through Den sync, once through the local PUT /env route. Each rotation must produce a new engine generation, a completed reply with the new key, and zero requests carrying the revoked key.

Verdict: Incomplete. cloud-provider-sync-contract.e2e (the predicate fix) needs a Den + Electron lane run (pnpm evals:e2e cloud-provider-sync-contract) that has not been executed. Everything else above is passing at this head.

Rebase notes

Rebased onto current dev after #4358 (Gateway providers), #4876 and #4888 touched the same files. The fingerprint-skip exemption was re-applied by hand to the new per-directory reloadedDirectories check. The Gateway sync test fixtures were aligned with the Promise<RolloverOutcome> contract.

Deferred

  • v2 readiness matching unqualified model ids, empty desired providers passing vacuously, catalog fetch without per-request timeout: documented in the audit, owned by v2 files, not touched here.

UI/UX impact: None — server-only change, existing UI/UX preserved.

@vercel

vercel Bot commented Sep 11, 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 11, 2026 6:32pm UTC
openwork-den Ready Ready Preview Sep 11, 2026 6:32pm UTC
openwork-diagnostics Ready Ready Preview Sep 11, 2026 6:32pm UTC
openwork-landing Ready Ready Preview, v0 Sep 11, 2026 6:32pm UTC

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Passed · 12/12 tests · 18/18 assertions · 8 images

Commit 0d12b096940d928dbe318a14cc5539675d0b892c · selected evidence

Open review report

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Warden review summary — Clear

Native findings: 0. Blocking policy matches before consolidation: 0. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run

Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (195354 ms), confidentiality-review (245271 ms), spec-provenance-review (261166 ms).

Blockers

  • None.

Advisories

  • None.

Needs recheck

  • None.

Observed review-thread metrics

  • Unique observed run attempts in retained window: 2
  • Distinct heads in retained window: 2
  • Current unresolved Warden threads: 0 of 0 observed
  • Observed resolved/unresolved transitions in retained snapshots: 0 / 0
  • First observed resolved/unresolved (state at first collection, not event time): 0 / 0
  • Precision: unavailable (no adjudications; no TP/FP values are inferred)
  • Observation window: 2/20 run attempts retained; truncated: false
  • Transition snapshot: 0/0 current attributed threads retained (limit 500); truncated: false

Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority.

diff-warden[bot]
diff-warden Bot previously approved these changes Sep 11, 2026

@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 (e2f9f1d9b7288bbe29b6818ad786569065539bde). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

Benjamin Shafii and others added 3 commits September 11, 2026 11:20
… state

- engine-pool: forceStandby bypasses the unchanged-fingerprint guard so a
  credential-only rotation (invisible to the config fingerprint) produces
  an applied rollover instead of a skipped ack
- engine-pool: a failed or hung standby seed no longer flips the pool; the
  standby is closed, the primary keeps serving and the rollover rejects
  (bounded by OPENWORK_ENGINE_STANDBY_PREPARE_TIMEOUT_MS)
- engine-pool: requests coalesced into an in-flight rollover settle with
  the queued rollover's outcome instead of an immediate coalesced ack
- managed-provider-auth: bounded timeout on engine auth PUT/DELETE
- server: reloadOpencodeEngine returns the RolloverOutcome; a standby with
  failed credential seeds is not promoted
- cloud-provider-sync: reloadPending clears only on an applied outcome;
  skipped/coalesced stay pending and retry, skipped marks the run failed

Coverage: engine-pool, managed-provider-auth, reload-guard, drain-defer
unit owners extended; managed-provider-env-delivery-reload boundary spec
gains a real managed v1 engine key-only rotation witness.
…ter deletion

The restart recovery reused a predicate requiring both originally
published providers, one of which the journey deletes earlier, so a
correct server could never satisfy it. Terminal status now requires the
currently assigned providers present, the deleted provider absent, and no
reload pending.
…tions

A key-only rotation through PUT /env never shows in the pool's config
fingerprint, so the unforced rollover request was skipped while the
route reported the reload as done and the engine kept the previous
credential. Force the standby path like cloud sync does, and only
answer reloaded once the pool applied the change; otherwise keep the
reload owed for the sync retry.

Extends the key-rotation journey with the local route and aligns the
Gateway sync fixture with the RolloverOutcome contract.

@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 (0d12b096940d928dbe318a14cc5539675d0b892c). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@reachjalil
reachjalil merged commit b72d9f0 into dev Sep 11, 2026
28 checks passed

This branch was successfully deployed

4 active deployments
Preview – openwork-den — 0d12b096 Deployed Sep 11, 2026 by vercel[bot]
Preview – openwork-landing — 0d12b096 Deployed Sep 11, 2026 by vercel[bot]
Preview – openwork-app — 0d12b096 Deployed Sep 11, 2026 by vercel[bot]
Preview – openwork-diagnostics — 0d12b096 Deployed Sep 11, 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.

2 participants