fix: harden pi maintenance lifecycle

This commit is contained in:
2026-08-04 19:09:04 +02:00
parent 8fde1f81c7
commit 0b9ad7f53f
21 changed files with 432 additions and 171 deletions
+9
View File
@@ -37,6 +37,8 @@ export function sessionRoutes(
legacyWorkspaceMode?: boolean;
/** Fail-closed installation/runtime transport capability check. */
workspaceRuntimeSupport: (workspace: WorkspaceDescriptor) => boolean;
/** Host-controlled admission guard. Existing runtimes deliberately continue. */
maintenanceGate: () => boolean;
},
) {
const lifecycleTails = new Map<string, Promise<void>>();
@@ -75,6 +77,11 @@ export function sessionRoutes(
return typeof runner.withPrincipal === "function" ? runner.withPrincipal(principal) : runner;
};
const maintenanceReply = (reply: any) => reply.code(503).send({
code: "maintenance",
error: "Session admission is temporarily paused for maintenance. Try again shortly.",
});
/** Include retained historical descriptors so removed workspaces remain resumable. */
const sessionRevisions = async () => {
const registry = d.workspaceRegistry as Partial<WorkspaceRegistry>;
@@ -272,6 +279,7 @@ export function sessionRoutes(
});
app.post("/sessions", async (req, reply) => {
if (d.maintenanceGate()) return maintenanceReply(reply);
const b = req.body as {
question: string; name?: string; workspace?: string; workspaceId?: string;
provider?: string; model?: string; thinking?: string;
@@ -502,6 +510,7 @@ export function sessionRoutes(
return reply.code(204).send();
});
app.post("/sessions/:id/resume", async (req, reply) => {
if (d.maintenanceGate()) return maintenanceReply(reply);
const id = (req.params as any).id;
const principal = getPrincipal(req);
return withSessionLifecycle(id, async () => {