Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions docs/execution-boundaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ provider webhook -> SourceAdapter -> WorkItem -> prompt renderer
Durable Object orchestrator -> ExecutionBackend -> external execution system
```

`SourceAdapter` owns provider payload normalization. It must not know about VMs,
Herdr, or a coding harness. `ExecutionBackend` owns launch, prompt delivery,
inspection, output, and stopping. The orchestrator owns durable queue, claim,
concurrency, and delivery state, but does not construct backend commands.
`SourceAdapter` owns provider payload normalization. It must not know about VMs
or a coding harness. `ExecutionBackend` owns launch, inspection, and stopping.
Prompt delivery, output retrieval, and recovery are declared capabilities, not
requirements. The orchestrator persists the backend kind, its opaque handle,
capabilities, and observation destination URL; it never interprets the handle.

Backends map their native lifecycle into `queued`, `starting`, `running`,
`blocked`, `stopping`, `stopped`, `succeeded`, or `failed`. Historical `done`,
`recovering`, and `cancelled` rows are presented as `succeeded`, `starting`, and
`stopped` respectively, avoiding a risky rewrite of durable history.

The current `ExeHerdrBackend` is one implementation. exe.dev supplies command
transport and VM wake-up, Herdr supplies workspace and agent supervision, and
Expand Down
29 changes: 19 additions & 10 deletions packages/app/src/exe-herdr-backend.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
import type { ExecutionBackend, LaunchRequest, PromptDeliveryReceipt, RunHandle } from "./execution";
import { agentOutputCommand, agentStatusCommand, exec, launchAgentCommand, promptAgentCommand, stopAgentCommand, type ExeConnection } from "./exe";
import type { ExecutionBackend, ExecutionObservation, LaunchReceipt, LaunchRequest, PromptDeliveryReceipt, RunHandle } from "./execution";
import { agentOutputCommand, agentStatusCommand, exec, herdrAgentStatus, launchAgentCommand, promptAgentCommand, stopAgentCommand, type ExeConnection } from "./exe";

/** Execution adapter for the current exe.dev transport, Herdr supervisor, and configured harness. */
export class ExeHerdrBackend implements ExecutionBackend {
readonly kind = "exe-herdr";
readonly capabilities = ["output", "prompt-delivery", "recovery"] as const;

constructor(private readonly connection: ExeConnection) {}
constructor(private readonly connection: ExeConnection, private readonly launchContext?: { agentName: string; workspaceName: string; runPath: string; lease: string }) {}

async launch(request: LaunchRequest) {
const command = await exec(this.connection, launchAgentCommand(request.agentName, this.connection, request.workspaceName, request.runPath, request.lease, request.prompt));
return { handle: { backend: this.kind, agentName: request.agentName }, command };
async launch(request: LaunchRequest): Promise<LaunchReceipt> {
if (!this.launchContext) throw new Error("ExeHerdrBackend launch context is required");
const { agentName, workspaceName, runPath, lease } = this.launchContext;
const command = await exec(this.connection, launchAgentCommand(agentName, this.connection, workspaceName, runPath, lease, request.prompt));
return { handle: { backendKind: this.kind, id: agentName }, destinationUrl: "https://exe.dev/", capabilities: this.capabilities, observation: { state: command.ok ? "starting" : "failed", command }, command };
}

async deliverPrompt(handle: RunHandle, prompt: string): Promise<PromptDeliveryReceipt> {
const command = await exec(this.connection, promptAgentCommand(this.connection, handle.agentName, prompt));
const command = await exec(this.connection, promptAgentCommand(this.connection, this.agentName(handle), prompt));
const state = command.ok && (command.exitCode === null || command.exitCode === 0)
? "accepted"
: command.status >= 500 || command.exitCode === null ? "ambiguous" : "failed";
return { state, command };
}

inspect(handle: RunHandle) { return exec(this.connection, agentStatusCommand(this.connection, handle.agentName)); }
readOutput(handle: RunHandle) { return exec(this.connection, agentOutputCommand(this.connection, handle.agentName)); }
stop(handle: RunHandle) { return exec(this.connection, stopAgentCommand(this.connection, handle.agentName)); }
async inspect(handle: RunHandle): Promise<ExecutionObservation> {
const command = await exec(this.connection, agentStatusCommand(this.connection, this.agentName(handle)));
if (!command.ok) return { state: "failed", detail: "Execution could not be inspected", command };
const state = herdrAgentStatus(command.body);
return { state: state === "blocked" ? "blocked" : state === "done" || state === "idle" ? "succeeded" : "running", command };
}
async readOutput(handle: RunHandle) { const command = await exec(this.connection, agentOutputCommand(this.connection, this.agentName(handle))); return command.ok ? command.body : null; }
async stop(handle: RunHandle): Promise<ExecutionObservation> { const command = await exec(this.connection, stopAgentCommand(this.connection, this.agentName(handle))); return { state: command.ok ? "stopped" : "failed", command }; }
private agentName(handle: RunHandle): string { if (handle.backendKind !== this.kind || !handle.id) throw new Error(`Invalid ${this.kind} execution handle`); return handle.id; }
}
45 changes: 31 additions & 14 deletions packages/app/src/execution.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type ExecutionState = "queued" | "starting" | "running" | "blocked" | "stopping" | "stopped" | "succeeded" | "failed";
export type ExecutionCapability = "output" | "prompt-delivery" | "recovery";
export type PromptDeliveryState = "pending" | "submitting" | "accepted" | "ambiguous" | "failed";

export interface BackendCommandResult {
Expand All @@ -10,34 +12,49 @@ export interface BackendCommandResult {

export interface LaunchRequest {
runId: string;
agentName: string;
workspaceName: string;
runPath: string;
lease: string;
prompt: string;
}

export interface RunHandle {
backend: string;
agentName: string;
/** Opaque to orchestration. Only the backend that created it may interpret id. */
export interface RunHandle { backendKind: string; id: string; }

export interface ExecutionObservation {
state: ExecutionState;
detail?: string;
command?: BackendCommandResult;
}

export interface LaunchReceipt {
handle: RunHandle;
command: BackendCommandResult;
destinationUrl: string;
capabilities: readonly ExecutionCapability[];
observation: ExecutionObservation;
command?: BackendCommandResult;
}

export interface PromptDeliveryReceipt {
state: Exclude<PromptDeliveryState, "pending" | "submitting">;
command: BackendCommandResult;
command?: BackendCommandResult;
}

/** Boundary implemented by exe.dev + Herdr today and by alternative runners later. */
/** Provider-neutral boundary. Output and recovery are opt-in capabilities. */
export interface ExecutionBackend {
readonly kind: string;
readonly capabilities: readonly ExecutionCapability[];
launch(request: LaunchRequest): Promise<LaunchReceipt>;
deliverPrompt(handle: RunHandle, prompt: string): Promise<PromptDeliveryReceipt>;
inspect(handle: RunHandle): Promise<BackendCommandResult>;
readOutput(handle: RunHandle): Promise<BackendCommandResult>;
stop(handle: RunHandle): Promise<BackendCommandResult>;
inspect(handle: RunHandle): Promise<ExecutionObservation>;
stop(handle: RunHandle): Promise<ExecutionObservation>;
deliverPrompt?(handle: RunHandle, prompt: string): Promise<PromptDeliveryReceipt>;
readOutput?(handle: RunHandle): Promise<string | null>;
}

/** Maps persisted pre-contract states without rewriting historical rows. */
export function normalizeExecutionState(state: unknown): ExecutionState {
switch (String(state)) {
case "queued": case "starting": case "running": case "blocked": case "stopping": case "stopped": case "succeeded": case "failed": return String(state) as ExecutionState;
case "recovering": return "starting";
case "done": return "succeeded";
case "cancelled": return "stopped";
default: return "failed";
}
}
Loading