Skip to content

fix: use prctl FFI to set process name as 'agent' in top/ps#151

Merged
konard merged 4 commits intomainfrom
issue-144-e4442be326dd
Feb 12, 2026
Merged

fix: use prctl FFI to set process name as 'agent' in top/ps#151
konard merged 4 commits intomainfrom
issue-144-e4442be326dd

Conversation

@konard
Copy link
Copy Markdown
Contributor

@konard konard commented Feb 11, 2026

Summary

Fixes #144 — Our Agent CLI should be identified in top as agent not bun command.

Root Cause

The previous fix (PR #145) used process.title = 'agent' and process.argv0 = 'agent', but Bun does not implement the process.title setter unlike Node.js. Setting these properties only changes in-process JavaScript values but does not call prctl(PR_SET_NAME) under the hood like Node.js does.

Evidence from experiments:

// After process.title = 'agent':
/proc/PID/comm: bun          # Still shows 'bun'
ps COMMAND: bun               # Still shows 'bun'

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 in top, ps, and htop.

On macOS and Windows, no FFI is needed:

  • macOS: When installed via bun install -g, the symlink is named agent, so macOS already shows agent in ps/top
  • Windows: Task Manager always shows the executable name

Verification

After the fix on Linux:

/proc/PID/comm: agent         # Now shows 'agent'
ps COMMAND: agent              # Now shows 'agent'

Changes

  • js/src/cli/process-name.ts — New module with setProcessName() using Bun FFI prctl(PR_SET_NAME) on Linux
  • js/src/index.js — Replaced ineffective process.title/process.argv0 with setProcessName('agent') import
  • js/tests/process-name.test.js — Autonomous test that spawns a bun process, calls setProcessName, and verifies the kernel comm name equals agent (Linux-only, skips on macOS/Windows)
  • .github/workflows/js.yml — Added process-name.test.js to CI test runner
  • js/.changeset/fix-process-name-ffi.md — Changeset for patch release
  • experiments/ — Research scripts documenting the investigation

Test plan

  • bun test tests/process-name.test.js passes locally (Linux)
  • bun test tests/json-standard-unit.test.js passes (no regression)
  • ESLint + Prettier checks pass
  • CI passes on Ubuntu (Linux assertions pass)
  • CI passes on macOS (tests gracefully skip with message)
  • CI passes on Windows (tests gracefully skip with message)

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #144
@konard konard self-assigned this Feb 11, 2026
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>
@konard konard changed the title [WIP] Our Agent CLI should be identified in top as agent not bun command fix: use platform-specific FFI to set process name as 'agent' in top/ps Feb 11, 2026
macOS 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>
@konard konard changed the title fix: use platform-specific FFI to set process name as 'agent' in top/ps fix: use prctl FFI to set process name as 'agent' in top/ps Feb 11, 2026
@konard konard marked this pull request as ready for review February 11, 2026 22:02
@konard
Copy link
Copy Markdown
Contributor Author

konard commented Feb 11, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $7.762179
  • Calculated by Anthropic: $5.306180 USD
  • Difference: $-2.455999 (-31.64%)
    📎 Log file uploaded as Gist (974KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 34ba2ef into main Feb 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Our Agent CLI should be identified in top as agent not bun command

1 participant