From 30ec83f6b848c5fe6b7a04c28f9a20fb5e818045 Mon Sep 17 00:00:00 2001 From: finallylly Date: Thu, 19 Nov 2026 14:53:32 +0800 Subject: [PATCH] fix(chat): run Codex threads in the native sandbox workspace The Codex app-server adapter always sent cwd=/ws on thread/start and thread/resume. On macOS seatbelt there is no mount namespace, so the runtime starts the CLI in the run workspace instead, and /ws is not writable there. Codex then ran shell commands in the cache directory and relative writes such as git clone or mkdir failed with "Operation not permitted". Send cwd="." so the thread follows the process working directory chosen by the runtime for each sandbox. Platform mode, Docker, bwrap and runner execution still start the CLI in /ws, so they are unchanged. The cwd is also sent on resume, because Codex otherwise keeps the directory recorded when the thread started. --- internal/httpapi/assistant_engine_codex.go | 8 +++++++- internal/httpapi/assistant_engine_codex_test.go | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/httpapi/assistant_engine_codex.go b/internal/httpapi/assistant_engine_codex.go index 21c2ebb25..764d01966 100644 --- a/internal/httpapi/assistant_engine_codex.go +++ b/internal/httpapi/assistant_engine_codex.go @@ -189,7 +189,13 @@ func (s *codexAppServer) response(message codexRPCMessage) []string { // App-server builds each thread's hook trust from its own config. // Both the platform guard and workspace approval hook are generated // and reviewed by the platform. - params := map[string]any{"developerInstructions": s.opts.SystemPrompt, "sandbox": "read-only", "approvalPolicy": "never", "cwd": filepath.Join(s.opts.Root, "ws"), "config": map[string]any{"bypass_hook_trust": true}} + // The runtime starts the CLI in its per-sandbox working directory: + // /ws in platform mode, Docker and bwrap, but the run workspace + // itself on macOS seatbelt, which cannot map /ws. A relative cwd + // resolves against that directory. It must be sent on resume too: + // without it Codex keeps the cwd recorded when the thread started, so a + // platform-mode thread handed to a workspace would stay in /ws. + params := map[string]any{"developerInstructions": s.opts.SystemPrompt, "sandbox": "read-only", "approvalPolicy": "never", "cwd": ".", "config": map[string]any{"bypass_hook_trust": true}} if s.opts.Model != "" { params["model"] = s.opts.Model } diff --git a/internal/httpapi/assistant_engine_codex_test.go b/internal/httpapi/assistant_engine_codex_test.go index e142d3b29..6d8b072ea 100644 --- a/internal/httpapi/assistant_engine_codex_test.go +++ b/internal/httpapi/assistant_engine_codex_test.go @@ -128,6 +128,11 @@ func TestCodexAppServerTurn(t *testing.T) { if config, _ := start.Params["config"].(map[string]any); config["bypass_hook_trust"] != true { t.Fatalf("platform denial hook not trusted by thread: %+v", start) } + // The runtime picks the working directory per sandbox (the run workspace + // on macOS seatbelt); the thread must follow it, not /ws. + if start.Params["cwd"] != "." { + t.Fatalf("thread/start cwd must follow the process working directory: %+v", start.Params["cwd"]) + } if out := inv.translate(`{"id":2,"result":{"thread":{"id":"019a-thread"}}}`); len(out) != 1 || !strings.Contains(out[0], `"session_id":"019a-thread"`) { t.Fatalf("thread started: %v", out) } @@ -240,6 +245,11 @@ func TestCodexAppServerResume(t *testing.T) { if config, _ := m.Params["config"].(map[string]any); config["bypass_hook_trust"] != true { t.Fatalf("resumed thread lost denial hook trust: %+v", m) } + // Without an explicit cwd Codex resumes in the directory recorded when the + // thread started, so a thread handed to a seatbelt workspace stays in /ws. + if m.Params["cwd"] != "." { + t.Fatalf("thread/resume cwd must override the recorded directory: %+v", m.Params["cwd"]) + } // A thread the server cannot load reads as a missing session. out := inv.translate(`{"id":2,"error":{"code":-32600,"message":"no rollout found for thread id 019a-old"}}`) if len(out) != 1 || !strings.Contains(out[0], "No conversation found with session ID: 019a-old") {