Skip to content

Latest commit

 

History

History
140 lines (102 loc) · 6.11 KB

io_trace.md

File metadata and controls

140 lines (102 loc) · 6.11 KB

io_trace.sh

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

io_trace.sh observes which files a gate actually reads and writes, and persists that observation as the gate→inputs map.

This is the mechanism that makes sound gate selection possible. affected_set.py can only skip a gate when it knows that gate's real inputs; guessing the inputs from a script's source text is the guess that lets a real regression slip through. So the inputs are measured, not inferred — by running the gate under strace and reading the paths the kernel was actually asked to open.

The load-bearing detail is the syscall layer only ever sees the path after shell expansion. A gate that builds a path dynamically ("$DIR/$name.sh") shows up as the resolved path, not as a template string. A source scanner would record the literal template and then match nothing.

Two subcommands:

Form Meaning
io_trace.sh <gate-script> [args...] Bare form — same as trace.
io_trace.sh trace <gate-script> [args...] Trace one gate, emit its read/write sets.
io_trace.sh build-map [...] Trace every gate under a directory and persist the map.

Prerequisites

  • sh, python3, strace with -f support. Missing strace or python3 is a tracer-level failure (exit 2) — never a silent pass.
  • lib/io_trace_parse.py and lib/io_trace_build_map.py beside it.
  • For build-map: a sections directory of *.sh gate scripts, and a writable map database path.

No environment variables are read.

Usage examples

# observe one gate's inputs; args after the script are passed to the gate
sh scripts/fastcycle/gates/io_trace.sh scripts/gates/cm_fetch_before_edit_audit.sh --root .

# explicit form
sh scripts/fastcycle/gates/io_trace.sh trace scripts/gates/some_gate.sh

# rebuild the persisted map, re-tracing only scripts whose hash changed
sh scripts/fastcycle/gates/io_trace.sh build-map \
  --sections-dir device/rockchip/rk3588/tests \
  --db .cache/fastcycle/io_map.sqlite

# trace device-mutating scripts (refused by default — see below)
sh scripts/fastcycle/gates/io_trace.sh build-map --allow-device-scripts

# bound each traced script
sh scripts/fastcycle/gates/io_trace.sh build-map --per-script-timeout 120

trace prints exactly one JSON object on stdout:

{"reads": ["/abs/path/a", "..."], "writes": ["/abs/path/b"]}

Exit codes

Code Meaning
0 The trace succeeded. This is exit 0 even when the traced gate itself failed — the tracer observes, it does not judge.
2 Tracer-level failure: strace unavailable, python3 unavailable, the gate script missing or unreadable, or a usage error.

The distinction is the point: a 1 here would be indistinguishable from "the gate failed", so tracer faults use 2 and never 0/1.

build-map exits 0 on a completed map build and 2 on the same tracer-level failures.

Classification rules

For each observed path argument of an openat / stat / newfstatat / lstat / execve call:

  • openat with O_WRONLY, O_RDWR or O_CREAT → write;
  • any other openat → read;
  • any stat-family call → read. Deciding on a file's existence is genuinely consuming it as an input, which is why stat counts as a read rather than being ignored.

Noise filtered out, as a documented and reviewable list rather than an unstated heuristic: /lib/, /lib64/, /usr/lib/, /etc/ld.so.cache, /etc/ld.so.preload, /proc/, /dev/, /sys/, /etc/nsswitch.conf, /etc/localtime. These are what a traced sh interpreter opens during its own startup. A tracer that leaked them into the reported set would be a §11.4.201(1) false positive on the tracer itself.

Edge cases

  • A dynamically built path. Reported resolved, never as the template — this is the golden-bad fixture the tracer exists to satisfy.
  • Device-mutating scripts. build-map refuses to trace a script matching a device-mutating pattern (adb, reboot, settings put, flash/power-cycle tooling, rm -rf outside a scratch tree) unless --allow-device-scripts is passed. Tracing executes the gate for real, so this is a host- and device-safety refusal, not a style preference (§12, §11.4.225).
  • Unchanged scripts. build-map computes each script's content sha256 and re-traces only those whose hash differs from, or is absent in, the persisted map. Re-tracing everything is the backstop's job, not this subcommand's.
  • A gate that hangs. Bounded by --per-script-timeout; without a bound, a hanging gate hangs the map build.
  • strace present but lacking -f. Not probed separately; a failure surfaces as a tracer-level 2.

Internal behaviour

  1. Validates subcommand and arguments (exit 2 via the usage path).
  2. Requires strace and python3 before doing any work (exit 2 if absent).
  3. Runs the gate under strace -f -e trace=openat,stat,newfstatat,lstat,execve in the current (already-clean) checkout.
  4. Parses the raw strace log for path arguments, classifies each as read or write, and drops the documented noise prefixes.
  5. Emits one JSON object on stdout and exits 0.

build-map additionally walks --sections-dir for *.sh, hashes each, applies the device-mutating refusal, and delegates the incremental re-trace and persistence to lib/io_trace_build_map.py.

Related scripts

Called by scripts/fastcycle/gates/backstop.sh, scripts/fastcycle/gates/lib/gate_runner_order.py, scripts/fastcycle/gates/lib/gate_runner_shard.py and scripts/fastcycle/review/lib/precheck_pack_run.py.

Calls scripts/fastcycle/gates/lib/io_trace_parse.py, scripts/fastcycle/gates/lib/io_trace_build_map.py.

Guarded by scripts/fastcycle/tests/test_io_trace_red.sh (T052), fixtures under scripts/fastcycle/tests/fixtures/io_trace/.

See also docs/scripts/affected_set.py.md (the consumer of this map) and docs/scripts/gate_runner.sh.md.

Last verified

2026-12-04 — bash -n scripts/fastcycle/gates/io_trace.sh → exit 0. sh scripts/fastcycle/gates/io_trace.sh with no arguments prints the three-form usage block on stderr and exits 2.