Skip to content

Commit 4cbbccd

Browse files
fix(workboard): ignore caller-supplied archivedAt when creating a card (#116412)
Archiving is a lifecycle transition owned by archive(), which routes through updateCard and appends the matching `archived` event. createDirect had no such guard: it passed input.metadata straight into normalizeMetadata, which treats archivedAt as an ordinary caller-supplied field. A card could therefore be created already archived. Archived cards are excluded from dispatch at every status, so the card was unstartable from the instant it existed, while its event log contained only `created` - no archive ever happened, so no `archived` event was ever recorded. The board reported work that could never start, and the missing event sent operators looking for a rogue archiver that did not exist. normalizeMetadata already carries an options bag for rules that are stricter on create than on update (allowDependencyLinks). Add allowArchivedAt alongside it and pass false from createDirect, so archivedAt falls back to the create fallback (undefined) instead of the caller's value. The update path is unchanged: patches that set archivedAt still archive the card and still emit the event. Fixes #116395
1 parent 22a902c commit 4cbbccd

4 files changed

Lines changed: 52 additions & 3 deletions

File tree

‎extensions/workboard/src/dispatcher-ownership.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ function createMemoryStore(): WorkboardKeyedStore {
2424
}
2525

2626
describe("Workboard dispatcher ownership", () => {
27+
it("dispatches a card whose create input tried to inject archivedAt", async () => {
28+
const store = new WorkboardStore(createMemoryStore());
29+
const now = 10;
30+
const card = await store.create({
31+
title: "Injected archive",
32+
status: "ready",
33+
workspaceAccess: { unrestricted: true },
34+
metadata: { archivedAt: now },
35+
});
36+
const run = vi.fn().mockResolvedValue({ runId: "run-injected" });
37+
38+
await dispatchAndStartWorkboardCards({
39+
store,
40+
subagent: { run },
41+
options: { now, maxStarts: 1 },
42+
});
43+
44+
expect(run).toHaveBeenCalledTimes(1);
45+
await expect(store.get(card.id)).resolves.toMatchObject({
46+
execution: { runId: "run-injected" },
47+
});
48+
});
49+
2750
it("falls back to one default owner for persisted blank and unassigned agents", async () => {
2851
const keyed = createMemoryStore();
2952
const store = new WorkboardStore(keyed);

‎extensions/workboard/src/store-core.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export class WorkboardCoreStore {
389389
templateId: normalizeTemplateId(input.templateId),
390390
...(childAutomation ? { automation: childAutomation } : {}),
391391
},
392-
{ allowDependencyLinks: false },
392+
{ allowDependencyLinks: false, allowArchivedAt: false },
393393
);
394394
const syncedMetadata = trimMetadataToBudget(
395395
syncExecutionAttemptMetadata(metadata, execution, now),

‎extensions/workboard/src/store-normalizers.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,11 @@ export function appendCompletionProof(
10241024
export function normalizeMetadata(
10251025
value: unknown,
10261026
fallback: WorkboardMetadata = {},
1027-
options: { allowDependencyLinks?: boolean; preserveProofId?: string } = {},
1027+
options: {
1028+
allowDependencyLinks?: boolean;
1029+
allowArchivedAt?: boolean;
1030+
preserveProofId?: string;
1031+
} = {},
10281032
): WorkboardMetadata {
10291033
if (!value || typeof value !== "object" || Array.isArray(value)) {
10301034
return trimMetadataToBudget(fallback, options);
@@ -1034,7 +1038,11 @@ export function normalizeMetadata(
10341038
record.stale && typeof record.stale === "object" && !Array.isArray(record.stale)
10351039
? (record.stale as Record<string, unknown>)
10361040
: null;
1037-
const hasArchivedAt = Object.hasOwn(record, "archivedAt");
1041+
// Archival is a transition owned by archive(), which appends the matching
1042+
// `archived` event. Callers that cannot produce that event (create) must not
1043+
// be able to declare it, or the card is excluded from dispatch from the
1044+
// instant it exists with an event log recording only `created`.
1045+
const hasArchivedAt = Object.hasOwn(record, "archivedAt") && options.allowArchivedAt !== false;
10381046
const hasStale = Object.hasOwn(record, "stale");
10391047
const hasLifecycleStatusSourceUpdatedAt = Object.hasOwn(record, "lifecycleStatusSourceUpdatedAt");
10401048
const links = Array.isArray(record.links)

‎extensions/workboard/src/store.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,24 @@ describe("WorkboardStore", () => {
10101010
expect(restored.events?.at(-1)).toMatchObject({ kind: "unarchived" });
10111011
});
10121012

1013+
it("ignores caller-supplied archivedAt on create so no card is born archived", async () => {
1014+
const store = new WorkboardStore(createMemoryStore());
1015+
const card = await store.create({
1016+
title: "Injected archive",
1017+
metadata: { archivedAt: Date.now() },
1018+
});
1019+
1020+
// Archival is a transition owned by archive(), which appends the matching
1021+
// event. Honouring it here would exclude the card from dispatch from birth
1022+
// with an event log recording only "created".
1023+
expect(card.metadata?.archivedAt).toBeUndefined();
1024+
expect(card.events?.map((event) => event.kind)).toEqual(["created"]);
1025+
1026+
const archived = await store.archive(card.id, true);
1027+
expect(archived.metadata?.archivedAt).toBeGreaterThan(0);
1028+
expect(archived.events?.at(-1)).toMatchObject({ kind: "archived" });
1029+
});
1030+
10131031
it("resolves matching unknown proof on completion without duplicating it", async () => {
10141032
vi.useFakeTimers();
10151033
try {

0 commit comments

Comments
 (0)