codex-supervisor-mcp 0.14.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +37 -45
- package/README.md +37 -45
- package/package.json +2 -2
- package/skills/codex-supervisor/SKILL.md +88 -91
- package/src/app/acceptance.js +5 -5
- package/src/app/auto-cleanup.js +6 -5
- package/src/app/cleanup-facts.js +21 -16
- package/src/app/cleanup-plan.js +22 -20
- package/src/app/context-compiler.js +2 -1
- package/src/app/dispatch.js +17 -15
- package/src/app/followup.js +5 -4
- package/src/app/land-chain.js +5 -4
- package/src/app/landing.js +8 -8
- package/src/app/ownership.js +1 -1
- package/src/app/rebase.js +1 -1
- package/src/app/restore-worktree.js +2 -1
- package/src/app/resume.js +11 -6
- package/src/app/worktree-setup.js +58 -16
- package/src/domain/acceptance-spec.js +1 -1
- package/src/domain/failure-class.js +36 -4
- package/src/domain/prompt.js +7 -7
- package/src/domain/status.js +15 -2
- package/src/domain/thread-health.js +2 -2
- package/src/domain/worker-branch.js +6 -0
- package/src/domain/worker-changes.js +3 -3
- package/src/domain/worker-preflight.js +2 -1
- package/src/infra/cleanup-hint.js +1 -1
- package/src/infra/crash-guard.js +44 -0
- package/src/infra/external-output.js +2 -2
- package/src/infra/git.js +35 -4
- package/src/infra/sandbox-roots.js +1 -1
- package/src/infra/store/event-body.js +82 -0
- package/src/infra/store/events.js +9 -6
- package/src/infra/store/reconcile.js +4 -3
- package/src/infra/store/tasks.js +15 -1
- package/src/infra/update/auto-update-worker.js +3 -3
- package/src/infra/update/auto-update.js +4 -4
- package/src/infra/update/update-check.js +3 -3
- package/src/infra/workspace-kind.js +8 -8
- package/src/infra/worktree.js +4 -3
- package/src/interface/bin/acceptance-cli.js +4 -4
- package/src/interface/bin/monitor.jsx +6 -6
- package/src/interface/bin/setup.js +3 -3
- package/src/interface/bin/stage.js +2 -2
- package/src/interface/bin/web-server.js +2 -0
- package/src/interface/mcp/{tools → handlers}/delivery.js +30 -62
- package/src/interface/mcp/handlers/dispatch.js +233 -0
- package/src/interface/mcp/{tools → handlers}/facts.js +30 -65
- package/src/interface/mcp/handlers/overview.js +106 -0
- package/src/interface/mcp/{tools → handlers}/results.js +31 -60
- package/src/interface/mcp/{tools → handlers}/review.js +16 -36
- package/src/interface/mcp/{tools → handlers}/wait.js +13 -17
- package/src/interface/mcp/server.js +20 -50
- package/src/interface/mcp/tools/deliver.js +48 -0
- package/src/interface/mcp/tools/dispatch.js +78 -257
- package/src/interface/mcp/tools/optional.js +57 -0
- package/src/interface/mcp/tools/read.js +115 -0
- package/src/interface/mcp/tools/run.js +57 -0
- package/src/interface/mcp/tools/shapes.js +66 -0
- package/src/interface/mcp/tools/track.js +84 -0
- package/src/interface/mcp/views/task.js +8 -7
- package/src/interface/web/views.js +5 -2
- package/src/run-host/entry.js +3 -0
- package/src/run-host/finalize.js +8 -1
- package/src/run-host/launch.js +7 -7
- package/src/run-host/live-run.js +2 -0
- package/src/run-host/streams.js +28 -5
- package/src/run-host/track.js +5 -2
- package/src/runners/codex/tool-guard.js +6 -6
- package/web/dist/assets/{index-fJQbspTY.js → index-BnV-AYYI.js} +1 -1
- package/web/dist/assets/index-f8esISCp.css +2 -0
- package/web/dist/index.html +2 -2
- package/src/domain/overview-delta.js +0 -77
- package/src/interface/mcp/tools/overview.js +0 -202
- package/src/interface/mcp/tools/poll.js +0 -58
- package/web/dist/assets/index-DI1hLMxE.css +0 -2
package/src/app/auto-cleanup.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// It rides on the polling tools, so a batch that is never cleaned up by hand
|
|
3
3
|
// does not grow without bound. A sweep is throttled and bounded: it must never
|
|
4
4
|
// make a poll slow.
|
|
5
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
5
6
|
import "./compose.js";
|
|
6
7
|
import { holdMsFrom } from "../domain/cleanup-policy.js";
|
|
7
8
|
import { TERMINAL_STATUSES } from "../domain/status.js";
|
|
@@ -19,8 +20,8 @@ const SWEEP_LIMIT = 20;
|
|
|
19
20
|
let lastSweepAt = 0;
|
|
20
21
|
|
|
21
22
|
function intervalMs() {
|
|
22
|
-
const raw = Number(process.env.
|
|
23
|
-
return Number.isFinite(raw) && raw >= 0 && process.env.
|
|
23
|
+
const raw = Number(process.env.AGENT_SUPERVISOR_CLEANUP_INTERVAL_MS);
|
|
24
|
+
return Number.isFinite(raw) && raw >= 0 && process.env.AGENT_SUPERVISOR_CLEANUP_INTERVAL_MS !== undefined ? raw : DEFAULT_INTERVAL_MS;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const finishedAt = (task) => Date.parse(task.completed_at ?? task.updated_at ?? "") || 0;
|
|
@@ -32,7 +33,7 @@ async function sweepWorktree(task, tasks, now) {
|
|
|
32
33
|
// The worktree is gone whether or not the audit row can be written.
|
|
33
34
|
await recordRemoval(task, { actor: "auto_cleanup", checkpoint, reasons: assessed.reasons })
|
|
34
35
|
.catch((error) => process.stderr.write(`[codex-supervisor] removed ${task.id} but could not record it: ${error.message}\n`));
|
|
35
|
-
return { task_id: task.id, kind: "worktree", branch:
|
|
36
|
+
return { task_id: task.id, kind: "worktree", branch: branchOf(task), checkpoint_commit: checkpoint, reasons: assessed.reasons };
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// A scratch directory holds a research worker's drafts; its report is in the
|
|
@@ -40,7 +41,7 @@ async function sweepWorktree(task, tasks, now) {
|
|
|
40
41
|
async function sweepScratch(task, now) {
|
|
41
42
|
const path = join(scratchDir, task.id);
|
|
42
43
|
const finished = finishedAt(task);
|
|
43
|
-
if (!finished || now < finished + holdMsFrom(process.env.
|
|
44
|
+
if (!finished || now < finished + holdMsFrom(process.env.AGENT_SUPERVISOR_CLEANUP_HOLD_DAYS) || !existsSync(path)) return null;
|
|
44
45
|
const claim = await claimIdleTask(task.id);
|
|
45
46
|
if (!claim) return null;
|
|
46
47
|
try {
|
|
@@ -55,7 +56,7 @@ async function sweepScratch(task, now) {
|
|
|
55
56
|
|
|
56
57
|
// Returns what was removed. One failure never stops the sweep or the poll.
|
|
57
58
|
export async function sweepCleanup({ now = Date.now(), force = false } = {}) {
|
|
58
|
-
if (process.env.
|
|
59
|
+
if (process.env.AGENT_SUPERVISOR_NO_AUTO_CLEANUP === "1") return [];
|
|
59
60
|
if (!force && now - lastSweepAt < intervalMs()) return [];
|
|
60
61
|
lastSweepAt = now;
|
|
61
62
|
let tasks;
|
package/src/app/cleanup-facts.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
// Reads what the cleanup policy needs to know about one worker's worktree.
|
|
2
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
2
3
|
import "./compose.js";
|
|
3
|
-
import { ACTIVE_STATUSES, TERMINAL_STATUSES } from "../domain/status.js";
|
|
4
|
-
import {
|
|
4
|
+
import { ACTIVE_STATUSES, TERMINAL_STATUSES, runIsOver } from "../domain/status.js";
|
|
5
|
+
import { gitSucceedsAsync, runGitAsync } from "../infra/git.js";
|
|
5
6
|
import { worktreesDir } from "../infra/paths.js";
|
|
6
|
-
import { isPidAlive } from "../infra/store/tasks.js";
|
|
7
|
+
import { isGroupAlive, isPidAlive } from "../infra/store/tasks.js";
|
|
7
8
|
import { parsePorcelainLine, resolveWorktreeBase, workspaceSetupIgnorePaths, worktreeRef } from "../infra/worktree.js";
|
|
8
9
|
import { lstat, realpath } from "node:fs/promises";
|
|
9
10
|
import { resolve } from "node:path";
|
|
10
11
|
|
|
11
12
|
// Raw output: porcelain status lines start with a significant space, and a
|
|
12
13
|
// quoted path would never match a setup path. Callers trim single values.
|
|
13
|
-
const git = (cwd, args) =>
|
|
14
|
+
const git = (cwd, args) => runGitAsync(cwd, args, { timeout: 15000, noOptionalLocks: true, rawPaths: true, trim: false });
|
|
14
15
|
const lines = (text) => text.split("\n").filter(Boolean);
|
|
15
16
|
|
|
16
17
|
function activeReason(task) {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
// Once the run is over its pids may belong to anyone.
|
|
19
|
+
const settled = runIsOver(task);
|
|
20
|
+
if (!settled && task.pid && isPidAlive(task.pid)) return "worker process is still active";
|
|
21
|
+
if (!settled && task.run_host_pid && isPidAlive(task.run_host_pid)) return "run host process is still active";
|
|
22
|
+
// A lost run can leave a process behind that still writes in the worktree; only a recorded exit rules that out.
|
|
23
|
+
if (task.exit_code == null && isGroupAlive(task.run_host_pid)) return "a process of the worker's run is still active";
|
|
19
24
|
const acceptance = task.acceptance_results;
|
|
20
25
|
if (acceptance?.status === "running" || (acceptance?.supervisor_pid && isPidAlive(acceptance.supervisor_pid))) return "acceptance process is still active";
|
|
21
26
|
return null;
|
|
@@ -31,9 +36,9 @@ async function identityProblem(task) {
|
|
|
31
36
|
const info = await lstat(path);
|
|
32
37
|
if (info.isSymbolicLink()) return "worktree is a symlink";
|
|
33
38
|
if (await realpath(path) !== await realpath(managed)) return "worktree realpath is unexpected";
|
|
34
|
-
const branch = git(path, ["symbolic-ref", "--short", "HEAD"]).trim();
|
|
35
|
-
if (branch !==
|
|
36
|
-
const registered = git(task.project_root, ["worktree", "list", "--porcelain", "-z"]).split("\0").filter((line) => line.startsWith("worktree "));
|
|
39
|
+
const branch = (await git(path, ["symbolic-ref", "--short", "HEAD"])).trim();
|
|
40
|
+
if (branch !== branchOf(task)) return "worktree branch ownership is unexpected";
|
|
41
|
+
const registered = (await git(task.project_root, ["worktree", "list", "--porcelain", "-z"])).split("\0").filter((line) => line.startsWith("worktree "));
|
|
37
42
|
const own = await realpath(path);
|
|
38
43
|
for (const line of registered) {
|
|
39
44
|
// A registration whose directory someone deleted has no realpath; it is not ours either way.
|
|
@@ -55,20 +60,20 @@ function setupFilter(task) {
|
|
|
55
60
|
function isLanded(task) {
|
|
56
61
|
if (!task.landed_at || !task.landed_head) return false;
|
|
57
62
|
const target = task.landed_branch ? `refs/heads/${task.landed_branch}` : "HEAD";
|
|
58
|
-
return
|
|
63
|
+
return gitSucceedsAsync(task.project_root, ["merge-base", "--is-ancestor", task.landed_head, target]);
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
function worktreeState(task) {
|
|
66
|
+
async function worktreeState(task) {
|
|
62
67
|
const path = resolve(task.worktree_path);
|
|
63
68
|
const keep = setupFilter(task);
|
|
64
|
-
const status = lines(git(path, ["status", "--porcelain", "--untracked-files=all"]));
|
|
69
|
+
const status = lines(await git(path, ["status", "--porcelain", "--untracked-files=all"]));
|
|
65
70
|
const uncommittedPaths = status.map(parsePorcelainLine).filter((entry) => entry && keep(entry));
|
|
66
71
|
// Without the base the worker's own commits cannot be counted, and "nothing
|
|
67
72
|
// to keep" could not be told from "cannot tell".
|
|
68
73
|
const base = resolveWorktreeBase(path, worktreeRef(task));
|
|
69
74
|
if (!base) throw new Error("the commit this worker started from is unknown");
|
|
70
|
-
const unlandedCommits = lines(git(path, ["rev-list", `${base}..HEAD`])).length;
|
|
71
|
-
return { uncommittedPaths, unlandedCommits, head: git(path, ["rev-parse", "HEAD"]).trim() };
|
|
75
|
+
const unlandedCommits = lines(await git(path, ["rev-list", `${base}..HEAD`])).length;
|
|
76
|
+
return { uncommittedPaths, unlandedCommits, head: (await git(path, ["rev-parse", "HEAD"])).trim() };
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
export async function cleanupFacts(task, tasks) {
|
|
@@ -83,8 +88,8 @@ export async function cleanupFacts(task, tasks) {
|
|
|
83
88
|
facts.identity = await identityProblem(task);
|
|
84
89
|
if (facts.identity) return facts;
|
|
85
90
|
try {
|
|
86
|
-
const state = worktreeState(task);
|
|
87
|
-
facts.landed = isLanded(task);
|
|
91
|
+
const state = await worktreeState(task);
|
|
92
|
+
facts.landed = await isLanded(task);
|
|
88
93
|
facts.uncommittedPaths = state.uncommittedPaths;
|
|
89
94
|
facts.uncommitted = state.uncommittedPaths.length;
|
|
90
95
|
facts.unlandedCommits = state.unlandedCommits;
|
package/src/app/cleanup-plan.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// safe, review or blocked; applying one removes only safe worktrees, after
|
|
3
3
|
// saving any uncommitted edits as a checkpoint commit on the worker's branch.
|
|
4
4
|
// Branches, task rows, events, logs and artifacts are never removed.
|
|
5
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
5
6
|
import "./compose.js";
|
|
6
7
|
import { cleanupVerdict, holdMsFrom } from "../domain/cleanup-policy.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import { gitSucceedsAsync, runGitAsync } from "../infra/git.js";
|
|
9
|
+
import { runFile } from "../infra/process.js";
|
|
9
10
|
import { runIdFor } from "../infra/store/db.js";
|
|
10
11
|
import { appendTaskEvent } from "../infra/store/events.js";
|
|
11
12
|
import { markCleanupPlanItemApplied, updateWorkItemDelivery } from "../infra/store/records.js";
|
|
@@ -21,17 +22,18 @@ export const CLEANUP_PLAN_TTL_MS = 15 * 60 * 1000;
|
|
|
21
22
|
export const CLEANUP_POLICY = "keep_branch_and_evidence_checkpoint_before_removal";
|
|
22
23
|
const RETAINED = ["branch", "task", "events", "jsonl", "artifacts"];
|
|
23
24
|
|
|
24
|
-
const git = (cwd, args, options = {}) =>
|
|
25
|
-
const holdMs = () => holdMsFrom(process.env.
|
|
25
|
+
const git = (cwd, args, options = {}) => runGitAsync(cwd, args, { timeout: 15000, noOptionalLocks: true, ...options });
|
|
26
|
+
const holdMs = () => holdMsFrom(process.env.AGENT_SUPERVISOR_CLEANUP_HOLD_DAYS);
|
|
26
27
|
|
|
28
|
+
// The size is a hint for the reader of a plan. Where du is missing or slow
|
|
29
|
+
// the answer is 0, never a failed plan.
|
|
27
30
|
function directoryBytes(path) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
31
|
+
return new Promise((resolveSize) => {
|
|
32
|
+
runFile("du", ["-sk", path], { encoding: "utf8", timeout: 30000 }, (error, stdout) => {
|
|
33
|
+
const kib = error ? NaN : Number(stdout.trim().split(/\s+/)[0]);
|
|
34
|
+
resolveSize(Number.isFinite(kib) ? kib * 1024 : 0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
// A plan item is only applied to the worktree it was made for: same commit,
|
|
@@ -59,7 +61,7 @@ export async function createCleanupPlan({ taskIds = null, projectRoot = null, no
|
|
|
59
61
|
reasons: result.reasons,
|
|
60
62
|
checkpoint: result.checkpoint,
|
|
61
63
|
fingerprint: result.fingerprint,
|
|
62
|
-
reclaimable_bytes: result.verdict === "safe" ? directoryBytes(task.worktree_path) : 0,
|
|
64
|
+
reclaimable_bytes: result.verdict === "safe" ? await directoryBytes(task.worktree_path) : 0,
|
|
63
65
|
eligible_after: result.eligible_after ?? (result.verdict === "safe" ? new Date(now).toISOString() : null)
|
|
64
66
|
});
|
|
65
67
|
}
|
|
@@ -77,13 +79,13 @@ export async function createCleanupPlan({ taskIds = null, projectRoot = null, no
|
|
|
77
79
|
|
|
78
80
|
// Saves the worker's uncommitted edits as one commit on its branch. Setup
|
|
79
81
|
// links are left out; hooks are skipped because nobody is there to answer them.
|
|
80
|
-
function checkpointUncommitted(task) {
|
|
82
|
+
async function checkpointUncommitted(task) {
|
|
81
83
|
const path = resolve(task.worktree_path);
|
|
82
84
|
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0", GIT_EDITOR: "true", ...identityEnv(path) };
|
|
83
85
|
const exclude = workspaceSetupIgnorePaths(task).map((entry) => `:(exclude)${entry}`);
|
|
84
|
-
git(path, ["add", "-A", "--", ".", ...exclude], { env });
|
|
85
|
-
if (
|
|
86
|
-
git(path, ["commit", "-q", "--no-verify", "-m", `Checkpoint before worktree cleanup (${task.id})`], { env });
|
|
86
|
+
await git(path, ["add", "-A", "--", ".", ...exclude], { env });
|
|
87
|
+
if (await gitSucceedsAsync(path, ["diff", "--cached", "--quiet"])) return null;
|
|
88
|
+
await git(path, ["commit", "-q", "--no-verify", "-m", `Checkpoint before worktree cleanup (${task.id})`], { env });
|
|
87
89
|
return git(path, ["rev-parse", "HEAD"]);
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -100,12 +102,12 @@ export async function removeSafeWorktree(task, fingerprint) {
|
|
|
100
102
|
if (result.fingerprint !== fingerprint) throw new Error("worktree changed since cleanup plan; create a new plan");
|
|
101
103
|
// The same lock that creating and restoring a worktree takes.
|
|
102
104
|
return await withWorktreeCreationLock(task.project_root, async () => {
|
|
103
|
-
const checkpoint = result.checkpoint ? checkpointUncommitted(task) : null;
|
|
105
|
+
const checkpoint = result.checkpoint ? await checkpointUncommitted(task) : null;
|
|
104
106
|
// What is left now is setup links and ignored build output, neither of
|
|
105
107
|
// which is the worker's work; a plain remove would refuse them.
|
|
106
|
-
git(task.project_root, ["worktree", "remove", "--force", task.worktree_path]);
|
|
108
|
+
await git(task.project_root, ["worktree", "remove", "--force", task.worktree_path]);
|
|
107
109
|
try {
|
|
108
|
-
git(task.project_root, ["worktree", "prune"]);
|
|
110
|
+
await git(task.project_root, ["worktree", "prune"]);
|
|
109
111
|
} catch {
|
|
110
112
|
// pruning is housekeeping; the worktree is already gone
|
|
111
113
|
}
|
|
@@ -126,7 +128,7 @@ export async function recordRemoval(task, { actor, planId = null, itemId = null,
|
|
|
126
128
|
removed_at: removedAt,
|
|
127
129
|
reasons,
|
|
128
130
|
checkpoint_commit: checkpoint,
|
|
129
|
-
branch:
|
|
131
|
+
branch: branchOf(task),
|
|
130
132
|
retained: RETAINED
|
|
131
133
|
}, { runId: runIdFor(task.id, task.run_count ?? 1), actor });
|
|
132
134
|
return removedAt;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
1
2
|
import { gitSucceeds } from "../infra/git.js";
|
|
2
3
|
import "./compose.js";
|
|
3
4
|
import { buildHandoff } from "../infra/handoff.js";
|
|
@@ -44,7 +45,7 @@ export async function compileWorkerContext(task, { attempt }) {
|
|
|
44
45
|
`- run_id: ${runIdFor(task.id, attempt)}`,
|
|
45
46
|
`- project_root: ${task.project_root}`,
|
|
46
47
|
`- base_sha: ${task.base_commit ?? "unknown"}`,
|
|
47
|
-
`- branch: ${task.worktree_path ?
|
|
48
|
+
`- branch: ${task.worktree_path ? branchOf(task) : "not applicable (in-place workspace)"}`,
|
|
48
49
|
`- worktree: ${task.worktree_path ?? task.cwd}`,
|
|
49
50
|
`- owned_paths: ${JSON.stringify(task.owned_paths ?? [])}`,
|
|
50
51
|
`- acceptance_source: ${Array.isArray(task.acceptance) && task.acceptance.length > 0 ? "dispatch or session policy; commands stay outside this capsule" : "no acceptance configured"}`,
|
package/src/app/dispatch.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { newWorkerBranch } from "../domain/worker-branch.js";
|
|
1
2
|
import { failedStart } from "./run-state.js";
|
|
2
3
|
import "./compose.js";
|
|
3
4
|
import { frameWorkerPrompt } from "../domain/prompt.js";
|
|
@@ -26,7 +27,7 @@ function validateGoal(goal) {
|
|
|
26
27
|
}
|
|
27
28
|
const tokenBudget = goal.tokenBudget ?? goal.token_budget ?? null;
|
|
28
29
|
if (tokenBudget !== null && (!Number.isInteger(tokenBudget) || tokenBudget <= 0)) {
|
|
29
|
-
throw new Error("goal.
|
|
30
|
+
throw new Error("goal.token_budget must be a positive integer when provided");
|
|
30
31
|
}
|
|
31
32
|
return { objective: goal.objective, tokenBudget };
|
|
32
33
|
}
|
|
@@ -77,7 +78,7 @@ async function validateDependencies(dependsOn, projectRoot, baseCommit) {
|
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
80
|
if (!baseCommit || !containsCommit(projectRoot, dependency.landed_head, baseCommit)) {
|
|
80
|
-
throw dependencyError("dependency_base_mismatch", `worker base does not contain landed dependency ${dependencyId}; use the integrated branch or a newer
|
|
81
|
+
throw dependencyError("dependency_base_mismatch", `worker base does not contain landed dependency ${dependencyId}; use the integrated branch or a newer workspace.base_ref`, {
|
|
81
82
|
dependency_id: dependencyId,
|
|
82
83
|
dependency_head: dependency.landed_head,
|
|
83
84
|
base_commit: baseCommit ?? null
|
|
@@ -115,10 +116,10 @@ async function validateDispatch(input) {
|
|
|
115
116
|
const acceptanceCommands = normalizeAcceptance(acceptance);
|
|
116
117
|
if (!cwd || typeof cwd !== "string") throw new Error("cwd is required");
|
|
117
118
|
if (!allowedReasoningEfforts.has(reasoningEffort)) {
|
|
118
|
-
throw new Error(`unsupported
|
|
119
|
+
throw new Error(`unsupported reasoning_effort: ${reasoningEffort}`);
|
|
119
120
|
}
|
|
120
121
|
if (!Array.isArray(ownedPaths)) {
|
|
121
|
-
throw new Error("
|
|
122
|
+
throw new Error("owned_paths is required; pass an empty list only for a worker that must never land a change (a read-only verifier, or a research worker that reads and reports)");
|
|
122
123
|
}
|
|
123
124
|
if (ownedPaths.length > 0 && acceptanceCommands?.length && acceptanceCommands.every(isArtifactOnlyAcceptance)) {
|
|
124
125
|
throw new Error("a write worker cannot use only file-existence acceptance; add a real test, endpoint probe or structured execution evidence");
|
|
@@ -128,19 +129,19 @@ async function validateDispatch(input) {
|
|
|
128
129
|
await captureExternalOutputs(externalOutputs, { checkBaseline: true });
|
|
129
130
|
if (externalOutputs.length && !acceptanceCommands?.length) throw new Error("shared outputs require explicit acceptance commands");
|
|
130
131
|
if (externalOutputs.length && sandbox === "read-only") throw new Error("a read-only worker cannot declare writable shared outputs");
|
|
131
|
-
if (networkAccess && sandbox === "danger-full-access") throw new Error("
|
|
132
|
-
if (networkAccess && sandbox === "read-only") throw new Error("the read-only sandbox has no network (a fetch there fails on DNS even with network_access); for a worker that must fetch, use sandbox \"workspace-write\" with
|
|
132
|
+
if (networkAccess && sandbox === "danger-full-access") throw new Error("sandbox.network_access is only for the sandboxed workers");
|
|
133
|
+
if (networkAccess && sandbox === "read-only") throw new Error("the read-only sandbox has no network (a fetch there fails on DNS even with network_access); for a worker that must fetch, use sandbox \"workspace-write\" with sandbox.network_access: true and owned_paths: []");
|
|
133
134
|
if (!Array.isArray(writableRoots) || writableRoots.length > 20 || writableRoots.some((root) => typeof root !== "string" || !isAbsolute(root))) {
|
|
134
|
-
throw new Error("
|
|
135
|
+
throw new Error("sandbox.writable_roots must be a list of at most 20 absolute paths");
|
|
135
136
|
}
|
|
136
|
-
if (writableRoots.length && sandbox !== "workspace-write") throw new Error("
|
|
137
|
+
if (writableRoots.length && sandbox !== "workspace-write") throw new Error("sandbox.writable_roots is only configurable for workspace-write workers");
|
|
137
138
|
// Codex refuses a writable root with a symlink component and then fails every
|
|
138
139
|
// command in the worker, so a declared root is stored resolved. Passing the
|
|
139
140
|
// alias would look fine in the receipt and break the run.
|
|
140
141
|
const resolvedWritableRoots = [];
|
|
141
142
|
for (const root of writableRoots) {
|
|
142
143
|
const resolved = resolveWritableRoot(root);
|
|
143
|
-
if (resolved.error) throw new Error(`
|
|
144
|
+
if (resolved.error) throw new Error(`sandbox.writable_roots entry is unusable: ${root} (${resolved.error}); pass an existing directory whose path has no symlink component`);
|
|
144
145
|
resolvedWritableRoots.push(resolved.path);
|
|
145
146
|
}
|
|
146
147
|
for (const value of [maxRunMs, maxTotalMs]) if (value !== null && (!Number.isInteger(value) || value < 1000)) throw new Error("time limits must be integer milliseconds of at least 1000");
|
|
@@ -150,7 +151,7 @@ async function validateDispatch(input) {
|
|
|
150
151
|
if (baseRef && !isGitCheckout(cwd)) throw invalidBaseRefError(cwd, baseRef);
|
|
151
152
|
if (preflight && (!Array.isArray(preflight.probeCommands) || preflight.probeCommands.length === 0
|
|
152
153
|
|| preflight.probeCommands.some((command) => typeof command !== "string" || !command.trim()))) {
|
|
153
|
-
throw new Error("preflight.
|
|
154
|
+
throw new Error("preflight.probe_commands must be a nonempty list of shell commands");
|
|
154
155
|
}
|
|
155
156
|
return { acceptanceCommands, validatedGoal, resolvedWritableRoots };
|
|
156
157
|
}
|
|
@@ -172,7 +173,7 @@ async function claimWorkspace(input, id, acceptanceCommands) {
|
|
|
172
173
|
const projectRoot = workspace.sourceRoot;
|
|
173
174
|
const normalizedOwnedPaths = normalizeOwnedPaths([...ownedPaths, ...externalOutputs.map((entry) => entry.path)], projectRoot);
|
|
174
175
|
const normalizedWorkspaceSetup = normalizeWorkspaceSetup(workspaceSetup, projectRoot);
|
|
175
|
-
if (normalizedWorkspaceSetup && workspace.kind !== "git_worktree") throw new Error("
|
|
176
|
+
if (normalizedWorkspaceSetup && workspace.kind !== "git_worktree") throw new Error("workspace.setup is only supported for git_worktree workers");
|
|
176
177
|
const conflicts = await findOwnershipConflicts(normalizedOwnedPaths);
|
|
177
178
|
if (conflicts.length > 0) throw ownershipConflictError(conflicts);
|
|
178
179
|
return { workspace, projectRoot, normalizedOwnedPaths, normalizedWorkspaceSetup };
|
|
@@ -192,7 +193,7 @@ async function sessionPolicy({ sessionId, sessionTitle, sessionNote }, acceptanc
|
|
|
192
193
|
// model edits. Remove it normally; never force-remove user work.
|
|
193
194
|
async function discardWorktree(projectRoot, worktreePath, id) {
|
|
194
195
|
await runToExit(gitBin(), ["-C", projectRoot, "worktree", "remove", worktreePath]).catch(() => {});
|
|
195
|
-
await runToExit(gitBin(), ["-C", projectRoot, "branch", "-D",
|
|
196
|
+
await runToExit(gitBin(), ["-C", projectRoot, "branch", "-D", newWorkerBranch(id)]).catch(() => {});
|
|
196
197
|
}
|
|
197
198
|
|
|
198
199
|
async function createWorkerWorktree({ workspace, projectRoot, normalizedWorkspaceSetup }, id, baseRef) {
|
|
@@ -200,7 +201,7 @@ async function createWorkerWorktree({ workspace, projectRoot, normalizedWorkspac
|
|
|
200
201
|
? await withWorktreeCreationLock(projectRoot, () => ensureWorktree(projectRoot, id, baseRef))
|
|
201
202
|
: { path: null, baseCommit: null };
|
|
202
203
|
if (workspace.kind === "git_worktree" && !worktree.path) {
|
|
203
|
-
throw coded("git_worktree_unavailable", "
|
|
204
|
+
throw coded("git_worktree_unavailable", "workspace.kind git_worktree could not create an isolated worktree; use read_only_in_place for a non-writing inspection or initialize and commit the repository first");
|
|
204
205
|
}
|
|
205
206
|
if (normalizedWorkspaceSetup) {
|
|
206
207
|
try {
|
|
@@ -276,7 +277,8 @@ function buildRecord(input, parts) {
|
|
|
276
277
|
in_place_authorization: workspace.kind === "in_place_write" ? String(inPlaceAuthorization).trim() : null,
|
|
277
278
|
landable: workspace.landable,
|
|
278
279
|
cleanable: workspace.cleanable,
|
|
279
|
-
setup: normalizedWorkspaceSetup
|
|
280
|
+
setup: normalizedWorkspaceSetup,
|
|
281
|
+
branch: worktreePath ? newWorkerBranch(id) : null
|
|
280
282
|
},
|
|
281
283
|
sandbox,
|
|
282
284
|
model,
|
|
@@ -333,7 +335,7 @@ async function assertPreflightMatches(preflightId, runtimeContract) {
|
|
|
333
335
|
}
|
|
334
336
|
const contractHash = runtimeContractHash(runtimeContract);
|
|
335
337
|
if (preflightResult.contract_hash === contractHash) return;
|
|
336
|
-
throw coded("preflight_mismatch", `preflight ${preflightId} does not match this worker's runtime contract; create a new preflight after changing
|
|
338
|
+
throw coded("preflight_mismatch", `preflight ${preflightId} does not match this worker's runtime contract; create a new preflight after changing workspace.base_ref, sandbox, owned_paths, commands, context, contracts, network or writable roots`, {
|
|
337
339
|
preflight_id: preflightId,
|
|
338
340
|
expected_contract_hash: contractHash,
|
|
339
341
|
actual_contract_hash: preflightResult.contract_hash,
|
package/src/app/followup.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
1
2
|
import "./compose.js";
|
|
2
3
|
import { readTaskEvents } from "../infra/store/events.js";
|
|
3
4
|
import { getTask } from "../infra/store/tasks.js";
|
|
@@ -10,10 +11,10 @@ import { resolveCommit } from "./worktree-setup.js";
|
|
|
10
11
|
function followupBaseRef(parent, baseRef) {
|
|
11
12
|
if (baseRef || parent.landed_at || !parent.project_root || !parent.worktree_path) return baseRef ?? null;
|
|
12
13
|
try {
|
|
13
|
-
resolveCommit(parent.project_root,
|
|
14
|
-
return
|
|
14
|
+
resolveCommit(parent.project_root, branchOf(parent));
|
|
15
|
+
return branchOf(parent);
|
|
15
16
|
} catch {
|
|
16
|
-
const error = new Error(`parent checkpoint
|
|
17
|
+
const error = new Error(`parent checkpoint ${branchOf(parent)} is unavailable; restore it or choose an explicit workspace.base_ref`);
|
|
17
18
|
error.code = "followup_checkpoint_missing";
|
|
18
19
|
throw error;
|
|
19
20
|
}
|
|
@@ -90,7 +91,7 @@ export async function createFollowupWorker(options) {
|
|
|
90
91
|
workspaceSetup: workspaceSetup ?? parent.workspace_metadata?.setup ?? null,
|
|
91
92
|
baseRef: inheritedBaseRef,
|
|
92
93
|
// Inherited unless given; the follow-up runs in a fresh worktree cut
|
|
93
|
-
// from the parent's
|
|
94
|
+
// from the parent's branch, so checks that depend on the
|
|
94
95
|
// parent checkpoint are valid before the parent has landed on the target.
|
|
95
96
|
acceptance: acceptance === undefined ? inheritedAcceptance : acceptance,
|
|
96
97
|
acceptanceTimeoutMs: acceptanceTimeoutMs ?? parent.acceptance_timeout_ms ?? null
|
package/src/app/land-chain.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
1
2
|
import { ensureTaskWorktree } from "./restore-worktree.js";
|
|
2
3
|
import "./compose.js";
|
|
3
4
|
import { runGit } from "../infra/git.js";
|
|
@@ -84,7 +85,7 @@ export async function landOneWorkerTask(taskId, options = {}) {
|
|
|
84
85
|
return { error: "acceptance_not_run", task_id: taskId };
|
|
85
86
|
}
|
|
86
87
|
git(task.project_root, ["merge-base", "--is-ancestor", task.landed_head, "HEAD"]);
|
|
87
|
-
return { task_id: taskId, title: task.title, status: task.status, branch:
|
|
88
|
+
return { task_id: taskId, title: task.title, status: task.status, branch: branchOf(task), skipped: "already_landed", landed_at: task.landed_at, landed_head: task.landed_head };
|
|
88
89
|
} catch {
|
|
89
90
|
return { error: "landed_commit_unreachable", task_id: taskId, reason: "the removed ancestor worktree cannot be skipped without proving its landed commit is on the current target" };
|
|
90
91
|
}
|
|
@@ -106,15 +107,15 @@ export async function landOneWorkerTask(taskId, options = {}) {
|
|
|
106
107
|
task_id: taskId,
|
|
107
108
|
title: task.title,
|
|
108
109
|
status: task.status,
|
|
109
|
-
branch:
|
|
110
|
+
branch: branchOf(task),
|
|
110
111
|
...outcome,
|
|
111
112
|
skipped: "already_in_target",
|
|
112
113
|
lifecycle_recorded: !alreadyRecorded && Boolean(outcome.matched_head)
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
|
-
if (outcome.error) return { task_id: taskId, title: task.title, status: task.status, branch:
|
|
116
|
+
if (outcome.error) return { task_id: taskId, title: task.title, status: task.status, branch: branchOf(task), ...outcome };
|
|
116
117
|
await recordWorkerLanded(task, { head: outcome.head, branch: outcome.onto, target: outcome.target, alreadyLanded: outcome.already_landed ?? [] });
|
|
117
|
-
return { task_id: taskId, title: task.title, status: task.status, branch:
|
|
118
|
+
return { task_id: taskId, title: task.title, status: task.status, branch: branchOf(task), ...outcome };
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
export async function followupChainIds(taskId) {
|
package/src/app/landing.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Landing a worker's commits where they were dispatched from.
|
|
2
2
|
//
|
|
3
|
-
// A worker commits on
|
|
3
|
+
// A worker's commits live on its own branch inside its own worktree. Getting that
|
|
4
4
|
// work onto the branch the main thread integrates on used to be the main
|
|
5
5
|
// thread's job, one cherry-pick per step, dozens of times per batch. This
|
|
6
6
|
// does the same thing with the same guard rails a careful person would use:
|
|
@@ -129,8 +129,8 @@ function hasStagedChanges(cwd) {
|
|
|
129
129
|
// (task.project_root: the row's cwd is the worktree the worker ran in).
|
|
130
130
|
// `onto`, when given, must name that branch: it is a guard, not a switch.
|
|
131
131
|
//
|
|
132
|
-
// `
|
|
133
|
-
// first, as one commit on
|
|
132
|
+
// `commit_message` commits what the worker left uncommitted in its worktree
|
|
133
|
+
// first, as one commit on its branch. A worker in Codex's workspace-write
|
|
134
134
|
// sandbox cannot commit at all (the sandbox keeps .git read-only), so this
|
|
135
135
|
// is how "one step, one commit" is kept without giving workers full access.
|
|
136
136
|
//
|
|
@@ -145,14 +145,14 @@ function acceptanceRefusal(task) {
|
|
|
145
145
|
if (acceptance.passed === false) {
|
|
146
146
|
return {
|
|
147
147
|
error: "acceptance_failed",
|
|
148
|
-
reason: `the worker's acceptance run failed${failing ? ` on "${failing.command.slice(0, 120)}" (exit ${failing.error ?? (failing.baseline?.passed === false ? "baseline/evidence mismatch" : failing.timed_out ? "timeout" : failing.exit_code)})` : acceptance.error ? ` (${acceptance.error})` : ""}; resume the worker with the failing output and land once it passes.
|
|
148
|
+
reason: `the worker's acceptance run failed${failing ? ` on "${failing.command.slice(0, 120)}" (exit ${failing.error ?? (failing.baseline?.passed === false ? "baseline/evidence mismatch" : failing.timed_out ? "timeout" : failing.exit_code)})` : acceptance.error ? ` (${acceptance.error})` : ""}; resume the worker with the failing output and land once it passes. ignore_acceptance: true lands anyway, only when the user said to.`,
|
|
149
149
|
acceptance: { status: acceptance.status, passed: false, checks: acceptance.checks ?? [], error: acceptance.error ?? null }
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
if (acceptance.status === "running" || acceptance.status === "interrupted" || acceptance.status === "cancelled") {
|
|
153
153
|
return {
|
|
154
154
|
error: "acceptance_not_run",
|
|
155
|
-
reason: `the worker's acceptance is ${acceptance.status}; wait for it (or resume the worker to run it again) before landing.
|
|
155
|
+
reason: `the worker's acceptance is ${acceptance.status}; wait for it (or resume the worker to run it again) before landing. ignore_acceptance: true lands anyway, only when the user said to.`,
|
|
156
156
|
acceptance: { status: acceptance.status, passed: null }
|
|
157
157
|
};
|
|
158
158
|
}
|
|
@@ -163,7 +163,7 @@ function acceptanceRefusal(task) {
|
|
|
163
163
|
function targetState(task, onto) {
|
|
164
164
|
const target = task.project_root;
|
|
165
165
|
if (!task.worktree_path || !existsSync(task.worktree_path)) {
|
|
166
|
-
return { error: "no_worktree", reason: "this worker has no worktree (it ran in place), so there is
|
|
166
|
+
return { error: "no_worktree", reason: "this worker has no worktree (it ran in place), so there is no worker branch to land" };
|
|
167
167
|
}
|
|
168
168
|
if (!target || !existsSync(target)) {
|
|
169
169
|
return { error: "no_target", reason: `the directory the worker was dispatched from (${target}) no longer exists` };
|
|
@@ -191,7 +191,7 @@ function ownershipRefusal(task) {
|
|
|
191
191
|
const paths = [...filterWorkspaceSetupChanges(task, readWorktreeChanges(task.worktree_path, worktreeRef(task))),
|
|
192
192
|
...diff.files.flatMap((file) => [file.path, file.from].filter(Boolean).map((path) => join(task.worktree_path, path)))];
|
|
193
193
|
const { outside } = findOutsideOwnedChanges(task, [...new Set(paths)]);
|
|
194
|
-
if (outside.length) return { error: "outside_owned_paths", reason: "worker changes exceed declared
|
|
194
|
+
if (outside.length) return { error: "outside_owned_paths", reason: "worker changes exceed declared owned_paths; review them and obtain explicit authorization before allowing an exception", outside_paths: outside.map((entry) => relative(task.worktree_path, entry)) };
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
197
|
|
|
@@ -267,7 +267,7 @@ function nothingToLand(proof, { branch, target, uncommitted, base }) {
|
|
|
267
267
|
return {
|
|
268
268
|
error: "nothing_to_land",
|
|
269
269
|
reason: uncommitted.length > 0
|
|
270
|
-
? "the worker made no commits on its branch (a workspace-write worker cannot: the sandbox keeps .git read-only); pass
|
|
270
|
+
? "the worker made no commits on its branch (a workspace-write worker cannot: the sandbox keeps .git read-only); pass commit_message to commit its edits as one commit and land that"
|
|
271
271
|
: "the worker made no commits and left no edits on its branch",
|
|
272
272
|
uncommitted,
|
|
273
273
|
base_commit: base
|
package/src/app/ownership.js
CHANGED
|
@@ -50,7 +50,7 @@ export async function findOwnershipConflicts(ownedPaths, { excludeTaskId = null
|
|
|
50
50
|
|
|
51
51
|
export function ownershipConflictError(conflicts) {
|
|
52
52
|
const owners = conflicts.map((conflict) => conflict.task_id).join(", ");
|
|
53
|
-
const error = new Error(`
|
|
53
|
+
const error = new Error(`owned_paths overlap with active worker(s): ${owners}`);
|
|
54
54
|
error.code = "ownership_conflict";
|
|
55
55
|
error.conflicts = conflicts;
|
|
56
56
|
return error;
|
package/src/app/rebase.js
CHANGED
|
@@ -182,7 +182,7 @@ function popOntoNewBase({ cwd, base, head }, ontoCommit) {
|
|
|
182
182
|
const popError = restoreStash(cwd, true);
|
|
183
183
|
return {
|
|
184
184
|
error: "stash_conflict",
|
|
185
|
-
reason: `the worker's uncommitted edits conflict with ${ontoCommit.slice(0, 12)}; the worktree is back as it was${popError ? " (but its stash could not be restored: run git stash pop there)" : ""}. Commit them first (
|
|
185
|
+
reason: `the worker's uncommitted edits conflict with ${ontoCommit.slice(0, 12)}; the worktree is back as it was${popError ? " (but its stash could not be restored: run git stash pop there)" : ""}. Commit them first (land_worker with commit_message) so the conflict is in a commit that can be resolved, or redispatch from the new commit with workspace.base_ref`,
|
|
186
186
|
files,
|
|
187
187
|
git: tail,
|
|
188
188
|
base_commit: base,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// A cleaned-up worker keeps its branch. When the main thread comes back to it
|
|
2
2
|
// (to resume or land), the worktree is cut again from that branch, with the
|
|
3
3
|
// same setup links, so cleanup never closes the door on unfinished work.
|
|
4
|
+
import { branchOf } from "../domain/worker-branch.js";
|
|
4
5
|
import "./compose.js";
|
|
5
6
|
import { gitBin, gitSucceeds } from "../infra/git.js";
|
|
6
7
|
import { runToExit } from "../infra/process.js";
|
|
@@ -20,7 +21,7 @@ function deliveryStepOf(task) {
|
|
|
20
21
|
// gone and cannot be brought back, so no caller carries on somewhere else.
|
|
21
22
|
export async function ensureTaskWorktree(task) {
|
|
22
23
|
if (!task.worktree_path || !task.project_root || existsSync(task.worktree_path)) return false;
|
|
23
|
-
const branch =
|
|
24
|
+
const branch = branchOf(task);
|
|
24
25
|
if (!gitSucceeds(task.project_root, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`])) {
|
|
25
26
|
const error = new Error(`the worktree of ${task.id} is gone and its branch ${branch} does not exist, so it cannot be restored`);
|
|
26
27
|
error.code = "worktree_unrecoverable";
|
package/src/app/resume.js
CHANGED
|
@@ -2,11 +2,11 @@ import { mkdir } from "node:fs/promises";
|
|
|
2
2
|
import { ensureTaskWorktree } from "./restore-worktree.js";
|
|
3
3
|
import "./compose.js";
|
|
4
4
|
import { frameWorkerPrompt } from "../domain/prompt.js";
|
|
5
|
-
import { ACTIVE_STATUSES } from "../domain/status.js";
|
|
5
|
+
import { ACTIVE_STATUSES, runIsOver } from "../domain/status.js";
|
|
6
6
|
import { buildHandoff } from "../infra/handoff.js";
|
|
7
7
|
import { appendTaskEvent } from "../infra/store/events.js";
|
|
8
8
|
import { getSession } from "../infra/store/sessions.js";
|
|
9
|
-
import { claimTaskRun, getTask, readTasks, releaseTaskRun, upsertTask } from "../infra/store/tasks.js";
|
|
9
|
+
import { claimTaskRun, getTask, isGroupAlive, readTasks, releaseTaskRun, upsertTask } from "../infra/store/tasks.js";
|
|
10
10
|
import { codexRunner } from "../runners/codex/adapter.js";
|
|
11
11
|
import { readNativeGoalState } from "../runners/codex/goal-store.js";
|
|
12
12
|
import { DEFAULT_ACCEPTANCE_TIMEOUT_MS, normalizeAcceptance } from "./acceptance.js";
|
|
@@ -21,7 +21,7 @@ import { appendFile } from "node:fs/promises";
|
|
|
21
21
|
// goal are all inherited from the original task, and the row is reused so one
|
|
22
22
|
// logical piece of work stays one row.
|
|
23
23
|
//
|
|
24
|
-
// `
|
|
24
|
+
// `rebase_onto` names a ref, resolved in the project directory (HEAD, main, a
|
|
25
25
|
// sha): the worktree is moved onto it first so the worker continues on
|
|
26
26
|
// current code, and base_commit is recorded before the worker starts so a
|
|
27
27
|
// spawn failure cannot leave the row describing the old base. A rebase that
|
|
@@ -64,7 +64,7 @@ async function rebaseBeforeResume(task, rebaseOnto) {
|
|
|
64
64
|
try {
|
|
65
65
|
ontoCommit = resolveCommit(task.project_root, rebaseOnto);
|
|
66
66
|
} catch {
|
|
67
|
-
throw coded("invalid_rebase_onto", `
|
|
67
|
+
throw coded("invalid_rebase_onto", `rebase_onto "${rebaseOnto}" does not resolve to a commit in ${task.project_root}`);
|
|
68
68
|
}
|
|
69
69
|
const rebase = rebaseWorktree(task, ontoCommit);
|
|
70
70
|
if (rebase.error) throw coded(rebase.error, rebase.reason, rebase);
|
|
@@ -104,7 +104,7 @@ async function resumeClaimed(claimed, { prompt, rebaseOnto, acceptance }) {
|
|
|
104
104
|
let task = await refreshAcceptance(claimed, session, acceptance);
|
|
105
105
|
if (!task.thread_id) {
|
|
106
106
|
throw new Error(
|
|
107
|
-
`task ${task.id} has no Codex thread_id recorded. Only workers created by this version of codex-supervisor-mcp can be resumed; use
|
|
107
|
+
`task ${task.id} has no Codex thread_id recorded. Only workers created by this version of codex-supervisor-mcp can be resumed; use create_worker with followup_of otherwise.`
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
await ensureTaskWorktree(task);
|
|
@@ -158,7 +158,12 @@ export async function recoverEligibleRuns() {
|
|
|
158
158
|
|| ["blocked", "paused", "budget_limited", "usage_limited"].includes(task.goal_status)
|
|
159
159
|
|| /401|403|unauthori[sz]ed|not logged|permission denied|approval|rate.?limit|429/i.test(task.error ?? "")
|
|
160
160
|
|| /time_limit|quota/.test(`${task.attention_reason ?? ""} ${task.error ?? ""}`)
|
|
161
|
-
|
|
161
|
+
// Once the run is over its pids may belong to anyone.
|
|
162
|
+
|| (!runIsOver(task) && (await isPidAlive(task.pid) || await isPidAlive(task.run_host_pid)))
|
|
163
|
+
// Something of the dead run is still alive and holds the session;
|
|
164
|
+
// resuming now fails with "already has an active writer". A later poll retries.
|
|
165
|
+
// A recorded exit is the one thing that rules a survivor out.
|
|
166
|
+
|| (task.exit_code == null && isGroupAlive(task.run_host_pid))) continue;
|
|
162
167
|
const session = task.session_id ? await getSession(task.session_id) : null;
|
|
163
168
|
if (session?.approval_state === "waiting_user") continue;
|
|
164
169
|
try {
|