fix(scheduler): cache hits keep the full pend reason; sim uses the cache (bug-1932)

The session-level unsatisfiable-resreq cache stored only the exhausted
attempt's main reason (an int). The allocators record shortfalls as
per-host/per-resource entries and leave main_reason at 0, so every cache
hit in the live scheduler pended its job with an empty reason. The
simulator registered no cache at all (its table lived on xce_scheduler_t),
so it searched every identical pending job again and its traces differed
from production.

- The cache table moves to xce_sched_core_t; cache_lookup/insert/clear and
  the hook adapters take the core, with no cast to a driver struct.
  sched_init() builds it, cache_clear() rebuilds it per session,
  xce_sched_core_fini() destroys it.
- A cache entry is a deep copy of the attempt's full xce_job_preason_t
  plus the job that proved the request unsatisfiable (core->alloc_jobid,
  set by sched_allocator()). A hit moves a copy into ctx->reason; a miss
  leaves ctx->reason untouched.
- main.c passes the same three adapters to the simulator through new
  sched_sim_args_t fields; sched_sim_driver_start() sets them on the sim
  core (plain field writes: white-box tests include sim.c alone).
- Decision trace: a hit renders "no plan generated: skipped, same request
  as <job> proved unsatisfiable earlier this session" (new
  XCE_TRACE_NOPLAN_KNOWN_UNSAT via sched_trace_known_unsat()); the outcome
  shows the restored reasons.
- sim_verify keeps its main-only PEND compare (old recordings carry
  main-only hits); comments and the scheduler-sim-live-allocation design
  note updated.

Tests: full-reason assertions in the cache dispatch tests (RED before:
"a cache hit must restore the original attempt's FULL pend reason"),
test_alloc_cache.c ported to the new API (deep copy, clear frees, -EEXIST
frees), a sim-registered clear test, a renderer test, and a sim e2e
scenario with two identical unsatisfiable jobs (204, 205) where 205 is
skipped with 204's full reasons (RED before: no skip line).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-09 08:02:18 +00:00
parent cff3304f5d
commit 0317c7af98
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
27 changed files with 982 additions and 737 deletions

View file

@ -175,27 +175,6 @@ typedef struct {
typedef struct {
xce_sched_core_t core;
xcecli_ctx_t apictx;
/* Req 7.1 (scheduler-allocation spec, task 2.2): the per-session
* unsatisfiable-resreq fingerprint cache -- a kvtab_t (kv.h, RTTI `var`)
* keyed by xce_cache_key_t (sched/alloc_cache.h), value = a pend-reason
* category boxed as (void*)(intptr_t)category (Req 7.5). Constructed in
* sched_init(), destroyed in sched_fini() (scheduler.c) -- both minimal
* construct/destroy calls only, using the exported cache_key_ops
* (sched/alloc_cache.h), mirroring xce_select.c's sel_node_table_init()
* convention for a composite-struct-keyed kvtab_t. Lookup/insert
* (cache_lookup()/cache_insert(), alloc_cache.c) are confined to the
* allocator thread; NULL until sched_init() constructs it.
*
* NOTE (task 2.2 CONCERN, for a later task's attention): Req 7.2
* requires cache_clear() to run inside core_begin_session_internal()
* (core_session.c), which only receives xce_sched_core_t* core, not
* xce_scheduler_t* -- this field lives on the outer driver struct per
* this task's own scope, not on `core` above. Wiring AC 2's clear call
* is explicitly a later task (tasks.md 5.2), not this one; whoever
* implements it will need to either reach the owning xce_scheduler_t
* from `core` (core is this struct's first member, so the standard
* pointer-to-first-member idiom applies) or relocate this field. */
var unsatisfiable_cache;
xce_cluster_config_t
cluster_cfg; /* HA candidate list. Empty (candidates_count==0) only
* transiently before sched_init() runs, when no