--- id: "bug-1602" status: "fixed" status_updated: "2026-09-24" status_note: "" component: "scheduler" severity: "unknown" timestamp: "2026-08-20T08:30:00Z" last_seen: "2026-09-19T09:00:00Z" occurrences: 1 files: ["src/scheduler/src/repl_break.c", "src/scheduler/src/sim.c"] tags: ["scheduler", "repl", "sim", "replay", "session", "feature", "observability"] related: ["bug-1595"] legacy: true --- # bug-1602: User request: scheduler simulation mode should show event time and session when events occur, and… ## Description User request: scheduler simulation mode should show event time and session when events occur, and loading a replay file should show its total session count up front. ## Environment _Not recorded (migrated from buglog.json)._ ## Reproduction _Not recorded (migrated from buglog.json)._ ## Root cause Feature gap, not a defect: repl_print_event_summary() (interactive REPL event echo) printed only the event type/payload, no clock time or session number; sched_sim_driver_start() never reported how many sessions a loaded .replay file contains before stepping through it. ## Fix repl_print_event_summary() now prefixes each echoed event with "[sim] t= () session=". Non-obvious correctness point found via sim_loop.c inspection (not assumption): events are read+echoed individually AS THEY STREAM from the file, and the ReplaySession/begin_round message for that batch -- which is what increments rs->session_count via xce_repl_on_begin_round() -- comes AFTER those events in file order (file layout is event,event,...,ReplaySession). So every echoed event always belongs to the UPCOMING session; the function reports session_count+1, not the raw count. A first attempt using the raw count failed its own new test (session=0 instead of session=1) and was corrected after tracing the real sim_loop.c call order (xce_repl_check_event at line ~593 vs xce_repl_check_begin_round at ~631) rather than trusting the repl.h doc comment's summary. Added sim_prescan_session_count() (sim.c): scans sim->replay_file from the current position using msg_root_has_shape() shape-only classification (ReplayEvent/ReplaySession/SnapshotEntry, matching sim_loop.c main loop's own three-way dispatch) to count ReplaySession messages, then rewinds via fseek back to the captured ftell() position -- mirrors sim_locate_and_load_snapshot()'s own established rewind pattern. Confirmed safe via research: capn_init_fp() in this codebase is always unpacked (packed=0), reading via a single plain fread() per message with no internal read-ahead buffer, so ftell/fseek stay exactly in sync with message boundaries. Wired into sched_sim_driver_start() right after sim_set_virtual_clock(): prints "[sim] replay file contains N sessions" once at load, non-fatal on scan failure. User explicitly chose this pre-scan approach over a recording-time trailer message (would have required a schema change and only worked for newly-recorded files) via AskUserQuestion. Added test_replay_load_reports_total_session_count (2-session fixture) and extended test_step_echoes_events_before_session_decisions with t=/session=1 assertions in test_repl_breakpoints_inspection.c. Full scheduler suite: 42/43 Ok, only pre-existing unrelated bug-1560 remains (now 3 occurrences). ## Verification _Not recorded (migrated from buglog.json)._ ## References - Related: bug-1595