refactor(scheduler-sim-decision-trace): split trace sources under the 800-line cap

Task 2.4: outcome capture moves to sched_trace_outcome.c and the
position/host/summary/rollback half of the model to sched_trace_scan.c;
shared helpers go behind sched_trace_internal.h (sti_ prefix). Code is
moved unchanged; every target that compiles the trace sources gets all
four, and the core isolation scan covers the new files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-08 10:16:46 +00:00
parent eacb1fa599
commit 144a01982e
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
40 changed files with 1355 additions and 1094 deletions

View file

@ -82,7 +82,7 @@
- a full allocation with tracing never enabled creates no record.
- _Requirements: 11.1, 11.2, 11.3_
- [ ] 2. Allocator-side capture of scheduler state
- [x] 2. Allocator-side capture of scheduler state
- [x] 2.1 Capture job selection facts, cluster-wide limits and attempt failure reasons, test first
- Selection capture: policy name, the job's queue and queue priority, the job's priority and its queue time.
- Cluster-wide limit capture: each matched limit's name and scope instance, read from the job's matched cluster-wide limits.
@ -114,7 +114,7 @@
- The full scheduler test suite, including the 28 tests updated in 1.6, must still build and pass under ASAN with the completed capture source. Missing scheduler sources are added to those tests, or stubbed.
- _Requirements: 2.5, 6.1, 6.2, 6.3, 6.4, 9.4_
- [ ] 2.4 Split the trace sources under the 800-line file cap, with no behaviour change
- [x] 2.4 Split the trace sources under the 800-line file cap, with no behaviour change
- Added during implementation (2026-10-08, user decision). After 2.3, `sched_trace.c` is 1130 lines and `sched_trace_capture.c` is 1065, both over the scheduler's 800-line cap (src/scheduler/CLAUDE.md).
- Move outcome capture (dispatch, pend, reconstructed record) into a new `src/sched_trace_outcome.c`. Split `sched_trace.c` along a clear seam, e.g. entries and line budget versus counters, summaries and rollback, so every trace source is under 800 lines. Shared static helpers go behind an internal header (e.g. `src/sched_trace_internal.h`); the public `include/sched/trace.h` interface is unchanged.
- Register every new source in the scheduler's main source list, in the core isolation test's scan and no-stdio check, and in each white-box test that includes the trace sources (the 27 from 1.6, plus the trace model, capture and gate tests).
@ -359,3 +359,4 @@
- 2.2: rows go through `sched_trace_row()`, a model addition not named in the design, as CHECK_ROW (cluster-wide check, all rows) or HOST_ROW (host scope, unmet rows only). Host rows are held until the host verdict is stored and then stored one level deeper, each counting against the budget; they are dropped at summary level, where the verdict bits and limit tally are still set. Rows arriving outside an open check (`rec->check_open`) or a host scope are dropped, so 3.3/3.4 must open a host scope before host_iter's pre-filter calls `sched_check_host_satisfy` and must call `sched_trace_check_end` on every exit path of the cluster-wide check. 4.1 must render a NULL row name by its index, `limited_res == NULL` as a raw amount, and HOST_ROW at host depth + 1. Capture now calls librtti `vget()`, which every test already links.
- 2.2 OPEN for 6.2: if `limit_row()` runs out of memory, `sched_trace_check_rows` returns early, so that row's LIMIT bit and later rows' SHORTFALL bits are lost. The verdict derived from rows then becomes SELECT and the Req 9.3 counts are off. This needs fault injection to test, so fix it in 6.2: keep setting the verdict bits and continue.
- 2.3: the outcome capture functions are `sched_trace_capture_dispatch`, `sched_trace_capture_pend` and `sched_trace_rec_reconstructed`, declared in trace.h; 3.x and 5.3 call them. Limit charges are classified by the limit flag or a `limit=` prefix and resolved via glimits (shared) or the worker's hlimits (host, worker looked up by host name). An unresolved charge has `limited_res == NULL`, which is the raw-number fallback. Shared pend entries carry host "" and are treated as host-less. For 4.1: limit totals over omitted hosts have a scope without the host, and a NULL host name yields the scope "h=". Follow-up (low): capture's `key_find`/`vget` on resmgr/workers run without the RTTI read lock that `sched_get_worker` takes. That is safe while the sim runs in lock-step; the 2.4 split may wrap them.
- 2.4: the trace sources are now sched_trace.c (record, arena, entries, budget, requirement/plan/check), sched_trace_scan.c (positions, host verdicts/rows, tallies, rollback, commit, search end), sched_trace_capture.c, sched_trace_outcome.c (dispatch, pend, reconstructed) and sched_trace_internal.h (12 shared `sti_` helpers). Every target that compiles one trace .c file needs all four. Later tasks that extend the trace must keep each file under 800 lines and add new files to the core isolation scan.