Repository navigation
heavy facts: per-kind fits from the kernel ledger; kit capacity evaluator and callers - #786
Conversation
Lens B (correctness, parity, tests): NOT SAFEReviewed head Blocking
Major
Minor
What I checked
🤖 Generated with Claude Code |
Fix round (head 6bdf78d)Reviews: lens A, lens B. Leftovers: #800.
Red on the old code (the new tests on 95bc951): 21 of 39 facts tests fail, among them every new Red checks (fix line taken out, the test fails):
Runs (via |
…ator and callers Dynamic slots design row D6. The kit gets a Python evaluator of the shared capacity rule (lib/capacity_rule.py) that passes every vector and format case the TypeScript tests read, and `heavy facts [--kind K] [--mb N]`: one free/v1 object with per-kind "fits" from a ledger read from the kernel (heavy's live tickets plus T3's agent scopes, unlabelled = writer), a 5 s cache, the Basic tier, unreadable signals as elevated, and per-folder reservations. bin/t3-capacity and bin/agent-slots are thin callers of it that keep the older output and exit codes; a facts call that is slow (5 s) or fails is never free. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and other users fail closed Fix round for the two D6 reviews. - A heavy ticket whose kind the rule does not know (tsc, gradle, a project's own) is the rule's unknownKinds.job, never an agent; heavy facts --kind with an unknown name asks for that job too. - A reservation folder matches itself and what is below it, with or without a trailing '/', never a sibling sharing its first letters; its real path matches too. The caller's own folder is its real working folder only. - Basic tier (no cgroup v2 or no user manager) is never free and fits 0. Full tier also counts every other user's heavy jobs and agent scopes from their user managers' cgroups; a folder that cannot be listed is basic. Without a cache folder every call starts "elevated". - lib/capacity_readings.py: the shared reader's port. It runs every capacity-readings.json case and the "a failed reading never admits more" check; memory, PSI, cores and container limits now come from it, a box with a live piece but no folder is unreadable, a cut-short memory.stat owes in full. - The cache has version 2 and a key of its settings; t3-capacity takes the rule's whole hold; a fill count of 2.5 asks three times, as in TypeScript. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6bdf78d to
4a8f615
Compare
… kit path The heavy kit's evaluator, its tests and heavy-install read the capacity rule from its one source, packages/shared/src/capacity, but the sparse checkouts of the workflows, action_tests and kit_tests jobs left that folder out, so install.test.py and facts.test.py found no capacity-rule.json. The folder is now in the three lists (and in the `workflows` comment that says why each app file is there). The "//" notes of capacity-rule.json and capacity-readings.json named the kit's Python files, which the fork-owned-reads lint counts as app code reading a fork-owned path; they now point to README.md beside them, which names them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…top of the kit capacity check Built on the kit's `heavy facts` and its thin `t3-capacity` caller (#786) instead of a second capacity evaluator. What the older host check had that the kit's did not: - heavy.capacity.holds in the machine file: a cgroup outside the user managers (a CI runners' slice) that is in use keeps its budget less its use, as a reservation, for every user but its own. Missing file, section or key: no holds; a broken one: no answer (t3-capacity NOT OK naming the key); a changed one is read again at once (cache key). - The sweep and the queue accept the new `capacity` key. - Tests for the state question: holds in use or idle, own users, missing cgroup, unreadable memory.max or memory.stat, machine file missing/empty/garbled/writable by others/unknown key, a changed file within the cache's 5 s, a reservation file cut short, a reservation whose processes are gone; one red check. Part of #834 (G2, first half). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
(Reposted 2026-11-22 with private details removed; original 2026-11-21.) Lens AVerdict: NOT SAFE. One blocking path makes Blocking
Major
Minor
Checked and fine
|
#786 landed on main as one squash commit. Conflicts in fork-kit/heavy/README.md, lib/heavy_facts.py and tests/facts.test.py: main's copies are byte-identical to #786's last branch commit (3989409), which this branch builds on, so the branch's copies are kept. The PR's diff against main is now only its own commit (machine-file holds). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ests build the gate at START The merge of main brought the heavy kit's Python evaluator of the capacity rule (#786), written for the rule before this PR. This PR's rule counts swap by its trend (pressure.swapFillingMb; calm.swapFreeAtLeastPercent gone), so the kit read a key the shared rule no longer has (KeyError in capacity_rule.test.py and every heavy facts call). - lib/capacity_rule.py mirrors capacityPressure.ts and pressureOf: raw_level takes the last read's swap free (filling = it fell by more than swapFillingMb; nearly full counts only while filling; filling is never calm; no previous swap read = trend unknown), next_pressure keeps or starts the calm wait on an unknown trend but never ends it, and the kept state carries swapFreeMb for the next read (heavy facts' cache carries it). The shared capacity-vectors.json swap-trend cases and the facts carry test fail when any part is undone. - capacity_rule.test.py: a kit copy of the rule from before the swap trend is refused by name; an empty or missing rule file raises (heavy facts then answers "not available", never free). - agentSlotRoutes.test.ts: the gate's 30 s enforce sampler starts when the gate is built. Built at the test clock's 0, the tests' move to START ran every sample in the 56 years between (about 59 million): Test Server 5 hung until its 20 min cancel. boot now sets the clock to START first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cked on #786) (#843) * heavy facts: per-kind fits from the kernel ledger; kit capacity evaluator and callers Dynamic slots design row D6. The kit gets a Python evaluator of the shared capacity rule (lib/capacity_rule.py) that passes every vector and format case the TypeScript tests read, and `heavy facts [--kind K] [--mb N]`: one free/v1 object with per-kind "fits" from a ledger read from the kernel (heavy's live tickets plus T3's agent scopes, unlabelled = writer), a 5 s cache, the Basic tier, unreadable signals as elevated, and per-folder reservations. bin/t3-capacity and bin/agent-slots are thin callers of it that keep the older output and exit codes; a facts call that is slow (5 s) or fails is never free. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * heavy facts: every ticket is a job, folders match exactly, basic tier and other users fail closed Fix round for the two D6 reviews. - A heavy ticket whose kind the rule does not know (tsc, gradle, a project's own) is the rule's unknownKinds.job, never an agent; heavy facts --kind with an unknown name asks for that job too. - A reservation folder matches itself and what is below it, with or without a trailing '/', never a sibling sharing its first letters; its real path matches too. The caller's own folder is its real working folder only. - Basic tier (no cgroup v2 or no user manager) is never free and fits 0. Full tier also counts every other user's heavy jobs and agent scopes from their user managers' cgroups; a folder that cannot be listed is basic. Without a cache folder every call starts "elevated". - lib/capacity_readings.py: the shared reader's port. It runs every capacity-readings.json case and the "a failed reading never admits more" check; memory, PSI, cores and container limits now come from it, a box with a live piece but no folder is unreadable, a cut-short memory.stat owes in full. - The cache has version 2 and a key of its settings; t3-capacity takes the rule's whole hold; a fill count of 2.5 asks three times, as in TypeScript. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * heavy facts: kit tests check out the capacity rule; its JSON names no kit path The heavy kit's evaluator, its tests and heavy-install read the capacity rule from its one source, packages/shared/src/capacity, but the sparse checkouts of the workflows, action_tests and kit_tests jobs left that folder out, so install.test.py and facts.test.py found no capacity-rule.json. The folder is now in the three lists (and in the `workflows` comment that says why each app file is there). The "//" notes of capacity-rule.json and capacity-readings.json named the kit's Python files, which the fork-owned-reads lint counts as app code reading a fork-owned path; they now point to README.md beside them, which names them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fork-kit/heavy: machine-file holds for heavy facts (t3-capacity), on top of the kit capacity check Built on the kit's `heavy facts` and its thin `t3-capacity` caller (#786) instead of a second capacity evaluator. What the older host check had that the kit's did not: - heavy.capacity.holds in the machine file: a cgroup outside the user managers (a CI runners' slice) that is in use keeps its budget less its use, as a reservation, for every user but its own. Missing file, section or key: no holds; a broken one: no answer (t3-capacity NOT OK naming the key); a changed one is read again at once (cache key). - The sweep and the queue accept the new `capacity` key. - Tests for the state question: holds in use or idle, own users, missing cgroup, unreadable memory.max or memory.stat, machine file missing/empty/garbled/writable by others/unknown key, a changed file within the cache's 5 s, a reservation file cut short, a reservation whose processes are gone; one red check. Part of #834 (G2, first half). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
) * Slot gate: enforce the capacity rule by default (dynamic slots D4) The capacity rule now decides agent starts (mode "enforce", the default when agentSlots has no mode and is switched off): - owed term: every agent still starting, held slot or waiter ahead owes its full cost, so two starts in one second both count; - kinds from the task role: research, review and design are light, anything else or no role is a writer; a light agent that grows past the light cost counts as a writer, so a wrong role cannot hide one; - floors (2 agents, 1 job) and derived ceilings (3 agents per core, at most 64); - fallback to the fixed ceilings (10 agents, 4 jobs) with start costs raised 25% per trip after an OOM kill (oom_kill in /proc/vmstat rises) or swap under 10% free; it lifts after 10 minutes of calm, whole readings. A restart starts in the fallback and at "elevated"; unreadable readings are never calm. Typed limits still apply while enabled; "mode": "fixed" turns the rule off. The delegate_task route passes its role to the slot gate with the target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Slot gate: fix round after lenses A and B (D4) - floor always starts, also with failed, hung or out-of-range readings; after 2 minutes unread the fixed 10 counts alone - a restart lifts on calm for this host: swap counts by trend, the first calm needs the margin only; a 30 s timer takes readings - costs from the rule file (light 384, writer 768); light cost clamped - only agent-slice OOM kills raise costs; untold kills raise at most 2; each calm spell lowers one raise - basic tier (no scopes or no oom_kill) keeps the fixed 10; unread running agents count once as writers - unreadable settings use the fixed limits; true counts in refusals - tests for the held slot, the role line, no OOM counter Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Slot gate: kit evaluator follows the swap-trend rule; scheduled-run tests build the gate at START The merge of main brought the heavy kit's Python evaluator of the capacity rule (#786), written for the rule before this PR. This PR's rule counts swap by its trend (pressure.swapFillingMb; calm.swapFreeAtLeastPercent gone), so the kit read a key the shared rule no longer has (KeyError in capacity_rule.test.py and every heavy facts call). - lib/capacity_rule.py mirrors capacityPressure.ts and pressureOf: raw_level takes the last read's swap free (filling = it fell by more than swapFillingMb; nearly full counts only while filling; filling is never calm; no previous swap read = trend unknown), next_pressure keeps or starts the calm wait on an unknown trend but never ends it, and the kept state carries swapFreeMb for the next read (heavy facts' cache carries it). The shared capacity-vectors.json swap-trend cases and the facts carry test fail when any part is undone. - capacity_rule.test.py: a kit copy of the rule from before the swap trend is refused by name; an empty or missing rule file raises (heavy facts then answers "not available", never free). - agentSlotRoutes.test.ts: the gate's 30 s enforce sampler starts when the gate is built. Built at the test clock's 0, the tests' move to START ran every sample in the 56 years between (about 59 million): Test Server 5 hung until its 20 min cancel. boot now sets the clock to START first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
What and why
Dynamic slots design row D6: the kit learns to answer "may one more piece of work start here?" from the kernel, with the same capacity rule the TypeScript side uses.
lib/capacity_rule.py: the kit's evaluator ofpackages/shared/src/capacity/capacity-rule.json. It reads the rule, format and vectors files from that folder (or the installed copy in<kit>/capacity) and passes every vector and every format case, the same onescapacityRule.test.tsruns. No number is copied.heavy facts [--kind K] [--mb N] [--fresh](lib/heavy_facts.py): prints one free/v1 object (FREE.md; exit 0 free, 75 busy, anything else not available). It includes per-kindfits, the memory budget, the queue and notes. The ledger comes from the kernel:/proc/meminfo, PSI, cores and load;t3code-*.scopeunder anapp-t3code*.slice), which carry no kind label yet, so each counts as a writer.Other behaviour:
peaks.json.memory.pressure) gives elevated, never ok.Reservations:
~/.config/t3-capacity/reserve.d/*.conf, with lines<MB> <absolute folder prefix> [until=YYYY-MM-DD]. A reservation holds back its MB minus what processes in that folder already use. A caller inside the folder is not held back by its own reservation. Ended, broken or unreadable lines hold nothing and give a note.Thin callers
bin/t3-capacity [--kind K] [MB]andbin/agent-slots:available=..MB swapfree=..MB load=..), the lastOK/NOT OK: whyline, the exit codes 0/1/2, and the hook output shapes. The MB argument still works (default 3072).agent-slotsgives free = min(process limit, the machine'sfitsfor its kind).heavy factsthat does not answer within 5 s (its process group is killed), fails, or prints something invalid is never free.Installer: copies the new files plus the three capacity JSON files into each version. Its self-test runs
heavy facts --help, which loads the rule from that copy.Four new vectors in
capacity-vectors.json, so every rule number is held by some vector: job core share for default jobs, servers, and a typecheck whose cost is exactly free; and calm needing available at 150 % of the margin. The TS tests pass with them (248 passed). I did not change any TypeScript.Size: about 1085 lines of code (rule evaluator 412, facts 469, callers 204), over the row's ~450. The evaluator mirrors the TS rule line by line, so it cannot be shorter without dropping parts of the rule.
Tests
fork-kit/heavy/tests/capacity_rule.test.py(new):startCentiCoresvalues: no decision reads them, because the core check is for jobs only, and the test lists them by name.job-default.startCentiCores250→251 made both this test and the TS test red.fork-kit/heavy/tests/facts.test.py(new, 23 tests). They run on a fake/procand/sys(HEAVY_FACTS_ROOT) with a temporary queue, home and cache, and fake slow or failingheavyscripts. Covered:t3-capacity's first line, exit codes, reservations line and pipe warning, and that a slow, failing or garbledheavy factsis never OK (a child of the slow one does not survive);agent-slots: the min of both limits, and no slot when facts do not answer.install.test.py: the moved installed copy runsheavy facts --helpfrom its owncapacity/.RedChecktest);int(count)in the evaluator's fill;memory.pressure= unreadable;Spot-check results (each line removed, then restored):
Ledger.test_agent_scopes_count_as_writers)int(count)removed: RED (Vectors.test_every_vector)Ledger.test_an_unreadable_signal_is_elevated_never_ok)State.test_a_second_call_within_5_s_uses_the_cache_and_later_reads_again)Reservations.test_own_other_ended_broken_and_missing)Run here: capacity_rule, facts, install, queue, measure (all OK), and the packages/shared capacity vitest (248 passed).
vp fmt --checkon the changed files passes (the vectors file was reformatted by it).vp linthas nothing to check here: no JS/TS file changes.fork-seam-checkpasses.General vs project
All general: nothing names a project, host, user or path outside the user's own home config and
/run/user/<uid>.t3code-*.scope,app-t3code*.slice).max_aliveall come from the user's config files.Dynamic slots design row D6
heavy factsgives per-kind fits and counts agent scopes;t3-capacityandagent-slotsare its callers. Both evaluators pass the same vectors, it works with T3 down, and it handles reservations.Not in this row (stated limits):
capacity-readings.json's fixture cases.🤖 Generated with Claude Code