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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All notable changes to this project are documented in this file. The format is b

### Fixed

- **A command that exits 124 no longer removes the Docker worker.** The runner treated every exit code 124 as its own timeout and removed the task's worker container, which also stopped the task's background jobs. Commands such as `timeout 5 curl ...` exit 124 by themselves. An exit 124 now counts as a runner timeout only when the command ran for at least `timeout_ms`.
- **An `exact_ip` task allow rule grants sandbox egress**: the egress allowlist read task allow rules of kind `ip`, which the rule tables never store, so an `exact_ip` allow rule granted nothing. A task scoped to one private address (`10.0.0.5`) could not reach it from the sandbox, directly or through a name resolving only to it. `exact_ip` allow rules now join the allowed CIDRs as a host prefix, like `cidr` allow rules.
- **`GET /api/tasks/{id}/scope` reports scope approval**: the query behind it did not select `approved_by_operator` or `expanded`, so every row came back with `approved_by_operator: false` and `expanded: false`, including operator-approved rows that grant sandbox egress. The rows now carry both columns as stored, for the task's own scope and for its source tasks' scope.
- **The OpenAI Responses format no longer defaults to `gpt-5`**: OpenAI shuts `gpt-5` down on 2026-12-11 and lists `gpt-6.2-sol` as its replacement, so `ARTEX_LLM_PROVIDER=openai-responses` without `ARTEX_LLM_MODEL` (or a profile saved through the API without a model) would start failing then. The default is now `gpt-6.2-sol`; a model set in the profile or in `ARTEX_LLM_MODEL` is kept as is. A gateway set with `ARTEX_LLM_BASE_URL` that does not serve `gpt-6.2-sol` needs `ARTEX_LLM_MODEL` set explicitly.
Expand Down
7 changes: 6 additions & 1 deletion sandbox/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ func (b *DockerBackend) Exec(ctx context.Context, taskID string, req ExecRequest
execCtx, cancel := context.WithTimeout(ctx, time.Duration(req.TimeoutMS)*time.Millisecond+12*time.Second)
defer cancel()

execStart := time.Now()
startResp, err := b.dockerDo(execCtx, http.MethodPost, "/exec/"+url.PathEscape(created.ID)+"/start", map[string]any{
"Detach": false,
"Tty": false,
Expand Down Expand Up @@ -700,7 +701,11 @@ func (b *DockerBackend) Exec(ctx context.Context, taskID string, req ExecRequest
}

exitCode := *ins.ExitCode
timedOut := exitCode == 124
// artex-exec-wrap exits 124 when it enforces timeout_ms, but the command
// itself can also exit 124 (coreutils `timeout N cmd` does). Only the
// wrapper's own timeout can take timeout_ms or longer, so a 124 that came
// back sooner is the command's exit code: keep the worker.
timedOut := exitCode == 124 && time.Since(execStart) >= time.Duration(req.TimeoutMS)*time.Millisecond
if timedOut || ctx.Err() != nil {
// Process-group timeout cannot kill setsid/double-fork descendants.
// Destroy the captured container, including its PID namespace and cgroup.
Expand Down
3 changes: 3 additions & 0 deletions sandbox/docker_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"sync"
"testing"
"time"
)

// fakeDocker is a minimal Docker Engine API stub over a unix socket. It records
Expand All @@ -29,6 +30,7 @@ type fakeDocker struct {
inspectBody string
streamReady chan struct{}
streamStarted bool
execDelay time.Duration // delay before the exec stream answers, as a running command would
}

func (f *fakeDocker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Expand All @@ -51,6 +53,7 @@ func (f *fakeDocker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(f.execStartCode)
return
}
time.Sleep(f.execDelay)
w.WriteHeader(http.StatusOK)
f.mu.Lock()
firstStream := f.streamReady != nil && !f.streamStarted
Expand Down
47 changes: 47 additions & 0 deletions sandbox/docker_timeout_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,50 @@ time.sleep(10)`
t.Fatalf("child continued after timeout: %v", err)
}
}

// A command that exits 124 by itself must not be treated as the runner's
// timeout: the worker, and with it the task's background jobs, stays.
func TestDockerCommandExit124KeepsWorker(t *testing.T) {
if os.Getenv("ARTEX_SANDBOX_DOCKER_TEST") != "1" {
t.Skip("requires live Docker and built sandbox images")
}
ws, au := t.TempDir(), t.TempDir()
id := fmt.Sprintf("exit124-%d", time.Now().UnixNano())
egressNet := "artex-test-egress-" + id
for _, dir := range []string{ws, au, filepath.Join(ws, id), filepath.Join(au, id)} {
if err := os.MkdirAll(dir, 0o777); err != nil {
t.Fatal(err)
}
if err := os.Chmod(dir, 0o777); err != nil {
t.Fatal(err)
}
}
b := NewDockerBackend(DockerConfig{WorkspaceRoot: ws, HostWorkspaceRoot: ws, AuditRoot: au, HostAuditRoot: au,
TaskNetPrefix: "artex-test-task-", EgressNet: egressNet})
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
t.Cleanup(func() {
_ = b.Delete(context.Background(), id)
_ = b.removeNetwork(context.Background(), egressNet)
})
if err := b.Ping(ctx); err != nil {
t.Fatal(err)
}
tc, err := b.ensureTask(ctx, id, nil, nil)
if err != nil {
t.Fatal(err)
}
worker := tc.workerID
res, err := b.Exec(ctx, id, ExecRequest{Argv: []string{"timeout", "1", "sleep", "5"}, Workdir: "/workspace", TimeoutMS: 30000})
if err != nil || res.ExitCode != 124 || res.TimedOut {
t.Fatalf("response=%+v error=%v", res, err)
}
r, err := b.dockerDo(ctx, http.MethodGet, "/containers/"+worker+"/json", nil)
if err != nil {
t.Fatal(err)
}
defer r.Body.Close()
if r.StatusCode != http.StatusOK {
t.Fatalf("worker removed after the command's own exit 124: HTTP %d", r.StatusCode)
}
}
32 changes: 28 additions & 4 deletions sandbox/exec_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestExecFailsClosedAndRemovesWorker(t *testing.T) {
fake *fakeDocker
wantErr bool
}{
{"timeout", &fakeDocker{execExitCode: 124}, false},
{"timeout", &fakeDocker{execExitCode: 124, execDelay: 20 * time.Millisecond}, false},
{"still_running", &fakeDocker{execRunning: true}, true},
{"truncated_stream", &fakeDocker{execStream: []byte{1, 0, 0}}, true},
{"truncated_payload", &fakeDocker{execStream: []byte{1, 0, 0, 0, 0, 0, 0, 4, 'x'}}, true},
Expand All @@ -27,7 +27,11 @@ func TestExecFailsClosedAndRemovesWorker(t *testing.T) {
b := newFakeDockerBackend(t, test.fake)
tc := seedTask(b, "t1", "worker-1", "proxy-1", "artex-task-t1")
tc.scopeHash = scopeFingerprint(nil, nil)
res, err := b.Exec(context.Background(), "t1", ExecRequest{Argv: []string{"true"}, TimeoutMS: 1000})
timeoutMS := 1000
if test.fake.execDelay > 0 {
timeoutMS = 10
}
res, err := b.Exec(context.Background(), "t1", ExecRequest{Argv: []string{"true"}, TimeoutMS: timeoutMS})
if (err != nil) != test.wantErr {
t.Fatalf("response=%+v error=%v", res, err)
}
Expand Down Expand Up @@ -70,11 +74,11 @@ func TestExecCancellationCleansUpWithFreshContext(t *testing.T) {
}

func TestExecTimeoutRemovalFailureKeepsWorker(t *testing.T) {
f := &fakeDocker{execExitCode: 124, deleteCode: map[string]int{"worker-1": 500}}
f := &fakeDocker{execExitCode: 124, execDelay: 20 * time.Millisecond, deleteCode: map[string]int{"worker-1": 500}}
b := newFakeDockerBackend(t, f)
tc := seedTask(b, "t1", "worker-1", "proxy-1", "artex-task-t1")
tc.scopeHash = scopeFingerprint(nil, nil)
if _, err := b.Exec(context.Background(), "t1", ExecRequest{Argv: []string{"true"}, TimeoutMS: 1000}); err == nil {
if _, err := b.Exec(context.Background(), "t1", ExecRequest{Argv: []string{"true"}, TimeoutMS: 10}); err == nil {
t.Fatal("cleanup failure hidden")
}
if tc.workerID != "worker-1" {
Expand Down Expand Up @@ -106,3 +110,23 @@ func TestDelayedExecCleanupPreservesReplacementWorker(t *testing.T) {
t.Fatal("late cleanup targeted or forgot replacement worker")
}
}

// A command that exits 124 by itself (coreutils `timeout 1 sleep 5`) did not
// hit the runner's timeout: report its exit code and keep the worker, so the
// task's background jobs survive.
func TestExecCommandExit124BeforeTimeoutKeepsWorker(t *testing.T) {
f := &fakeDocker{execExitCode: 124}
b := newFakeDockerBackend(t, f)
tc := seedTask(b, "t1", "worker-1", "proxy-1", "artex-task-t1")
tc.scopeHash = scopeFingerprint(nil, nil)
res, err := b.Exec(context.Background(), "t1", ExecRequest{Argv: []string{"timeout", "1", "sleep", "5"}, TimeoutMS: 30000})
if err != nil {
t.Fatal(err)
}
if res.ExitCode != 124 || res.TimedOut {
t.Fatalf("command exit 124 reported as runner timeout: %+v", res)
}
if tc.workerID != "worker-1" || f.seen("DELETE /containers/worker-1") {
t.Fatal("worker removed after the command's own exit 124")
}
}
3 changes: 2 additions & 1 deletion sandbox/exec_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestExecTimeoutStopsSiblingsButPreservesOtherTask(t *testing.T) {
}
}
case p == "/exec/timeout/start":
time.Sleep(20 * time.Millisecond)
w.WriteHeader(http.StatusOK)
case p == "/exec/sibling/json":
http.Error(w, "worker removed", http.StatusNotFound)
Expand Down Expand Up @@ -89,7 +90,7 @@ func TestExecTimeoutStopsSiblingsButPreservesOtherTask(t *testing.T) {
waitSignal(t, ctx, siblingStarted)
go run("b", "other", otherDone)
waitSignal(t, ctx, otherStarted)
res, err := b.Exec(ctx, "a", ExecRequest{Argv: []string{"timeout"}, TimeoutMS: 1000})
res, err := b.Exec(ctx, "a", ExecRequest{Argv: []string{"timeout"}, TimeoutMS: 10})
if err != nil || !res.TimedOut {
t.Fatalf("timeout response=%+v err=%v", res, err)
}
Expand Down
Loading