feat(scheduler-allocation): clear unsatisfiable-resreq cache per session

Clear the cache inside core_begin_session_internal() so a job cached as
unsatisfiable in one session is re-evaluated fresh in the next (Req 7.2).

An initial weak-symbol cast-based approach was rejected: it corrupted
xce_sched_sim_driver_t.alt_events_file, since core_begin_session_internal()
is shared between driver.c (real xce_scheduler_t) and sim_loop.c (a
structurally different, deliberately isolated sim driver struct with no
cache field at the same byte offset) -- the strong cache_clear() symbol
won unconditionally for both, invisible to ASAN and untested by any
test_sim_*.c file.

Fixed via a driver-registered callback: xce_sched_core_t gains a
cache_clear_cb hook (NULL by default, per xce_sched_core_init()'s
full-struct memset), set only in main.c's driver-mode branch --
mirroring the existing on_decision/xce_core_set_decision_cb() pattern.
--sim mode returns before that registration is ever reached, so its hook
stays NULL and core_begin_session_internal()'s guarded call is a no-op.
The real xce_scheduler_t-casting adapter lives in alloc_cache.c rather
than driver.c, since ~11 tests white-box-include driver.c without
linking alloc_cache.c.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XYdtrEWWZfKRRGED7raEYg
This commit is contained in:
Rongsong Shen 2026-09-05 00:57:46 +00:00
parent 5c022d0b4f
commit e8c2087d5e
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
9 changed files with 614 additions and 4 deletions

View file

@ -1579,6 +1579,58 @@ sched_alloc_cache_test = executable(
dependencies: [scheduler_test_deps],
install: false)
# Unit test for task 5.2 (scheduler-allocation spec, Req 7.2): clearing the
# unsatisfiable-resreq cache at the start of every scheduling session, from
# inside core_begin_session_internal() (core_session.c), via the
# driver-registered xce_core_cache_clear_cb_t hook (round 2 -- replaces
# round 1's unconditional weak-symbol cache_clear() call, found to be a
# CRITICAL type-confusion bug against simulation-mode sessions; see
# test_sim_cache_clear_isolation_test below). See this test file's own
# header comment for why it lists core.c/core_clock.c/core_session.c/
# decision.c/alloc_cache.c as genuinely SEPARATE compiled sources rather
# than white-box #include-ing them into one TU (the same "real,
# separately-linked scheduler internals" technique task 5.1's own
# sched_cache_dispatch_test above already established for this feature,
# scaled down to just the files this narrower test needs) -- this test's
# own registered cache_clear_cb calls the REAL, strong cache_clear()
# (alloc_cache.c), which is only meaningfully distinguishable from a stub
# across genuinely separate object files, never within one merged
# translation unit.
sched_core_session_cache_clear_test = executable(
'sched_core_session_cache_clear_test',
['test_core_session_cache_clear.c',
'../src/core.c',
'../src/core_clock.c',
'../src/core_session.c',
'../src/decision.c',
'../src/alloc_cache.c'],
include_directories:[incdir],
dependencies: [scheduler_test_deps],
install: false)
# Regression test for task 5.2 ROUND 2 (scheduler-allocation spec, Req 7.2):
# the CRITICAL defect that got round 1 REJECTED -- core_begin_session_
# internal() must NEVER touch xce_sched_sim_driver_t's alt_events_file (or
# any other sim-only field) even with alloc_cache.c's real, strong
# cache_clear(xce_scheduler_t*) linked into the same binary, because
# sim_loop.c never registers a cache_clear_cb (Req 5 AC 17 "Simulation
# isolation" -- a simulation-mode core has no cache to clear at all). Same
# separate-compiled-sources technique as sched_core_session_cache_clear_test
# above, for the same reason: this test needs the real, strong
# cache_clear() actually present in the binary to prove the NULL-hook path
# still never calls it.
sched_sim_cache_clear_isolation_test = executable(
'sched_sim_cache_clear_isolation_test',
['test_sim_cache_clear_isolation.c',
'../src/core.c',
'../src/core_clock.c',
'../src/core_session.c',
'../src/decision.c',
'../src/alloc_cache.c'],
include_directories:[incdir],
dependencies: [scheduler_test_deps],
install: false)
# Task 3.1 (scheduler-allocation spec, Req 9.1, 4.6): seqjob_allocator.c's
# rewrap onto the shared plan_iter/host_iter interfaces, plus the new
# maxTasks==1 guard on seqjob_prepare_allocation() (Req 4.6). Same
@ -1823,6 +1875,12 @@ test('scheduler host iter test',
test('scheduler alloc cache test',
sched_alloc_cache_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
test('scheduler core session cache clear test',
sched_core_session_cache_clear_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
test('scheduler sim cache clear isolation test',
sched_sim_cache_clear_isolation_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])
test('scheduler seqjob allocator test',
sched_seqjob_allocator_test, suite: 'scheduler',
env: ['ASAN_OPTIONS=detect_leaks=0'])