Skip to content

fix(bin): make the ps-fallback watcher identity immune to terminal width - #5517

Merged
kunchenguid merged 2 commits into
kunchenguid:mainfrom
karotkriss:fm/fm-up-799-ps-ww-pid-identity
Sep 24, 2026
Merged

kunchenguid merged 2 commits into
kunchenguid:mainfrom
karotkriss:fm/fm-up-799-ps-ww-pid-identity

Conversation

@karotkriss

@karotkriss karotkriss commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #799

On hosts without a readable /proc, the watcher identity is computed from ps -p <pid> -o lstart= -o command=, and when that runs inside a hook with a narrow COLUMNS the command column is truncated, so the recorded identity never matches the live one and the continuity guard denies every fleet command until the captain intervenes.
Make the identity immune to terminal width so a narrow hook context yields the same identity as a wide shell.
This closes upstream issue #799.

What Changed

  • Pass -ww to the ps -p <pid> -o lstart= -o command= fallback in fm_pid_identity, so the command column is never cut to the ambient terminal width; an identity written from a wide shell now matches the one re-read inside a narrow-COLUMNS hook (issue Watcher-continuity deadlock: fm_pid_identity ps command truncated in narrow-COLUMNS hook context #799).
  • Add test_pid_identity_is_terminal_width_invariant, which asserts the fallback returns a byte-identical identity carrying the full command under COLUMNS=20 and COLUMNS=1000, and registers it in the test runner.

Risk Assessment

✅ Low: A one-flag (-ww) fix at the shared identity helper directly satisfies the stated intent, is portable across the targeted ps variants, keeps write/read identities consistent for every caller, and is covered by a proper behavioral regression test.

Testing

I exercised the real fm_pid_identity function through its portable ps fallback (with /proc forced absent) at both narrow and wide COLUMNS. At the target commit the two readings are byte-identical and carry the whole command; against an un-fixed copy of the lib the narrow reading truncates to sleep 300.00000 while the wide reading is complete, reproducing the mismatch that makes the continuity guard deny fleet commands (issue #799). The added regression test drives this same path and passes. No screenshot applies — this is a shell/process-identity change with no UI surface. Worktree left clean; temp files removed.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Identity is identical whether computed in a narrow hook (COLUMNS=20) or a wide shell (COLUMNS=1000) ✅ pass live Drove real fm_pid_identity via FM_PROC_ROOT_OVERRIDE with a long-argument process; narrow and wide outputs byte-identical and carried the full command
Regression #799: without -ww a narrow COLUMNS truncates the command and the identity mismatches (guard would deny every fleet command) ✅ pass live Same drive against an un-fixed copy of the lib produced narrow 'sleep 300.00000' vs full wide command (MISMATCH); raw ps at COLUMNS=20 confirmed the truncation source
Added regression test drives the terminal-width path end-to-end ✅ pass live bash tests/fm-watcher-lock.test.sh -> 'ok - fm_pid_identity ps fallback is terminal-width-invariant'
Evidence: Raw ps truncation vs -ww (narrow COLUMNS=20)
no -ww, COLUMNS=20: Thu Sep 24 08:39:49 2026 sleep 300.00000
no -ww, COLUMNS=1000: Thu Sep 24 08:39:49 2026 sleep 300.0000...(full)
-ww, COLUMNS=20: Thu Sep 24 08:39:49 2026 sleep 300.0000...(full)
-ww, COLUMNS=1000: Thu Sep 24 08:39:49 2026 sleep 300.0000...(full)
Evidence: fm_pid_identity fixed: narrow == wide
NARROW: Thu Sep 24 08:40:00 2026 sleep 300.0000...(full)
WIDE: Thu Sep 24 08:40:00 2026 sleep 300.0000...(full)
RESULT: identical (invariant)
Evidence: fm_pid_identity un-fixed: mismatch (regression reproduced)
NARROW: Thu Sep 24 08:41:54 2026 sleep 300.00000
WIDE: Thu Sep 24 08:41:54 2026 sleep 300.0000...(full)
RESULT: MISMATCH (bug reproduced -> guard would deny)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Identity is identical whether computed in a narrow hook (COLUMNS=20) or a wide shell (COLUMNS=1000) ✅ pass live Drove real fm_pid_identity via FM_PROC_ROOT_OVERRIDE with a long-argument process; narrow and wide outputs byte-identical and carried the full command
Regression #799: without -ww a narrow COLUMNS truncates the command and the identity mismatches (guard would deny every fleet command) ✅ pass live Same drive against an un-fixed copy of the lib produced narrow 'sleep 300.00000' vs full wide command (MISMATCH); raw ps at COLUMNS=20 confirmed the truncation source
Added regression test drives the terminal-width path end-to-end ✅ pass live bash tests/fm-watcher-lock.test.sh -> 'ok - fm_pid_identity ps fallback is terminal-width-invariant'
  • LC_ALL=C COLUMNS=20/1000 ps [-ww] -p &lt;pid&gt; -o lstart= -o command= — showed raw ps truncates the command column at COLUMNS=20 without -ww and returns the full command with -ww
  • Drove the real fm_pid_identity via FM_PROC_ROOT_OVERRIDE=&lt;absent&gt; bash -c &#39;. fm-wake-lib.sh; fm_pid_identity &lt;pid&gt;&#39; under COLUMNS=20 and COLUMNS=1000 — identities byte-identical (invariant) at target commit
  • Same drive against an un-fixed copy of the lib (-ww removed) — narrow yielded sleep 300.00000, wide yielded the full command: MISMATCH, reproducing the guard-denial regression
  • bash tests/fm-watcher-lock.test.sh — added regression test fm_pid_identity ps fallback is terminal-width-invariant passes
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799
… cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Contract-class: restore — tip vs main 5842d423 (post-#5528): main fm_pid_identity ps fallback still runs LC_ALL=C ps -p … -o lstart= -o command= with no width pin, so a narrow-COLUMNS hook truncates the command and the continuity guard denies live watchers; tip pins COLUMNS=10000 (mirrors existing fm_pending_reply_pid_identity) plus a regression test. Unconfigured path: same identity helper, no new surface. Restores the already-specified continuity-match path that was broken (issue #799). Not new-default (FM-LEARN-4627). Author's earlier -ww approach was replaced by the COLUMNS pin to keep fake-ps argv fixtures intact — same restore intent.

VISION.md (each rule)

  • One captain, one interface: aligns — false continuity denials that block every fleet command destroy looking-away confidence.
  • Authority is explicit: aligns — no new grant; restores identity matching the product already required.
  • Scripts own the mechanics: aligns — pid identity is exact script mechanics.
  • A restart is a non-event: aligns — continuity must hold across hook vs wide-shell contexts.
  • Delegation with a spine: aligns — unblocks existing fleet commands; no new task shape.
  • The fleet outlives any vendor: aligns — width pin is harness-agnostic (incident was Claude Code hooks; fix is general).
  • Scope: aligns — wake-lib identity helper in the command layer.

aligns when / resist when: Aligns — strengthens a refusal/continuity path. Sibling fm-afk-start.sh daemon substring fallback noted in #799 is out of scope here.

Closes check: Author Fixes #799 verified against issue body (narrow-COLUMNS truncation → continuity deadlock) and tip diff. Issue labeled ready-for-pr.

CI/NM: all SUCCESS. Attestation MATCH on HEAD 188fcca4. MERGEABLE/CLEAN after #5528. Safe review; no security tip. Auto-merge as restore.

@kunchenguid
kunchenguid merged commit e1d6cf9 into kunchenguid:main Sep 24, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @karotkriss — really appreciate you taking the time on this.

mituso89 pushed a commit to mituso89/firstmate that referenced this pull request Sep 26, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 26, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
mehulbhagwani pushed a commit to mehulbhagwani/firstmate that referenced this pull request Sep 27, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change
RooseveltAdvisors pushed a commit to RooseveltAdvisors/firstmate that referenced this pull request Sep 29, 2026
…dth (kunchenguid#5517)

* fix(bin): keep the ps fallback identity independent of terminal width

fm_pid_identity's portable fallback read the command column at the
ambient COLUMNS width, so an identity recorded from a wide shell never
matched the one recomputed inside a narrow hook and the continuity guard
denied every fleet command. Pass -ww so the column is never cut.

Fixes kunchenguid#799

* no-mistakes(ci): Fixed CI failure in Behavior portable serial 4. Root cause: the -ww flag added in commit ac7ab5d to fm_pid_identity (bin/fm-wake-lib.sh) shifted the ps argv so $1 became -ww instead of -p, breaking the positional fake-ps fixtures in tests/fm-procevent.test.sh (lines 2736, 3571) which then fell through to real ps and failed the fm-procevent test. Fix (already applied in the worktree, matching the authoritative user instruction exactly): replaced -ww with a COLUMNS=10000 environment pin so the call is COLUMNS=10000 LC_ALL=C ps -p "$pid" -o lstart= -o command=, mirroring fm_pending_reply_pid_identity in bin/fm-pending-reply-lib.sh:982. argv is back to -p PID -o lstart= -o command=, so the fixtures match again with no fixture edits. Comments above the call in bin/fm-wake-lib.sh and in test_pid_identity_is_terminal_width_invariant (tests/fm-watcher-lock.test.sh) now describe the COLUMNS pin instead of -ww; the regression test still asserts narrow-vs-wide byte equality and the full command. Verified: the terminal-width-invariant regression test passes. The only local not-ok results were flaky, run-varying timing tests (procevent launch/claim confirmation, listener reparenting) that differ each run and are unrelated to the ps argv change