--- id: "bug-1834" status: "fixed" status_updated: "2026-09-24" status_note: "" component: "scheduler" severity: "unknown" timestamp: "2026-09-20T09:35:00Z" last_seen: "2026-09-20T10:15:00Z" occurrences: 1 files: ["src/scheduler/src/plugins/limit.c"] tags: ["scheduler", "limit-plugin", "resource-accounting", "mem-vs-maxmem", "swap-vs-maxswap", "percent-limit-capacity", "update_limit_res_value", "instantiate_limit", "design-gap", "user-identified", "needs-owner", "related-to-bug-1831", "related-to-bug-1832", "night_mem_pct"] related: ["bug-1831", "bug-1832"] legacy: true gitea_issue: 61 gitea_synced_status: "fixed" --- # bug-1834: User-identified design gap (not yet reproduced as a live symptom, code-traced and confirmed): for… ## Description User-identified design gap (not yet reproduced as a live symptom, code-traced and confirmed): for a percent-based limit whose `resname` is a dynamic/consumable resource (e.g. `mem`, `swap`), the limit's CAPACITY is computed as percent * the resource's current LIVE value, not percent * the resource's static total. This means the same limit's enforced cap drifts up and down as unrelated memory pressure on the host changes, rather than staying pinned to a stable fraction of total capacity (e.g. 'this queue may use up to 20% of the host's total memory' should not shrink because some other job is currently using more memory). ## Environment _Not recorded (migrated from buglog.json)._ ## Reproduction _Not recorded (migrated from buglog.json)._ ## Root cause update_limit_res_value() (limit.c:142-165) computes `val = get_resvals(array, 1, &(vres->res->idx), &val); val = val * vres->limit->val.val;` for any percent!=0 limit -- `vres->res` is resolved in instantiate_limit() (xcelimit.c:574) via a single key_find(resmgr, limit->val.resname, ...), i.e. exactly the resource named by the limit's OWN `resname` field. `resname` today serves two roles that this code conflates: (1) selecting the accounting/consumable resource the limit's virtual resource (`vres->vres`) is keyed against for usage tracking (correctly `mem`, since jobs consume `mem`), and (2) supplying the live base value multiplied by percent to derive capacity (currently ALSO `mem`, the dynamic worker-reported load index per .kiro/steering/resource-accounting.md -- 'mem is not maxmem... mem is a dynamic load index... refreshed on the worker's regular load-report cadence'). Role (2) should read a static/non-consumable resource instead (`maxmem` for `mem`, `maxswap` for `swap`) -- both already exist as registered per-host resources (src/configs/resources.yaml:108 `maxmem`, :112 `maxswap`, 'self-reported once by the worker at join time and never refreshed' per resource-accounting.md) so no new resource type is needed, only a change to which resource the percent multiplication reads. xce_limit_val_t/xce_limit_config_t (types.h:800-818) have no field today to name this second resource explicitly -- resname is single-purpose in the struct. ## Fix FIXED (2026-09-20). Added xce_vres_t.percent_res (src/include/xce/types.h) -- a resolved xce_resource_t* pointer for the percent-branch capacity read, kept separate from `res` (which stays the limit's own accounting resource, unchanged) so the two roles are no longer conflated. instantiate_limit() (src/lib/xcelimit.c) resolves it ONCE at instantiation time via a small table-driven static lookup (percent_capacity_resource_map[]: mem->maxmem, swap->maxswap) -- table-driven per user request, so a future dynamic/static pair (e.g. tmp/maxtmp) is a one-line addition. A missing/unregistered counterpart is NOT a hard failure: percent_res stays NULL and update_limit_res_value() (src/scheduler/src/plugins/limit.c) falls back to `res`, preserving today's behavior for any resource with no known static pair -- this is what keeps every pre-existing percent-limit test passing unchanged (they never register 'maxmem' in their resmgr fixtures, and none of them exercise update_limit_res_value()'s real computation anyway -- its existing white-box harness, test_repl_limit_table.c, stubs get_resvals()/put_resvals() as no-ops). New coverage: 4 unit tests in src/lib/testsuite/test_limit.c proving percent_res resolves to maxmem/maxswap for mem/swap, stays NULL for percent=0, and stays NULL (graceful fallback, not -ENOENT) for a percent-based limit on a resource with no known static counterpart (e.g. ncpus). Extended the shared src/lib/testsuite/test_resmgr_fixture.c/.h with maxmem/swap/maxswap test resources for this. Full lib (314 tests) and scheduler (85 test binaries) suites pass with zero regressions -- confirmed via raw testlog grep for ':FAIL:', not just the meson aggregate summary. ## Verification _Not recorded (migrated from buglog.json)._ ## References - Related: bug-1831, bug-1832 - Gitea: #61