feat(kvb-org-queue): cap the booked RAM share per kind with ram_cap_percent
Operator order relayed by Main on 2026-11-14 22:25: book at most 30 % RAM for test jobs.
learn() folds ram_cap_percent {kind: percent} into each kind the way it folds light_kinds;
footprint() and ceiling() book min(share, cap), while the learned shares and the history
rows stay raw. A cap map that is not {kind: percent above 0 up to 100} makes hold exit 2,
keeps fresh() on the last good config and makes admit refuse. learning.md documents the
key and the re-hold after an install.
Security acceptances (kvb-think-criticize with an independent skeptic; false positives or
by design, all in unchanged lines of the touched files): MEDUSA-MM-SCAN-058 queue.py 375
377 621 623 624 629 630 633 634; MEDUSA-ACP-SCAN-028 queue.py 297; MEDUSA-RT-SCAN-054
queue.py 731; MEDUSA-AI-BACKDOOR-006 queue.py 746 806 1140 1166 1189 1190 1243 and
history.py 353; MEDUSA-WM-SCAN-780 queue.py 1215.
🎯 Fix: 88 %
💥 Break: 3 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: ~100 %
🏆 Score: 85
🚦 Gate: ⛔ fix 88 % < 90
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b95e305db0
commit
e1445cb88b
5 files changed
+96
-17
No files matched your search
@@ -1339,6 +1339,21 @@ class TestHistory(unittest.TestCase):
|
||||
signatures, kinds = self.learn(small[:4])
|
||||
self.assertIsNone(footprint("test", ("make test",), signatures, kinds))
|
||||
|
||||
def test_the_ram_cap_lowers_what_footprint_and_ceiling_book_and_leaves_the_learned_shares_raw(self):
|
||||
small = [history_row(n, signature="make test", mem_max=25, cpu_max=20) for n in range(5)]
|
||||
big = [history_row(n + 5, kind="quality-high", signature="make verify-test", mem_max=80, cpu_max=90) for n in range(5)]
|
||||
cfg = {"load_limits": {"mem_percent": 80, "cpu_percent": 90}, "ram_cap_percent": {"quality-high": 30, "test": 90}}
|
||||
signatures, kinds = self.history.learn([*small, *big], NOW, cfg)
|
||||
for booked in (self.history.footprint, self.history.ceiling):
|
||||
with self.subTest(booked=booked.__name__):
|
||||
self.assertEqual(booked("quality-high", ("make verify-test",), signatures, kinds), {"ram": 30, "cpu": 80})
|
||||
self.assertEqual(booked("test", ("make test",), signatures, kinds), {"ram": 5, "cpu": 10})
|
||||
self.assertEqual((kinds["quality-high"]["ram_share"], signatures["quality-high", "make verify-test"]["ram_share"]), (60, 60))
|
||||
self.assertEqual((kinds["quality-high"]["ram_cap"], kinds["test"]["ram_cap"]), (30, 90))
|
||||
signatures, kinds = self.learn([*small, *big])
|
||||
self.assertIsNone(kinds["quality-high"]["ram_cap"])
|
||||
self.assertEqual(self.history.footprint("quality-high", ("make verify-test",), signatures, kinds), {"ram": 60, "cpu": 80})
|
||||
|
||||
def test_slot_limits_take_the_learned_limit_else_the_seed_and_a_smaller_cap(self):
|
||||
kinds = {"deploy": {"limit": 3}, "build": {"limit": None}}
|
||||
self.assertEqual(self.history.slot_limits(kinds, {"deploy": 2, "swarm": 0, "test": 9}, ["test", "gate"]), {
|
||||
@@ -1806,6 +1821,21 @@ class TestQueueCommands(unittest.TestCase):
|
||||
with self.subTest(error=error), mock.patch.object(queue.watch, "load_config", side_effect=error):
|
||||
self.assertEqual(queue.fresh(good), good)
|
||||
|
||||
def test_a_broken_ram_cap_keeps_the_last_good_config_and_a_hold_refuses_it(self):
|
||||
queue = _load(QUEUE)
|
||||
good = {**self.cfg, "ram_cap_percent": {"test": 30}}
|
||||
capped = {**self.cfg, "ram_cap_percent": {"test": 30, "quality-high": 100}}
|
||||
with mock.patch.object(queue.watch, "load_config", return_value=capped):
|
||||
self.assertEqual(queue.fresh(good), capped)
|
||||
for caps in ({"test": 0}, {"test": 101}, {"test": "30"}, {"test": True}, {"test": float("nan")}, [30]):
|
||||
with self.subTest(caps=caps), mock.patch.object(queue.watch, "load_config", return_value={**self.cfg, "ram_cap_percent": caps}):
|
||||
self.assertEqual(queue.fresh(good), good)
|
||||
self.config.write_text(json.dumps({**self.cfg, "ram_cap_percent": {"test": 101}}), encoding="utf-8")
|
||||
result = self.run_queue("hold", "--kind", "test", "--task", "work/a", "--session", "s1", "--", "true")
|
||||
self.assertEqual(result.returncode, 2)
|
||||
self.assertIn("ram_cap_percent is no {kind: percent above 0 up to 100} map", result.stderr)
|
||||
self.assertFalse((self.root / "queue.json").exists())
|
||||
|
||||
def test_hold_takes_the_need_learned_for_its_command_from_both_history_files(self):
|
||||
self.cfg["slot_limits"]["deploy"] = 0
|
||||
self.write_config()
|
||||
|
||||
@@ -1148,6 +1148,17 @@ class TestWatchCommands(unittest.TestCase):
|
||||
self.assertEqual(short.returncode, 3)
|
||||
self.assertIn("memory stage stop", short.stdout)
|
||||
|
||||
def test_admit_refuses_while_the_ram_cap_is_broken_and_grants_under_a_valid_one(self):
|
||||
self.cfg["thresholds_gb"] = {"warn": 0, "stop": 0, "critical": 0}
|
||||
self.cfg["ram_cap_percent"] = {"test": "30"}
|
||||
self._write_config()
|
||||
denied = self._run("admit", "--kind", "test", "--", "true")
|
||||
self.assertEqual(denied.returncode, 3)
|
||||
self.assertIn("ram_cap_percent is no {kind: percent above 0 up to 100} map", denied.stdout)
|
||||
self.cfg["ram_cap_percent"] = {"test": 30}
|
||||
self._write_config()
|
||||
self.assertEqual(self._run("admit", "--kind", "test", "--", "true").returncode, 0)
|
||||
|
||||
def test_admit_refuses_a_heavy_command_and_names_the_queue_hold_of_kind_test(self):
|
||||
self.cfg["thresholds_gb"] = {"warn": 0, "stop": 0, "critical": 0}
|
||||
self.cfg["slot_need_gb"]["test-nostack"] = 0
|
||||
|
||||
Reference in new issue
Block a user