Cat Pranks

Cat Pranks

Andrew Kelley Did Nothing Wrong

You might be familiar with the recent post from Anthropic detailing the story of Claude rewriting Bun in Rust. Bun was previously written in Zig. Andrew Kelley, the creator of Zig, wrote a very spicy rage post condemning the rewrite and the author of Bun. Here is how I was personally touched by these events.

I recently ran an overnight Claude Code session where its job was to oversee a Codex subagent doing the actual work. The subagent was wrapped in custom tooling that presented a shell command interface to Claude Code. Fable kept noticing the shell commands dying for no reason in the middle of active work. I asked another instance of Fable to investigate.

After a bit of prodding, Fable started digging through the Claude Code binary (you can't guardrail the cyber out of Mythos, I guess) and discovered the following snippet. This code listens for Bun's memoryPressure events. If the user hasn't typed anything for 30 minutes, the harness kills background shell tasks, including my active Codex session. I'll set CLAUDE_CODE_DISABLE_BG_SHELL_PRESSURE_REAP=1 to fix it but I still want to throw Boris into a volcano.

if (
  agentId === undefined &&
  isInteractive() &&
  !env.CLAUDE_CODE_DISABLE_BG_SHELL_PRESSURE_REAP
) {
  const reap = () => {
    const task = registry.get(taskId);
    if (
      task?.status !== "running" ||
      task.notified ||
      Date.now() - lastInteractionTime() < 30 * 60 * 1000 ||
      mainLoopBusy() ||
      anyAgentTaskActive(registry.all())
    )
      return; // skip killing if there was recent input

    telemetry("task_local_shell_pressure_reap");
    notify(taskId, description, "killed" /* … */);
    kill(taskId, registry); // ruin my day
  };

  process.on("memoryPressure", reap); // Bun's new event
}

Added in Claude Code 2.1.193.

But wait, there is more. What is this memoryPressure stuff? Linux has a mechanism to alert userspace if the system is under resource pressure. Bun first tries to use the system-wide procfs interface, then falls back to /proc/self/cgroup.

/// 150 ms of "some"-stall in any 2 s window. 2 s is the minimum
/// window for unprivileged PSI triggers (kernel 6.6+).
const TRIGGER: &[u8] = b"some 150000 2000000";

let paths = [
    Some(bun_core::zstr!("/proc/pressure/memory")), // system-wide procfs
    own_cgroup_pressure_path(&mut cgroup_buf),      // cgroup memory.pressure
];

for path in paths.into_iter().flatten() {
    /* ... */
    if bun_sys::write(fd, TRIGGER).is_ok() { // truncated write doesn't succeed
        return Some(fd);
    }

Notice something? I didn't, but GPT did. TRIGGER is missing a NUL terminator. The kernel overwrites the last byte of the request with \0, then rejects the truncated 200,000 µs value from an unprivileged client with EINVAL. On my setup, the cgroup route fails as well because the cgroup is owned by root. So why is this relevant? I ran the original session under tmux which does create its own user-owned cgroup. The memory pressure task killer did kick in there!

This mis-feature was added to Bun after the Rust rewrite in the triumphal afterglow of a successful slop project.