Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "desktop",
"version": "0.8.7",
"version": "0.8.8",
"description": "ClosedLoop Desktop",
"author": "ClosedLoop AI <support@closedloop.ai>",
"private": true,
Expand Down
25 changes: 23 additions & 2 deletions apps/desktop/src/server/operations/symphony-job-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ export async function readEffectiveStatusFromState(statePath: string): Promise<{
}
}

// ---------------------------------------------------------------------------
// Guard terminal status from state.json when process is alive
// ---------------------------------------------------------------------------

/**
* Suppress terminal status from state.json when the process is still alive.
*/
export function shouldApplyStateStatus(
stateStatus: string,
processRunning: boolean
): boolean {
if (!processRunning) return true;
return !isTerminalJobStatus(stateStatus as LocalJobStatus);
}

// ---------------------------------------------------------------------------
// Task progress / currentTaskId from plan.json
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -179,13 +194,19 @@ export async function enrichJobSnapshot(job: LocalJob): Promise<JobSnapshot> {
if (job.statePath) {
const stateData = await readEffectiveStatusFromState(job.statePath);
if (stateData.phase) {
phase = stateData.phase;
if (processRunning && stateData.status && isTerminalJobStatus(stateData.status)) {
// Don't apply "Completed" phase text while process is still alive
} else {
phase = stateData.phase;
}
}
// Apply effective status from state.json for non-terminal jobs.
// Terminal statuses (COMPLETED, FAILED, CANCELLED, STOPPED) set by the
// process exit handler are authoritative and should not be overridden.
if (stateData.status && !isTerminalJobStatus(status)) {
status = stateData.status;
if (shouldApplyStateStatus(stateData.status, processRunning)) {
status = stateData.status;
}
}
}

Expand Down
43 changes: 42 additions & 1 deletion apps/desktop/src/server/operations/symphony-kill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,46 @@ import path from "node:path";
import type { OperationDispatcher, OperationRequestContext } from "../operation-dispatcher.js";
import { DirectoryNotAllowedError, assertPathAllowed } from "../security.js";
import { expandHome, resolveWorktreeDir } from "./symphony-utils.js";
import type { JobStore, LocalJob } from "../../main/job-store.js";

type ResolveResult =
| { pid: number; pidFilePath: string | null; worktreeDir: string | null }
| { noPidFile: true; worktreeDir: string }
| { error: string; status: number };

function findJobForKill(
jobStore: JobStore,
pid: number | null,
worktreeDir: string | null
): LocalJob | undefined {
const running = jobStore.listRunning();
if (pid != null) {
const byPid = running.find((j) => j.pid === pid);
if (byPid) return byPid;
}
if (worktreeDir != null) {
return running.find((j) => j.worktreeDir === worktreeDir);
}
return undefined;
}

function markJobStopped(
jobStore: JobStore | undefined,
pid: number | null,
worktreeDir: string | null
): void {
if (!jobStore) return;
const job = findJobForKill(jobStore, pid, worktreeDir);
if (job) {
const now = new Date().toISOString();
jobStore.upsert({ ...job, status: "STOPPED", updatedAt: now, completedAt: now });
}
}

export function registerSymphonyKillRoutes(
dispatcher: OperationDispatcher,
getAllowedDirectories: () => string[]
getAllowedDirectories: () => string[],
jobStore?: JobStore
): void {
dispatcher.register("POST", "/api/engineer/symphony/kill", async (context) => {
try {
Expand All @@ -30,6 +61,7 @@ export function registerSymphonyKillRoutes(
if ("noPidFile" in resolved) {
cancelLoop(resolved.worktreeDir);
markStateAsStopped(resolved.worktreeDir);
markJobStopped(jobStore, null, resolved.worktreeDir);
json(context, 200, {
success: true,
message: "No process to kill (no PID file), state marked as stopped"
Expand All @@ -50,6 +82,7 @@ export function registerSymphonyKillRoutes(
if (worktreeDir) {
markStateAsStopped(worktreeDir);
}
markJobStopped(jobStore, pid, worktreeDir);
json(context, 200, { success: true, message: "Process already terminated", pid });
return;
}
Expand All @@ -69,6 +102,7 @@ export function registerSymphonyKillRoutes(
if (worktreeDir) {
markStateAsStopped(worktreeDir);
}
markJobStopped(jobStore, pid, worktreeDir);

json(context, 200, { success: true, message: "Process terminated", pid });
} catch (error) {
Expand All @@ -78,6 +112,13 @@ export function registerSymphonyKillRoutes(
if (worktreeDir) {
markStateAsStopped(worktreeDir);
}
if (jobStore) {
const job = findJobForKill(jobStore, pid, worktreeDir);
if (job) {
const now = new Date().toISOString();
jobStore.upsert({ ...job, status: "STOPPED", updatedAt: now, completedAt: now });
}
}
json(context, 200, { success: true, message: "Process already terminated", pid });
return;
}
Expand Down
Loading
Loading