Skip to content

refactor(app): session-route decomposition round 2 — engine reload, typed sessions (zero any), settings picker adoption - #2201

Merged
benjaminshafii merged 3 commits into
devfrom
refactor/session-route-hooks-2
Jun 12, 2026
Merged

benjaminshafii merged 3 commits into
devfrom
refactor/session-route-hooks-2

Conversation

@benjaminshafii

@benjaminshafii benjaminshafii commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

What

Continues #2200 (steps 7–9 of the session-route decomposition). Three commits, each independently gated and revertable.

Commit Change
8451b3bd4 useEngineReload (shell/use-engine-reload.ts): UI-triggered engine reload, reload-coordinator registration, post-org-onboarding reload latch, reload-event polling (per-workspace cursor), desktop engine info. Reload events now flow through their existing OpenworkReloadEvent type instead of (item: any). shareWorkspaceState relocated below the hook (its outputs are only consumed later; behavior unchanged).
04ce94089 RouteSession typing: sessionsByWorkspaceId was Record<string, any[]> in both routes even though listSessions has returned typed SDK Session[] all along. New RouteSession (SDK Session + the defensive run-status fields the sidebar probes). Kills 4 session as any inserts and 14 (session: any) lambdas — session-route.tsx now contains zero as any/: any (24 at survey time, highest in the repo).
d62e5c8e8 settings-route adopts useModelPicker (-99 lines): settings carried a drifted copy of the picker + option loader that rendered the RAW model list — models from org-blocked providers (dev #1505 desktop policy) were selectable from Settings while the session route filtered them. Adopting the shared hook closes the hole. Settings-specific behavior preserved: refreshProviders() on open + error toast via the hook's new optional onLoadError.

Running tally for the decomposition: session-route.tsx 3,328 → 2,677 · settings-route.tsx 2,595 → 2,402 · third latent bug fixed by deduplication (after the settings remote-clobber fix in #2200 and the macOS reload-trigger fix in #2199).

Tests (ran after every commit)

pnpm --filter @openwork/app typecheck   # clean
pnpm --filter @openwork/app test        # 58 pass, 0 fail
pnpm --filter @openwork/app build       # vite production build clean
pnpm --filter @openwork/app test:e2e    # 23/23 assertions ok (real app + opencode)

No video: behavior-preserving refactor (the one intentional change is the restriction-filter fix described above, UI-visible only when org policies block providers). Reviewer repro: commands above; for the policy fix, set a desktop policy blocking a provider and open Settings → model picker.

Review in cubic

UI-triggered engine reload, reload-coordinator registration, the
post-org-onboarding reload latch, server reload-event polling (cursor per
workspace), and desktop engine info move verbatim to
shell/use-engine-reload.ts. Reload events flow through their existing
OpenworkReloadEvent type instead of (item: any). shareWorkspaceState moved
below the hook so routeEngineInfo exists before it is consumed; behavior
unchanged (its outputs are only read later).

The engineInfo() cast is pre-existing (dynamic desktop-bridge Proxy) and
keeps a pointer to the queued typed-IPC work.

session-route.tsx: 2,777 -> 2,676 lines.

Tested: pnpm typecheck clean; bun test 58 pass; pnpm build clean;
pnpm test:e2e 23/23 assertions ok.
…ero any

sessionsByWorkspaceId was Record<string, any[]> in both routes even though
openwork-server's listSessions has returned typed SDK Session[] all along.
New RouteSession (Session + the defensive run-status fields the sidebar
probes) in route-workspaces.ts; both routes' state/refs/lambdas now use it,
getSessionStatus and toSessionGroups are properly typed, and the 4
'session as any' inserts plus 14 '(session: any)' lambdas are gone.

session-route.tsx now contains zero 'as any' / ': any' (24 at the start of
this effort, highest in the repo).

Tested: pnpm typecheck clean; bun test 58 pass; pnpm build clean;
pnpm test:e2e 23/23 assertions ok.
…iction bypass

settings-route carried its own copy of the model picker state + lazy option
loader, and it had drifted: the settings picker rendered the RAW option list
with no org-restriction filtering, so models from providers blocked by
desktop policy (dev #1505) were selectable from Settings while the session
route filtered them. Adopting the shared hook closes that hole.

Preserved settings-specific behavior:
- providerAuthStore.refreshProviders() on picker open (small effect)
- error toast on option-load failure via the hook's new optional
  onLoadError (the session route stays silent, unchanged default)

Convergences (now session behavior): query is no longer cleared by the
open event, and recently-added provider ids are captured for the
'Recently added' section, which settings previously ignored.

settings-route.tsx: 2,473 -> 2,402 lines.

Tested: pnpm typecheck clean; bun test 58 pass; pnpm build clean;
pnpm test:e2e 23/23 assertions ok.
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview, Comment Jun 12, 2026 8:33pm
openwork-den Ready Ready Preview, Comment Jun 12, 2026 8:33pm
openwork-den-worker-proxy Ready Ready Preview, Comment Jun 12, 2026 8:33pm
openwork-landing Ready Ready Preview, Comment, Open in v0 Jun 12, 2026 8:33pm

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/app/src/react-app/shell/use-engine-reload.ts">

<violation number="1" location="apps/app/src/react-app/shell/use-engine-reload.ts:113">
P2: Reload-event cursor updates are not monotonic under overlapping polls. A late stale response can move the workspace cursor backward and trigger duplicate/stale reload-required events.</violation>
</file>

<file name="apps/app/src/react-app/shell/settings-route.tsx">

<violation number="1" location="apps/app/src/react-app/shell/settings-route.tsx:2386">
P3: Model picker close flow leaves recent-provider highlight state stale. Previously-added providers can stay marked as "Recently added" on later opens.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

typeof currentCursor === "number" ? { since: currentCursor } : undefined,
);
if (cancelled) return;
reloadEventCursorByWorkspaceRef.current[workspaceId] =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Reload-event cursor updates are not monotonic under overlapping polls. A late stale response can move the workspace cursor backward and trigger duplicate/stale reload-required events.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/app/src/react-app/shell/use-engine-reload.ts, line 113:

<comment>Reload-event cursor updates are not monotonic under overlapping polls. A late stale response can move the workspace cursor backward and trigger duplicate/stale reload-required events.</comment>

<file context>
@@ -0,0 +1,158 @@
+          typeof currentCursor === "number" ? { since: currentCursor } : undefined,
+        );
+        if (cancelled) return;
+        reloadEventCursorByWorkspaceRef.current[workspaceId] =
+          typeof response.cursor === "number"
+            ? response.cursor
</file context>

onBehaviorChange={() => {}}
onOpenSettings={() => {}}
onClose={() => setModelPickerOpen(false)}
onClose={() => modelPicker.setOpen(false)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: Model picker close flow leaves recent-provider highlight state stale. Previously-added providers can stay marked as "Recently added" on later opens.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/app/src/react-app/shell/settings-route.tsx, line 2386:

<comment>Model picker close flow leaves recent-provider highlight state stale. Previously-added providers can stay marked as "Recently added" on later opens.</comment>

<file context>
@@ -2449,11 +2379,11 @@ function SettingsRouteContent(props: SettingsSurfaceProps = {}) {
         onBehaviorChange={() => {}}
         onOpenSettings={() => {}}
-        onClose={() => setModelPickerOpen(false)}
+        onClose={() => modelPicker.setOpen(false)}
       />
     </>
</file context>

This branch was successfully deployed

4 active deployments
Preview – openwork-den-worker-proxy — d62e5c8e Deployed Jun 12, 2026 by vercel[bot]
Preview – openwork-landing — d62e5c8e Deployed Jun 12, 2026 by vercel[bot]
Preview – openwork-den — d62e5c8e Deployed Jun 12, 2026 by vercel[bot]
Preview – openwork-app — d62e5c8e Deployed Jun 12, 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