executor

package
v0.7.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 41 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package executor defines the worker abstraction (§48–§50). The deterministic `internal` executor is the first implementation; OMP is validated behind this same interface as `local_external`.

Package executor defines the worker abstraction (§48–§50). The deterministic `internal` executor is the first implementation; OMP is validated behind this same interface as `local_external`.

Package executor defines the worker abstraction (§48–§50). The deterministic `internal` executor is the first implementation; OMP is validated behind this same interface as `local_external`.

Index

Constants

View Source
const (
	ContainerUID = 65532
	ContainerGID = 65532
)
View Source
const (
	// OpenHandsAPIVersion is the server release this client was written
	// against. GET /server_info reports the server's own; a different one is
	// reported by setup and doctor, not refused -- the routes used here have
	// been stable across the 1.x releases checked.
	OpenHandsAPIVersion = "1.54.0"
)

The OpenHands Agent Server API this client speaks.

Pinned to openhands-agent-server v1.54.0 (OpenHands/software-agent-sdk, released 2026-10-09; image ghcr.io/openhands/agent-server:1.54.0-python), read from the server's own routers rather than from prose docs:

https://github.com/OpenHands/software-agent-sdk/tree/v1.54.0/openhands-agent-server/openhands/agent_server
  conversation_router.py   POST/GET /api/conversations[/{id}], /interrupt, /pause
  event_router.py          GET /api/conversations/{id}/events/search
  file_router.py           POST /api/file/upload, GET /api/file/download, GET /api/file/archive
  bash_router.py           POST /api/bash/execute_bash_command
  server_details_router.py GET /server_info
  sockets.py               /sockets/events/{id} (first-frame auth)
  dependencies.py          X-Session-API-Key
https://docs.openhands.dev/sdk (the SDK's RemoteConversation/RemoteWorkspace
clients, openhands-sdk/openhands/sdk/conversation/impl/remote_conversation.py
and .../workspace/remote/remote_workspace_mixin.py, call these same routes)

What is confirmed, and how, is listed in docs/agents.md ("OpenHands Agent Server"): most of it from the source, and the paging, archive layout, tar, 404 and auth behaviour also against the real image (TestOpenHandsAgainstRealAgentServer). The one part still assumed -- the JSON shape of a conversation secret -- is confined to acpSecrets in openhands.go, so a server that differs breaks in one place.

View Source
const TrustUnassigned domain.ExecutorTrust = ""

TrustUnassigned is the tier an unknown executor kind gets: none of the domain's tiers, so no action is ever granted to it.

Variables

View Source
var ErrOpenHandsAuth = errors.New("openhands: the Agent Server refused the session API key")

ErrOpenHandsAuth is a 401/403: the session API key is missing or wrong. Never retried -- the same key will be refused the same way.

View Source
var ErrOpenHandsNotFound = errors.New("openhands: not found on the Agent Server")

ErrOpenHandsNotFound is a 404 on a conversation: it does not exist (any more) on that server.

View Source
var ErrSteeringUnsupported = errors.New("executor: this run cannot be steered")

ErrSteeringUnsupported is what a Steerer returns for an attempt it cannot deliver a note to (finished, or not running yet).

View Source
var ErrUnknownAttempt = errors.New("executor: unknown attempt")

ErrUnknownAttempt is returned for an attempt this executor does not track -- including one already removed, which is how a caller knows its container is gone.

Functions

func ConversationURL added in v0.7.0

func ConversationURL(uiURL, conversationID string) string

ConversationURL is the run's page in an OpenHands web UI, when the operator configured one (executor.openhands.ui_url): <ui_url>/conversations/ <conversation id>. Empty without a configured UI -- the Agent Server itself serves no UI, and its address is not guessed at.

func DefaultAgentImage

func DefaultAgentImage(kind string) string

DefaultAgentImage returns the pinned default container image for a coding agent, or "" when no canonical image exists (the caller should then require an explicit --image). Hermes has an official image; OMP and ACP agents do not.

func DockerReachable added in v0.7.0

func DockerReachable(ctx context.Context) bool

DockerReachable reports whether a Docker daemon answers, cached for 15 s. It is how an unset executor.kind decides between a real agent and the placeholder executor, so it must not be slow and must not lie: only a server version actually returned counts.

func IdempotencyKey added in v0.7.0

func IdempotencyKey(taskID string, attempt int) string

IdempotencyKey is the remote-run key for one (task, attempt). Deterministic, so a retry after a crash computes the same key and finds the same row.

func ProbeACP added in v0.7.0

func ProbeACP(ctx context.Context, image string, command []string) (string, error)

ProbeACP checks that image runs an ACP agent: it starts command in the same hardened container with --network none (no key, no model call, nothing to reach), sends initialize, and requires a protocol-version-1 answer. It is `idea executors setup --kind acp`'s presence check -- the ACP counterpart of VerifyAgentCLI's `<cli> --version`, which an ACP adapter need not implement. Returns the agent's self-reported name and version.

func ProbeOpenHands added in v0.7.0

func ProbeOpenHands(ctx context.Context, serverURL, sessionKey string) (string, error)

ProbeOpenHands checks a server before it is configured or relied on: the URL is safe to use, GET /server_info answers, and the session key is accepted. It returns the server's version.

func PullImage

func PullImage(ctx context.Context, image string) (string, error)

PullImage ensures image is present locally (docker pull only if absent) and returns its image ID so the caller can surface exactly what was downloaded.

For a digest-pinned reference (repo[:tag]@sha256:…) it also refuses an image whose RepoDigests do not include that digest for that repository. Docker already verifies content pulled by digest; this catches the remaining ways a reference can name one thing while the local store holds another (a registry mirror or proxy configured in the daemon, a tampered local store, a future change to how a tag@digest reference is resolved).

func RecoverWorkRoots added in v0.7.0

func RecoverWorkRoots(stateRoot string) (recovered int, err error)

RecoverWorkRoots hands back what a root daemon killed mid-run left in a container user's hands, and touches nothing outside stateRoot's own work directories:

  • an initiative work root (projects/<id>/work/<initiative>) is kept -- it is the next attempt's base until re-seeded, and a stopped run's partial files are read from it -- so every path in it not owned by the daemon is chowned back to the daemon, as Restore would have done;
  • a quality-dimension copy (projects/<id>/quality-*) and a metric command's scratch root (projects/<id>/metric-*) are disposable temp roots, so they are removed. Metric commands wait for the startup sweep before they start, so none of this daemon's can be caught here.

Agent homes (work/.agent-home-*) are SweepAgentLeftovers' to remove. A symlink is never followed: one at the top of a root is skipped, one inside it is chowned as a link. Call it only once no container of an earlier daemon can still be running -- a live one could swap a directory for a symlink mid-walk -- i.e. after SweepAgentLeftovers reported every leftover container gone. A non-root daemon does nothing: it never handed anything over. Best effort; the first error is returned after every root was tried.

func SmokeACPAgent added in v0.7.0

func SmokeACPAgent(ctx context.Context, opts ACPOptions, provider AgentProvider, lookupKey func(string) string, workDir string) error

SmokeACPAgent is SmokeAgent for the acp kind, whose configuration is more than an image and a model: the agent's argv, the key's name inside the container, MCP servers. The same trivial task, the same assertion.

func SmokeAgent

func SmokeAgent(ctx context.Context, kind, image, model string, provider AgentProvider, lookupKey func(string) string, workDir string) error

SmokeAgent runs a trivial coding task through the agent in an isolated container and asserts it produced at least one file in the work root. It verifies the full CLI contract end-to-end (the exact agent invocation), not just that the binary exists. It requires the provider API key for model to be present in the environment (the agent needs it to call its model).

provider is resolved by the caller from the project's provider view, so the smoke calls the endpoint the real executor will -- including a custom provider or an Ollama moved to another port -- rather than a preset's.

lookupKey reads the provider key; the CLI passes one that falls back to the project's .env, as the daemon does, so a key `idea execute` would accept is not refused here.

workDir is where the smoke's work root is made. The daemon passes a directory under its state root: the system temp directory is not visible to Docker under snap-installed Docker or Colima, and a smoke there reported "produced no files" for a setup that worked. "" uses the temp directory, which is right for the CLI.

func SmokeOpenHands added in v0.7.0

func SmokeOpenHands(ctx context.Context, opts OpenHandsOptions, provider AgentProvider, lookupKey func(string) string, workDir string) error

SmokeOpenHands runs the smoke task through an Agent Server: the trivial task every agent kind's smoke runs, the same assertion that a file came back. Its run record lives in a throwaway database under workDir.

func SweepAgentLeftovers added in v0.5.0

func SweepAgentLeftovers(ctx context.Context, stateRoot string) (allGone bool)

SweepAgentLeftovers removes the agent containers and agent homes that a previous daemon left behind anywhere under stateRoot. Collect and Cancel remove them in the normal course, and a daemon that is stopped cancels its runs first; this covers one that was killed or crashed mid-run, which used to leave the container, and the provider key in its config, on disk with nothing that would ever find it.

Call it before this daemon starts any operation, so no attempt of its own can be running. It finds leftovers by their agent-home directories, and then by container label as a backstop for one whose directory is gone.

It reports whether every leftover container is known to be gone: false when Docker could not be asked or a removal failed, so a caller must not then walk a work root a live container may still hold (RecoverWorkRoots).

func TestOnlySetKnownIncompatible added in v0.6.0

func TestOnlySetKnownIncompatible(kind, spec, reason string) (restore func())

TestOnlySetKnownIncompatible appends a fixture row to the known-incompatible table and returns a func that restores it -- for a test outside this package (internal/cli's, internal/daemon's and internal/workflow's own executor-setup tests) that needs to prove the refusal mechanism still works, without the test depending on knownIncompatible actually holding a real row (it does not, as of the fix that made gpt-4.1-mini's context window explicit instead of refusing it -- see knownIncompatible's own doc comment).

This mutates package-level state with no synchronization, so calling it from anything other than a test would be a real, exploitable defect: any importer of this package could silently poison every other caller's CheckModelCompat result. It cannot simply move into a `_test.go` file the way an internal-only test seam normally would (LOW, release-gate report, "move it behind a test-only file") -- Go never links one package's `_test.go` files into another package's build, and the three callers named above are in different packages, so a `_test.go` version of this function would compile clean for `go test ./internal/executor` and then fail to resolve for every other package that needs it. testing.Testing() (stable since Go 1.21, and this module already requires 1.25) is the enforcement a file rename can't provide here: it reports whether the CURRENT BINARY was built by `go test`, not merely whether this call happens to be reachable from test code, so a production `idea`/`idea-harness` build panics instead of quietly accepting the mutation.

func TrustAllows

func TrustAllows(trust domain.ExecutorTrust, action string) bool

TrustAllows reports whether an action is permitted for an executor's engine-assigned trust tier. It is the policy gate used before any execution, independent of the executor's self-declared capability list.

func TrustTierFor

func TrustTierFor(name string) domain.ExecutorTrust

TrustTierFor maps an executor's Name() (== the selected executor kind) to its engine-assigned trust tier. It is the single source of truth, never the executor's self-declared Capabilities().Trust, and it fails closed for any unknown kind (review: system-deny / engine-assigned trust).

An unknown kind used to land in remote_external, which then had to allow nothing. Now that a real remote kind exists (openhands) and remote_external grants it read/write, an unknown kind gets no tier at all, which allows nothing -- the same fail-closed backstop, no longer borrowing a real tier's name.

func VerifyAgentCLI

func VerifyAgentCLI(ctx context.Context, image, cli string) error

VerifyAgentCLI checks that an agent CLI is present in a container image, WITHOUT pulling and with the same hardened flags the sandbox uses at runtime (no network, read-only root, dropped capabilities, non-root, bounded memory/ pids). It is a UX presence check only — trust must come from the image source, not this probe (review: v1 agent setup). The image must already be present locally; a missing image is a distinct error, not a CLI-missing result.

func VerifyPinnedDigest added in v0.7.0

func VerifyPinnedDigest(ref string, repoDigests []string) error

VerifyPinnedDigest checks that an image pulled by a digest-pinned reference carries that digest for that repository among its RepoDigests. A reference with no digest passes: there is nothing to verify it against.

Types

type ACPExecutor added in v0.7.0

type ACPExecutor struct {
	// contains filtered or unexported fields
}

ACPExecutor drives any Agent Client Protocol agent -- Claude Code (claude-code-acp), Codex (codex-acp), Gemini CLI (`gemini --experimental-acp`), OpenHands (`openhands acp`), OpenCode -- as the coding executor. The agent runs in the same hardened container as hermes/omp (read-only root, --cap-drop ALL, no-new-privileges, host uid, memory and pid limits, only the work root and a fresh home writable, only its own provider's key inside), attached with `docker run -i`; the harness speaks JSON-RPC to it over that container's stdin/stdout.

What the harness implements as the ACP client, and advertises -- nothing more:

  • fs/read_text_file and fs/write_text_file, confined to the work root: a path outside /work (after cleaning, and after resolving symlinks on the host side) is refused, never followed.
  • session/request_permission, answered allow_once (allow_always only when the agent offers no allow_once) without asking anyone. The container is the sandbox boundary, exactly as hermes's --yolo and omp's --auto-approve are; every request and its answer is kept and recorded on the run manifest so nothing approved on the operator's behalf is invisible.
  • terminal/* is NOT advertised (clientCapabilities.terminal is false): the agent runs its own commands inside its own container, and a client-side terminal would run them on the host.

A prompt turn is bounded by ACPOptions.Timeout. When it expires, or the run is cancelled, the client sends session/cancel, waits acpCancelGrace for the agent to stop cleanly, then kills the container.

func NewACPExecutor added in v0.7.0

func NewACPExecutor(opts ACPOptions, provider AgentProvider) *ACPExecutor

NewACPExecutor returns an ACP executor pinned to provider, which the engine resolves with ResolveAgentProvider.

func (*ACPExecutor) Cancel added in v0.7.0

func (e *ACPExecutor) Cancel(ctx context.Context, id string) error

Cancel ends the turn (session/cancel, then kill after a grace period) and removes the container and agent home.

func (*ACPExecutor) Capabilities added in v0.7.0

func (e *ACPExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities matches the other agent kinds: real filesystem/process isolation, network egress for the model API.

func (*ACPExecutor) Collect added in v0.7.0

func (e *ACPExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect waits for the turn to end and cleans up. The engine computes the diff from the work root itself.

func (*ACPExecutor) EmitsRunEvents added in v0.7.0

func (e *ACPExecutor) EmitsRunEvents() bool

EmitsRunEvents: the ACP client maps the agent's own structured updates.

func (*ACPExecutor) Name added in v0.7.0

func (e *ACPExecutor) Name() string

Name reports the executor's registered name.

func (*ACPExecutor) OutputTail added in v0.7.0

func (e *ACPExecutor) OutputTail(ctx context.Context, id string, lines int) string

OutputTail implements OutputTailer: the agent's messages, tool calls, permission answers and stderr, sanitized and with its secrets redacted.

func (*ACPExecutor) PermissionLog added in v0.7.0

func (e *ACPExecutor) PermissionLog(id string) []domain.ACPPermission

PermissionLog returns the permission requests the agent made and the answers given, in order. Read it before Collect or Cancel, which forget the attempt.

func (*ACPExecutor) SetKeyLookup added in v0.7.0

func (e *ACPExecutor) SetKeyLookup(lookup func(name string) string)

SetKeyLookup sets where the provider key and MCP value_env values are read from (the daemon's environment, then the project's .env).

func (*ACPExecutor) Start added in v0.7.0

func (e *ACPExecutor) Start(ctx context.Context, req Request) (Attempt, error)

Start launches the agent and runs one prompt turn in the background. Start returns once the process is running; Status reports the turn's progress.

func (*ACPExecutor) Status added in v0.7.0

func (e *ACPExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the prompt turn's progress.

func (*ACPExecutor) Steer added in v0.7.0

func (e *ACPExecutor) Steer(ctx context.Context, id, note string, interrupt bool) (string, error)

Steer queues a human's note as the agent's next prompt turn (or, with interrupt, ends the current turn with session/cancel and sends it at once).

type ACPOptions added in v0.7.0

type ACPOptions struct {
	Image   string
	Model   string
	Command []string
	// KeyEnv is the name the provider key is exposed under inside the
	// container ("" keeps the provider's own variable name).
	KeyEnv     string
	Timeout    time.Duration
	MCPServers []config.MCPServerConfig
}

ACPOptions is the acp kind's configuration, from harness.yaml's executor block.

func ACPOptionsFrom added in v0.7.0

func ACPOptionsFrom(ec config.ExecutorConfig, model string) ACPOptions

ACPOptionsFrom builds ACPOptions from harness.yaml's executor block.

type AgentProvider added in v0.5.0

type AgentProvider struct {
	Name    string              // provider key, e.g. "openai"
	Type    config.ProviderType // the API it speaks natively
	KeyEnv  string              // env var holding its API key; "" for a keyless provider
	BaseURL string              // its API root
}

AgentProvider is the model endpoint a coding agent is pinned to.

func ResolveAgentProvider added in v0.5.0

func ResolveAgentProvider(model, defaultModel string, providers map[string]config.ProviderConfig) (AgentProvider, error)

ResolveAgentProvider resolves the provider a coding-agent model spec names, the same way the model registry does: a `providers:` entry in harness.yaml first (which falls back to the preset for its missing fields), then the built-in preset.

The entry is consulted BEFORE the preset. Checking the preset first handed the agent the preset's own endpoint and key variable, so an Ollama moved to another port, or an OpenAI key under a project-specific variable, reached every model call except the coding agent's.

A bare model id (no `/`) takes the provider of defaultModel, which the operator chose explicitly. A spec WITH a provider prefix never falls back: `opneai/gpt-x` is a typo, and resolving it to the default provider would send a model id nobody chose to an endpoint the typo did not name.

func (AgentProvider) Validate added in v0.5.0

func (p AgentProvider) Validate() error

Validate reports what would stop the agent from using this provider, so it is caught before a multi-gigabyte image pull rather than at Start.

type Attempt

type Attempt struct {
	ID       string `json:"id"`
	Executor string `json:"executor"`
	Status   string `json:"status"` // running|succeeded|failed|cancelled
	Phase    string `json:"phase"`  // Planning|Editing|Testing|Waiting|Reviewing|Finished
}

Attempt is the durable handle returned by Start.

type Capabilities

type Capabilities struct {
	Trust        domain.ExecutorTrust `json:"trust"`
	SandboxMode  domain.SandboxMode   `json:"sandbox_mode"`
	Network      bool                 `json:"network"`
	Capabilities []string             `json:"capabilities"`
}

Capabilities declares the executor's trust, sandbox mode, and (deterministic, not model-granted) capabilities.

type CapabilityBroker

type CapabilityBroker struct{}

CapabilityBroker authorizes tool actions against an executor's declared capability set. It is a pure gate: it can only deny, never grant.

func (CapabilityBroker) Authorize

func (CapabilityBroker) Authorize(caps []string, action string) error

Authorize returns nil if every declared capability required by action is present in caps, and an error otherwise. An unknown action is always denied.

func (CapabilityBroker) GrantSuggested

func (CapabilityBroker) GrantSuggested(suggested []string) []string

GrantSuggested returns an empty set: models cannot grant capabilities. The suggested list is deliberately ignored so a model can never widen its own executor's declared capability set (§50).

type ContainerExecutor

type ContainerExecutor struct {
	// contains filtered or unexported fields
}

ContainerExecutor runs a task inside a Docker container with no network and a read-only-by-convention workspace mount, collecting the produced patch from a mounted hand-off file (§52 SandboxContainer).

func NewContainerExecutor

func NewContainerExecutor(store *blob.Store, image string) *ContainerExecutor

NewContainerExecutor returns a ContainerExecutor that persists produced patch content to the given blob store. image defaults to a minimal Alpine image when empty; dockerPath is the Docker CLI (override for tests).

func (*ContainerExecutor) Cancel

func (e *ContainerExecutor) Cancel(ctx context.Context, id string) error

Cancel removes the container, terminating the attempt.

func (*ContainerExecutor) Capabilities

func (e *ContainerExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities declares the container executor's deterministic capabilities.

func (*ContainerExecutor) Collect

func (e *ContainerExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect reads the produced patch from the mounted hand-off file, cleans up the container, and persists the content to the blob store.

func (*ContainerExecutor) Name

func (e *ContainerExecutor) Name() string

Name reports the executor's registered name.

func (*ContainerExecutor) Start

func (e *ContainerExecutor) Start(ctx context.Context, req Request) (Attempt, error)

Start launches the task in a detached container and records its container id.

func (*ContainerExecutor) Status

func (e *ContainerExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the container's run state by inspecting the Docker daemon.

type ContainerSandbox

type ContainerSandbox struct {
	// contains filtered or unexported fields
}

ContainerSandbox runs a command inside an isolated Docker container: no network, read-only root filesystem, dropped capabilities, bounded memory/pids, and a non-root user. The daemon's own UID/GID is not the same as non-root (a root daemon's is 0), so it is used only when the daemon is not root; a root daemon passes the fixed unprivileged ContainerUID:ContainerGID instead, with the work root handed to it for the run (containeruser.go). Only the work root (mounted at /work) and a /tmp tmpfs are writable; an optional project root is mounted read-only at /repo. This is the OS-isolation boundary for external coding agents and deterministic checks (§52, review B2/H3).

The /tmp tmpfs mounts are explicitly `exec` (Docker's tmpfs default is `noexec`). A compiled toolchain -- `go test`, jest's native transforms, cargo build scripts, pytest's compiled extensions -- stages its binary under $TMPDIR/os.TempDir() before it fork/execs it; under a noexec /tmp that exec fails with "permission denied" even though the compile itself succeeded (review defect #1). TMPDIR is set explicitly so every toolchain -- not just Go, which already defaults to os.TempDir() -- resolves its scratch directory to this same exec-capable tmpfs rather than whatever its own default happens to be.

func NewContainerSandbox

func NewContainerSandbox(image string) *ContainerSandbox

NewContainerSandbox returns a sandbox using image (defaulting to a minimal Alpine image). dockerPath is the Docker CLI (override for tests).

func (*ContainerSandbox) Run

func (s *ContainerSandbox) Run(ctx context.Context, opts RunOptions) (stdout, stderr string, exitCode int, err error)

Run executes cmd in the sandbox and returns stdout, stderr, and the exit code. The container is started detached so a context timeout/cancellation can be enforced by `docker rm -f` (a hung build/test is genuinely killed, not left orphaned). A non-zero exit code is not a Go error; only a failure to launch Docker is.

type EventSink added in v0.7.0

type EventSink func(domain.RunEvent)

EventSink receives one normalized run event. Implementations must be safe for concurrent use and must not block for long: an ACP agent's stdout reader calls it inline.

type Executor

type Executor interface {
	Name() string
	Capabilities(ctx context.Context) Capabilities
	Start(ctx context.Context, req Request) (Attempt, error)
	Status(ctx context.Context, id string) (Status, error)
	Cancel(ctx context.Context, id string) error
	Collect(ctx context.Context, id string) (Result, error)
}

Executor runs a Task in an isolated worker and returns a patch.

type InternalExecutor

type InternalExecutor struct {
	// contains filtered or unexported fields
}

InternalExecutor runs tasks deterministically in-process. It is hermetic: it performs no network I/O and depends on no external services.

func NewInternalExecutor

func NewInternalExecutor(store *blob.Store) *InternalExecutor

NewInternalExecutor returns a ready-to-use InternalExecutor that persists produced patch content to the given content-addressed blob store.

func (*InternalExecutor) Cancel

func (e *InternalExecutor) Cancel(ctx context.Context, id string) error

Cancel marks an attempt cancelled. It is a no-op after the attempt has already succeeded or been cancelled.

func (*InternalExecutor) Capabilities

func (e *InternalExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities declares the executor's deterministic capabilities. Trust and sandbox mode are fixed by construction; the capability set is never model-granted (§49, §50).

func (*InternalExecutor) Collect

func (e *InternalExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect writes the deterministic implementation file into the isolated work root and returns an empty Result. The engine (orchestrator) snapshots the work root before/after and computes the real diff (§36); the executor's job is only to produce file changes, never to self-declare the diff.

func (*InternalExecutor) EmitsRunEvents added in v0.7.0

func (e *InternalExecutor) EmitsRunEvents() bool

EmitsRunEvents: the internal executor emits its own synthetic events.

func (*InternalExecutor) Name

func (e *InternalExecutor) Name() string

Name reports the executor's registered name.

func (*InternalExecutor) Start

func (e *InternalExecutor) Start(ctx context.Context, req Request) (Attempt, error)

Start records a new attempt and returns its durable handle. The isolated work root is created so the engine can snapshot it before/after and compute the diff.

func (*InternalExecutor) Status

func (e *InternalExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the next step of the deterministic progression. It is idempotent at the terminal phase and never exposes chain-of-thought.

type ModelCompat added in v0.6.0

type ModelCompat struct {
	// Blocked means the combination is known to fail every time -- a real
	// call, not a flaky one -- and the caller should refuse rather than spend
	// an image pull or a paid call on it.
	Blocked bool
	// Message explains why, and how to change it. Empty when the combination
	// is verified and nothing needs to be said.
	Message string
}

ModelCompat is a verdict on one executor-kind/model combination: whether it is known to fail deterministically, or simply untested (§ docs/agents.md "Known executor/model compatibility").

func CheckModelCompat added in v0.6.0

func CheckModelCompat(kind, modelSpec string) ModelCompat

CheckModelCompat reports whether kind (hermes|omp) paired with modelSpec ("provider/model") is known to fail, or merely untested. modelSpec with no provider prefix (a bare model, or "" when nothing is configured yet) is always treated as untested -- there is nothing to match in either table.

type OpenHandsExecutor added in v0.7.0

type OpenHandsExecutor struct {
	// contains filtered or unexported fields
}

OpenHandsExecutor delegates the agent run to an OpenHands Agent Server: the server is the execution plane, idea-harness stays the control plane. What the server is trusted with, and what it is not:

  • It receives the work root (the seeded copy of the workspace, already stripped of .env files, credential-looking files and the control plane), the implementation brief, and -- unless withheld -- the coding model's provider key. That is what leaves the machine.
  • It decides nothing. Approval, the workflow state, the change set and its review all stay here. What the agent wrote comes back as files into the local work root, and the engine snapshots, diffs, secret- sweeps and reviews them exactly as it does a local agent's.

Runs are durable (store.remote_runs): the conversation keeps going on the server when the daemon stops, and is re-attached to rather than started twice. See RemoteSupervisor for the reconciliation side.

func NewOpenHandsExecutor added in v0.7.0

func NewOpenHandsExecutor(opts OpenHandsOptions, provider AgentProvider, runs *store.DB, sup *RemoteSupervisor) *OpenHandsExecutor

NewOpenHandsExecutor returns the executor. runs is the project's state database (the remote_runs table); sup is the engine's supervisor, shared by every Start so one watcher follows each remote run.

func (*OpenHandsExecutor) Cancel added in v0.7.0

func (e *OpenHandsExecutor) Cancel(ctx context.Context, runID string) error

Cancel stops the run: marked cancelled here first (a terminal status the watcher and any later poll respect), then interrupted on the server, with pause as the fallback. Whatever the agent had written is brought back into the work root, so Stop keeps it like it does for a local agent.

While the daemon is shutting down it does none of that: the run keeps going on the server and is re-attached to on the next start, which is the point of a remote execution plane.

func (*OpenHandsExecutor) Capabilities added in v0.7.0

func (e *OpenHandsExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities: the agent runs on another machine, in whatever sandbox that server provides -- which the harness neither sees nor enforces, so it is reported as remote, not container.

func (*OpenHandsExecutor) Collect added in v0.7.0

func (e *OpenHandsExecutor) Collect(ctx context.Context, runID string) (Result, error)

Collect brings the server's files back into the work root -- the moment the remote result enters the local pipeline -- and marks the run collected. The engine then snapshots and diffs the work root as for any agent, secret sweep and review included.

func (*OpenHandsExecutor) EmitsRunEvents added in v0.7.0

func (e *OpenHandsExecutor) EmitsRunEvents() bool

EmitsRunEvents: the watcher maps the server's own structured events.

func (*OpenHandsExecutor) Name added in v0.7.0

func (e *OpenHandsExecutor) Name() string

Name reports the executor's registered name.

func (*OpenHandsExecutor) OutputTail added in v0.7.0

func (e *OpenHandsExecutor) OutputTail(ctx context.Context, runID string, lines int) string

OutputTail implements OutputTailer from the run's stored progress log, which was redacted as it was ingested.

func (*OpenHandsExecutor) SetKeyLookup added in v0.7.0

func (e *OpenHandsExecutor) SetKeyLookup(lookup func(string) string)

SetKeyLookup sets where the session key and the provider key are read from (the daemon's environment, then the project's .env).

func (*OpenHandsExecutor) SetRedactor added in v0.7.0

func (e *OpenHandsExecutor) SetRedactor(redact func(string) string)

SetRedactor sets the redaction applied to everything stored from the server's events (the project's redactor: its known secrets and the credential patterns). The executor's own secrets are removed first either way.

func (*OpenHandsExecutor) Start added in v0.7.0

func (e *OpenHandsExecutor) Start(ctx context.Context, req Request) (Attempt, error)

Start dispatches the run, or re-attaches to the one already dispatched for this (task, attempt).

func (*OpenHandsExecutor) Status added in v0.7.0

func (e *OpenHandsExecutor) Status(ctx context.Context, runID string) (Status, error)

Status reports the run as the harness last recorded it; the supervisor's watcher keeps the record current.

func (*OpenHandsExecutor) Steer added in v0.7.0

func (e *OpenHandsExecutor) Steer(ctx context.Context, runID, note string, _ bool) (string, error)

Steer sends a human's note into the running conversation as a user message. The server's agent loop reads it at its next step, so it is delivered, not queued; interrupt is not needed for that and is ignored.

type OpenHandsOptions added in v0.7.0

type OpenHandsOptions struct {
	URL                 string
	APIKeyEnv           string
	Agent               string // openhands | acp
	ACPCommand          []string
	WorkspaceDir        string
	Model               string
	WithholdProviderKey bool
	MaxIterations       int
	Timeout             time.Duration
}

OpenHandsOptions is the openhands kind's configuration.

func OpenHandsOptionsFrom added in v0.7.0

func OpenHandsOptionsFrom(ec config.ExecutorConfig, model string) OpenHandsOptions

OpenHandsOptionsFrom builds OpenHandsOptions from harness.yaml.

type OpenHandsReconcile added in v0.7.0

type OpenHandsReconcile struct {
	SessionKey func(serverURL string) string
	Redact     func(string) string
	Timeout    time.Duration
}

OpenHandsReconcile is what reconciliation needs from the current configuration: how to read the session key, and how to redact.

type OutputTailer added in v0.5.0

type OutputTailer interface {
	OutputTail(ctx context.Context, id string, lines int) string
}

OutputTailer is implemented by executors that run an external agent and can report the end of its own output. The engine uses it to say WHY an attempt failed or changed nothing -- a 401, a retired model id -- which the attempt status alone does not carry. It must be read before Collect or Cancel, which discard the output.

type PermissionLogger added in v0.7.0

type PermissionLogger interface {
	PermissionLog(id string) []domain.ACPPermission
}

PermissionLogger is implemented by executors whose agent asks for permissions the harness answers on the operator's behalf.

type RemoteSupervisor added in v0.7.0

type RemoteSupervisor struct {
	// contains filtered or unexported fields
}

RemoteSupervisor follows remote runs for one project: one watcher per run, whoever asked for it -- an Execute that dispatched or re-attached, or the daemon's reconciliation at start. It is never under the engine lock: a watcher only writes its own remote_runs row.

func NewRemoteSupervisor added in v0.7.0

func NewRemoteSupervisor(log *slog.Logger) *RemoteSupervisor

NewRemoteSupervisor returns a supervisor. log may be nil.

func (*RemoteSupervisor) Detach added in v0.7.0

func (s *RemoteSupervisor) Detach()

Detach stops every watcher WITHOUT stopping the runs: the daemon is shutting down, and the runs are re-attached to on the next start. Cancel on an executor of a detached supervisor leaves the server alone.

func (*RemoteSupervisor) Detached added in v0.7.0

func (s *RemoteSupervisor) Detached() bool

Detached reports whether Detach was called.

func (*RemoteSupervisor) Reconcile added in v0.7.0

func (s *RemoteSupervisor) Reconcile(ctx context.Context, runs *store.DB, rc OpenHandsReconcile) (int, error)

Reconcile re-attaches to every non-terminal remote run in runs: on daemon start, a run the previous daemon left going is caught up from its event cursor and followed to the end -- finished (collected by the next execute of its task), failed, or found vanished. It returns at once; the watchers run in the background on the supervisor's own context.

func (*RemoteSupervisor) SetPollIntervalForTest added in v0.7.0

func (s *RemoteSupervisor) SetPollIntervalForTest(d time.Duration)

SetPollIntervalForTest makes watchers poll faster.

func (*RemoteSupervisor) Wait added in v0.7.0

func (s *RemoteSupervisor) Wait()

Wait blocks until every watcher has returned (tests).

type Request

type Request struct {
	InitiativeID  string `json:"initiative_id"`
	TaskID        string `json:"task_id"`
	TaskTitle     string `json:"task_title"`
	TaskStatement string `json:"task_statement"`
	Brief         string `json:"brief,omitempty"`
	WorkRoot      string `json:"work_root"`
	// ExtraFiles is honored only by InternalExecutor.Collect: a list of extra
	// placeholder files, by workspace-relative path, to write beyond
	// hello.txt. It exists purely so internal/workflow's own tests can drive
	// a real Execute() call's diff past a file-count limit (review C's
	// blast-radius guard) -- or past a path the workspace's own .gitignore
	// excludes, for that guard's false-positive fixture -- without a real
	// coding agent. No production code path ever sets this; it is never
	// serialized (json:"-") because it crosses no process boundary.
	ExtraFiles []string `json:"-"`
	// ProjectRoot is the user's workspace the work root was copied from.
	// Under a root daemon the agent's container runs as its owner
	// (containeruser.go); nothing mounts it.
	ProjectRoot string `json:"project_root,omitempty"`
	// RunID is the agent run (runs.id) this attempt belongs to. An executor
	// whose events outlive the attempt in memory (openhands: its watcher
	// survives a daemon restart) records it durably so they still reach the
	// run's event stream.
	RunID string `json:"run_id,omitempty"`
	// Events receives the attempt's normalized run events as they happen.
	// May be nil (a smoke test, a probe); executors call Emit, which is
	// nil-safe. The sink redacts, bounds and persists -- an executor only
	// maps its own vocabulary onto domain.RunEvent, and must not block on it.
	Events EventSink `json:"-"`
}

Request is one execution request. The canonical workspace is never passed as a writable root — the executor receives an isolated WorkRoot (§37). Brief is the planner-produced implementation brief (rendered text) the implementer should follow; when empty the executor falls back to TaskStatement.

func (Request) Emit added in v0.7.0

func (r Request) Emit(ev domain.RunEvent)

Emit sends ev to the request's sink, if it has one.

type Result

type Result struct {
	PatchDigest string          `json:"patch_digest"`
	LogDigest   string          `json:"log_digest,omitempty"`
	Usage       domain.RunUsage `json:"usage,omitempty"`
}

Result is the collected execution output (content-addressed digests + usage).

type RunEventEmitter added in v0.7.0

type RunEventEmitter interface {
	EmitsRunEvents() bool
}

RunEventEmitter is implemented by executors that emit structured run events themselves (tool calls, file writes, permissions). For every other executor the engine derives coarse events from the agent's output tail and a scan of the work root.

type RunOptions

type RunOptions struct {
	WorkRoot string   // writable, mounted at /work
	RepoRoot string   // optional, mounted read-only at /repo (the canonical workspace)
	Cmd      []string // command + args (run with work dir /work)
	// Network gives the container Docker's default bridge network instead
	// of --network none. Every other restriction stays. Only verify's
	// explicitly configured prepare and scanner commands set it -- never a
	// build/test check, never an agent -- and docs/security-model.md says so.
	Network bool
	// Env adds environment variables (NAME=value) after the defaults, so a
	// caller can move a cache into the work root to survive between two
	// containers (a network prepare phase, then the offline run).
	Env []string
	// ProjectRoot is the project the check works for. Under a root daemon
	// the container runs as its owner (containeruser.go). Defaults to
	// RepoRoot; set it when the run mounts no /repo.
	ProjectRoot string
}

RunOptions configures a sandbox execution.

type SandboxedAgentExecutor

type SandboxedAgentExecutor struct {
	// contains filtered or unexported fields
}

SandboxedAgentExecutor runs a coding-agent CLI inside an isolated container (review B2, amended). The container gives FILESYSTEM/PROCESS isolation — read-only root, only the mounted /work and a /tmp tmpfs are writable — but NOT network isolation: the agent needs egress to reach its model API, so the provider keys are forwarded in and `--network none` is deliberately omitted. OMP and Hermes are the two agents; neither runs as a host subprocess. The agent writes files under /work (== req.WorkRoot); the engine snapshots that directory before/after and computes the diff (B3).

func NewHermesExecutor

func NewHermesExecutor(store *blob.Store, model, image string, provider AgentProvider) *SandboxedAgentExecutor

NewHermesExecutor returns a sandboxed Hermes (Nous Research) executor.

func NewOMPExecutor

func NewOMPExecutor(store *blob.Store, model, image string, provider AgentProvider) *SandboxedAgentExecutor

NewOMPExecutor returns a sandboxed OMP executor pinned to provider, which the engine resolves with ResolveAgentProvider.

func (*SandboxedAgentExecutor) Cancel

func (e *SandboxedAgentExecutor) Cancel(ctx context.Context, id string) error

Cancel removes the container, terminating the agent.

func (*SandboxedAgentExecutor) Capabilities

func (e *SandboxedAgentExecutor) Capabilities(ctx context.Context) Capabilities

Capabilities declares the agent's capabilities. The sandbox mode is REAL filesystem/process isolation (container, read-only root); Network is true because the agent needs egress to reach its model API.

func (*SandboxedAgentExecutor) Collect

func (e *SandboxedAgentExecutor) Collect(ctx context.Context, id string) (Result, error)

Collect cleans up the container and returns an empty Result. The engine computes the diff from the work root (B3); the executor's job is only to run the agent in isolation.

func (*SandboxedAgentExecutor) Name

func (e *SandboxedAgentExecutor) Name() string

Name reports the executor's registered name.

func (*SandboxedAgentExecutor) OutputTail added in v0.5.0

func (e *SandboxedAgentExecutor) OutputTail(ctx context.Context, id string, lines int) string

OutputTail implements OutputTailer. See tailLogs and tailRawMultiplier for how this actually delivers the requested line count (review defect F).

func (*SandboxedAgentExecutor) SetKeyLookup added in v0.5.0

func (e *SandboxedAgentExecutor) SetKeyLookup(lookup func(name string) string)

SetKeyLookup sets where the provider key's value is read from. The daemon passes one that falls back to the project's .env, as its model registry does; reading only the process environment gave the agent no key while every other model call had one.

func (*SandboxedAgentExecutor) Start

Start launches the agent inside the isolated container (detached) and records the container id. The provider keys are forwarded so the agent can reach its model; `--network none` is intentionally omitted (the agent must egress to the model API — this is a filesystem/process sandbox, not a network sandbox).

func (*SandboxedAgentExecutor) Status

func (e *SandboxedAgentExecutor) Status(ctx context.Context, id string) (Status, error)

Status reports the container's run state by inspecting the Docker daemon.

type Status

type Status struct {
	Status string `json:"status"`
	Phase  string `json:"phase"`
	Action string `json:"action"`
}

Status is a progress snapshot (§50). Never exposes chain-of-thought.

type Steerer added in v0.7.0

type Steerer interface {
	Steer(ctx context.Context, attemptID, note string, interrupt bool) (delivery string, err error)
}

Steerer is implemented by executors that can take a human's note while the agent runs. Steer returns how the note was delivered: domain.SteeringDelivered (the agent has it now, or the moment its current turn has been interrupted) or domain.SteeringQueued (it is sent as the agent's next turn once the current one ends). interrupt asks for the current turn to be ended first where the protocol has a clean way to do that; an executor without one ignores it. An executor that cannot steer this particular attempt (finished, or not running yet) returns ErrSteeringUnsupported.

Directories

Path Synopsis
Package ohfake is a fake OpenHands Agent Server for tests: the subset of the v1.54.0 API the openhands executor uses, over a real directory standing in for the server's filesystem.
Package ohfake is a fake OpenHands Agent Server for tests: the subset of the v1.54.0 API the openhands executor uses, over a real directory standing in for the server's filesystem.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL