Skip to content

Commit 25981f8

Browse files
committed
🤖 fix: emit metadata when tasks report
Emit workspace metadata updates when agent tasks transition to taskStatus="reported" (agent_report and fallback paths), so clients can refresh UI state even when the workspace can't be deleted immediately. Signed-off-by: Thomas Kosiewski <tk@coder.com> --- _Generated with `codex cli` • Model: `gpt-5.2` • Thinking: `xhigh`_ <!-- mux-attribution: model=gpt-5.2 thinking=xhigh --> Change-Id: I3579450266b79be91c0d1364a3606ff902517e1d
1 parent 056c660 commit 25981f8

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/node/services/taskService.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ describe("TaskService", () => {
733733
expect(ws?.taskStatus).toBe("reported");
734734
expect(ws?.reportedAt).toBeTruthy();
735735

736+
expect(emit).toHaveBeenCalledWith(
737+
"metadata",
738+
expect.objectContaining({ workspaceId: childId })
739+
);
740+
736741
expect(remove).toHaveBeenCalled();
737742
expect(resumeStream).toHaveBeenCalled();
738743
expect(emit).toHaveBeenCalled();
@@ -1027,6 +1032,16 @@ describe("TaskService", () => {
10271032

10281033
await internal.handleStreamEnd({ type: "stream-end", workspaceId: childId });
10291034

1035+
const emitCalls = (emit as unknown as { mock: { calls: Array<[string, unknown]> } }).mock.calls;
1036+
const metadataEmitsForChild = emitCalls.filter((call) => {
1037+
const [eventName, payload] = call;
1038+
if (eventName !== "metadata") return false;
1039+
if (!payload || typeof payload !== "object") return false;
1040+
const maybePayload = payload as { workspaceId?: unknown };
1041+
return maybePayload.workspaceId === childId;
1042+
});
1043+
expect(metadataEmitsForChild).toHaveLength(2);
1044+
10301045
const parentHistory = await historyService.getHistory(parentId);
10311046
expect(parentHistory.success).toBe(true);
10321047
if (parentHistory.success) {

src/node/services/taskService.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,15 @@ export class TaskService {
788788
return config;
789789
});
790790

791+
// Notify clients immediately even if we can't delete the workspace yet.
792+
const updatedMetadata = (await this.config.getAllWorkspaceMetadata()).find(
793+
(m) => m.id === childWorkspaceId
794+
);
795+
this.workspaceService.emit("metadata", {
796+
workspaceId: childWorkspaceId,
797+
metadata: updatedMetadata ?? null,
798+
});
799+
791800
await this.deliverReportToParent(parentWorkspaceId, entry, {
792801
reportMarkdown,
793802
title: `Subagent (${agentType}) report (fallback)`,
@@ -882,6 +891,15 @@ export class TaskService {
882891
return config;
883892
});
884893

894+
// Notify clients immediately even if we can't delete the workspace yet.
895+
const updatedMetadata = (await this.config.getAllWorkspaceMetadata()).find(
896+
(m) => m.id === childWorkspaceId
897+
);
898+
this.workspaceService.emit("metadata", {
899+
workspaceId: childWorkspaceId,
900+
metadata: updatedMetadata ?? null,
901+
});
902+
885903
const cfg = this.config.loadConfigOrDefault();
886904
const childEntry = this.findWorkspaceEntry(cfg, childWorkspaceId);
887905
const parentWorkspaceId = childEntry?.workspace.parentWorkspaceId;

0 commit comments

Comments
 (0)