Skip to content

refactor(task-runner): share the tracker wire format, document unsafe, validate seccomp jumps - #250

Merged
prisis merged 4 commits into
nextfrom
t3/fspy-shared-protocol-safety
Nov 25, 2026
Merged

prisis merged 4 commits into
nextfrom
t3/fspy-shared-protocol-safety

Conversation

@prisis

@prisis prisis commented Nov 25, 2026

Copy link
Copy Markdown
Member

What

A code-review pass over the tracker crates under packages/tooling/task-runner/native/, in three commits.

  1. Shared wire format. The macOS dylib, the Windows DLL and their two parents each had their own copy of the opcodes, the [u8 op][path] framing, the buffer sizes, the pipe name and the opcode→kind table. They now share one dependency-free crate, fspy_wire:
    • the opcodes, plus begin/encode (no allocation, never panics, for use inside arbitrary processes), decode, kind_name and pipe_name;
    • the buffer caps (DATAGRAM_MAX, PIPE_MESSAGE_MAX) and the reporting-socket env name.
      It is a workspace member, so plain cargo test runs its 14 tests. The Linux tracker has no injected library (the kernel delivers notifications), so fspy_seccomp does not use it.
  2. unsafe and constants.
    • Every unsafe block in fspy_macos, fspy_windows, fspy_seccomp and the root addon (src/macos.rs, src/windows.rs, src/seccomp.rs) has a // SAFETY: comment, and clippy::undocumented_unsafe_blocks = "warn" is set in each of those Cargo.tomls.
    • Magic numbers are named:
      • the Windows write-intent flags come from windows-sys;
      • SECCOMP_IOCTL_NOTIF_RECV/SEND come from libc (so the minimum libc is now 0.2.187);
      • the AUDIT_ARCH_* values are built from libc's EM_*;
      • the syscall table is built from libc::SYS_* (aarch64 renameat is a local const because glibc's libc lacks it);
      • poll/pipe sizes, handle counts, helper exit codes and FSPY_SOCK are named constants.
    • Compile-time assertions pin every libc syscall number and ioctl to the kernel's value.
  3. Seccomp jump validation. build_program no longer counts offsets by hand: each jump to the notify return is recorded when pushed and patched once its position is known. validate_program (also a debug_assert!) checks that the program ends in ret ALLOW, ret USER_NOTIF, uses only expected opcodes, and that every jump stays in bounds and lands on the notify return. New tests cover valid programs and corrupted offsets.
  4. CI. The fspy crates are outside the workspace, so the existing clippy step never linted them. Clippy now runs on fspy_seccomp (Linux job) and on the native addon plus fspy_macos/fspy_windows on the macOS/Windows runners. The path filters, macOS native paths and the build cache key include fspy_wire.

Behaviour is unchanged, with one unreachable difference: the Windows parent now maps opcode 4 to "missing" like macOS does. The DLL never sends it.

Verification

Run locally on macOS (aarch64):

  • cargo fmt --check for the root workspace and for fspy_macos, fspy_windows, fspy_seccomp.
  • cargo clippy --all-targets -- -D warnings for the root workspace, fspy_macos, fspy_windows, fspy_seccomp, and the root crate, on x86_64/aarch64 Linux gnu, x86_64/aarch64 Linux musl (fspy_seccomp) and x86_64 Windows msvc (root + fspy_windows).
  • cargo test for the root workspace (fspy_wire 14, task-runner-core 169, plus the rest), fspy_macos and fspy_windows (the platform-independent path/pe tests, 20).
  • cargo deny --workspace check: ok. Cargo.lock files only gain fspy-wire.
  • The compile-time pins (syscall numbers, ioctl values, struct sizes) are evaluated by the cross-target clippy/check runs. I confirmed a wrong number fails the build.
  • An end-to-end run of the rebuilt macOS dylib: a C probe under DYLD_INSERT_LIBRARIES sent read, stat, missing and write datagrams in the expected [op][path] layout.
  • The new filter.rs tests (builder, validate_program, corrupted offsets) were executed against a scratch harness that compiles the real filter.rs with a stand-in libc (hand-typed constant values). That shows the logic works. It does not show the Linux tests pass.

Compile-checked only (not run here): all fspy_seccomp tests and the Linux/Windows code paths, via cargo check --tests / clippy for the targets above.

Never run locally: the Windows runtime (DLL injection, named pipe), the Node/vitest suites (no node_modules here), and the new CI steps. CI covers those.

task-runner-core has no fspy code and was left alone (it has its own unsafe, not touched here).

🤖 Generated with Claude Code

prisis and others added 3 commits November 25, 2026 12:24
…afe blocks

The macOS dylib, the Windows DLL and the two parents each carried their own
copy of the opcodes, the `[op][path]` framing, the buffer sizes, the pipe name
and the opcode-to-kind table. They now come from one dependency-free
`fspy_wire` crate: opcodes, `begin`/`encode` (no allocation, never panics, for
use inside arbitrary processes), `decode`, `kind_name`, `pipe_name`, the
datagram/pipe buffer sizes and the reporting-socket env name. It is a workspace
member, so plain `cargo test` runs its tests.

Every `unsafe` block in the macOS dylib, the Windows DLL and the two parents
now states its invariant in a `// SAFETY:` comment, and
`clippy::undocumented_unsafe_blocks` is set to warn in those crates.

Magic numbers are named: the write-intent access flags come from
`windows-sys`, and the pipe wait, pipe sizes, `poll` timeout and handle counts
are named constants or derived from the array they describe.

Behaviour is unchanged. Opcode 4 (`missing`) now maps to "missing" on the
Windows parent too; the DLL never sends it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ers, document unsafe

The filter no longer counts jump offsets by hand. Each jump to the notify
return is recorded as it is pushed and patched once that return's position is
known. `validate_program` checks that the program ends in `ret ALLOW` then
`ret USER_NOTIF`, uses only the expected opcodes, and that every jump stays
inside the program and lands on the notify return. It runs as a
`debug_assert!` in `build_program` and is covered by tests, including
corrupted offsets.

`AUDIT_ARCH_*` values are built from libc's `EM_*` numbers and the audit
flags, and `__X32_SYSCALL_BIT` gets a name; the tests use the same constants.
`SECCOMP_IOCTL_NOTIF_RECV`/`SEND` come from libc (>= 0.2.187) instead of a
hand-rolled `_IOWR`, with a test pinning them to the kernel macro's values.
The syscall table is built from libc's `SYS_*` constants for the build target
(aarch64's `renameat`, which glibc's libc lacks, is a local constant), and
compile-time assertions pin each of them to the kernel's number. The helper's
exit codes and the `FSPY_SOCK` name are named constants, shared between the
helper and the library.

Every `unsafe` block carries a `// SAFETY:` comment, and
`clippy::undocumented_unsafe_blocks` is set to warn for the crate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The fspy crates are outside the cargo workspace, so the existing clippy step
never linted them or the `cfg`-gated macOS/Windows sources. Clippy now runs on
`fspy_seccomp` (Linux job), and on the native addon plus `fspy_macos` /
`fspy_windows` on the macOS and Windows runners. The path filters, the macOS
native paths and the build cache key include the new `fspy_wire` crate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo did not review this PR because this workspace reached its daily trial limit of 100 reviews. Reviews start again at 00:00 UTC. Choose a plan to continue now.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34543a49-01da-436e-bdce-24d0a2fb8cca

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions github-actions Bot added package: task-runner size:XXL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list. labels Nov 25, 2026
…assertion

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@prisis
prisis deployed to benchmarks November 25, 2026 11:26 — with GitHub Actions Active
@codspeed

codspeed Bot commented Nov 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

🆕 7 new benchmarks
⏩ 113 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 file_hasher/hash_bytes[1048576] N/A 1.2 ms N/A
🆕 file_hasher/hash_bytes[4096] N/A 9.3 µs N/A
🆕 file_hasher/hash_bytes[65536] N/A 79.1 µs N/A
🆕 graph/find_all_cycles/200 N/A 5.7 ms N/A
🆕 graph/topological_sort[200] N/A 4.7 ms N/A
🆕 graph/topological_sort[600] N/A 23 ms N/A
🆕 graph/get_transitive_deps/200 N/A 5.2 ms N/A

Comparing t3/fspy-shared-protocol-safety (02e862f) with next (1078fa9)2

Open in CodSpeed

Footnotes

  1. 113 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on next (b2ddc1c) during the generation of this report, so 65c051d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@prisis
prisis merged commit 883492e into next Nov 25, 2026
27 of 40 checks passed

This branch was successfully deployed

1 active deployment
benchmarks — 02e862f8 Deployed Nov 25, 2026 by prisis via Bench native (task-runner) #420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: task-runner size:XXL Size of the change, tests and generated files excluded. vouch:trusted PR author is a collaborator, a bot or on the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant