Skip to content

Commit 8392dad

Browse files
feat(web): every thread group has a parent that carries it to Working (#1904)
## Problem Upstream's Working shelf pulls each working thread out of its group, so a group splits across two sections while any member works. A group could also have no parent, which left no thread to decide where the group belongs. ## Change **Every group has a parent** - **New group:** its first thread leads - **Drop on a thread:** the target leads - **Drop under the tab:** dragged thread leads - **Parent leaves:** first remaining member leads - **Swap:** "Set as group parent" on any child - **Removed:** "Clear group parent" - **Legacy null parent:** first member leads **Working shelf follows the parent** - **Parent works:** whole group moves to Working - **Child works, parent idle:** group stays Active - **That child:** one line, even expanded - **Collapsed group:** blue dot on the tab The contract reducer, server, MCP tool description and web client all share the required parent. ## Scope and approval The human asked for parent-led groups, no parentless group, and a compact working child. They chose to keep the title tab above the parent. ## Verification Isolated dev instance, seeded copy of real data, dark mode. **1. Parent works: group moves to Working** https://github.com/user-attachments/assets/93618826-3a1d-4c86-bc89-3202b406af39 **2. Child works: group stays, child compacts** https://github.com/user-attachments/assets/f3b3b184-90a4-4dd4-bb7c-69b9112c074e **3. Swap parent from the menu** https://github.com/user-attachments/assets/53dbc64b-fc8b-4e89-95a7-695afe325cfb **4. Parent leaves: Child A takes over** https://github.com/user-attachments/assets/fbb3683a-9ff6-4680-be95-0b5da73dfa4b **5. Drag: create, join, lead** https://github.com/user-attachments/assets/739f3193-aa4c-4731-b10a-e4e91c292298 **6. Collapsed group, child works** https://github.com/user-attachments/assets/2d8556e3-e7a3-4a50-b014-7273784561eb **7. Parent settled** https://github.com/user-attachments/assets/7af89656-0958-4df0-a4cf-13171e9c30dd - [x] `vp run check:changed` → exit 0 (5461 tests) - [x] `vp run fork:ci` → exit 0 - [x] Legacy null parent persisted on next write **Known edges** - Working count includes idle children - Group lingers under Working after Done - Settled parent: plain header, no parent row - Agent tool budget: 4815 → 4783 bytes Claude Opus 5.5 via Claude Code. ## Fork trailers Fork-Domain: thread-ordering Fork-Tier: qol Co-authored-by: donjor <[email protected]>
1 parent d3e402c commit 8392dad

24 files changed

Lines changed: 378 additions & 168 deletions

‎apps/server/src/mcp/toolkits/threadGroups/handlers.fork.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const startGroup = ThreadGroups.ThreadGroupsServiceFork.pipe(
6767
groups.mutate({
6868
type: "set-membership",
6969
threadIds: [orchestrator, first],
70-
target: { type: "new", groupId: "g1", title: "Work", asParent: true },
70+
target: { type: "new", groupId: "g1", title: "Work" },
7171
}),
7272
),
7373
);

‎apps/server/src/mcp/toolkits/threadGroups/tools.fork.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const ThreadGroupListTool = Tool.make("t3_thread_group_list", {
3636

3737
const ThreadGroupUpdateTool = Tool.make("t3_thread_group_update", {
3838
description:
39-
'Change the sidebar thread groups every client of this environment shows. Pass one change as edit. type="set-membership" moves threadIds into target {type:"existing",groupId}, a {type:"new",title} group of at least two threads, or out of any group with {type:"none"}; asParent makes the first thread the group\'s parent, shown first with the rest under it. type="rename" retitles a group, "set-parent" sets or clears (null) its parent, "remove" dissolves it without touching its threads. A thread belongs to at most one group, and a group left with fewer than two threads dissolves. Returns every group after the change.',
39+
'Change the sidebar thread groups every client of this environment shows. Pass one change as edit. type="set-membership" moves threadIds into target {type:"existing",groupId}, a {type:"new",title} group of at least two threads, or out of groups with {type:"none"}. Groups lead with a parent: a new group\'s first thread, or a joining thread with asParent. type="rename" retitles a group, "set-parent" picks another member, "remove" dissolves it, threads kept. A thread is in at most one group; a group under two threads dissolves, and a leaving parent passes to the next member. Returns every group after the change.',
4040
// MCP needs an object root, so the edit union sits under one key.
4141
parameters: Schema.Struct({ edit: ThreadGroupEditFork }),
4242
success: ThreadGroupsDescribedFork,

‎apps/server/src/orchestration-v2/ThreadGroupsService.fork.test.ts‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Effect from "effect/Effect";
66
import * as Exit from "effect/Exit";
77
import * as Fiber from "effect/Fiber";
88
import * as Layer from "effect/Layer";
9+
import * as SqlClient from "effect/sql/SqlClient";
910
import * as Stream from "effect/Stream";
1011

1112
import { ensureForkSchema } from "../persistence/ForkSchema.ts";
@@ -49,7 +50,7 @@ database("ThreadGroupsServiceFork", (it) => {
4950
yield* service.mutate({
5051
type: "set-membership",
5152
threadIds: [a, b],
52-
target: { type: "new", groupId: "g1", title: "Orchestrator", asParent: true },
53+
target: { type: "new", groupId: "g1", title: "Orchestrator" },
5354
});
5455
yield* service.mutate({
5556
type: "set-membership",
@@ -63,7 +64,7 @@ database("ThreadGroupsServiceFork", (it) => {
6364
Effect.gen(function* () {
6465
const service = yield* ThreadGroups.ThreadGroupsServiceFork;
6566
const before = yield* service.snapshot;
66-
// The parent leaving stops it leading; the group keeps two members.
67+
// The parent leaving hands the lead to the next member.
6768
const afterParentLeaves = yield* service.mutate({
6869
type: "set-membership",
6970
threadIds: [a],
@@ -81,7 +82,7 @@ database("ThreadGroupsServiceFork", (it) => {
8182
{ id: "g1", title: "Orchestrator", threadIds: [a, b, c], parentThreadId: a },
8283
]);
8384
assert.deepStrictEqual(reloaded.afterParentLeaves.groups, [
84-
{ id: "g1", title: "Orchestrator", threadIds: [b, c] },
85+
{ id: "g1", title: "Orchestrator", threadIds: [b, c], parentThreadId: b },
8586
]);
8687
assert.deepStrictEqual(reloaded.dissolved.groups, []);
8788
}),
@@ -148,16 +149,40 @@ database("ThreadGroupsServiceFork import", (it) => {
148149
const imported = yield* service.mutate({
149150
type: "import",
150151
groups: [
151-
{ id: "g1", title: "Same id", threadIds: [c, d] },
152+
{ id: "g1", title: "Same id", threadIds: [c, d], parentThreadId: c },
152153
{ id: "g2", title: "Grouped or dead", threadIds: [b, c, deleted], parentThreadId: b },
153154
{ id: "g3", title: "Local", threadIds: [c, missing, d], parentThreadId: missing },
154155
],
155156
});
156157
assert.deepStrictEqual(imported.groups, [
157-
{ id: "g1", title: "Server", threadIds: [a, b] },
158-
{ id: "g3", title: "Local", threadIds: [c, d] },
158+
{ id: "g1", title: "Server", threadIds: [a, b], parentThreadId: a },
159+
{ id: "g3", title: "Local", threadIds: [c, d], parentThreadId: c },
159160
]);
160161
}),
161162
),
162163
);
163164
});
165+
166+
database("ThreadGroupsServiceFork legacy rows", (it) => {
167+
it.effect("leads a group saved without a parent with its first member", () =>
168+
Effect.gen(function* () {
169+
yield* ensureForkSchema();
170+
const sql = yield* SqlClient.SqlClient;
171+
yield* sql`INSERT INTO fork_thread_groups ${sql.insert({
172+
group_id: "g1",
173+
position: 0,
174+
title: "Legacy",
175+
thread_ids_json: JSON.stringify([b, a]),
176+
parent_thread_id: null,
177+
})}`;
178+
const snapshot = yield* withService(
179+
Effect.gen(function* () {
180+
return yield* (yield* ThreadGroups.ThreadGroupsServiceFork).snapshot;
181+
}),
182+
);
183+
assert.deepStrictEqual(snapshot.groups, [
184+
{ id: "g1", title: "Legacy", threadIds: [b, a], parentThreadId: b },
185+
]);
186+
}),
187+
);
188+
});

‎apps/server/src/orchestration-v2/ThreadGroupsService.fork.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ const decodeGroup = Schema.decodeSync(ThreadGroupForkSchema);
9191
/** Compares snapshots by value, so a no-op mutation neither writes nor notifies. */
9292
const encodeGroups = Schema.encodeSync(Schema.fromJsonString(Schema.Array(ThreadGroupForkSchema)));
9393

94-
const rowToGroup = (row: ThreadGroupRow): ThreadGroupFork =>
95-
decodeGroup({
94+
const rowToGroup = (row: ThreadGroupRow): ThreadGroupFork => {
95+
const threadIds = decodeThreadIds(row.thread_ids_json);
96+
// Rows written before every group had a parent fall back to the first member.
97+
const parent = threadIds.find((threadId) => threadId === row.parent_thread_id);
98+
return decodeGroup({
9699
id: row.group_id,
97100
title: row.title,
98-
threadIds: decodeThreadIds(row.thread_ids_json),
99-
...(row.parent_thread_id === null ? {} : { parentThreadId: row.parent_thread_id }),
101+
threadIds,
102+
parentThreadId: parent ?? threadIds[0]!,
100103
});
104+
};
101105

102106
const make = Effect.gen(function* () {
103107
const sql = yield* SqlClient.SqlClient;
@@ -123,7 +127,7 @@ const make = Effect.gen(function* () {
123127
position,
124128
title: group.title,
125129
thread_ids_json: encodeThreadIds(group.threadIds),
126-
parent_thread_id: group.parentThreadId ?? null,
130+
parent_thread_id: group.parentThreadId,
127131
})}`;
128132
}
129133
},
@@ -189,7 +193,7 @@ const make = Effect.gen(function* () {
189193
Effect.map((members) => ({
190194
id: group.id,
191195
title: group.title,
192-
parentThreadId: group.parentThreadId ?? null,
196+
parentThreadId: group.parentThreadId,
193197
threads: members.flatMap((shell) =>
194198
shell === null || shell.deletedAt !== null
195199
? []

‎apps/server/src/provider/agentContextOverhead.fork.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const forkContextOverhead = {
22
claudeSystemAppendBytes: 821,
33
codexAdditionalContextBytes: 821,
4-
mcpToolListJsonBytes: 4815,
4+
mcpToolListJsonBytes: 4783,
55
};
66

77
export function subtractForkContextOverhead(measured: typeof forkContextOverhead): void {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2+
import { describe, expect, it } from "vite-plus/test";
3+
4+
import { regroupWorkingShelfFork } from "./Sidebar.groupWorking.fork";
5+
6+
const environmentId = EnvironmentId.make("env");
7+
const thread = (id: string) => ({ environmentId, id: ThreadId.make(id) });
8+
const [parent, child, other] = [thread("p"), thread("c"), thread("o")];
9+
const group = {
10+
id: "env:g",
11+
title: "G",
12+
threadIds: ["env:p", "env:c"],
13+
parentThreadId: "env:p",
14+
collapsed: false,
15+
};
16+
const ids = (threads: readonly { readonly id: string }[]) => threads.map((t) => t.id);
17+
18+
describe("regroupWorkingShelfFork", () => {
19+
it("moves a group with its working parent, and keeps a working child home", () => {
20+
const active = [child, other];
21+
const working = [parent];
22+
regroupWorkingShelfFork(active, working, [group]);
23+
expect([ids(active), ids(working)]).toEqual([["o"], ["c", "p"]]);
24+
25+
const home = [parent, other];
26+
const shelf = [child];
27+
regroupWorkingShelfFork(home, shelf, [group]);
28+
expect([ids(home), ids(shelf)]).toEqual([["p", "o", "c"], []]);
29+
});
30+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment";
2+
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
3+
4+
import type { SidebarThreadGroup } from "../state/threadGroups";
5+
6+
// Upstream's Working shelf takes each working thread out of the inbox. A group
7+
// moves whole instead, following its parent: a working parent carries the group
8+
// to the shelf, and a working child stays home under an idle parent.
9+
10+
/** Moves grouped inbox threads between the active list and the shelf, whole groups at a time. */
11+
export function regroupWorkingShelfFork<
12+
T extends { readonly environmentId: EnvironmentId; readonly id: ThreadId },
13+
>(active: T[], working: T[], groups: readonly SidebarThreadGroup[]): void {
14+
if (groups.length === 0) return;
15+
const keyOf = (thread: T) => scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
16+
const isWorking = new Set(working.map(keyOf));
17+
const inbox = [...active, ...working];
18+
const shelved = new Map<string, boolean>();
19+
for (const group of groups) {
20+
const members = inbox.map(keyOf).filter((key) => group.threadIds.includes(key));
21+
// Below two inbox members the group does not render; each thread places itself.
22+
if (members.length < 2) continue;
23+
const toShelf = isWorking.has(group.parentThreadId);
24+
for (const key of members) shelved.set(key, toShelf);
25+
}
26+
const onShelf = (thread: T) => shelved.get(keyOf(thread)) ?? isWorking.has(keyOf(thread));
27+
active.splice(0, active.length, ...inbox.filter((thread) => !onShelf(thread)));
28+
working.splice(0, working.length, ...inbox.filter(onShelf));
29+
}

‎apps/web/src/components/Sidebar.logic.fork.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ describe("sidebar thread groups", () => {
2222
id: "group-1",
2323
title: "Related work",
2424
threadIds: ["thread-b", "thread-c"],
25+
parentThreadId: "thread-b",
2526
collapsed: false,
2627
},
2728
],
@@ -31,11 +32,12 @@ describe("sidebar thread groups", () => {
3132
{ kind: "thread", thread: threads[0] },
3233
{
3334
kind: "group",
34-
hasParent: false,
35+
hasParent: true,
3536
group: {
3637
id: "group-1",
3738
title: "Related work",
3839
threadIds: ["thread-b", "thread-c"],
40+
parentThreadId: "thread-b",
3941
collapsed: false,
4042
},
4143
threads: [threads[1], threads[2]],
@@ -54,6 +56,7 @@ describe("sidebar thread groups", () => {
5456
id: "group-1",
5557
title: "Related work",
5658
threadIds: ["thread-b", "thread-c"],
59+
parentThreadId: "thread-c",
5760
collapsed: false,
5861
},
5962
],
@@ -62,11 +65,12 @@ describe("sidebar thread groups", () => {
6265
).toEqual([
6366
{
6467
kind: "group",
65-
hasParent: false,
68+
hasParent: true,
6669
group: {
6770
id: "group-1",
6871
title: "Related work",
6972
threadIds: ["thread-b", "thread-c"],
73+
parentThreadId: "thread-c",
7074
collapsed: false,
7175
},
7276
threads: [threads[2], threads[1]],
@@ -166,6 +170,7 @@ describe("buildSidebarListItems", () => {
166170
id: "group-1",
167171
title: "Related work",
168172
threadIds: ["thread-b", "thread-c"],
173+
parentThreadId: "thread-b",
169174
collapsed: true,
170175
},
171176
],
@@ -203,6 +208,7 @@ describe("buildSidebarListItems", () => {
203208
id: "group-1",
204209
title: "Related work",
205210
threadIds: ["thread-b", "thread-c"],
211+
parentThreadId: "thread-b",
206212
collapsed: false,
207213
},
208214
],

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ export type SidebarThreadGroupContextMenuId =
713713
| "move-to-group"
714714
| `move-to-group:${string}`
715715
| "move-out-of-group"
716-
| "set-group-parent"
717-
| "clear-group-parent"; // fork-hook: thread-ordering/group-menu-id
716+
| "set-group-parent"; // fork-hook: thread-ordering/group-menu-id
718717

719718
export function isSidebarThreadGroupContextMenuId(
720719
id: string,
@@ -724,7 +723,6 @@ export function isSidebarThreadGroupContextMenuId(
724723
id === "move-to-group" ||
725724
id === "move-out-of-group" ||
726725
id === "set-group-parent" ||
727-
id === "clear-group-parent" ||
728726
id.startsWith("move-to-group:")
729727
);
730728
} // fork-hook: upstream-fixes/split-session-permissions
@@ -772,9 +770,10 @@ export function buildThreadGroupMembershipContextMenuItems(input: {
772770
icon: "folder",
773771
separatorBefore: availableGroups.length === 0,
774772
},
775-
input.isGroupParent
776-
? { id: "clear-group-parent" as const, label: "Clear group parent" }
777-
: { id: "set-group-parent" as const, label: "Set as group parent" },
773+
// A parent steps down by promoting another member.
774+
...(input.isGroupParent
775+
? []
776+
: [{ id: "set-group-parent" as const, label: "Set as group parent" }]),
778777
]),
779778
];
780779
} // fork-hook: thread-ordering/group-menu-items

0 commit comments

Comments
 (0)