Repository navigation
fix(desktop): commit cross-server handoffs atomically - #4054
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Test evidence — a-cross-server-handoff-commits-origin-credential-and-organization-atomically-or- — 0/0 screenshots passed · 5 assertions✅ 0/0 screenshots passed · 5 assertions · 5 expectations passed · 0 failed · 0 pending
ℹ️ ASSERTION — 1. Same-origin handoff enrolled control plane AThe app signed in to Handoff Atomic A with the enrollment origin stamped to A.
ℹ️ ASSERTION — 2. Bootstrap persistence failure left the complete A enrollment activeWith bootstrap writes failing, the B handoff was rejected: the bootstrap file, token, organization, and enrollment origin all still belong to A, and no success state was published.
ℹ️ ASSERTION — 3. The retried handoff committed B atomicallyOrigin (bootstrap file), credential, organization (Handoff Atomic B), and enrollment marker switched to B together.
ℹ️ ASSERTION — 4. A consumed one-time grant cannot be replayedRe-exchanging the spent grant failed and the committed B enrollment was untouched.
ℹ️ ASSERTION — 5. Restart restored the complete B enrollmentAfter a relaunch, the app came back signed in to Handoff Atomic B with the B credential and enrollment origin.
Test run created 2026-08-24T23:50:58.754Z · Source: |
A Desktop handoff for control plane B could partially succeed while control plane A stayed active: the bearer token, active organization, durable bootstrap origin, and renderer success state each transitioned independently, so a bootstrap write failure, app exit, concurrent attempt, or missing destination organization could leave a hybrid enrollment (B's token active against A's persisted origin, A's organization leaking into B, or UI success published before the durable commit). Make the handoff a single enrollment transaction in exchangeHandoffAndSignIn, which every entry point (deep link, pasted code, control action, prepared bootstrap, enterprise activation) already funnels through: - resolve the destination once (including its published runtime-config API base) and construct the exchange client from it, so the grant can only be sent to — and the credential can only come from — the origin that will be persisted; the redundant caller-supplied client option is removed - persist the destination bootstrap durably, then confirm the committed bootstrap is the intended destination before anything becomes active, folding enterprise activation stamps and consumed-grant cleanup into the same commit instead of separate follow-up writes - publish origin, token, and organization in one write; an organization never carries into a different origin unless the destination returns one - roll back to the previous coherent enrollment when persistence, read-back confirmation, or activation fails, and report consumed one-time grants as non-retriable so entry points stop replaying spent grants - serialize commits and reject late results from superseded attempts so concurrent handoffs cannot interleave or cross their fields Crash windows between the durable bootstrap commit and the session write are covered by the session-origin coherence gate introduced in #4050: the transaction's single activation write stamps the issuing origin, so an interrupted commit resumes as signed-out-at-the-destination, never as a hybrid of two control planes.
…off grant A destination's runtime-published denApiUrl is adopted for the one-time handoff exchange only when it is same-origin with the destination web origin or its deterministic hosted API sibling; every other published value keeps the exchange on the destination's own /api/den proxy. Cross-origin handoff commits now clear the previous origin's enterprise activation stamp explicitly, so a new control plane can never inherit an activation recorded against a different Den base URL.
e16262e to
69347c0
Compare
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (69347c0b5552b45250fc87f0ffd9217dfe20a323). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
…ct snapshot and trusted inventory #4054 added evals/specs/cross-server-handoff-atomic-commit.e2e.test.ts without mapping it, so the PR lane on dev fails two governance specs for every PR: - spec-impact: "every E2E spec is mapped to an implementation contract or explicitly allowlisted" - spec-quarantine: "the enabled E2E set equals the evidence-backed inventory" (38 vs 37) Map it to desktop.onboarding-cloud-auth (which already owns den-auth-provider.tsx and forced-signin-page.tsx), add den-handoff.ts to that contract's implementation, and list the spec in expectedEnabled. Control: the same two specs fail identically on a clean origin/dev (3e425fa) checkout. (cherry picked from commit 1ab90db)
…K smoke (#4375) * test(evals): register the cross-server handoff e2e spec in the contract snapshot and trusted inventory #4054 added evals/specs/cross-server-handoff-atomic-commit.e2e.test.ts without mapping it, so the PR lane on dev fails two governance specs for every PR: - spec-impact: "every E2E spec is mapped to an implementation contract or explicitly allowlisted" - spec-quarantine: "the enabled E2E set equals the evidence-backed inventory" (38 vs 37) Map it to desktop.onboarding-cloud-auth (which already owns den-auth-provider.tsx and forced-signin-page.tsx), add den-handoff.ts to that contract's implementation, and list the spec in expectedEnabled. Control: the same two specs fail identically on a clean origin/dev (3e425fa) checkout. * test(evals): route cross-server handoff helpers through testkit The same newly added e2e spec also broke the eval-runner layer ratchet by importing @openwork/behaviors and @openwork/hosts directly. Re-export its four required runtime helpers from @openwork/testkit and import all eval primitives and types through that package. This removes the two new specs-use-testkit-only violations instead of expanding the 206-entry known violation baseline. Proof: pnpm test:eval-runner passes 225/225; lint:layers reports zero new dependency violations. * test(app): isolate the SDK smoke engine from user and CI runner state The app SDK smoke inherited the runner's real OpenCode database, plugins, MCPs, and project config even though it only verifies core SDK calls. On both CI runners /global/health waited five minutes on unrelated setup, then path.get hit a vanished process; rerunning reproduced it exactly. Give this one smoke process a temporary database and minimal config, disable external setup, and remove the temp directory after close. A PR-lane witness runs the real script and asserts health, path.get, session operations, and SSE all complete without an error step. Locally it completes in 4.6 seconds instead of failing after five minutes. * test(app): isolate every SDK smoke engine by default The first isolated script passed in CI, but session-switch then inherited the runner's real config and failed after the same five-minute wait. Move the hermetic defaults into spawnOpencodeServe so every core smoke process gets a temporary database and minimal config. browser-entry opts out of pure config because it deliberately tests a project command, while retaining the private database. Cleanup runs even when the child exits early. The agent-first witness now executes the exact app test:e2e package command: core SDK calls, session switching, filesystem operations, and browser-entry.
Problem
A user can accept a Desktop sign-in, organization, install-link, or enterprise handoff for control plane B while control plane A is still active — and end up with a partially switched Desktop state. Concretely:
Root cause
The handoff sequence updated its pieces independently:
exchangeHandoffAndSignInwrote the token and organization to session storage synchronously, while the bootstrap origin was persisted by a fire-and-forget write (void setDenBootstrapConfig(...).catch(() => undefined)) insidewriteDenSettings, and thedenSessionUpdatedsuccess event fired before either was confirmed. Enterprise activation stamps and consumed-grant cleanup were separate follow-up bootstrap writes after the session had already switched. Nothing versioned attempts, so late or concurrent exchanges raced. The exchange client was supplied redundantly by each caller, so the exchange target and the persisted destination were only coincidentally the same.Transaction boundary
exchangeHandoffAndSignInis now a single enrollment transaction with explicit phases:resolveDenBaseUrlsForDestination, which prefers the API base the destination publishes in its runtime config — the same source the bootstrap commit uses) and number the attempt.clientoption is removed.requireSignin, enterprise activation stamps, and consumed-grant cleanup that used to be follow-up writes), then re-read and confirm the committed bootstrap is the intended destination. On divergence, restore the previous bootstrap.writeDenSettingscall publishes origin, token, and organization together (stamping the issuing origin next to the token via the fix(desktop): keep bootstrap and retained Den sessions origin-coherent #4050 invariant).denSessionUpdated: success.Commits are serialized through a module-level queue, and each attempt carries a generation number checked at the commit boundary.
Invariant
A cross-server handoff's origin, credential, organization, and enrollment generation become active together, or none of them do. The current enrollment remains authoritative until the candidate has been validated against the expected destination, durably persisted, confirmed as the committed bootstrap, promoted to the active session, and only then published as successful.
Solution details
stale: true, activates nothing, and publishes nothing; concurrent A→B / A→C attempts cannot cross fields — the newest attempt wins whole.grantConsumed: true; the deep-link and prepared-bootstrap entry points stop retrying spent grants (the prepared-bootstrap path strips the spent grant from disk best-effort) — recovery is a fresh handoff link.Preservation
saveControlPlaneUrl) keep their existing semantics; the transaction adopts the same persist-then-activate order that path already modeled.Proof
Two deterministic Den identities (two independent local Den servers, orgs "Handoff Atomic A"/"Handoff Atomic B") and an injected bootstrap-persistence failure (the Electron profile root is made read-only so the shell's atomic
bootstrap.jsonwrite fails).pnpm --filter @openwork/app test(890 tests, incl. 18 handoff transaction tests + the 13 #4050 origin-coherence tests)devin this environment (verified by an A/B run on the clean base: identical set, e.g. missingwindow.matchMedia)pnpm --filter @openwork/app typecheckpnpm --filter @openwork/app buildpnpm evals:e2e cross-server-handoff-atomic-commit --localat the exact headfirst-run-bootstrap-contract's gating)pnpm --dir evals run lint:layerspnpm evals:e2e first-run-bootstrap-contract --localTestkit spec:
evals/specs/cross-server-handoff-atomic-commit.e2e.test.tsproves, in one journey against the real app: same-origin enrollment to A → injected bootstrap-persistence failure leaves the complete A enrollment (bootstrap file, token, organization, session origin) active with an error and no success event → a fresh grant commits B's origin, credential, and organization together (file + storage + session-origin all B) → the consumed grant cannot be replayed → a restart restores the complete B enrollment.Unit/integration (
apps/app/tests/den-handoff.test.ts, 18 tests) covers the full matrix: atomic cross-origin commit, no org inheritance, persistence-failure rollback with no success publication and no credential exposure (exchange requests asserted to reach only the destination API host — the negative network half), read-back origin mismatch rejection with durable rollback, stale-attempt rejection, concurrent-attempt isolation, interrupted-commit restart state (never hybrid), committed-commit restart restore, desktop-initiated org deferral, and log capture asserting grants/tokens never appear in diagnostics.Negative proof
denSessionUpdatedstream containserrorand nosuccess(e2e + unit).stale: trueand the persisted state is entirely the newer attempt's — asserted field-by-field (unit).Dependency statement
Independent. The bootstrap/session-origin coherence work landed on
devas #4050 while this change was in flight; this PR is rebased onto it and reuses itssessionOrigininvariant for the crash-window guarantee instead of duplicating a second marker (an earlier draft's separate enrollment marker was removed during reconciliation). No stacked base or special merge order is required.Risk and rollback
clientoption was only ever passed with the same base URL the callers already supplied.Scope exclusions
This PR does not redesign general Connect policy reconciliation (see #4052), does not change release or deployment behavior, and does not alter Den-side grant issuance.