Repository navigation
fix(qa): replace Linux-only /proc probes in the Telegram proof harness - #127718
Merged
Merged
Conversation
The Mantis lane and the Telegram user driver reached for /proc to enforce media containment and to prove a pid was still alive. Off Linux those paths do not exist, so the containment check compared a literal "/proc/self/fd/N" string against the output root and refused every file, while both liveness probes silently reported "gone": the lane stole a held harness lock and the driver deleted the observer pid file without ever signalling the process. Containment now uses each runtime's strongest portable construct. Python descends the media path one component at a time from an open directory descriptor (O_DIRECTORY|O_NOFOLLOW, dir_fd), which is race-free and also covers the intermediate directories the old leaf-only O_NOFOLLOW did not. Node has no openat(2), so publicRelativePath re-walks the resolved components after the descriptor is open and refuses any that became a symlink. Liveness moves to process.kill(pid, 0) and to ps state/args, which keeps the pid-reuse and zombie handling the /proc reads provided. The compound-command approval binding test asserted an operand count that only held where the host interpreters live in a root-owned prefix; a Homebrew python3 is writable, so it correctly binds as a third executable operand. Assert the script operands by path instead.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
August 22, 2026 00:36
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 22, 2026
openclaw#127718) The Mantis lane and the Telegram user driver reached for /proc to enforce media containment and to prove a pid was still alive. Off Linux those paths do not exist, so the containment check compared a literal "/proc/self/fd/N" string against the output root and refused every file, while both liveness probes silently reported "gone": the lane stole a held harness lock and the driver deleted the observer pid file without ever signalling the process. Containment now uses each runtime's strongest portable construct. Python descends the media path one component at a time from an open directory descriptor (O_DIRECTORY|O_NOFOLLOW, dir_fd), which is race-free and also covers the intermediate directories the old leaf-only O_NOFOLLOW did not. Node has no openat(2), so publicRelativePath re-walks the resolved components after the descriptor is open and refuses any that became a symlink. Liveness moves to process.kill(pid, 0) and to ps state/args, which keeps the pid-reuse and zombie handling the /proc reads provided. The compound-command approval binding test asserted an operand count that only held where the host interpreters live in a root-owned prefix; a Homebrew python3 is writable, so it correctly binds as a third executable operand. Assert the script operands by path instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Three tests failed on a macOS developer host while
main's CI check-runs were green, because the Telegram proof harness and one approval-binding assertion encode host assumptions that only hold on the Linux CI runner.scripts/e2e/telegram-user-driver.py—resolve_mediaopened the file withO_NOFOLLOW, then re-derived the opened path withos.path.realpath("/proc/self/fd/N")and checked that againstmedia_root. Off Linux there is no/proc,realpathreturns the literal string, and containment fails for every file:command_terminate_observerhad the same problem in a worse shape:/proc/<pid>/statand/proc/<pid>/cmdlineare the liveness and identity probes, and off Linux both raiseFileNotFoundError, sorunning()returnsFalse. Cleanup then deletes the observer pid file and returns without ever signalling the process — a silent no-op, not a visible failure. This was masked until now becauseresolve_mediaaborted the test first.scripts/e2e/telegram-mantis-lane.ts—readPublicFileused the same/proc/self/fdre-resolution (fs.realpathSyncthrowsENOENT: lstat '/proc'), andacquireHarnessLockprobedfs.existsSync("/proc/<owner>")to decide whether a lock owner was still alive. Off Linux every owner reads as dead, so the "shared Telegram harness already has a command in progress" guard silently steals a held lock. Five of this file's eighteen tests failed, not the three originally reported — the other two are--actions-file/lock-guard cases that fail for the same two causes.src/infra/system-run-approval-binding.test.ts—sh first.sh && python3 second.pyassertedoperandshad length 2. The production resolver is right:prepareMutableFileBindingsForSegmentsalso binds a resolved executable whose pathpathLooksMutableForShellPayloadSyncconsiders writable, and a Homebrewpython3(/opt/homebrew/Cellar/[email protected]/...) is user-writable, so it correctly binds as a thirdexecutable: trueoperand./bin/shis root-owned and does not. The count only ever described a host whose interpreters live in a root-owned prefix.Why This Change Was Made
Each fix uses the strongest construct the runtime actually offers, rather than dropping the guarantee to gain portability.
Python gets a strictly stronger check.
open_contained_filedescends the media path one component at a time from an open directory descriptor (O_DIRECTORY | O_NOFOLLOWwithdir_fd=). Because every component is opened relative to an already-pinned parent, no symlink can be traversed and no directory can be swapped mid-walk. That is race-free, and it covers the intermediate directories the old code never protected —/proc/self/fdcaught an escape after the fact, but the open itself only hadO_NOFOLLOWon the leaf.Node has no
openat(2), sopublicRelativePathre-walks the resolved components after the descriptor is open and refuses any that became a symlink;readPublicFilenow runs containment after the open for that ordering to mean something. Statically this matches the old behaviour (a symlink planted in the public dir is refused either way); against an active racer it catches "swap a directory component, leave it swapped", which is the case/proccovered. The named residual is a swap-and-restore inside the window betweenrealpathSyncandopenSync, which cannot be closed in Node withoutopenat. One deliberate narrowing: a symlink pointing back inside the root used to be accepted and is now refused, on both sides. Nothing in the harness relies on that.Liveness probes move to
process.kill(pid, 0)(EPERM means alive under another user, only ESRCH proves gone) and tops -p <pid> -o state= -o args=, which preserves both properties the/procreads had: zombies count as gone because they hold their table entry until reaped and their pid cannot be reused, and argv is still checked so a recycled pid cannot redirectkillpgat an unrelated process group.scripts/vitest-process-group.mtsalso reads/proc, but it is explicitlyinspectLinuxVitestProcessGroup, try/catch-wrapped, and degrades to"unavailable"— correctly designed and left alone.User Impact
No user-visible behaviour change; this is QA harness and test-only. Operator-visible effects for anyone running the harness off Linux: media resolution and public-file reads work, the harness lock is no longer stolen from a live owner, and observer cleanup actually terminates the process instead of silently deleting its pid file.
Production LOC:
+34 / −30across the two scripts (net +4 excluding the invariant comments and docstrings the descriptor walk and thepscontract require). The growth is the security-invariant replacement itself; there is no smaller shape that keeps containment and pid-reuse handling.Evidence
Reproduced on macOS 27.0 / Homebrew Python 3.14.7 against clean
origin/mainbefore any change:src/infra/system-run-approval-binding.test.ts—expected [...] to have a length of 2 but got 3; probe confirmed the third operand is/opt/homebrew/Cellar/[email protected]/3.14.7/.../bin/python3.14withexecutable: true.test/scripts/telegram-user-observer.test.ts— 1 failed, the/proc/self/fd/4ValueErrorabove.test/scripts/telegram-mantis-lane.test.ts— 5 of 18 failed (ENOENT: lstat '/proc'×3, plus the--actions-fileand lock-guard knock-ons).After:
node scripts/check-changed.mjs— exit 0 (format,tsgo:core:test/tsgo:scripts/tsgo:test:root, oxlint,lint:scripts, script-erasability, and the repo guards).Direct probe of the new Python walk (nested legit file opens; directory-symlink escape and leaf symlink both refused):
Added coverage, both of which fail pre-fix on this host:
telegram-user-observer.test.ts—resolve_media("escape/credential.txt")through a directory symlink is refused. The existing case only covered a leaf symlink.telegram-mantis-lane.test.ts— a nested public file (public/nested/body.txt) reads through the new component walk, and a file reached through a symlinked directory component is refused. Nested reads were previously untested and are the false-rejection risk the walk introduces.mantis-telegram-desktop-proof-workflow.test.ts— the mechanism grep moves from/proc/self/fd/${descriptor}toisSymbolicLink().Proof gap, stated plainly: the pre-fix failure for the two harness scripts is host-conditioned. On Linux the
/procpaths were correct, so no portable test can fail against pre-fix code there — the reproduction is the macOS run above. The Node component walk is TOCTOU hardening and is not statically observable; the new lane test pins the behaviour it must not break rather than claiming to prove the race.$autoreview(codex / gpt-5.6-sol, xhigh): clean, no accepted or actionable findings.