Skip to content

feat(app): session management primitives (pin, archive, groups, manual order) - #2035

Merged
benjaminshafii merged 5 commits into
devfrom
feat/session-management-primitives
Jun 2, 2026
Merged

benjaminshafii merged 5 commits into
devfrom
feat/session-management-primitives

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Session management primitives (pin, archive, custom groups, manual order)

From the team discussion on session management: instead of one opinionated
take, this PR exposes a few unopinionated primitives so people can manage their
own workflow (Omar's emoji/status renaming, ben's "let people control this +
custom separators", Jean's "needs an archive feature").

What's included

  • Pin session — pinned root sessions float to the top. Global, persisted
    to localStorage (openwork.react.pinnedSessions). Quick win Omar suggested.
  • Manual ordering — drag-reorder root sessions per workspace, persisted to
    localStorage (openwork.react.sessionOrder). Mirrors the existing
    workspace-reorder pattern.
  • Custom separators / groups — user-defined buckets (defaults to "Done" /
    "In progress", then anything you want) with per-session assignment via a
    "Move to group" submenu. Persisted to localStorage
    (openwork.react.sessionGroups).
  • Archive session — non-destructive, backed by OpenCode's native
    session.time.archived (session.update). Archived sessions move to a
    collapsible "Archived (n)" section instead of being deleted — important for
    orgs with audit/retention policies that forbid deletion. Unarchive restores
    them.

All actions are available in both the ... dropdown and the right-click
context menu on each session.

Design notes

  • Pin / order / groups are pure client-side view state (no server schema
    needed), following the precedent already set by workspace ordering in
    session-memory.ts. Easy to migrate to a server DB later ("once we have our
    db up").
  • Archive is the one server-persisted primitive, leveraging the field
    OpenCode already ships. The standard list endpoint still returns archived
    sessions, so they're filtered client-side into the Archived section.
  • No behavior change when none of these are used: with zero pins/groups/order,
    the sidebar renders exactly as before.

Files

  • session-memory.ts — new persistence helpers (pins, per-workspace order,
    groups + assignments) + cleanup on workspace forget.
  • opencode-session.ts — setSessionArchived() helper.
  • sidebar/utils.ts — pin-first + manual-order sorting, archived partition,
    group-separator interleaving; FlattenedSessionRow is now a discriminated
    union (session | separator).
  • sidebar/app-sidebar.tsx + app-sidebar-provider.tsx — menu items, pin
    indicator, drag Reorder.Group, group separators, Archived section.
  • chat/session-page.tsx + shell/session-route.tsx — prop plumbing + handlers.
  • i18n/locales/en.ts — new session_management.* keys.

Tests run

pnpm --filter @openwork/app run typecheck   # exit 0, 0 errors
pnpm --filter @openwork/app run build        # exit 0 (vite build OK)

End-to-end evidence (real Electron on Daytona, via CDP)

Drove the real desktop app in a Daytona sandbox: created a workspace, created
5 sessions, then exercised every primitive.

Verified in the running app:

  1. Context menu shows Pin / Rename / Archive / Delete (+ "Move to group" in
    the ... dropdown).
  2. Pin — session floats to top with a pin icon; persisted to
    openwork.react.pinnedSessions.
  3. Archive — session.update({ time: { archived } }) succeeds, session
    moves into a collapsible Archived (1) section; active count drops 5 → 4.
  4. Groups — created "Done" and "In progress" separators and assigned
    sessions; sidebar renders the separators with sessions bucketed under each,
    ungrouped sessions below, Archived at the bottom.

Final sidebar state (grouped + pinned + archived all at once):

DONE
  📌 New session        <- pinned
IN PROGRESS
  New session
  New session
  New session            <- ungrouped
▸ Archived (1)

Notes / follow-ups

  • Drag-reorder is wired and persisted; it's only active in the ungrouped view
    (grouped view orders by group). Couldn't reliably script HTML5 drag over CDP,
    but pin-first ordering (same code path) is shown working.
  • The OpenCode sidecar was initially slow to bootstrap in the fresh dev sandbox
    (matches the "a bit more broken in dev" note in the thread); a reload
    bootstrapped it and everything worked. Unrelated to this change.

…l order)

Adds four user-controllable, unopinionated session-management primitives to
the workspace sidebar, per the team discussion:

- Pin session: pinned roots float to the top (global, localStorage).
- Manual ordering: drag-reorder root sessions per workspace (localStorage).
- Custom separators/groups: user-defined buckets ('Done', 'In progress',
  ...) with per-session assignment via a submenu (localStorage).
- Archive session: non-destructive, backed by OpenCode's native
  session.time.archived. Archived sessions move to a collapsible 'Archived'
  section instead of being deleted - important for audit/retention policies.

Pin/order/groups are pure client-side view state (mirrors the existing
workspace-order pattern in session-memory.ts); archive is server-persisted
via session.update. Sidebar actions are exposed in both the '...' dropdown
and the right-click context menu.
@vercel

vercel Bot commented Jun 2, 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 2, 2026 2:08am
openwork-den Ready Ready Preview, Comment Jun 2, 2026 2:08am
openwork-den-worker-proxy Ready Ready Preview, Comment Jun 2, 2026 2:08am
openwork-landing Ready Ready Preview, Comment, Open in v0 Jun 2, 2026 2:08am

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

3 issues found across 9 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/domains/session/sidebar/app-sidebar.tsx">

<violation number="1" location="apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx:1023">
P2: Reordering with a truncated preview overwrites manual order with only visible root IDs, causing hidden sessions to lose their saved order.</violation>
</file>

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

<violation number="1" location="apps/app/src/react-app/shell/session-route.tsx:2723">
P1: Archive requests are sent using the selected workspace client/root, so archiving from another workspace row can hit the wrong backend context.</violation>
</file>

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

Re-trigger cubic

opencodeClient,
sessionId,
archived,
selectedWorkspaceRoot || undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Archive requests are sent using the selected workspace client/root, so archiving from another workspace row can hit the wrong backend context.

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/session-route.tsx, line 2723:

<comment>Archive requests are sent using the selected workspace client/root, so archiving from another workspace row can hit the wrong backend context.</comment>

<file context>
@@ -2588,6 +2644,99 @@ export function SessionRoute() {
+          opencodeClient,
+          sessionId,
+          archived,
+          selectedWorkspaceRoot || undefined,
+        );
+        await refreshRouteState();
</file context>

Replace ~200 lines of manual localStorage code in session-memory.ts and ~80
lines of state/handlers/memos in session-route.tsx with a single Zustand store
(session-management-store.ts) using zustand/middleware/persist.

- Pin/order/groups read from the store via selectors imported directly by
  sidebar components (like useSessionActivityStore already does), avoiding
  context/prop drilling through 3 layers.
- Reverted FlattenedSessionRow to its original type; group separators are
  rendered inline at the .map() call site instead of a discriminated union.
- Removed 6 new fields from SidebarContextValue and corresponding props from
  AppSidebarProps and SessionPageSidebarProps.

Net diff vs origin/dev shrinks from 933/82 to 569/78 (-39%).

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

4 issues found across 7 files (changes from recent commits).

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/session-route.tsx">

<violation number="1" location="apps/app/src/react-app/shell/session-route.tsx:2723">
P1: Archive requests are sent using the selected workspace client/root, so archiving from another workspace row can hit the wrong backend context.</violation>
</file>

<file name="apps/app/src/react-app/domains/session/sidebar/session-management-store.ts">

<violation number="1" location="apps/app/src/react-app/domains/session/sidebar/session-management-store.ts:92">
P2: Workspace-specific session-management state cleanup was added but is unused, so forgetting a workspace leaves stale persisted order/group data.</violation>
</file>

<file name="apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx">

<violation number="1" location="apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx:177">
P2: The "New group" action is rendered as clickable even though no create-group callback is wired from SessionPage, so the menu item is a no-op.</violation>
</file>

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

Re-trigger cubic

};
}),

forgetWorkspace: (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: Workspace-specific session-management state cleanup was added but is unused, so forgetting a workspace leaves stale persisted order/group data.

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/domains/session/sidebar/session-management-store.ts, line 92:

<comment>Workspace-specific session-management state cleanup was added but is unused, so forgetting a workspace leaves stale persisted order/group data.</comment>

<file context>
@@ -0,0 +1,126 @@
+          };
+        }),
+
+      forgetWorkspace: (workspaceId) =>
+        set((state) => {
+          const { [workspaceId]: _o, ...orderRest } = state.orderByWorkspace;
</file context>

</DropdownMenuItem>
))}
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => ctx.onOpenCreateGroupModal?.(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: The "New group" action is rendered as clickable even though no create-group callback is wired from SessionPage, so the menu item is a no-op.

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/domains/session/sidebar/app-sidebar.tsx, line 177:

<comment>The "New group" action is rendered as clickable even though no create-group callback is wired from SessionPage, so the menu item is a no-op.</comment>

<file context>
@@ -167,39 +158,35 @@ function SessionGroupSubmenu(props: {
-          </>
-        ) : null}
+        <DropdownMenuSeparator />
+        <DropdownMenuItem onClick={() => ctx.onOpenCreateGroupModal?.(workspaceId)}>
+          <FolderPlus className="size-4" />
+          {t("session_management.new_group")}
</file context>

Add a Dialog-based modal for creating custom session groups (separators).
Clicking 'New group...' in the session dropdown submenu now opens a proper
input dialog instead of a window.prompt. Uses the same Dialog/Input/Button
primitives as the existing rename/delete modals.
- useCanManageSession always returns true (pin/group actions come from
  the store and should always be accessible, not gated on rename/delete)
- Group separator detection compares against previous root-level row,
  not any row (avoids spurious separators between parent and children)
- Reorder appends non-visible root IDs so hidden sessions keep their
  saved order when only a preview subset is shown
- Wire forgetWorkspace store cleanup in handleForgetWorkspace so stale
  persisted order/group data is pruned when a workspace is removed
Groups are workspace-scoped, so creating them from the workspace '...'
dropdown is the natural entry point alongside the per-session submenu.

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

1 issue found across 2 files (changes from recent commits).

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/domains/session/sidebar/app-sidebar.tsx">

<violation number="1" location="apps/app/src/react-app/domains/session/sidebar/app-sidebar.tsx:980">
P2: Reordering visible sessions can overwrite hidden root-session order because hidden IDs are appended from raw server order instead of existing manual order.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment on lines +980 to +981
const allRootIds = getRootSessions(activeSessions).map((s) => s.id);
const full = [...ids, ...allRootIds.filter((id) => !visible.has(id))];

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: Reordering visible sessions can overwrite hidden root-session order because hidden IDs are appended from raw server order instead of existing manual order.

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/domains/session/sidebar/app-sidebar.tsx, line 980:

<comment>Reordering visible sessions can overwrite hidden root-session order because hidden IDs are appended from raw server order instead of existing manual order.</comment>

<file context>
@@ -971,13 +974,24 @@ function WorkspaceSidebarGroup({
+                      onReorder={(ids) => {
+                        // Append non-visible root IDs so hidden sessions keep their saved order.
+                        const visible = new Set(ids);
+                        const allRootIds = getRootSessions(activeSessions).map((s) => s.id);
+                        const full = [...ids, ...allRootIds.filter((id) => !visible.has(id))];
+                        store.getState().reorderSessions(workspace.id, full);
</file context>
Suggested change
const allRootIds = getRootSessions(activeSessions).map((s) => s.id);
const full = [...ids, ...allRootIds.filter((id) => !visible.has(id))];
const serverRootIds = getRootSessions(activeSessions).map((s) => s.id);
const orderedRootIds = [...orderIds.filter((id) => serverRootIds.includes(id)), ...serverRootIds.filter((id) => !orderIds.includes(id))];
const full = [...ids, ...orderedRootIds.filter((id) => !visible.has(id))];

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