@h-rig/server 0.0.6-alpha.21 → 0.0.6-alpha.23
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/dist/src/index.js +313 -57
- package/dist/src/server-helpers/http-router.js +157 -6
- package/dist/src/server-helpers/pi-session-proxy.js +84 -0
- package/dist/src/server-helpers/run-io.js +17 -1
- package/dist/src/server-helpers/run-mutations.js +134 -59
- package/dist/src/server-helpers/run-writers.js +7 -0
- package/dist/src/server-helpers/ws-router.js +9 -5
- package/dist/src/server.js +313 -57
- package/package.json +4 -4
|
@@ -6,7 +6,7 @@ import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as rea
|
|
|
6
6
|
import { dirname as dirname6, relative as relative2, resolve as resolve10 } from "path";
|
|
7
7
|
import {
|
|
8
8
|
listAuthorityRuns as listAuthorityRuns7,
|
|
9
|
-
readAuthorityRun as
|
|
9
|
+
readAuthorityRun as readAuthorityRun9,
|
|
10
10
|
resolveAuthorityRunDir as resolveAuthorityRunDir4,
|
|
11
11
|
writeJsonFile as writeJsonFile4
|
|
12
12
|
} from "@rig/runtime/control-plane/authority-files";
|
|
@@ -363,6 +363,12 @@ function patchRunRecord(projectRoot, runId, patch) {
|
|
|
363
363
|
writeJsonFile2(resolve6(resolveAuthorityRunDir2(projectRoot, runId), "run.json"), next);
|
|
364
364
|
return next;
|
|
365
365
|
}
|
|
366
|
+
function patchRunPiSessionMetadata(projectRoot, runId, metadata) {
|
|
367
|
+
return patchRunRecord(projectRoot, runId, {
|
|
368
|
+
piSession: metadata?.public ?? null,
|
|
369
|
+
piSessionPrivate: metadata
|
|
370
|
+
});
|
|
371
|
+
}
|
|
366
372
|
function buildRunStartPatch(startedAt) {
|
|
367
373
|
return {
|
|
368
374
|
status: "preparing",
|
|
@@ -460,7 +466,7 @@ var DEFAULT_TERMINAL_SHELL = process.env.SHELL || "/bin/zsh";
|
|
|
460
466
|
// packages/server/src/server-helpers/http-router.ts
|
|
461
467
|
import {
|
|
462
468
|
listAuthorityRuns as listAuthorityRuns4,
|
|
463
|
-
readAuthorityRun as
|
|
469
|
+
readAuthorityRun as readAuthorityRun6,
|
|
464
470
|
resolveAuthorityPaths,
|
|
465
471
|
writeJsonFile as writeJsonFile3
|
|
466
472
|
} from "@rig/runtime/control-plane/authority-files";
|
|
@@ -480,8 +486,11 @@ import {
|
|
|
480
486
|
RemoteWsClient
|
|
481
487
|
} from "@rig/runtime/control-plane/remote";
|
|
482
488
|
|
|
489
|
+
// packages/server/src/server-helpers/pi-session-proxy.ts
|
|
490
|
+
import { readAuthorityRun as readAuthorityRun4 } from "@rig/runtime/control-plane/authority-files";
|
|
491
|
+
|
|
483
492
|
// packages/server/src/server-helpers/run-steering.ts
|
|
484
|
-
import { appendJsonlRecord as appendJsonlRecord2, readAuthorityRun as
|
|
493
|
+
import { appendJsonlRecord as appendJsonlRecord2, readAuthorityRun as readAuthorityRun5, resolveAuthorityRunDir as resolveAuthorityRunDir3 } from "@rig/runtime/control-plane/authority-files";
|
|
485
494
|
|
|
486
495
|
// packages/server/src/server-helpers/http-router.ts
|
|
487
496
|
import { buildRigInitConfigSource } from "@rig/core";
|
|
@@ -925,7 +934,7 @@ import {
|
|
|
925
934
|
RemoteWsClient as RemoteWsClient2
|
|
926
935
|
} from "@rig/runtime/control-plane/remote";
|
|
927
936
|
import { deleteRunState } from "@rig/runtime/control-plane/native/run-ops";
|
|
928
|
-
import { readAuthorityRun as
|
|
937
|
+
import { readAuthorityRun as readAuthorityRun7 } from "@rig/runtime/control-plane/authority-files";
|
|
929
938
|
|
|
930
939
|
// packages/server/src/server-helpers/inspector-jobs.ts
|
|
931
940
|
import { readJsonFile as readJsonFile2 } from "@rig/runtime/control-plane/authority-files";
|
|
@@ -938,7 +947,7 @@ import {
|
|
|
938
947
|
} from "@rig/runtime/control-plane/native/run-ops";
|
|
939
948
|
import {
|
|
940
949
|
listAuthorityRuns as listAuthorityRuns5,
|
|
941
|
-
readAuthorityRun as
|
|
950
|
+
readAuthorityRun as readAuthorityRun8
|
|
942
951
|
} from "@rig/runtime/control-plane/authority-files";
|
|
943
952
|
|
|
944
953
|
// packages/server/src/inspector/service.ts
|
|
@@ -1326,10 +1335,10 @@ function closeoutPhasePatch(phase, status, extra = {}) {
|
|
|
1326
1335
|
const updatedAt = new Date().toISOString();
|
|
1327
1336
|
return {
|
|
1328
1337
|
serverCloseout: {
|
|
1338
|
+
...extra,
|
|
1329
1339
|
phase,
|
|
1330
1340
|
status,
|
|
1331
|
-
updatedAt
|
|
1332
|
-
...extra
|
|
1341
|
+
updatedAt
|
|
1333
1342
|
}
|
|
1334
1343
|
};
|
|
1335
1344
|
}
|
|
@@ -1447,8 +1456,60 @@ async function updateRunTaskSourceLifecycle(projectRoot, run, status, summary, o
|
|
|
1447
1456
|
});
|
|
1448
1457
|
}
|
|
1449
1458
|
}
|
|
1459
|
+
async function markServerOwnedCloseoutFailed(state, runId, error) {
|
|
1460
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1461
|
+
const current = readAuthorityRun9(state.projectRoot, runId);
|
|
1462
|
+
patchRunRecord(state.projectRoot, runId, {
|
|
1463
|
+
status: "failed",
|
|
1464
|
+
completedAt: new Date().toISOString(),
|
|
1465
|
+
errorText: detail,
|
|
1466
|
+
...closeoutPhasePatch("failed", "failed", { error: detail })
|
|
1467
|
+
});
|
|
1468
|
+
appendRunLogEntryAndBroadcast(state, runId, {
|
|
1469
|
+
id: `log:${runId}:server-closeout-failed`,
|
|
1470
|
+
title: "Server-owned closeout failed",
|
|
1471
|
+
detail,
|
|
1472
|
+
tone: "error",
|
|
1473
|
+
status: "failed",
|
|
1474
|
+
createdAt: new Date().toISOString()
|
|
1475
|
+
}, "server-closeout-failed");
|
|
1476
|
+
if (current?.taskId) {
|
|
1477
|
+
await updateRunTaskSourceLifecycle(state.projectRoot, { ...current, status: "failed", errorText: detail }, "failed", "Rig server-owned closeout failed.", { errorText: detail }).catch((sourceError) => {
|
|
1478
|
+
appendRunLogEntry(state.projectRoot, runId, {
|
|
1479
|
+
id: `log:${runId}:task-source-closeout-failed-update`,
|
|
1480
|
+
title: "Task source closeout failure update failed",
|
|
1481
|
+
detail: sourceError instanceof Error ? sourceError.message : String(sourceError),
|
|
1482
|
+
tone: "error",
|
|
1483
|
+
status: "failed",
|
|
1484
|
+
createdAt: new Date().toISOString()
|
|
1485
|
+
});
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
function scheduleServerOwnedPrCloseout(state, runId, reason) {
|
|
1490
|
+
const startedAt = new Date().toISOString();
|
|
1491
|
+
state.runProcesses.set(runId, {
|
|
1492
|
+
runId,
|
|
1493
|
+
child: null,
|
|
1494
|
+
startedAt,
|
|
1495
|
+
stopped: false
|
|
1496
|
+
});
|
|
1497
|
+
queueMicrotask(() => {
|
|
1498
|
+
withServerAuthorityEnvIfNeeded(state.projectRoot, async () => {
|
|
1499
|
+
try {
|
|
1500
|
+
await runServerOwnedPrCloseout(state, runId);
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
await markServerOwnedCloseoutFailed(state, runId, error);
|
|
1503
|
+
} finally {
|
|
1504
|
+
state.runProcesses.delete(runId);
|
|
1505
|
+
broadcastSnapshotInvalidation(state, `server-closeout-${reason}-terminal`);
|
|
1506
|
+
await reconcileScheduler(state, `server-closeout-${reason}-terminal`);
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1450
1511
|
async function runServerOwnedPrCloseout(state, runId) {
|
|
1451
|
-
const run =
|
|
1512
|
+
const run = readAuthorityRun9(state.projectRoot, runId);
|
|
1452
1513
|
if (!run)
|
|
1453
1514
|
throw new Error(`Run not found: ${runId}`);
|
|
1454
1515
|
const closeout = closeoutRecord(run);
|
|
@@ -1458,7 +1519,7 @@ async function runServerOwnedPrCloseout(state, runId) {
|
|
|
1458
1519
|
if (!taskId)
|
|
1459
1520
|
throw new Error("Server-owned closeout requires a task id.");
|
|
1460
1521
|
const workspace = normalizeString(closeout.runtimeWorkspace) ?? normalizeString(run.worktreePath) ?? state.projectRoot;
|
|
1461
|
-
|
|
1522
|
+
let branch = normalizeString(closeout.branch) ?? `rig/${taskId}-${runId}`;
|
|
1462
1523
|
const config = await loadRigLifecycleConfig(state.projectRoot);
|
|
1463
1524
|
const runPrMode = normalizeString(run.prMode);
|
|
1464
1525
|
const prMode = runPrMode === "auto" || runPrMode === "ask" || runPrMode === "off" ? runPrMode : config?.pr?.mode ?? "off";
|
|
@@ -1471,7 +1532,7 @@ async function runServerOwnedPrCloseout(state, runId) {
|
|
|
1471
1532
|
autoFixReview: false
|
|
1472
1533
|
}
|
|
1473
1534
|
};
|
|
1474
|
-
const readCurrentRun = () =>
|
|
1535
|
+
const readCurrentRun = () => readAuthorityRun9(state.projectRoot, runId) ?? run;
|
|
1475
1536
|
const sourceTask = runSourceTaskIdentity(run);
|
|
1476
1537
|
const closeoutPhase = normalizeString(closeout.phase)?.toLowerCase() ?? "";
|
|
1477
1538
|
const closeoutStatus = normalizeString(closeout.status)?.toLowerCase() ?? "";
|
|
@@ -1532,6 +1593,12 @@ async function runServerOwnedPrCloseout(state, runId) {
|
|
|
1532
1593
|
const githubEnv = githubToken ? { RIG_GITHUB_TOKEN: githubToken, GITHUB_TOKEN: githubToken, GH_TOKEN: githubToken } : {};
|
|
1533
1594
|
const gitCommand = createCommandRunner("git", githubEnv);
|
|
1534
1595
|
const ghCommand = createCommandRunner("gh", githubEnv);
|
|
1596
|
+
const workspaceBranch = await gitCommand(["rev-parse", "--abbrev-ref", "HEAD"], { cwd: workspace });
|
|
1597
|
+
const currentWorkspaceBranch = workspaceBranch.exitCode === 0 ? normalizeString(workspaceBranch.stdout) : null;
|
|
1598
|
+
if (currentWorkspaceBranch && currentWorkspaceBranch !== "HEAD" && currentWorkspaceBranch !== branch) {
|
|
1599
|
+
appendCloseoutStage(state, runId, "branch", `Using runtime workspace branch ${currentWorkspaceBranch} instead of recorded branch ${branch}.`, "reviewing", "info");
|
|
1600
|
+
branch = currentWorkspaceBranch;
|
|
1601
|
+
}
|
|
1535
1602
|
const setCloseout = (phase, status, extra = {}) => {
|
|
1536
1603
|
const previous = closeoutRecord(readCurrentRun()) ?? closeout;
|
|
1537
1604
|
patchRunRecord(state.projectRoot, runId, {
|
|
@@ -1768,7 +1835,7 @@ async function createRunRecord(projectRoot, input, readTasks = readWorkspaceTask
|
|
|
1768
1835
|
}
|
|
1769
1836
|
}
|
|
1770
1837
|
async function startLocalRun(state, runId, options) {
|
|
1771
|
-
const run =
|
|
1838
|
+
const run = readAuthorityRun9(state.projectRoot, runId);
|
|
1772
1839
|
if (!run) {
|
|
1773
1840
|
throw new Error(`Run not found: ${runId}`);
|
|
1774
1841
|
}
|
|
@@ -1902,6 +1969,25 @@ async function startLocalRun(state, runId, options) {
|
|
|
1902
1969
|
broadcastSnapshotInvalidation(state);
|
|
1903
1970
|
continue;
|
|
1904
1971
|
}
|
|
1972
|
+
if (line.startsWith("__RIG_WRAPPER_EVENT__")) {
|
|
1973
|
+
try {
|
|
1974
|
+
const wrapperEvent = JSON.parse(line.slice("__RIG_WRAPPER_EVENT__".length));
|
|
1975
|
+
const eventType = normalizeString(wrapperEvent.type);
|
|
1976
|
+
const payload = wrapperEvent.payload && typeof wrapperEvent.payload === "object" && !Array.isArray(wrapperEvent.payload) ? wrapperEvent.payload : {};
|
|
1977
|
+
if (eventType === "pi.session.ready" && payload.privateMetadata && typeof payload.privateMetadata === "object" && !Array.isArray(payload.privateMetadata)) {
|
|
1978
|
+
patchRunPiSessionMetadata(state.projectRoot, runId, payload.privateMetadata);
|
|
1979
|
+
}
|
|
1980
|
+
appendRunTimelineEntry(state.projectRoot, runId, {
|
|
1981
|
+
id: `timeline:${runId}:${Date.now()}:wrapper:${eventType ?? "event"}`,
|
|
1982
|
+
type: "wrapper-event",
|
|
1983
|
+
eventType,
|
|
1984
|
+
payload,
|
|
1985
|
+
createdAt: normalizeString(wrapperEvent.at) ?? new Date().toISOString()
|
|
1986
|
+
});
|
|
1987
|
+
} catch {}
|
|
1988
|
+
broadcastSnapshotInvalidation(state, "wrapper-event");
|
|
1989
|
+
continue;
|
|
1990
|
+
}
|
|
1905
1991
|
appendRunLogEntryAndBroadcast(state, runId, {
|
|
1906
1992
|
id: `log:${runId}:${Date.now()}`,
|
|
1907
1993
|
title,
|
|
@@ -1926,11 +2012,17 @@ async function startLocalRun(state, runId, options) {
|
|
|
1926
2012
|
if (exit.error) {
|
|
1927
2013
|
throw new Error(`Failed to start task run: ${exit.error.message}`);
|
|
1928
2014
|
}
|
|
1929
|
-
const current =
|
|
2015
|
+
const current = readAuthorityRun9(state.projectRoot, runId);
|
|
1930
2016
|
if (!current) {
|
|
1931
2017
|
return;
|
|
1932
2018
|
}
|
|
1933
|
-
if (
|
|
2019
|
+
if (closeoutRecord(current)?.status === "pending") {
|
|
2020
|
+
try {
|
|
2021
|
+
await runServerOwnedPrCloseout(state, runId);
|
|
2022
|
+
} catch (closeoutError) {
|
|
2023
|
+
await markServerOwnedCloseoutFailed(state, runId, closeoutError);
|
|
2024
|
+
}
|
|
2025
|
+
} else if (exit.code !== 0 && current.status !== "completed" && current.status !== "stopped") {
|
|
1934
2026
|
const completedAt = current.completedAt ?? new Date().toISOString();
|
|
1935
2027
|
const failureSummary = normalizeString(current.errorText) ?? summarizeRunValidationFailure(state.projectRoot, current) ?? `Rig task-run exited with code ${String(exit.code ?? "unknown")}`;
|
|
1936
2028
|
if (current.status !== "failed") {
|
|
@@ -1965,38 +2057,6 @@ ${sourceFailure}` });
|
|
|
1965
2057
|
agent: current.runtimeAdapter,
|
|
1966
2058
|
summary: failureSummary
|
|
1967
2059
|
});
|
|
1968
|
-
} else if (closeoutRecord(current)?.status === "pending") {
|
|
1969
|
-
try {
|
|
1970
|
-
await runServerOwnedPrCloseout(state, runId);
|
|
1971
|
-
} catch (closeoutError) {
|
|
1972
|
-
const closeoutFailure = closeoutError instanceof Error ? closeoutError.message : String(closeoutError);
|
|
1973
|
-
patchRunRecord(state.projectRoot, runId, {
|
|
1974
|
-
status: "failed",
|
|
1975
|
-
completedAt: new Date().toISOString(),
|
|
1976
|
-
errorText: closeoutFailure,
|
|
1977
|
-
...closeoutPhasePatch("failed", "failed", { error: closeoutFailure })
|
|
1978
|
-
});
|
|
1979
|
-
appendRunLogEntryAndBroadcast(state, runId, {
|
|
1980
|
-
id: `log:${runId}:server-closeout-failed`,
|
|
1981
|
-
title: "Server-owned closeout failed",
|
|
1982
|
-
detail: closeoutFailure,
|
|
1983
|
-
tone: "error",
|
|
1984
|
-
status: "failed",
|
|
1985
|
-
createdAt: new Date().toISOString()
|
|
1986
|
-
}, "server-closeout-failed");
|
|
1987
|
-
if (current.taskId) {
|
|
1988
|
-
await updateRunTaskSourceLifecycle(state.projectRoot, { ...current, status: "failed", errorText: closeoutFailure }, "failed", "Rig server-owned closeout failed.", { errorText: closeoutFailure }).catch((error) => {
|
|
1989
|
-
appendRunLogEntry(state.projectRoot, runId, {
|
|
1990
|
-
id: `log:${runId}:task-source-closeout-failed-update`,
|
|
1991
|
-
title: "Task source closeout failure update failed",
|
|
1992
|
-
detail: error instanceof Error ? error.message : String(error),
|
|
1993
|
-
tone: "error",
|
|
1994
|
-
status: "failed",
|
|
1995
|
-
createdAt: new Date().toISOString()
|
|
1996
|
-
});
|
|
1997
|
-
});
|
|
1998
|
-
}
|
|
1999
|
-
}
|
|
2000
2060
|
}
|
|
2001
2061
|
broadcastSnapshotInvalidation(state);
|
|
2002
2062
|
} catch (error) {
|
|
@@ -2070,7 +2130,7 @@ function resolveLocalRunCliProjectRoot(projectRoot) {
|
|
|
2070
2130
|
return projectRoot;
|
|
2071
2131
|
}
|
|
2072
2132
|
async function resumeRunRecord(state, input) {
|
|
2073
|
-
const run =
|
|
2133
|
+
const run = readAuthorityRun9(state.projectRoot, input.runId);
|
|
2074
2134
|
if (!run) {
|
|
2075
2135
|
throw new Error(`Run not found: ${input.runId}`);
|
|
2076
2136
|
}
|
|
@@ -2085,14 +2145,20 @@ async function resumeRunRecord(state, input) {
|
|
|
2085
2145
|
}
|
|
2086
2146
|
const closeout = closeoutRecord(run);
|
|
2087
2147
|
const closeoutStatus = normalizeString(closeout?.status)?.toLowerCase() ?? "";
|
|
2088
|
-
if (
|
|
2089
|
-
|
|
2148
|
+
if (EXPLICIT_RESUMABLE_SERVER_CLOSEOUT_STATUSES.has(closeoutStatus)) {
|
|
2149
|
+
patchRunRecord(state.projectRoot, input.runId, {
|
|
2150
|
+
status: "reviewing",
|
|
2151
|
+
completedAt: null,
|
|
2152
|
+
errorText: null,
|
|
2153
|
+
...closeoutPhasePatch("queued", "pending", { ...closeout, resumedAt: input.createdAt })
|
|
2154
|
+
});
|
|
2155
|
+
scheduleServerOwnedPrCloseout(state, input.runId, "explicit-resume");
|
|
2090
2156
|
return;
|
|
2091
2157
|
}
|
|
2092
2158
|
await startLocalRun(state, input.runId, { promptOverride: input.promptOverride ?? null, resume: input.restart !== true });
|
|
2093
2159
|
}
|
|
2094
2160
|
function appendRunMessage(projectRoot, input) {
|
|
2095
|
-
const run =
|
|
2161
|
+
const run = readAuthorityRun9(projectRoot, input.runId);
|
|
2096
2162
|
if (!run) {
|
|
2097
2163
|
throw new Error(`Run not found: ${input.runId}`);
|
|
2098
2164
|
}
|
|
@@ -2116,7 +2182,7 @@ ${nextLine}
|
|
|
2116
2182
|
}
|
|
2117
2183
|
async function stopRunRecord(stateOrProjectRoot, input) {
|
|
2118
2184
|
const projectRoot = typeof stateOrProjectRoot === "string" ? stateOrProjectRoot : stateOrProjectRoot.projectRoot;
|
|
2119
|
-
const run =
|
|
2185
|
+
const run = readAuthorityRun9(projectRoot, input.runId);
|
|
2120
2186
|
if (!run) {
|
|
2121
2187
|
throw new Error(`Run not found: ${input.runId}`);
|
|
2122
2188
|
}
|
|
@@ -2174,6 +2240,7 @@ function removeTaskIdsFromQueueState2(projectRoot, taskIds) {
|
|
|
2174
2240
|
return next;
|
|
2175
2241
|
}
|
|
2176
2242
|
var RESUMABLE_SERVER_CLOSEOUT_STATUSES = new Set(["pending", "running"]);
|
|
2243
|
+
var EXPLICIT_RESUMABLE_SERVER_CLOSEOUT_STATUSES = new Set(["pending", "running", "needs_attention"]);
|
|
2177
2244
|
var ACTIVE_LOCAL_RUN_STATUSES = new Set(["created", "preparing", "running", "validating", "reviewing"]);
|
|
2178
2245
|
function processExists(pid) {
|
|
2179
2246
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
@@ -2189,7 +2256,23 @@ function recoverStaleLocalRun(projectRoot, run) {
|
|
|
2189
2256
|
const record = run;
|
|
2190
2257
|
if (run.mode !== "local")
|
|
2191
2258
|
return false;
|
|
2259
|
+
const closeout = closeoutRecord(record);
|
|
2260
|
+
const closeoutStatus = normalizeString(closeout?.status)?.toLowerCase() ?? "";
|
|
2192
2261
|
const status = normalizeString(record.status)?.toLowerCase() ?? "";
|
|
2262
|
+
if (RESUMABLE_SERVER_CLOSEOUT_STATUSES.has(closeoutStatus))
|
|
2263
|
+
return false;
|
|
2264
|
+
if (closeoutStatus === "needs_attention") {
|
|
2265
|
+
if (!ACTIVE_LOCAL_RUN_STATUSES.has(status))
|
|
2266
|
+
return false;
|
|
2267
|
+
const completedAt2 = record.completedAt ?? new Date().toISOString();
|
|
2268
|
+
patchRunRecord(projectRoot, run.runId, {
|
|
2269
|
+
status: "needs_attention",
|
|
2270
|
+
completedAt: completedAt2,
|
|
2271
|
+
errorText: normalizeString(record.errorText) ?? (Array.isArray(closeout?.feedback) ? closeout.feedback.map(String).join(`
|
|
2272
|
+
`) : null)
|
|
2273
|
+
});
|
|
2274
|
+
return true;
|
|
2275
|
+
}
|
|
2193
2276
|
if (!ACTIVE_LOCAL_RUN_STATUSES.has(status))
|
|
2194
2277
|
return false;
|
|
2195
2278
|
const serverPid = typeof record.serverPid === "number" ? record.serverPid : null;
|
|
@@ -2246,15 +2329,7 @@ async function reconcileScheduler(state, reason) {
|
|
|
2246
2329
|
status: "reviewing",
|
|
2247
2330
|
createdAt: new Date().toISOString()
|
|
2248
2331
|
});
|
|
2249
|
-
|
|
2250
|
-
const detail = error instanceof Error ? error.message : String(error);
|
|
2251
|
-
patchRunRecord(state.projectRoot, run.runId, {
|
|
2252
|
-
status: "failed",
|
|
2253
|
-
completedAt: new Date().toISOString(),
|
|
2254
|
-
errorText: detail,
|
|
2255
|
-
...closeoutPhasePatch("failed", "failed", { error: detail })
|
|
2256
|
-
});
|
|
2257
|
-
});
|
|
2332
|
+
scheduleServerOwnedPrCloseout(state, run.runId, "auto-resume");
|
|
2258
2333
|
changed = true;
|
|
2259
2334
|
}
|
|
2260
2335
|
if (changed) {
|
|
@@ -58,6 +58,12 @@ function patchRunRecord(projectRoot, runId, patch) {
|
|
|
58
58
|
writeJsonFile(resolve2(resolveAuthorityRunDir2(projectRoot, runId), "run.json"), next);
|
|
59
59
|
return next;
|
|
60
60
|
}
|
|
61
|
+
function patchRunPiSessionMetadata(projectRoot, runId, metadata) {
|
|
62
|
+
return patchRunRecord(projectRoot, runId, {
|
|
63
|
+
piSession: metadata?.public ?? null,
|
|
64
|
+
piSessionPrivate: metadata
|
|
65
|
+
});
|
|
66
|
+
}
|
|
61
67
|
function buildRunStartPatch(startedAt) {
|
|
62
68
|
return {
|
|
63
69
|
status: "preparing",
|
|
@@ -68,6 +74,7 @@ function buildRunStartPatch(startedAt) {
|
|
|
68
74
|
}
|
|
69
75
|
export {
|
|
70
76
|
patchRunRecord,
|
|
77
|
+
patchRunPiSessionMetadata,
|
|
71
78
|
buildRunStartPatch,
|
|
72
79
|
appendRunTimelineEntry,
|
|
73
80
|
appendRunLogEntry
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
RemoteWsClient as RemoteWsClient2
|
|
15
15
|
} from "@rig/runtime/control-plane/remote";
|
|
16
16
|
import { deleteRunState } from "@rig/runtime/control-plane/native/run-ops";
|
|
17
|
-
import { readAuthorityRun as
|
|
17
|
+
import { readAuthorityRun as readAuthorityRun9 } from "@rig/runtime/control-plane/authority-files";
|
|
18
18
|
|
|
19
19
|
// packages/server/src/server.ts
|
|
20
20
|
import {
|
|
@@ -409,12 +409,13 @@ var TERMINAL_RUN_STATUSES2 = new Set([
|
|
|
409
409
|
"stopped"
|
|
410
410
|
]);
|
|
411
411
|
var RESUMABLE_SERVER_CLOSEOUT_STATUSES = new Set(["pending", "running"]);
|
|
412
|
+
var EXPLICIT_RESUMABLE_SERVER_CLOSEOUT_STATUSES = new Set(["pending", "running", "needs_attention"]);
|
|
412
413
|
var ACTIVE_LOCAL_RUN_STATUSES = new Set(["created", "preparing", "running", "validating", "reviewing"]);
|
|
413
414
|
|
|
414
415
|
// packages/server/src/server-helpers/http-router.ts
|
|
415
416
|
import {
|
|
416
417
|
listAuthorityRuns as listAuthorityRuns5,
|
|
417
|
-
readAuthorityRun as
|
|
418
|
+
readAuthorityRun as readAuthorityRun7,
|
|
418
419
|
resolveAuthorityPaths,
|
|
419
420
|
writeJsonFile as writeJsonFile4
|
|
420
421
|
} from "@rig/runtime/control-plane/authority-files";
|
|
@@ -434,8 +435,11 @@ import {
|
|
|
434
435
|
RemoteWsClient
|
|
435
436
|
} from "@rig/runtime/control-plane/remote";
|
|
436
437
|
|
|
438
|
+
// packages/server/src/server-helpers/pi-session-proxy.ts
|
|
439
|
+
import { readAuthorityRun as readAuthorityRun5 } from "@rig/runtime/control-plane/authority-files";
|
|
440
|
+
|
|
437
441
|
// packages/server/src/server-helpers/run-steering.ts
|
|
438
|
-
import { appendJsonlRecord as appendJsonlRecord2, readAuthorityRun as
|
|
442
|
+
import { appendJsonlRecord as appendJsonlRecord2, readAuthorityRun as readAuthorityRun6, resolveAuthorityRunDir as resolveAuthorityRunDir4 } from "@rig/runtime/control-plane/authority-files";
|
|
439
443
|
|
|
440
444
|
// packages/server/src/server-helpers/http-router.ts
|
|
441
445
|
import { buildRigInitConfigSource } from "@rig/core";
|
|
@@ -460,7 +464,7 @@ import {
|
|
|
460
464
|
} from "@rig/runtime/control-plane/native/run-ops";
|
|
461
465
|
import {
|
|
462
466
|
listAuthorityRuns as listAuthorityRuns6,
|
|
463
|
-
readAuthorityRun as
|
|
467
|
+
readAuthorityRun as readAuthorityRun8
|
|
464
468
|
} from "@rig/runtime/control-plane/authority-files";
|
|
465
469
|
|
|
466
470
|
// packages/server/src/inspector/service.ts
|
|
@@ -786,7 +790,7 @@ async function routeWebSocketRequest(state, deps, request) {
|
|
|
786
790
|
if (!runId || !messageId || text === null) {
|
|
787
791
|
throw new Error("runId, messageId, and text are required");
|
|
788
792
|
}
|
|
789
|
-
const run =
|
|
793
|
+
const run = readAuthorityRun9(state.projectRoot, runId);
|
|
790
794
|
if (!run) {
|
|
791
795
|
throw new Error(`Run not found: ${runId}`);
|
|
792
796
|
}
|