fix(liveness): treat kill -0 EPERM as alive under the command sandbox#447
Open
TakahiroHaruyama wants to merge 1 commit into
Open
fix(liveness): treat kill -0 EPERM as alive under the command sandbox#447TakahiroHaruyama wants to merge 1 commit into
TakahiroHaruyama wants to merge 1 commit into
Conversation
Under Claude Code's command sandbox, `kill -0 <pid>` on a live process
outside the current session returns EPERM ("Operation not permitted"),
not ESRCH ("No such process"). The liveness checks treated any non-zero
`kill -0` exit as dead, so a live parent/sibling pid was misread as dead,
causing the monitor watcher to self-exit (silent outage) and the
SessionStart/SessionEnd GC to kill live watchers / delete live markers.
- _agmsg_pid_alive now inspects kill -0 stderr and treats only ESRCH as
dead; every other failure (EPERM included) is alive.
- Route the destructive / dedup liveness gates through it: session-start,
session-end, check-inbox, watch.sh prev-watcher dedup, resolve-project
marker GC (+ guard when the helper isn't loaded), and the
emit_monitor_directive dedup in delivery.sh / grok-build.
- Leave "wait until a pid dies" loops and non-destructive checks as raw
kill -0 by design.
Tests: _agmsg_pid_alive ESRCH/EPERM/unknown cases and marker-GC keep/drop/guard.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
Under Claude Code's command sandbox,
kill -0 <pid>on a live process outside the current session returnsEPERM("Operation not permitted"), notESRCH("No such process"). The liveness checks treated any non-zerokill -0exit as "dead", so a live parent/sibling pid was misread as dead, causing:Fix
_agmsg_pid_alive(scripts/lib/instance-id.sh): inspectskill -0stderr and treats onlyNo such process(ESRCH) as dead; every other failure — EPERM included — is alive.session-start.sh,session-end.sh,check-inbox.sh,watch.shprev-watcher dedup,resolve-project.shmarker GC (+ a guard: skip GC if the helper isn't loaded), and theemit_monitor_directivededup indelivery.sh/ grok-build.kill -0by design: the codex "wait until a pid dies" loops (fail-alive would hang them), and non-destructive checks whosepsfollow-up fails under the sandbox anyway.Tests
test_instance_id.bats:_agmsg_pid_alivefor real live/dead pids and stubbed signalable / ESRCH / EPERM / unknown-error cases.test_resolve_project.bats: marker GC keeps on EPERM, drops on ESRCH, skips when the helper is absent.bats tests/(green except pre-existing sandbox-only failures unrelated to this change).🤖 Generated with Claude Code