Repository navigation
fix(rpc): keep the omp child on every command timeout #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2fc8b75
bf8cd50
a2dbac9
e034c2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,13 @@ function newSessionErrorResponse(error: unknown) { | |
| // host_offline falls through to apiErrorResponse: 503 {hostOffline: true}. | ||
| if ((error instanceof WebRpcError && error.code !== "host_offline") || error instanceof RpcCommandError) { | ||
| return Response.json( | ||
| { error: error.message, code: error instanceof WebRpcError ? error.code : (error.code ?? "rpc_command_failed") }, | ||
| { | ||
| error: error.message, | ||
| code: error instanceof WebRpcError ? error.code : (error.code ?? "rpc_command_failed"), | ||
| // `maybeStarted`/`abortUnconfirmed` must reach the client, exactly as on | ||
| // POST /api/agent/[id]: without them a timeout looks like "not sent". | ||
| ...(error instanceof WebRpcError ? error.details : undefined), | ||
| }, | ||
| { status: 400 }, | ||
| ); | ||
| } | ||
|
|
@@ -70,6 +76,22 @@ export async function POST(req: Request) { | |
| }; | ||
| return await (preparing ? session.withPendingCommand(run, true) : run()); | ||
| } catch (error) { | ||
| // A command timeout means omp is busy, not dead: the frame may already sit | ||
| // in the child's stdin and a run it started must survive. Same contract as | ||
| // POST /api/agent/[id]; the liveness watchdog alone may dispose the child. | ||
| // The body carries the real session id so a client that posted the prompt | ||
| // directly here can still poll and adopt the run `maybeStarted` announced. | ||
| if (error instanceof WebRpcError && error.code === "session_slow") { | ||
| return Response.json( | ||
| { | ||
| error: error.message, | ||
| code: error.code, | ||
| sessionId: realSessionId, | ||
| ...error.details, | ||
| }, | ||
| { status: 400 }, | ||
|
Comment on lines
+84
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ); | ||
| } | ||
| // The child was spawned but the prompt never ran: without this cleanup a | ||
| // failed set_model/set_thinking_level/prompt leaves an orphaned omp | ||
| // process and a registry entry nobody will ever use. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,22 +27,47 @@ async function sessionState(id: string): Promise<Response> { | |
| if (rpc?.isAlive()) { | ||
| try { | ||
| const state = await rpc.send({ type: "get_state" }); | ||
| return Response.json({ running: true, state }); | ||
| return Response.json({ running: rpc.isRunning(), alive: true, state }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } catch (error) { | ||
| // omp being slow is not the run ending: answer 503 so clients retry | ||
| // instead of treating the session as idle/recovered. Both the code | ||
| // this tree raises (`session_slow`) and 0.6.0's own | ||
| // `session_state_timeout` mean the same thing to a client. | ||
| if (error instanceof WebRpcError && (error.code === "session_slow" || error.code === "session_state_timeout")) { | ||
| // The liveness watchdog disposes a child that stayed silent past its | ||
| // threshold; that child is gone, so the busy answer would be a lie. | ||
| // Its `detail: "stalled"` record answers like any other exit. | ||
| if (!rpc.isAlive()) { | ||
| const exited = getExitedRpcSession(id); | ||
| return Response.json({ running: false, alive: false, ...(exited ? { exited } : {}) }); | ||
| } | ||
| return Response.json( | ||
| { | ||
| error: error.message, | ||
| code: "session_slow", | ||
| ...error.details, | ||
| running: rpc.isRunning(), | ||
| alive: true, | ||
| silentForMs: rpc.silentForMs(), | ||
| }, | ||
| { status: 503 }, | ||
| ); | ||
| } | ||
| if (error instanceof WebRpcError && error.code === "session_unresponsive") { | ||
| return Response.json({ running: false, recovered: true }); | ||
| return Response.json({ running: false, alive: false, recovered: true }); | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| const exited = getExitedRpcSession(id); | ||
| if (exited) return Response.json({ running: false, exited }); | ||
| if (exited) return Response.json({ running: false, alive: false, exited }); | ||
|
|
||
| const resolved = await resolveSessionHostOr404(id); | ||
| if ("response" in resolved) return resolved.response; | ||
| const result = await resolved.host.sessionOps.readSessionState(id); | ||
| return result.ok ? Response.json(result.value) : opErrorResponse(result); | ||
| if (!result.ok) return opErrorResponse(result); | ||
| return Response.json({ ...(result.value as Record<string, unknown>), alive: false }); | ||
| } catch (error) { | ||
| return apiErrorResponse(error); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: kahme247/ompweb
Length of output: 2251
Script executed:
Repository: kahme247/ompweb
Length of output: 42002
Script executed:
Repository: kahme247/ompweb
Length of output: 44606
Script executed:
Repository: kahme247/ompweb
Length of output: 34783
Return the dead state after watchdog disposal.
If a state query times out after the stall threshold, the watchdog disposes the wrapper, but both routes return
503 session_slowwithalive: true. Return the dead state instead. For the sessions-state route, include the recorded stalled exit.