From f69f94e6589307df2e7e0de7604712ec98ac71fc Mon Sep 17 00:00:00 2001 From: simple-minded <191973953+hakarrr@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:44:25 +0530 Subject: [PATCH 1/4] fix(sandbox): warn when a task's egress allowlist comes up empty Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --- server/sandbox_empty_egress_warning_test.go | 91 +++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 server/sandbox_empty_egress_warning_test.go diff --git a/server/sandbox_empty_egress_warning_test.go b/server/sandbox_empty_egress_warning_test.go new file mode 100644 index 000000000..0a7c8ae2e --- /dev/null +++ b/server/sandbox_empty_egress_warning_test.go @@ -0,0 +1,91 @@ +package server + +import ( + "os" + "strconv" + "strings" + "testing" + "time" + + "github.com/Autumn-27/artex/db" +) + +// TestEmptyEgressScopeWarning covers the chat-spawn scope trap of issue #830: +// spawn_task stamps the company link approved_by_operator=false, so the task +// starts with an empty sandbox egress allowlist and every connection from the +// sandbox is denied, with nothing in the UI saying why. The engine must warn +// loudly when a task carries scope rows whose allowlist still comes up empty. +func TestEmptyEgressScopeWarning(t *testing.T) { + dsn := strings.TrimSpace(os.Getenv("ARTEX_PG_DSN")) + if dsn == "" { + t.Skip("ARTEX_PG_DSN not set") + } + pg, err := db.Open(dsn) + if err != nil { + db.SkipPGUnavailable(t, err) + } + t.Cleanup(func() { _ = pg.Close() }) + + suffix := strconv.FormatInt(time.Now().UnixNano(), 36) + compID, _, _, _, _, err := pg.Companies().CreateCompanyWithScope( + "EmptyEgressCo-"+suffix, "", + []db.ScopeInput{{Kind: "cidr", Value: "203.0.113.0/24"}}, + "test fixture", + true, + ) + if err != nil { + t.Fatalf("CreateCompanyWithScope: %v", err) + } + + warn := func(t *testing.T, taskID int64) string { + t.Helper() + info := taskSandboxRunInfo(pg, t.TempDir(), strconv.FormatInt(taskID, 10)) + return emptyEgressScopeWarning(pg, taskID, info) + } + + // Case 1, the trap: a chat-spawned task carries the company link stamped by + // the agent (approved_by_operator=false). The allowlist is empty and the + // operator must hear about it. + trap, err := pg.CreateTaskWithOptions("empty-egress-trap-"+suffix, "goal", db.TaskCreateOptions{ + CompanyIDs: []int64{compID}, + CompanyScopeByAgent: true, + }) + if err != nil { + t.Fatalf("CreateTaskWithOptions(trap): %v", err) + } + t.Cleanup(func() { _ = pg.DeleteTask(trap.ID) }) + trapInfo := taskSandboxRunInfo(pg, t.TempDir(), strconv.FormatInt(trap.ID, 10)) + if len(trapInfo.ScopeDomains)+len(trapInfo.ScopeCIDRs) != 0 { + t.Fatalf("precondition: agent-stamped company must grant no egress, got domains=%v cidrs=%v", + trapInfo.ScopeDomains, trapInfo.ScopeCIDRs) + } + if w := warn(t, trap.ID); w == "" { + t.Fatal("task with scope rows and an empty allowlist must warn (issue #830): got no warning") + } else if !strings.Contains(w, "approv") { + t.Fatalf("warning must point the operator at approval, got %q", w) + } + + // Case 2: the same company selected by the operator at creation. The + // allowlist is non-empty, so there is nothing to warn about. + okTask, err := pg.CreateTaskWithOptions("empty-egress-ok-"+suffix, "goal", db.TaskCreateOptions{ + CompanyIDs: []int64{compID}, + }) + if err != nil { + t.Fatalf("CreateTaskWithOptions(ok): %v", err) + } + t.Cleanup(func() { _ = pg.DeleteTask(okTask.ID) }) + if w := warn(t, okTask.ID); w != "" { + t.Fatalf("operator-approved scope must not warn, got %q", w) + } + + // Case 3: a scopeless task. The allowlist is empty by design; no rows, no + // warning. + bare, err := pg.CreateTaskWithOptions("empty-egress-bare-"+suffix, "goal", db.TaskCreateOptions{}) + if err != nil { + t.Fatalf("CreateTaskWithOptions(bare): %v", err) + } + t.Cleanup(func() { _ = pg.DeleteTask(bare.ID) }) + if w := warn(t, bare.ID); w != "" { + t.Fatalf("scopeless task must not warn, got %q", w) + } +} From 8a66f1ee9bdd9eb951e43fab57518cca1e15acf3 Mon Sep 17 00:00:00 2001 From: simple-minded <191973953+hakarrr@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:45:14 +0530 Subject: [PATCH 2/4] fix(sandbox): warn when a task's egress allowlist comes up empty Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --- server/sandbox.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/sandbox.go b/server/sandbox.go index 0bf26aee5..f9a2836db 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -160,3 +160,19 @@ func taskSandboxRunInfo(pg *db.DB, dataDir, taskID string) agent.SandboxRunInfo } return info } + +// emptyEgressScopeWarning describes the chat-spawn scope trap (#830): the task +// carries task_scope rows, but none of them widen the sandbox egress +// allowlist (agent-stamped rows are coverage-only until an operator approves +// them), so the per-task proxy starts empty and denies every connection. "" +// when there is nothing to warn about. +func emptyEgressScopeWarning(pg *db.DB, tid int64, info agent.SandboxRunInfo) string { + if pg == nil || tid <= 0 || len(info.ScopeDomains) > 0 || len(info.ScopeCIDRs) > 0 { + return "" + } + var n int + if err := pg.QueryRow(`SELECT count(*) FROM task_scope WHERE task_id=$1`, tid).Scan(&n); err != nil || n == 0 { + return "" + } + return fmt.Sprintf("sandbox egress empty: this task has %d scope row(s), but none currently grant egress, so every connection from the sandbox will be denied. Agent-added scope is coverage-only until an operator approves it, and the allowlist freezes at spawn: approve the scope, then restart the task.", n) +} From a5e00e776953ec563041ab288bcf55caabee3892 Mon Sep 17 00:00:00 2001 From: simple-minded <191973953+hakarrr@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:45:48 +0530 Subject: [PATCH 3/4] fix(sandbox): warn when a task's egress allowlist comes up empty Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --- server/engine.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/engine.go b/server/engine.go index 093c4cd44..6b0ae443f 100644 --- a/server/engine.go +++ b/server/engine.go @@ -952,6 +952,17 @@ func (e *Engine) Run(ctx context.Context, t *Task) { } return } + // Loud, not silent (#830): a chat-spawned task can carry scope rows that + // grant no egress (agent-stamped company links stay unapproved), leaving + // the proxy allowlist empty so every connection 403s with no hint why. + if e.m != nil && t.Store != nil { + if tid, perr := strconv.ParseInt(t.ID, 10, 64); perr == nil { + if msg := emptyEgressScopeWarning(e.m.pg, tid, taskSandboxRunInfo(e.m.pg, e.sandboxDataDir, t.ID)); msg != "" { + log.Printf("[sandbox] task %s: %s", t.ID, msg) + _, _ = t.Store.AppendActivity(db.Activity{Kind: "system", IsError: true, Summary: msg}) + } + } + } } else if e.sandboxMode == sandbox.ModeOff && t.Store != nil { _, _ = t.Store.AppendActivity(db.Activity{ Kind: "system", From fa3693ba175199ebafa0b1bb472852ac3939b4ef Mon Sep 17 00:00:00 2001 From: simple-minded <191973953+hakarrr@users.noreply.github.com> Date: Wed, 2 Dec 2026 19:36:01 +0530 Subject: [PATCH 4/4] fix(sandbox): correct the empty-egress warning: approved scope applies without a restart Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com> --- server/sandbox.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/sandbox.go b/server/sandbox.go index f9a2836db..368a555df 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -174,5 +174,5 @@ func emptyEgressScopeWarning(pg *db.DB, tid int64, info agent.SandboxRunInfo) st if err := pg.QueryRow(`SELECT count(*) FROM task_scope WHERE task_id=$1`, tid).Scan(&n); err != nil || n == 0 { return "" } - return fmt.Sprintf("sandbox egress empty: this task has %d scope row(s), but none currently grant egress, so every connection from the sandbox will be denied. Agent-added scope is coverage-only until an operator approves it, and the allowlist freezes at spawn: approve the scope, then restart the task.", n) + return fmt.Sprintf("sandbox egress empty: this task has %d scope row(s), but none currently grant egress, so every connection from the sandbox will be denied. Agent-added scope is coverage-only until an operator approves it; once the scope is approved, the egress proxy is recreated with the new allowlist without restarting the task.", n) }