Skip to content

refactor(app): session-route decomposition — 6 hook extractions, -551 lines - #2200

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

benjaminshafii merged 6 commits into
devfrom
refactor/session-route-hooks

Conversation

@benjaminshafii

@benjaminshafii benjaminshafii commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

What

Phase 2 of the architecture refactor (follow-up to #2199): decomposing the session-route.tsx god-component (3,328 lines, 32 effects, one component) into domain hooks. Six extractions, one commit each, every commit independently gated and revertable.

Commit Extraction Notes
c66c4014c shell/route-workspaces.ts — the helper family both routes duplicated (RouteWorkspace, mapDesktopWorkspace, mergeRouteWorkspaces, toSessionGroups, getSessionStatus, describe*Error, export/download helpers) The copies had drifted: settings-route was missing the mergeRouteWorkspaces fix that stops stale local-server registrations from clobbering desktop remote workspaces (latent bug, fixed by unification); also older getSessionStatus/isActiveSessionStatus. -290 duplicated lines
28157d200 domains/session/sync/use-session-interactions.ts — permissions/questions/todos (busy state, cache subscriptions, seed effects, reply handlers) + generic infra/query-cache-state.ts Verbatim move; 4 stable inputs
86de215d1 domains/cloud/use-openwork-models-startup-promo.ts — startup promo latch Self-acquires denAuth/platform/navigate (use-den-session pattern)
539efdf50 domains/session/surface/use-model-behavior.ts — provider catalog prefetch + variant pill computation Catalog now typed Record<providerID, Record<modelID, ProviderModel>> instead of Record<string, Record<string, any>>
2a3339230 domains/session/modals/use-model-picker.ts — picker state, lazy option loader, new-provider toast triggers, org-restriction filtering settings-route adoption queued as follow-up
3468f9787 shell/use-shell-shortcuts.ts — palette/search/terminal state + global Cmd-N/K/J/Shift-F keydown (useEffectEvent) Reads canCreateTask at event time, exactly as before

session-route.tsx: 3,328 → 2,777 lines (-551). All moves are verbatim (behavior-preserving); the only intentional behavior change is settings-route inheriting the newer merge/status helpers (the drift fix called out above).

Tests (ran locally after EVERY commit, not just at the end)

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 (boots real app + opencode)

Live checks: vite dev server serves the new module graph (200s) per step.

No video: behavior-preserving refactor with no UI change — the per-commit e2e runs are the end-to-end evidence. Reviewer repro: commands above on any commit in the stack.

Follow-ups queued (tracker)

useEngineReload · useWorkspaceSessions (types the session lists, kills ~21 anys) · useWorkspaceModals · useSessionProviderAuth · core useWorkspaceRouteState · settings-route adopts useModelPicker

Review in cubic

session-route.tsx and settings-route.tsx each carried a private copy of the
route-workspace helper family (RouteWorkspace, mapDesktopWorkspace,
workspaceLabel, mergeRouteWorkspaces, toSessionGroups, getSessionStatus,
isActiveSessionStatus, describe*Error, export/download helpers,
folderNameFromPath) — and the copies had drifted:

- settings-route was MISSING the mergeRouteWorkspaces fix that stops stale
  local-server registrations from clobbering desktop remote workspaces'
  routing fields (a latent settings-route bug, now fixed by unification)
- settings-route used older getSessionStatus (no normalizeSessionStatus)
  and isActiveSessionStatus (no 'streaming')

One canonical copy now lives in shell/route-workspaces.ts (the newer
session-route behavior). settings' toSessionGroups call passes an empty
loading set, preserving its previous output exactly.

session-route: 3,328 -> 3,161 lines; settings-route: 2,595 -> 2,472.

Tested:
- pnpm typecheck clean; bun test tests/ 58 pass
- pnpm build clean
- live: vite serves both routes' new module graph (200)
- pnpm test:e2e — 23/23 assertions ok (real app + opencode binary)
Permissions/questions/todos cluster (~170 lines: busy state, query-cache
subscriptions, snapshot seed effects, reply handlers) moves verbatim to
domains/session/sync/use-session-interactions.ts. Nothing in the component
read this cluster's internals except the JSX, so the seam is a single hook
call with four stable inputs (client, workspaceId, sessionId, workspaceRoot).

The generic useQueryCacheState helper moves to infra/query-cache-state.ts
next to the query-client singleton.

session-route.tsx: 3,161 -> 3,020 lines (3,328 at phase start).

Tested:
- pnpm typecheck clean; bun test tests/ 58 pass
- pnpm build clean
- pnpm test:e2e — 23/23 assertions ok (boots real app, exercises sessions,
  permissions among them)
The OpenWork Models startup promo (one-shot latch, promo-hidden listener,
schedule effect, subscribe/continue handlers) moves verbatim to
domains/cloud/use-openwork-models-startup-promo.ts. The hook self-acquires
denAuth/platform/navigate/shellConfig (same pattern as use-den-session) and
takes clientReady/workspaceId/providerConnectedIds as inputs.

session-route.tsx: 3,020 -> 2,973 lines.

Tested: pnpm typecheck clean; bun test 58 pass; pnpm build clean;
pnpm test:e2e 23/23 assertions ok.
Provider-catalog prefetch + reasoning/thinking variant computation move to
domains/session/surface/use-model-behavior.ts. The catalog is now properly
typed as Record<providerID, Record<modelID, ProviderModel>> instead of
Record<string, Record<string, any>> (ProviderModel is exactly
ProviderListItem['models'][string], so the SDK shape flows through to
getModelBehaviorSummary with no casts). The hook also returns the catalog
for the model picker's lazy loader until that extraction lands.

session-route.tsx: 2,973 -> 2,934 lines.

Tested: pnpm typecheck clean; bun test 58 pass; pnpm build clean;
pnpm test:e2e 23/23 assertions ok.
Model picker modal state (open/compact/query/options), the new-providers
toast event + pending-localStorage triggers, the lazy option loader with
'Recently added' flagging, and the org-restriction filter move verbatim to
domains/session/modals/use-model-picker.ts. The hook self-acquires the
desktop-restriction context and exposes raw setters so call sites stay
one-line renames. The render watchdog moved below the hook to keep its
modelPickerOpen attribution field.

session-route.tsx: 2,934 -> 2,815 lines (3,328 at phase start).
settings-route still carries its sibling copy of the option loader; adopting
this hook there is queued as its own commit.

Tested: pnpm typecheck clean; bun test 58 pass; pnpm build clean;
pnpm test:e2e 23/23 assertions ok.
Command palette / session search / terminal open-state plus the global
Cmd-N/K/J/Shift-F keydown handler (useEffectEvent) move verbatim to
shell/use-shell-shortcuts.ts. The hook reads canCreateTask/onCreateTask at
event time exactly as before; the call sits after
handleCreateTaskInWorkspace so nothing is referenced before declaration,
with the render watchdog relocated alongside to keep its panel-state
attribution fields.

session-route.tsx: 2,815 -> 2,777 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:09pm
openwork-den Ready Ready Preview, Comment Jun 12, 2026 8:09pm
openwork-den-worker-proxy Ready Ready Preview, Comment Jun 12, 2026 8:09pm
openwork-landing Ready Ready Preview, Comment, Open in v0 Jun 12, 2026 8:09pm

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

No issues found across 9 files

Re-trigger cubic

This branch was successfully deployed

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