Skip to content

Commit d0b1b6d

Browse files
authored
fix(workboard): keep cards synced when dashboard is closed (#125023)
* fix(workboard): own linked-session lifecycle sync gateway-side * test(workboard): align lifecycle proof with gateway ownership
1 parent 49b4775 commit d0b1b6d

19 files changed

Lines changed: 1041 additions & 1368 deletions

‎docs/plugins/workboard.md‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ resulting task, run id, and session key back onto the card. Each linked
131131
execution also records an attempt summary (engine, mode, model, run id,
132132
timestamps, status, rolling failure count) so repeated failures stay visible.
133133

134-
The dashboard refreshes task status from the Gateway task ledger, matching
135-
tasks to cards by task id, run id, or linked session key. A queued/running
136-
task keeps the card's lifecycle active; a finished, failed, timed-out, or
137-
cancelled task moves the card toward `review` or `blocked` using the same sync
138-
rule as linked sessions (see [Session lifecycle sync](#session-lifecycle-sync)).
134+
The dashboard refreshes task status from the Gateway task ledger for its
135+
lifecycle display, matching tasks to cards by task id, run id, or linked
136+
session key. Card status changes are persisted by the Gateway-side Workboard
137+
plugin using the linked run and session lifecycle (see
138+
[Session lifecycle sync](#session-lifecycle-sync)).
139139

140140
## Agent tools
141141

@@ -314,6 +314,13 @@ still offers start controls to restart into a fresh session. If an active
314314
linked session stops reporting recent activity, Workboard marks the card
315315
`stale` and stores that as metadata until the lifecycle clears it.
316316

317+
Lifecycle writes are owned by the Gateway-side Workboard plugin, so they do
318+
not depend on an open browser tab. Agent and subagent completion hooks persist
319+
terminal outcomes immediately. A bounded session sweep runs once per minute to
320+
reconcile active, idle, missing, and stale session state. Each store mutation
321+
emits the normal `plugin.workboard.changed` invalidation, so an open dashboard
322+
reloads the canonical card instead of writing its own lifecycle projection.
323+
317324
While a card is in an active work state, Workboard follows the linked session:
318325

319326
| Linked session state | Card status |

‎extensions/workboard/index.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { registerWorkboardGatewayMethods } from "./runtime-api.js";
44
import { createWorkboardChangeEventService } from "./src/change-events.js";
55
import { registerWorkboardCommand } from "./src/command.js";
66
import { cleanupWorkboardRunWorktree } from "./src/dispatcher-workspace.js";
7+
import {
8+
createWorkboardLifecycleService,
9+
readWorkboardLifecycleSessions,
10+
syncWorkboardAgentEnded,
11+
syncWorkboardSubagentEnded,
12+
} from "./src/lifecycle-sync.js";
713
import { WorkboardStore } from "./src/store.js";
814
import { createWorkboardTools } from "./src/tools.js";
915
import {
@@ -32,14 +38,26 @@ export default definePluginEntry({
3238
registerWorkboardGatewayMethods({ api, store });
3339
registerWorkboardCommand({ api, store });
3440
api.registerService(createWorkboardChangeEventService(store));
41+
api.registerService(
42+
createWorkboardLifecycleService({
43+
store,
44+
readSessions: async () => await readWorkboardLifecycleSessions(api.runtime.gateway),
45+
}),
46+
);
3547
api.on("subagent_ended", async (event) => {
36-
if (event.runId) {
37-
await cleanupWorkboardRunWorktree({
38-
store,
39-
worktrees: api.runtime.worktrees,
40-
runId: event.runId,
41-
});
42-
}
48+
await Promise.all([
49+
syncWorkboardSubagentEnded({ store, event }),
50+
event.runId
51+
? cleanupWorkboardRunWorktree({
52+
store,
53+
worktrees: api.runtime.worktrees,
54+
runId: event.runId,
55+
})
56+
: undefined,
57+
]);
58+
});
59+
api.on("agent_end", async (event, context) => {
60+
await syncWorkboardAgentEnded({ store, event, context });
4361
});
4462
api.registerCli(
4563
async ({ program }) => {

‎extensions/workboard/src/dispatcher.ts‎

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
resolveDispatchWorkspaceAccess,
1919
type ResolveAgentWorkspaceRuntime,
2020
} from "./dispatcher-workspace.js";
21+
import { workboardSessionKeyForCard } from "./session-link.js";
2122
import { cardBoardId } from "./store-card-helpers.js";
2223
import { isWorkboardClaimReclaimable } from "./store-constants.js";
2324
import { WorkboardStore, type WorkboardDispatchResult } from "./store.js";
@@ -74,15 +75,6 @@ type WorkboardDispatchStartParams = {
7475

7576
const pendingWorkboardDispatches = new WeakMap<WorkboardStore, Promise<void>>();
7677

77-
function sanitizeSessionSegment(value: string | undefined, fallback: string): string {
78-
const sanitized = (value ?? fallback)
79-
.trim()
80-
.replace(/[^a-zA-Z0-9_-]/g, "-")
81-
.replace(/-+/g, "-")
82-
.replace(/^-|-$/g, "");
83-
return (sanitized || fallback).slice(0, 96);
84-
}
85-
8678
function cardIsArchived(card: WorkboardCard): boolean {
8779
return Boolean(card.metadata?.archivedAt);
8880
}
@@ -92,13 +84,6 @@ function cardHasActiveClaim(card: WorkboardCard, now: number): boolean {
9284
return Boolean(claim && isFutureDateTimestampMs(claim.expiresAt, { nowMs: now }));
9385
}
9486

95-
function buildSessionKey(card: WorkboardCard): string {
96-
const boardId = sanitizeSessionSegment(cardBoardId(card), "default");
97-
const cardId = sanitizeSessionSegment(card.id, "card");
98-
const suffix = `subagent:workboard-${boardId}-${cardId}`;
99-
return card.agentId ? `agent:${sanitizeSessionSegment(card.agentId, "agent")}:${suffix}` : suffix;
100-
}
101-
10287
function buildExecution(params: {
10388
card: WorkboardCard;
10489
sessionKey: string;
@@ -347,7 +332,7 @@ async function runWorkboardDispatch(
347332
if (startedOwners.has(ownerId)) {
348333
continue;
349334
}
350-
const sessionKey = buildSessionKey(card);
335+
const sessionKey = workboardSessionKeyForCard(card);
351336
let claimValue = "";
352337
let materializedWorkspace: WorkboardWorkspace | undefined;
353338
let implicitWorkspaceCwd: string | undefined;

0 commit comments

Comments
 (0)