Repository navigation
fix slow COW listings, a freeze hang, and two profile recording gaps - #369
Open
ghazariann wants to merge 4 commits into
Open
ghazariann wants to merge 4 commits into
ghazariann wants to merge 4 commits into
Conversation
Once anything had been written in the COW branch, every getdents64 went through the merge, which stats each entry several times in the sequential supervisor loop. With a large workdir such as learn's "/", one write made every later listing slow and stalled the sandbox. Now only a directory that changed is merged: something was created or deleted inside it, or the directory itself was created or deleted. Every other directory is listed by the kernel as is. Signed-off-by: Vahagn <wanghang25@mails.tsinghua.edu.cn>
A process killed while frozen for another process's execve is a zombie still attached to the supervisor. Its exit goes to the tracer first, so its parent's wait does not see it. PTRACE_DETACH fails on it with ESRCH, the error was ignored, and the sandbox waited forever for its last process to exit. When PTRACE_DETACH fails, the supervisor calls waitpid on the tracee. For a dead tracee this ends the attachment and hands the zombie to its parent. A tracee killed but not yet a zombie is retried for up to 100ms. Signed-off-by: Vahagn <wanghang25@mails.tsinghua.edu.cn>
syscall_name mapped every legacy path syscall to its *at name except open, so a policy_fn saw a legacy open as "unknown" and missed the files opened with it, such as by musl binaries. Signed-off-by: Vahagn <wanghang25@mails.tsinghua.edu.cn>
The exec branch recorded the path as given, so a program that re-execs itself through /proc/self/exe got that /proc link as a grant, which run refuses. Canonicalize it like every other recorded path. Signed-off-by: Vahagn <wanghang25@mails.tsinghua.edu.cn>
ghazariann
force-pushed
the
fix/codex-under-learn
branch
from
December 3, 2026 15:26
e9cfef3 to
a12d0ea
Compare
This branch has not been deployed
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.
Four independent bugs found while running the Codex CLI under learn.
List a directory through the kernel unless it changed
Once anything had been written in the COW branch, every
getdents64went through the merge, which stats each entry several times in the sequential supervisor loop. With a large workdir such as learn's/, one write made every later listing slow and stalled the sandbox.Now only a directory that changed is merged: something was created or deleted inside it, or the directory itself was created or deleted. Every other directory is listed by the kernel as is.
Any workload that lists large directories after its first write pays for it, for example a zsh
compinitwalking$PATH. Repro:Without the
echo, this takes 214ms; with it, 2893ms.Release a traced process that died while frozen
A process killed while frozen for another process's execve is a zombie still attached to the supervisor. Its exit goes to the tracer first, so its parent's wait does not see it.
PTRACE_DETACHfails on it withESRCH, the error was ignored, and the sandbox waited forever for its last process to exit.When
PTRACE_DETACHfails, the supervisor callswaitpidon the tracee. For a dead tracee this ends the attachment and hands the zombie to its parent. A tracee killed but not yet a zombie is retried for up to 100ms.How the hang happens, step by step:
PTRACE_DETACH. That only works on a stopped process. zsh is dead, so the call fails withESRCH.waitdoes not see it while it is traced, and the tracer never collects it.About half of the learn runs hung after the workload finished, leaving a
[zsh] <defunct>traced by a supervisor thread. With the fix, 12 of 12 exited.Name legacy open(2) events "openat"
syscall_namemapped every legacy path syscall to its*atname exceptopen, so apolicy_fnsaw a legacy open as"unknown"and missed the files opened with it, such as by musl binaries.For Codex, a musl binary, the learned profile had no
/etc/resolv.confor~/.codexconfig, and the replay failed to connect.Resolve /proc/self/exe in an exec path
The exec branch recorded the path as given, so a program that re-execs itself through
/proc/self/exegot that/proclink as a grant, which run refuses. Canonicalize it like every other recorded path.runrefused such a profile with:Tests
needs_dir_intercept_ignores_a_write_elsewhere,needs_dir_intercept_sees_a_file_staged_inside,needs_dir_intercept_sees_a_deleted_child,needs_dir_intercept_sees_the_directory_deleted, and twohas_deleted_underteststest_learn_then_run_legacy_opentest_learn_then_run_exec_proc_self_exeVerified
With these fixes, the Codex CLI 0.173.0 works under
sandlock learnand thensandlock runwith the learned profile, for a plain answer, the shell tool, and file create plus apply_patch.The commands used, for reference.