fix(runtime): bound run_command with ctx + 2-minute per-command timeout#63
Merged
Merged
Conversation
execRunCommand built its child process with shellexec.Command — no
context. cmd.CombinedOutput() then blocked until the child exited
regardless of parent cancellation. A small model that asked the runtime
to run a slow or runaway command (e.g. `go test ./... -run TestSlow`
against a test it just wrote with an infinite loop) would pin the
iteration goroutine for the full 5-minute outer budget — and on a
single-GPU Ollama config (concurrency: 1) every other story in the
wave queued behind it.
- Thread ctx from Execute → executeTool → execRunCommand. File ops
(read/write/edit) stay context-free; they're fast.
- Wrap with context.WithTimeout(ctx, runCommandTimeout). 2 minutes is a
comfortable ceiling for `go build ./...` / `go test ./...` on a
modest repo. A hung child now receives SIGKILL via Go's os/exec
context handling.
- On DeadlineExceeded, return actionable text to the model
("command timed out after 2m0s — split into smaller commands or
fix the slow path") instead of a generic exec error so the agent can
self-correct.
- Test files updated to pass context.Background() — the existing test
surface is unchanged in intent, just receives ctx.
- New test TestExecRunCommand_CancelledContextKillsCommand asserts a
pre-cancelled ctx surfaces as IsError without blocking.
Surfaced by the 2026-06-11 security audit (SEC-H1).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
execRunCommandbuilt its child process withshellexec.Command— no context.cmd.CombinedOutput()then blocked until the child exited regardless of parent cancellation. A small model that asked the runtime to run a slow or runaway command (e.g.go test ./... -run TestSlowagainst a test it just wrote with an infinite loop) would pin the iteration goroutine for the full 5-minute outer budget. On a single-GPU Ollama config (concurrency: 1) every other story in the wave queued behind it.Changes
ctxfromExecute→executeTool→execRunCommand. File ops (read/write/edit) stay context-free — they're fast.context.WithTimeout(ctx, runCommandTimeout). 2 minutes ceiling — comfortable forgo build ./.../go test ./...on a modest repo.os/execcontext handling.DeadlineExceeded, return actionable text to the model ("command timed out after 2m0s — split into smaller commands or fix the slow path") so the agent can self-correct.Test plan
TestExecRunCommand_CancelledContextKillsCommandasserts a pre-cancelledctxsurfaces asIsErrorwithout blocking.context.Background()for the existing surface.go build ./...,go vet ./...,go test ./... -count=1 -timeout 240sall green locally.Audit traceability
Security finding SEC-H1 (2026-06-11 sweep).