Skip to content

fix(coding-agent): reclaim reused Termux lease pids - #910

Open
chai1any wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
chai1any:fix/868-termux-stale-lease
Open

fix(coding-agent): reclaim reused Termux lease pids#910
chai1any wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
chai1any:fix/868-termux-stale-lease

Conversation

@chai1any

@chai1any chai1any commented Aug 8, 2026

Copy link
Copy Markdown

Summary

  • refine kill(pid, 0) EPERM handling on Linux and Android with a /proc/<pid>/stat probe
  • treat a missing proc entry as a stale or reused lease-owner PID so the session lease can be reclaimed
  • retain conservative alive behavior for readable proc entries, other procfs errors, and non-procfs platforms
  • add platform-specific liveness regression coverage

On Termux, a dead worker PID can be reused by a SELinux-protected process. The signal probe then returns EPERM while the proc entry is hidden as ENOENT; previously both conditions were treated as proof that the original lease owner was still alive.

Verification

  • npx tsx ../../node_modules/vitest/dist/cli.js --run test/session-lease.test.ts (13 tests passed)
  • npm run check

Fixes #868

Note

Fix stale session lease detection for reused PIDs on Android/Termux

On Linux/Android, isProcessAlive previously treated EPERM from process.kill(pid, 0) as alive, which caused stale leases to become permanent when a dead worker's PID was reused by a protected process.

  • isProcessAlive in session-lease.ts now falls back to reading /proc/<pid>/stat when EPERM is received on Linux/Android; ENOENT in procfs means the process is dead.
  • On non-procfs platforms (e.g. Darwin), EPERM continues to be treated as alive.
  • The function is now exported and accepts injectable ProcessProbe dependencies for testing.
  • Behavioral Change: PIDs returning EPERM on Linux/Android are now considered dead if they have no /proc entry, changing the previous unconditional alive result.

Macroscope summarized c30502b.

When kill(pid, 0) returns EPERM on Linux or Android, use procfs to distinguish an existing owner from a missing stale or reused PID. Keep conservative behavior for inaccessible proc entries and non-procfs platforms.\n\nFixes PrimeIntellect-ai#868
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.

Session lease liveness check fails on Android/Termux: dead pid returns EPERM → permanent SessionAlreadyActiveError

1 participant