## Summary
A stale `serve.json` can name a PID recycled to an unrelated process.
Liveness alone then prevents `raven web` from starting and lets `raven
web --stop` signal the wrong process. Check the instance lock and the
recorded process's command line before treating that PID as a Raven
resident.
- Preserve resident, foreign, and unknown identities. An unavailable
argv probe keeps a live process's record and prevents duplicate startup;
stopping requires positive identity evidence.
- Read Linux argv directly from `/proc/<pid>/cmdline`, retaining
argument boundaries when rendering spaces. Fall back to untruncated
GNU/BSD `ps -ww`; Windows uses CIM. Decoding uses UTF-8 with
replacement. Recognize module and console-script launches of `serve`,
`web`, and `gateway`.
- Examine every console-script candidate. An earlier directory such as
`Raven copy` or a Windows profile named `Raven Smith` no longer hides
the actual executable and causes removal of a live resident's record.
- Return exit 1 when any resident stop is refused or fails, including
partial stops. The CLI no longer reports "nothing to stop" after
retaining live records. Unknown-identity refusals name the exact
serve.json, web.json, or viewer.pid record. Restore process access, or
remove that record only after confirming it is stale; the warning no
longer suggests signalling an unverified PID.
- Share the platform reader with the tracing viewer. Recognize `nodejs`
and versioned Node names as well as `node`/`node.exe`. An unreadable
live viewer keeps its record, cannot be signalled, and prevents a second
viewer from starting; a dead or proven foreign process can still be
cleared. Recognize unquoted spaced executable paths from POSIX ps as
well as quoted paths.
## Type
- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other
## Verification
- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed
Linux, Python 3.12, after rebasing onto current main:
```text
uv run --frozen --all-extras pytest tests/test_cli_serve_commands.py tests/test_utils_processes.py tests/test_cli_tracing_commands.py tests/test_cli_gateway_commands.py tests/test_cli_gateway_health.py tests/test_cli_gateway_page.py tests/test_rpc_serve_control.py -q -x --tb=short
```
Result: 328 passed, 1 skipped (the native Windows CIM case), using the
default four workers. The live procfs regression now waits for a bounded
child readiness signal before its single identity assertion, eliminating
the transient empty-cmdline startup race reported in review. The
container uses an init process to reap children from the real
process-group tests.
A follow-up CI run exposed two assertions that assumed Rich would not
wrap viewer.pid inside a long path. The assertions now tolerate display
line breaks. Re-running the entire tracing CLI test file with the
CI-shaped temporary path
(`--basetemp=/tmp/pytest-of-runner/pytest-0/popen-gw3`) passed all 40
tests.
Native Windows, Python 3.12:
```text
uv run --frozen pytest tests/test_cli_serve_commands.py::TestAnUnreadableIdentity tests/test_cli_serve_commands.py::TestARecycledPid tests/test_cli_serve_commands.py::TestAStopThatLosesItsTarget tests/test_cli_serve_commands.py::test_web_stop_reports_a_refused_or_partial_stop tests/test_cli_serve_commands.py::test_a_resident_below_a_raven_named_directory_keeps_its_record tests/test_utils_processes.py tests/test_cli_tracing_commands.py -n 0 -q -x --tb=short
```
Result: 102 passed, 7 Linux/POSIX-only skips. The Linux selection
includes a real child identified with ps absent from PATH. Tests force
the ps fallback when measuring its behavior, pin lowercase Raven
directories and uppercase executable names separately, and drive the
public viewer stop for an unquoted spaced Node path. Both new
spaced-path regressions failed before the viewer fix.
Four additional isolated mutations were caught: skipping procfs,
dropping the ps fallback, restoring first-match resident parsing while
removing case-insensitivity, and truncating the Node path at its first
space. The sources were restored and compared with the committed Git
blobs.
Additional checks passed:
```text
uv run --frozen pre-commit run --from-ref origin/main --to-ref HEAD
uv run --frozen --all-extras ty check raven/utils/processes.py raven/cli/serve_commands.py raven/cli/tracing_commands.py
uv run --frozen --all-extras lint-imports
uv run --frozen python scripts/check_commit_messages.py origin/main..HEAD
commitlint --from origin/main --to HEAD
uv run --frozen python scripts/check_source_language.py origin/main..HEAD
uv run --frozen python scripts/check_large_files.py origin/main..HEAD
git diff --check origin/main...HEAD
```
Import-linter kept all 10 contracts. The full repository suite and
native macOS were not rerun locally. No new command, setting, or visual
UI requires a screenshot or user guide; the affected code contracts and
this description are updated.
## Risk
- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes
A live process with an unreadable identity deliberately blocks
replacement and cannot be stopped through these commands. Restore the
process reader, or confirm the state record is stale before removing the
exact file named by the command. Scripts now receive failure for refused
or incomplete stops instead of a misleading success. Process recognition
remains a command-line heuristic, and the check and signal do not hold a
single OS process handle; this does not eliminate PID-reuse races.
Rollback: revert the squash commit, restoring the previous PID-based
behavior and its recycled-PID risk.
## Related Issues
N/A
---------
Co-authored-by: Claude (claude-fable-5) <noreply@anthropic.com>