Skip to content

claw CLI: happy path exits non-zero after sentinel-triggered proc.kill() #1312

@coderabbitai

Description

@coderabbitai

Bug report

File: .claude/skills/claw/scripts/claw

Summary

When the closing sentinel ---NANOCLAW_OUTPUT_END--- is detected in the container's stdout, the script calls proc.kill() to terminate the container early (to avoid the Node.js event loop keeping it alive). However, proc.kill() causes the subprocess to exit with a non-zero return code. Later, when the script reads status == "success" from the structured JSON output, it still propagates the container's non-zero return code to the caller — making a successful claw invocation look like a failure to shell scripts and CI pipelines.

Reproduction

claw "What is 2+2?"
echo $?   # prints non-zero even on a successful response

Root cause

In run_container(), the sentinel handling does:

if line.strip() == "---NANOCLAW_OUTPUT_END---":
    done.set()
    try:
        proc.kill()   # ← SIGKILL → non-zero exit code

And the exit-code propagation at the end of main() does not distinguish between a kill-induced non-zero and a real container failure, so a status=success response still causes claw to exit non-zero.

Suggested fix

Two complementary changes:

  1. Graceful shutdown on sentinel — replace proc.kill() with proc.terminate() (SIGTERM) followed by proc.wait(timeout=5) so the container can exit cleanly with code 0.
  2. Exit-code override on success — after confirming status == "success", return early (before any sys.exit based on the container return code) so the script always exits 0 on a successful response, regardless of how the container process ended.

References

Reported by @taslim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions