Skip to content

feat(fspy): detect nested fspy tracking across Linux, macOS, and Windows - #1034

Open
wan9chi wants to merge 1 commit into
fspy-linux/4-linux-elf-sigsys-trackerfrom
fspy-linux/5-nested-fspy-detection
Open

wan9chi wants to merge 1 commit into
fspy-linux/4-linux-elf-sigsys-trackerfrom
fspy-linux/5-nested-fspy-detection

Conversation

@wan9chi

@wan9chi wan9chi commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Motivation

When a cached vp run task invokes a nested vp run subprocess (for example, through a wrapper script or package script), attempting to install a second automatic file-access tracker inside an already-tracked process either fails (on Linux, where #1029 removes the Linux-only mincore/process_vm_readv probe and rejects nested fspy_preload_linux mappings with EEXIST) or duplicates interception and breaks outer tracking (on macOS and Windows).

Summary

  • Shared sentinel probe (fspy_shared::probe): Define hardcoded random-GUID sentinel paths beneath the OS null device (/dev/null/fspy_probe_92e41940-369e-42f1-876f-a8e2a614fbf2 on Linux and macOS, \??\NUL\fspy_probe_92e41940-369e-42f1-876f-a8e2a614fbf2 on Windows).
  • Preload short-circuiting across all platforms:
    • Linux (fspy_elf_loader + fspy_preload_linux): Add SyscallAction::Return(isize) and short-circuit Sysno::faccessat matching the sentinel path to Ok(SyscallAction::Return(0)) without recording a PathAccess.
    • macOS (fspy_preload_macos): Short-circuit faccessat matching the sentinel path to return 0 without recording a PathAccess.
    • Windows (fspy_preload_windows): Short-circuit NtQueryAttributesFile matching the sentinel path to zero-fill FILE_BASIC_INFORMATION and return STATUS_SUCCESS without recording a PathAccess.
  • Cached nested detection and clean delegation (fspy):
    • Probe the sentinel path directly via faccessat / NtQueryAttributesFile, cached process-wide in OnceLock<bool>.
    • When nested, run child commands directly without installing a second tracker (leaving the outer tracker to capture all nested accesses) and report UntrackedReason::Nested instead of UntrackedReason::Incomplete.
  • Dedicated user-facing cache-not-updated reason (vt):
    • Introduce CacheNotUpdatedReason::NestedTracking / SavedCacheNotUpdatedReason::NestedTracking explaining that automatic file tracking is already active in a parent task and that configuring input and output manually still enables caching on the nested task.
  • Note on mixed versions: If an older outer vp binary (without the sentinel probe interceptor) spawns a newer inner vp, the sentinel probe will not be intercepted and will fall back to the existing behavior.

Stacked on #1029.


Note

Medium Risk
Touches cross-platform syscall interception and cache eligibility logic; mistakes could break automatic tracking or allow incorrect caching of nested tasks.

Overview
Fixes nested vp run inside an already-tracked parent (e.g. wrapper scripts) by detecting an outer fspy instance on Linux, macOS, and Windows instead of installing a second tracker.

A shared null-device sentinel probe (fspy_shared::probe) is used: inner fspy probes a fixed GUID path under /dev/null or \??\NUL; outer preloads short-circuit that lookup to success without logging a file access (Linux adds SyscallAction::Return, macOS faccessat, Windows NtQueryAttributesFile). When nested, spawns run untracked and report UntrackedReason::Nested (replacing the single TrackingIncomplete type with Incomplete | Nested).

In vt, nested runs skip auto-cache with a dedicated NestedTracking reason and user message; the outer task still records nested file I/O. Integration and e2e tests cover delegation and that the sentinel path is not recorded.

Reviewed by Cursor Bugbot for commit e970d5c. Bugbot is set up for automated code reviews on this repo. Configure here.

@wan9chi
wan9chi force-pushed the fspy-linux/5-nested-fspy-detection branch from 297ebcc to ecbc3ce Compare November 28, 2026 04:49
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  +0.43%  [ -1.57% ..  +3.11%]  overhead  +112.20%
dynamic/access             change  -0.12%  [ -1.60% ..  +1.21%]  overhead  +386.54%
dynamic/access-relative    change  +0.10%  [ -0.91% ..  +1.19%]  overhead  +428.99%
dynamic/access-contended   change  -2.39%  [ -4.69% ..  +2.55%]  overhead  +161.50%
static/launch              change  +0.31%  [ -1.75% ..  +2.62%]  overhead  +245.71%
static/access              change  +0.11%  [ -1.10% ..  +1.56%]  overhead  +381.48%
static/access-relative     change  -0.10%  [ -1.30% ..  +1.53%]  overhead  +424.52%
static/access-contended    change  +0.28%  [ -4.69% ..  +3.96%]  overhead  +178.60%

macos

dynamic/launch             change  +0.26%  [ -2.09% ..  +3.11%]  overhead  +207.83%
dynamic/access             change  -0.39%  [ -2.77% ..  +2.89%]  overhead    +6.89%
dynamic/access-relative    change  -0.60%  [ -4.17% ..  +2.23%]  overhead  +265.78%
dynamic/access-contended   change  +1.93%  [ -2.65% ..  +4.59%]  overhead    +3.63%

windows

dynamic/launch             change  -0.29%  [ -1.85% ..  +1.37%]  overhead   +27.29%
dynamic/access             change  +0.00%  [ -0.95% ..  +0.74%]  overhead    +0.76%
dynamic/access-relative    change  +0.00%  [ -0.55% ..  +0.92%]  overhead    +1.11%
dynamic/access-contended   change  +0.00%  [ -0.71% ..  +0.53%]  overhead    +1.25%

@wan9chi
wan9chi force-pushed the fspy-linux/5-nested-fspy-detection branch 3 times, most recently from 2d67721 to 8c84032 Compare November 28, 2026 04:59
…-device sentinel probe

Co-authored-by: Gemini 4 Neon <noreply@google.com>
@wan9chi
wan9chi force-pushed the fspy-linux/5-nested-fspy-detection branch from 8c84032 to e970d5c Compare November 28, 2026 05:07
@wan9chi
wan9chi added this pull request to stack #1030 November 28, 2026 05:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant