Skip to content

fix(qa): replace Linux-only /proc probes in the Telegram proof harness - #127718

Merged
steipete merged 1 commit into
mainfrom
steipete/nostalgic-khorana-6f5322
Aug 22, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/nostalgic-khorana-6f5322

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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_media opened the file with O_NOFOLLOW, then re-derived the opened path with os.path.realpath("/proc/self/fd/N") and checked that against media_root. Off Linux there is no /proc, realpath returns the literal string, and containment fails for every file:

ValueError: '/proc/self/fd/4' is not in the subpath of '<tmp>/public'
→ DriverError: Media must be inside the Mantis output directory.

command_terminate_observer had the same problem in a worse shape: /proc/<pid>/stat and /proc/<pid>/cmdline are the liveness and identity probes, and off Linux both raise FileNotFoundError, so running() returns False. 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 because resolve_media aborted the test first.

scripts/e2e/telegram-mantis-lane.ts — readPublicFile used the same /proc/self/fd re-resolution (fs.realpathSync throws ENOENT: lstat '/proc'), and acquireHarnessLock probed fs.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.py asserted operands had length 2. The production resolver is right: prepareMutableFileBindingsForSegments also binds a resolved executable whose path pathLooksMutableForShellPayloadSync considers writable, and a Homebrew python3 (/opt/homebrew/Cellar/[email protected]/...) is user-writable, so it correctly binds as a third executable: true operand. /bin/sh is 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_file descends the media path one component at a time from an open directory descriptor (O_DIRECTORY | O_NOFOLLOW with dir_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/fd caught an escape after the fact, but the open itself only had O_NOFOLLOW on the leaf.

Node has no openat(2), so publicRelativePath re-walks the resolved components after the descriptor is open and refuses any that became a symlink; readPublicFile now 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 /proc covered. The named residual is a swap-and-restore inside the window between realpathSync and openSync, which cannot be closed in Node without openat. 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 to ps -p <pid> -o state= -o args=, which preserves both properties the /proc reads 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 redirect killpg at an unrelated process group.

scripts/vitest-process-group.mts also reads /proc, but it is explicitly inspectLinuxVitestProcessGroup, 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 / −30 across the two scripts (net +4 excluding the invariant comments and docstrings the descriptor walk and the ps contract 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/main before 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.14 with executable: true.
  • test/scripts/telegram-user-observer.test.ts — 1 failed, the /proc/self/fd/4 ValueError above.
  • test/scripts/telegram-mantis-lane.test.ts — 5 of 18 failed (ENOENT: lstat '/proc' ×3, plus the --actions-file and lock-guard knock-ons).

After:

node scripts/run-vitest.mjs \
  test/scripts/telegram-mantis-lane.test.ts \
  test/scripts/mantis-telegram-desktop-proof-workflow.test.ts \
  test/scripts/telegram-user-crabbox-proof.test.ts \
  test/scripts/mantis-build-telegram-desktop-proof-evidence.test.ts \
  test/scripts/telegram-user-observer.test.ts \
  src/infra/system-run-approval-binding.test.ts
→ 3 shards passed, 143 tests

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):

sub/ok.txt        -> OPENED b'ok'
escape/secret.txt -> refused NotADirectoryError 20
leaf              -> refused OSError 62 (ELOOP)

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} to isSymbolicLink().

Proof gap, stated plainly: the pre-fix failure for the two harness scripts is host-conditioned. On Linux the /proc paths 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.

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.
@clawsweeper

clawsweeper Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 22, 2026 00:36
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S maintainer Maintainer-authored PR labels Aug 22, 2026
@steipete
steipete merged commit 89bb601 into main Aug 22, 2026
228 checks passed
@steipete
steipete deleted the steipete/nostalgic-khorana-6f5322 branch August 22, 2026 00:45
@steipete

Copy link
Copy Markdown
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR scripts Repository scripts size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant