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

@ -173,22 +173,24 @@ int __wrap_sched_meet_host_selection(xce_sched_core_t* core,
static int g_lookup_cb_calls = 0;
static int g_populate_cb_calls = 0;
static int spy_unsatisfiable_lookup_cb(xce_sched_core_t* core,
static int spy_unsatisfiable_lookup_cb(xce_sched_core_t* core,
xce_sched_obj_t* obj,
int* out_reason_category)
xce_job_preason_t* out_reasons,
uint64_t* out_jobid)
{
g_lookup_cb_calls++;
return xce_alloc_cache_lookup_cb(core, obj, out_reason_category);
return xce_alloc_cache_lookup_cb(core, obj, out_reasons, out_jobid);
}
static void spy_unsatisfiable_populate_cb(xce_sched_core_t* core,
xce_sched_obj_t* obj,
int reason_category)
static void spy_unsatisfiable_populate_cb(xce_sched_core_t* core,
xce_sched_obj_t* obj,
const xce_job_preason_t* reasons,
uint64_t jobid)
{
g_populate_cb_calls++;
xce_alloc_cache_populate_cb(core, obj, reason_category);
xce_alloc_cache_populate_cb(core, obj, reasons, jobid);
}
void setUp(void) { return; }
@ -451,6 +453,21 @@ static void test_standalone_primary_cache_hit_skips_allocator(void)
decision2->u.reason->reasons->main_reason,
"a cache hit must attribute the SAME pend reason category as the "
"original unsatisfiable determination (Req 7.5)");
/* bug-1932: job 1's real cause is per-host (the worker's slots
* shortfall), with main reason 0; a hit that keeps only the main
* reason pends job 2 with an EMPTY reason. */
TEST_ASSERT_TRUE_MESSAGE(
(decision1->u.reason->reasons->nhost_reasons
+ decision1->u.reason->reasons->nres_reasons)
> 0,
"fixture: job 1's exhausted attempt must record a per-host or "
"per-resource reason (its one worker has no free slots)");
TEST_ASSERT_TRUE_MESSAGE(
job_preason_eq(decision1->u.reason->reasons,
decision2->u.reason->reasons, NULL),
"bug-1932: a cache hit must restore the original attempt's FULL "
"pend reason (main, per-host and per-resource), not only its main "
"reason");
TEST_ASSERT_EQUAL_INT_MESSAGE(
2, g_lookup_cb_calls,
"job 2's cache hit must also be consulted through core->"