Skip to content

fix(workspace): re-read persisted workspace approvals after a failed startup read - #755

Merged
DeadWaveWave merged 1 commit into
DeadWaveWave:mainfrom
anhnt256:fix/persisted-workspace-approval-retry
Nov 26, 2026
Merged

DeadWaveWave merged 1 commit into
DeadWaveWave:mainfrom
anhnt256:fix/persisted-workspace-approval-retry

Conversation

@anhnt256

Copy link
Copy Markdown
Contributor

💡 Change Scope

  • Small Change: Fast feedback, localized UI/logic, low-risk.
  • Large Change: New feature, cross-boundary logic, runtime-risk (persistence, IPC, lifecycle, recovery).

📝 What Does This PR Do?

Fixes #720.

When the first persistence read at startup fails (e.g. the local Worker is not up yet — "Storage is unavailable", as in the Windows CI run behind #717), createPersistedWorkspaceApprovalGate never registered any approved workspace roots for the whole session: the catch only called onError, the persisted roots were never registered, the extraRoots were not registered either (they were computed after the read), and every later registerRoot/isPathApproved awaited the same settled ready promise — so previously approved workspaces stayed unregistered until an app restart.

This restructures the gate around a retryable, single-flight ensureHydrated():

  • Each hydration attempt registers the normalized extraRoots first, unconditionally (guarded by a one-shot flag, so retries never re-register them) — extra roots are registered whatever the read does.
  • If an attempt fails, the failure time is recorded and onError fires, as today. The next registerRoot or isPathApproved call starts a new attempt; concurrent calls share the one in-flight attempt. Once an attempt succeeds, the gate is hydrated and no further reads happen.
  • A retry waits out the remainder of a 250 ms backoff since the last failure, so a burst of approval checks cannot hammer a still-starting Worker. Retries are driven by real approval checks — at most one attempt per call, no unbounded loop.
  • The public shape is unchanged ({ approvedWorkspaces, ready }; ready still resolves, never rejects, when the first attempt fails), so registerIpcHandlers.ts needs no change.

Tests (TDD, red → green): three new tests in persistedWorkspaceApproval.spec.ts — extra roots are registered and approved even when the startup read fails; a first read that rejects and a second that resolves approves the second read's roots without a restart (the issue's proposed test), with onError fired once and no further reads afterwards; registerRoot also triggers the re-read, and two concurrent checks share a single retry. The three new tests fail on unmodified code (3 failed / 2 passed) and pass with the fix (5/5). The adjacent bootstrapSpaceDirectory suite passes 4/4, pnpm check (typecheck) exits 0, and prettier + oxlint are clean on both changed files. pnpm verify:quick and E2E were not run locally (this environment has no Electron binary or node-pty native build); CI is the gate for those.


🏗️ Large Change Spec (Required if "Large Change" is checked)

1. Context & Business Logic

Workspace approval decides which directories OpenCove may open without asking again. The approved roots come from persisted app state, hydrated once at startup. A single transient read failure at startup permanently disabled that hydration for the session, so every previously approved workspace behaved as unapproved until a restart. This change makes hydration recover on next use instead of never.

2. State Ownership & Invariants

The gate in PersistedWorkspaceApproval.ts owns the hydration state; the underlying ApprovedWorkspaceStore is unchanged. Invariants: (1) a root is only ever registered from a successful read or from extraRoots; (2) at most one persistence read is in flight at any time (single-flight); (3) after the first successful read, readAppState is never called again.

3. Verification Plan & Regression Layer

Unit layer: the three new tests in persistedWorkspaceApproval.spec.ts pin the failure-then-recovery behavior, the extra-roots-on-failure behavior, and the single-flight retry — they fail on the unmodified code and pass with the fix, so the bug cannot silently return. The adjacent bootstrapSpaceDirectory suite (the other consumer of the gate) passes 4/4, and typecheck is clean. Full regression runs in PR CI.


🔗 Co-change partners left untouched

None: this change leaves no co-change partner untouched.

Considered and intentionally not changed: src/app/main/ipc/registerIpcHandlers.ts — the only production caller; the factory's contract is unchanged, so it needs no edit (its onError log line now also fires on a failed retry, which is the desired visibility). src/contexts/workspace/infrastructure/approval/ApprovedWorkspaceStore.ts and ApprovedWorkspaceStoreCore.ts — the store is unchanged; its registerRoot is set-based, so a retry re-registering a root is a no-op.


✅ Delivery & Compliance Checklist

  • The local quick gate passes: pnpm verify:quick / pnpm pre-commit is green; any additional focused tests are reported above.
  • Full CI passes on the final revision before merge; local quick checks are not reported as full regression.
  • I have signed the CLA if required (see CLA.md).
  • I have locked down the behavior with the strongest asset that fits, in this order: type or structure, mechanical check, runtime assertion, scenario test (or explicitly stated why none applies).
  • I have strictly adhered to the DEVELOPMENT.md architectural boundaries.
  • I have attached a screenshot or screen recording (if this touches the UI).
  • I have updated the documentation accordingly (if adding a feature or changing a contract).

📸 Screenshots / Visual Evidence

Not applicable — no UI change; the behavior is pinned by the unit tests described above.

@DeadWaveWave
DeadWaveWave merged commit f2d8b01 into DeadWaveWave:main Nov 26, 2026
13 checks passed
@DeadWaveWave

Copy link
Copy Markdown
Owner

Merged, thanks @anhnt256. Checked:

  • The three invariants hold. Roots come only from a successful read or from extraRoots. At most one read runs at a time. After the first success there are no more reads. The tests cover each of them, and each fails on the old code.
  • ready still never rejects, so registerIpcHandlers.ts needs no change.
  • Latency while the Worker stays down: each approval check can now wait for a read attempt. Every remote operation already waits on the same endpoint resolver recovery, the 250 ms backoff and the single in-flight attempt keep it bounded, and nothing loops on its own. So this adds no new kind of stall.
  • If registerRoot fails on an extra root, that root is not lost: the store adds it in memory before it persists, so the one-shot flag is safe.

It ships in the next release.

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.

Approved workspaces stay unregistered for the whole session when the first persistence read at start-up fails

2 participants