fix: use prctl FFI to set process name as 'agent' in top/ps#151
Merged
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #144
process.title does not work in Bun runtime. Use prctl(PR_SET_NAME) on Linux and pthread_setname_np on macOS via Bun FFI to correctly set the kernel-level process name so it shows as 'agent' in top/ps/htop. Adds autonomous test to verify the process name is set correctly. Fixes #144 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
top as agent not bun commandmacOS has no userspace API to change process comm shown in ps/top. When installed via `bun install -g`, the symlink is already named 'agent', so macOS correctly shows 'agent' in ps/top without FFI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This reverts commit a77d847.
Contributor
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
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.
Summary
Fixes #144 — Our Agent CLI should be identified in
topasagentnotbuncommand.Root Cause
The previous fix (PR #145) used
process.title = 'agent'andprocess.argv0 = 'agent', but Bun does not implement theprocess.titlesetter unlike Node.js. Setting these properties only changes in-process JavaScript values but does not callprctl(PR_SET_NAME)under the hood like Node.js does.Evidence from experiments:
Solution
Use Bun's FFI to call
prctl(PR_SET_NAME, "agent")on Linux, which sets/proc/<pid>/comm— the kernel-level process name visible intop,ps, andhtop.On macOS and Windows, no FFI is needed:
bun install -g, the symlink is namedagent, so macOS already showsagentinps/topVerification
After the fix on Linux:
Changes
js/src/cli/process-name.ts— New module withsetProcessName()using Bun FFIprctl(PR_SET_NAME)on Linuxjs/src/index.js— Replaced ineffectiveprocess.title/process.argv0withsetProcessName('agent')importjs/tests/process-name.test.js— Autonomous test that spawns a bun process, callssetProcessName, and verifies the kernel comm name equalsagent(Linux-only, skips on macOS/Windows).github/workflows/js.yml— Addedprocess-name.test.jsto CI test runnerjs/.changeset/fix-process-name-ffi.md— Changeset for patch releaseexperiments/— Research scripts documenting the investigationTest plan
bun test tests/process-name.test.jspasses locally (Linux)bun test tests/json-standard-unit.test.jspasses (no regression)🤖 Generated with Claude Code