fix(backend): robustness pass — spawn leak, timeouts, workspace fail-loud, 409 order, respond guard

Audit findings 4.1-4.6.

- spawnFor: a rejected configure/start no longer leaks a registered runtime
  with a live Pi child (identity-checked teardown + rethrow); every later
  start used to hit "session runtime already active".
- ThtRunner.run: default 60s timeout on every tht child (SIGKILL backstop),
  120s for DWH-touching calls (sql preview/export, search pack); a dropped
  VPN mid-call no longer wedges the HTTP request forever.
- configArg: a NAMED workspace whose yaml is missing now throws instead of
  silently falling back to the default config (operations were silently
  targeting the wrong workspace).
- resume: the finalized/archived 409 is evaluated BEFORE the alreadyActive
  fast-path — the manifest is the truth even with a lingering runtime.
- ollamaEnsure: exit-0 with non-JSON stdout is a failed check, not ok:true.
- SessionBridge.respond: only the response matching the pending descriptor
  is forwarded to Pi; stale/duplicate submissions return 409 instead of
  being sent with the current gate's RPC id.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 01:37:20 +02:00
co-authored by Claude Fable 5
parent 2958b32fd5
commit f772ef9dca
7 changed files with 92 additions and 34 deletions
+11 -2
View File
@@ -107,13 +107,22 @@ export class SessionBridge {
/** Eventi generati dal backend stesso (es. exit inatteso del child Pi), non da Pi. */
emitClientEvent(e: ClientEvent): void { this.fan(e); }
respond(uiResponse: object & { id: string }): void {
/**
* Deliver a reviewer response to Pi. Accepts ONLY a response matching the pending
* descriptor: a stale/duplicate response (old gate id, double submit) would otherwise
* be sent with the CURRENT gate's RPC id, flip the state to running, and leave the
* real gate waiting. Returns false when rejected so the route can 409.
*/
respond(uiResponse: object & { id: string }): boolean {
if (!this.pending || uiResponse.id !== (this.pending as { id?: unknown }).id) return false;
// Correla sull'id RPC di Pi; `value` porta l'uiResponse (con l'id del descriptor) cosi'
// il check interno del gate (resp.id === descriptor.id) regge.
const piId = this.pendingPiId ?? uiResponse.id;
this.state = "running";
this.rpc.send({ type: "extension_ui_response", id: piId, value: JSON.stringify(uiResponse) });
if (this.pending && uiResponse.id === this.pending.id) { this.pending = null; this.pendingPiId = null; }
this.pending = null;
this.pendingPiId = null;
return true;
}
steer(text: string): void {