Skip to content

perf(host-kit): read Linux process identity from /proc before ps - #5212

Merged
thymikee merged 5 commits into
mainfrom
perf/linux-identity-proc-first
Nov 29, 2026
Merged

thymikee merged 5 commits into
mainfrom
perf/linux-identity-proc-first

Conversation

@thymikee

@thymikee thymikee commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

On Linux the selected-PID identity snapshot ran ps, then replaced state and start token with /proc facts for every listed row. It now reads /proc first and runs one batch ps only for the PIDs left unread. Async identity reads (snapshot and ownership) read /proc through fs/promises. macOS and Windows still use their process tools; token formats are unchanged.

Intended change: a PID that /proc answers is observed even when ps fails, times out or omits it. Unread PIDs behave as before.

Out of scope: the ownership read still needs ps for command lines.

Stop and Windows row types moved to the type-only module, keeping host-process.ts at 1000 lines without adding a module to any import closure.

Tests that count process-tool runs hide /proc or claim a non-Linux platform.

Validation

Tested d294adc on macOS.

Process-tool runs per snapshot, counted by tests with Linux faked:

Selected PIDs Base Head
all readable 1 0
some unread 1, asking all 1, asking only unread
  • Liveness, lock-wait, metadata tests: 48 passed, 6 Linux-only skipped; with Linux simulated, all 54 passed.
  • The async no-blocking-read test fails against a75f848.
  • Scoped tsc passed.
  • e2e82f7 (tests, comments): changed test files 46 passed, 6 skipped; 52 passed with Linux simulated; package-boundary test passed.
  • CI owns the full gates. Latency was not measured: no Linux host.

🤖 Generated with Claude Code

The selected-pid identity snapshot ran `ps` and then replaced state and start
token from `/proc` for every listed row. Read `/proc` first and run one batch
`ps` only for the pids it left unread.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.70 MB 6.70 MB +439 B
Package (unpacked) 6.70 MB 6.70 MB +439 B
Package (download) 2.04 MB 2.04 MB +132 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 19.8 ms 22.9 ms +3.1 ms
CLI --help 40.4 ms 42.9 ms +2.6 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/revyl 179.6 kB → 179.6 kB (0 B) 179.2 kB → 179.2 kB (0 B) 58.2 kB → 58.2 kB (0 B)
@agent-device/testmu 26.1 kB → 26.1 kB (0 B) 25.7 kB → 25.7 kB (0 B) 9.4 kB → 9.4 kB (0 B)
@agent-device/tizen 97.5 kB → 97.5 kB (0 B) 97.1 kB → 97.1 kB (0 B) 34.4 kB → 34.4 kB (+1 B)
@agent-device/webos 96.4 kB → 96.4 kB (0 B) 96.1 kB → 96.1 kB (0 B) 34.0 kB → 34.0 kB (0 B)

@blacksmith-sh

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Async identity reads (snapshot and ownership) now use fs/promises for /proc,
including the re-read of each pid ps lists. The blocking snapshot stays
synchronous. Stop and read types move to the type-only module, so
host-process.ts stays at its line limit and no import closure gains a module.

The registration-read test hides /proc, so its positive control and its main
assertion both observe identity reads on Linux.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

No problem that needs a code change was found at d294adc: Linux selected-PID snapshots read /proc first and ask ps only about the PIDs left unread. The evidence required for this change is in place.

All 22 checks pass at this commit. The earlier Linux Coverage failure in the daemon-client metadata test does not recur, and the test now hides /proc.

Not verified here: behavior on a real Linux host and the latency gain were not checked, so Linux behavior rests on the code, the platform-faked unit tests and the Linux CI run.

Not verified here: it was not confirmed on a Linux host that ps -p on the base answered thread IDs the same way as /proc; from the code, a recorded PID reused as a thread ID reads with the thread's own start time and counts as reassigned, not alive.

Not blocking: these can be taken or left: hideLinuxProc duplicates mockLinuxProcessStatAbsent; the state assertions for snapshots no longer reach the conflicting ps state, which a failed first stat read in the retry test could cover for both zombie directions; the fallback comment describes a second read although the ownership path reads /proc there for the first time; and the types module comment implies that WindowsProcessRow is re-exported, but it is not.

Could host-kit own one test-only /proc-unavailable fixture and expose it the same way as archive-fixtures, so the daemon-client test can reuse it?

Two earlier inline threads no longer apply: the blocking async read is fixed because the async snapshot now reads through fs.promises.readFile, and the second /proc read is harmless because it runs only for unread PIDs that ps lists and keeps the linux: start time after a brief read failure.

No code change is needed before merge.

The daemon-client test claims a non-Linux platform instead of keeping its own
`/proc` fake. The snapshot retry test covers both conflicting zombie states.
Two comments now match the code.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@thymikee

Copy link
Copy Markdown
Member Author

Review notes applied in e2e82f7.

  • Duplicate /proc fake: removed, but not through a new export. To your question: no. R83 (package-export-surface) rejects any new test-only export, and I confirmed it flags a ./proc-fixtures entry; archive-fixtures predates that ratchet. test-kit cannot own the fixture for host-kit's tests either, because it depends on host-kit. So hideLinuxProc is deleted, and the daemon-client test uses test-kit's existing withMockedPlatform('darwin'). mockLinuxProcessStatAbsent is now the one /proc-unavailable fixture.
  • Zombie state: the failed-first-read retry test now covers both directions, sync and async; /proc wins. I removed the snapshot assertions that no longer reached ps; the ownership assertion stays.
  • Comments: both fixed (identityRows and the types module).

Local checks on macOS: both changed test files, 46 passed and 6 Linux-only skipped; with a Linux host simulated, 52 passed. The four retry cases fail if identityRows prefers the ps state, and the metadata control fails on simulated Linux without the platform claim. The package-boundary test passed. CI is pending.

@blacksmith-sh

This comment has been minimized.

thymikee and others added 2 commits November 29, 2026 17:24
…roc-first

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* origin/main:
  perf(apple): reuse the process identity for native-build cache locks (#5203)
  perf(apple): read the native-build toolchain identity with two concurrent probes (#5206)
  perf(macos): reuse the helper fingerprint between unchanged calls (#5207)
  docs(agents): add performance guidance (#5208)
  perf(daemon): classify a device claim owner only for refusals and settlement (#5210)
Linux process identity now reads /proc through fs.promises too, so hiding
only readFileSync let the lock's off-loop read remember a linux: token.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 84acff5

Since the review of d294adc: 0 new · 0 still open · 0 no longer raised

No open findings.

Reviewed with this repository's own Sentinel configuration (a0c616cd955d).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

The PR is ready at 84acff5.

Not blocking: this can be taken or left: the new /proc hiding in the host-lock test nearly repeats mockLinuxProcessStatAbsent, so as an optional follow-up that test could claim a non-Linux platform, as the daemon-client test now does, if it only needs a host where identity reads run ps.

The other earlier notes are addressed: hideLinuxProc is gone, the retry test now covers both zombie directions for snapshots, and both comments are corrected.

All 21 checks pass at this commit, including the Linux jobs that ran the changed tests.

Two earlier inline threads no longer apply: the blocking async read is fixed because async reads go through fs.promises.readFile, and the second /proc read is harmless because it runs only for unread PIDs that ps lists and keeps the linux: start time after a brief failure.

Not verified here: behavior on a real Linux host and the latency gain are unmeasured, so Linux behavior rests on the code, the platform-faked unit tests and Linux CI.

Not verified here: the rejection of a ./proc-fixtures export by rule R83 was not reproduced and rests on the author’s statement.

Nothing else is needed before merge.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 29, 2026
@thymikee
thymikee merged commit b7db7d0 into main Nov 29, 2026
21 checks passed
@thymikee
thymikee deleted the perf/linux-identity-proc-first branch November 29, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant