Files
oh-my-pi/packages/coding-agent/src/eval/bridge-timeout.ts
T
can1357 f74c6d892a feat(coding-agent-eval): renamed the eval helper API from llm() to completion()
- Renamed eval oneshot helper from llm() to completion() across JS/Python APIs.
- Remapped eval bridge internals to completion semantics (__completion__, runEvalCompletion, completion status op).
- Updated docs, prompts, and timeout guidance to describe completion() usage and behavior.
- Adjusted completion defaults for active-session model preference, fallback parsing, and slow-tier effort handling.
2026-06-08 12:22:47 +02:00

45 lines
1.8 KiB
TypeScript

/**
* Timeout suspension for in-flight host-side eval bridge calls.
*
* The eval watchdog caps a cell's `timeout` as a budget on the cell runtime's
* own work. Host-side `agent()` / `parallel()` / `completion()` bridge calls hand
* control to the outer TypeScript process, where the Python kernel or JS VM is
* only waiting for a result. While that delegated work is in flight, the cell
* timeout must be ignored completely; once the bridge returns and the runtime is
* back in control, the watchdog starts a fresh timeout window.
*
* Bridge helpers express that handoff with synthetic pause/resume status events
* on the existing `emitStatus → onStatus` path. Consumers MUST treat these as
* timeout-control events only: update the watchdog and drop them from rendered
* or persisted cell output.
*/
import type { JsStatusEvent } from "./js/shared/types";
/** Synthetic status op emitted when a bridge call leaves the cell runtime. */
export const EVAL_TIMEOUT_PAUSE_OP = "timeout-pause";
/** Synthetic status op emitted when a bridge call returns control to the runtime. */
export const EVAL_TIMEOUT_RESUME_OP = "timeout-resume";
/** Whether a status event is pure eval-timeout control and should not render. */
export function isEvalTimeoutControlEvent(event: JsStatusEvent): boolean {
return event.op === EVAL_TIMEOUT_PAUSE_OP || event.op === EVAL_TIMEOUT_RESUME_OP;
}
/**
* Run {@link operation} while suspending the eval watchdog through
* {@link emitStatus}. A no-op wrapper when no status sink is wired.
*/
export async function withBridgeTimeoutPause<T>(
emitStatus: ((event: JsStatusEvent) => void) | undefined,
operation: () => Promise<T>,
): Promise<T> {
if (!emitStatus) return operation();
emitStatus({ op: EVAL_TIMEOUT_PAUSE_OP });
try {
return await operation();
} finally {
emitStatus({ op: EVAL_TIMEOUT_RESUME_OP });
}
}