Skip to content

Commit 2d7bbe3

Browse files
committed
feat: update task run status during local session lifecycle
1 parent e1ec517 commit 2d7bbe3

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

apps/twig/src/renderer/features/sessions/service/service.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const mockAuthStore = vi.hoisted(() => ({
6161
client: {
6262
createTaskRun: vi.fn(),
6363
appendTaskRunLog: vi.fn(),
64+
updateTaskRun: vi.fn().mockResolvedValue(undefined),
6465
},
6566
})),
6667
},
@@ -237,6 +238,7 @@ describe("SessionService", () => {
237238
client: {
238239
createTaskRun: createTaskRunMock,
239240
appendTaskRunLog: vi.fn(),
241+
updateTaskRun: vi.fn().mockResolvedValue(undefined),
240242
},
241243
});
242244

@@ -373,6 +375,7 @@ describe("SessionService", () => {
373375
client: {
374376
createTaskRun: createTaskRunMock,
375377
appendTaskRunLog: vi.fn(),
378+
updateTaskRun: vi.fn().mockResolvedValue(undefined),
376379
},
377380
});
378381
mockTrpcAgent.start.mutate.mockResolvedValue({

apps/twig/src/renderer/features/sessions/service/service.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ export class SessionService {
390390
throw new Error("Failed to create task run. Please try again.");
391391
}
392392

393+
// Signal that the local run is now in progress
394+
auth.client
395+
.updateTaskRun(taskId, taskRun.id, { status: "in_progress" })
396+
.catch((err) => log.warn("Failed to update task run status", { err }));
397+
393398
const result = await trpcVanilla.agent.start.mutate({
394399
taskId,
395400
taskRunId: taskRun.id,
@@ -457,6 +462,17 @@ export class SessionService {
457462
const session = sessionStoreSetters.getSessionByTaskId(taskId);
458463
if (!session) return;
459464

465+
// Update remote status based on session state
466+
const auth = useAuthStore.getState();
467+
if (auth.client) {
468+
const status = session.isPromptPending ? "failed" : "completed";
469+
auth.client
470+
.updateTaskRun(taskId, session.taskRunId, { status })
471+
.catch((err) =>
472+
log.warn("Failed to update task run status on disconnect", { err }),
473+
);
474+
}
475+
460476
try {
461477
await trpcVanilla.agent.cancel.mutate({
462478
sessionId: session.taskRunId,
@@ -674,6 +690,20 @@ export class SessionService {
674690
notifyPromptComplete(session.taskTitle, stopReason);
675691
}
676692

693+
// Update remote task run status when agent turn completes with no pending work
694+
if (session.messageQueue.length === 0) {
695+
const auth = useAuthStore.getState();
696+
if (auth.client) {
697+
auth.client
698+
.updateTaskRun(session.taskId, taskRunId, { status: "completed" })
699+
.catch((err) =>
700+
log.warn("Failed to update task run status to completed", {
701+
err,
702+
}),
703+
);
704+
}
705+
}
706+
677707
// Process queued messages after turn completes - send all as one prompt
678708
if (session.messageQueue.length > 0 && session.status === "connected") {
679709
setTimeout(() => {
@@ -896,6 +926,16 @@ export class SessionService {
896926
promptStartedAt: Date.now(),
897927
});
898928

929+
// Ensure task run status reflects active work
930+
const auth = useAuthStore.getState();
931+
if (auth.client) {
932+
auth.client
933+
.updateTaskRun(session.taskId, session.taskRunId, {
934+
status: "in_progress",
935+
})
936+
.catch((err) => log.warn("Failed to update task run status", { err }));
937+
}
938+
899939
try {
900940
const result = await trpcVanilla.agent.prompt.mutate({
901941
sessionId: session.taskRunId,

0 commit comments

Comments
 (0)