GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Dynamic slots D5: agent costs learned from their last runs' memory (#882) by scuttletoby · Pull Request #1206 · scuttletoby/t3code

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Dynamic slots D5, part 1: the slot gate learns each agent kind's memory cost from what its runs really used, instead of only the rule file's fixed start costs (light 384 MB, writer 768 MB).

What

  • packages/shared/src/slotObserve.ts: recordAgentPeak keeps the highest memory demand (anon + shmem + swap) of each kind's last 20 runs; learnedAgentMb turns them into a cost: the highest peak x 1.15, rounded up to 128 MB, never below the rule's start cost. These are the same numbers heavy uses for job costs (fork-kit/heavy/README.md, "What a job reserves"). enforceCosts and enforceDecision take the peaks (no peaks: the start costs, so nothing changes until a run ends). OOM raises (25 % each) multiply the learned cost, and the rule still clamps every cost at learnedBounds.maxPercent (400 %), so one leaky run can cost at most 4x the start cost, and only for its kind's next 20 runs.
  • apps/server/src/slots/SlotGate.ts: on every reading (each decision and the 30 s timer), the gate keeps the highest demand of each child it started (its kind is known) while it runs. When the child stops running or starting (the place where its kind was already dropped), the peak goes into its kind's history, and a log line says when a kind's cost changes.

Choices

  • Learning only raises a cost. A kind whose runs stay small keeps the start cost. Letting costs drop (down to learnedBounds.minPercent) would admit more agents and could be a later owner choice; this part keeps the safe side.
  • Memory only. After a restart the gate learns again from the start costs, which is how the gate works today. Keeping the peaks across restarts can be the next part.
  • Only children the gate started (with a kind) are learned from; other agents still count as writers with their live demand, as before.
  • A peak is sampled at each reading (decisions and the 30 s timer), so a spike between readings can be missed. The live demand of running agents still counts directly in every decision.

Tests (red on main, green here)

  • packages/shared/src/slotObserve.test.ts, "enforce: costs learned from finished runs (dynamic slots D5)":
    • Does a kind with no finished run cost the start cost, and one whose run peaked at 1000 MB cost 1152 MB (the highest run, not the last one, and only for its own kind)?
    • Does a kind whose runs stay small keep the start cost (learning never lowers it)?
    • Does a big run stop counting after 20 newer runs?
    • Does a peak that is not a whole reading (NaN, negative, infinite) leave the history unchanged?
    • Do OOM raises multiply the learned cost?
    • Does a decision owe the learned cost, and is the cost still clamped at the rule's 400 % bound?
  • apps/server/src/slots/SlotObserver.test.ts, enforce mode:
    • After a light agent ran at 1000 MB and ended, is the next light start (574 MB free) refused for budget with cost 1152 MB? (On main it is allowed at 384 MB.)
    • After a light agent that stayed at 200 MB, does the next light start still fit at 384 MB? (Guard: passes on main too.)

Ran: packages/shared/src/slotObserve.test.ts, apps/server/src/slots/SlotObserver.test.ts, apps/server/src/slots/SlotGate.test.ts; typecheck of both packages; fork schema, upstream-files and seam checks.

Upstream fit

Fork-only files (slotObserve.ts, apps/server/src/slots/); no upstream file and no seam line changes.

Part of #882

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
scuttletoby and others added 2 commits November 28, 2026 17:50
@scuttletoby @claude
dynamic slots D5: agent costs learned from their last runs' memory
8b5dc96
The slot gate keeps the highest memory demand it reads of each child it
started while that child runs; when the run ends, the peak goes into its
kind's last 20 runs. A kind's cost is the highest of those x 1.15, rounded
up to 128 MB, never below the rule's start cost (as heavy learns job costs);
OOM raises multiply it and the rule still clamps it at learnedBounds.
Memory only: a restart starts again from the start costs.

Part of #882

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby @claude
fork changes: agent slots learn agent costs from their runs (#1206)
ad8c5ae
Part of #882

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scuttletoby

scuttletoby commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Opus 5.5 · read at: ad8c5ae

blocker: none
major: none
minor: Run boundaries are only seen at decisions: the kinds cleanup that calls runEnded sits in withCapacity, not in the 30 s sample. A child that ends and is resumed (a follow-up message) before the next delegate_task stays in kinds, so both turns merge into one peak under its first kind, and the sampler keeps sampling it. That errs high, not low, but a run then means "seen ended at a decision". Moving the cleanup into readAndStep (the sampler has the count read's visible too) would make the boundaries exact.
minor: The learned cost also raises the owed rest of every running agent of that kind (cost − live demand), not only the next start's cost. One outlier light run (capped at 1536 MB) makes each running light agent at about 300 MB owe about 1.2 GB for the kind's next 20 runs. That matches heavy's per-job reservation and is on the safe side, but the PR body and the change doc say only "the next start owes".
minor: The gate-level tests cover one run (1000 MB and 200 MB). No gate test checks that a child with a shared or unknown scope (ownScope undefined, demand null) teaches nothing, or that a child that never shows a run (no runPeaks entry) records nothing. Both are right by reading (demandMb === null skip; peakMb === undefined return), so these would only guard against regressions.

Checked and fine:

  • Rule: highest of the last 20 × 1.15, rounded up to 128 MB, never below startMb. Raises multiply the learned cost, and capacityRule clamps it at maxPercent (and runningKind clamps the same way). NaN, negative and infinite peaks are dropped.
  • Right tree: demand comes from ownScope(threadId), which is the thread's own scope unit. A shared scope gives undefined, so the demand is null and nothing is learned. Only threads in kinds (children the gate started) are sampled.
  • Races: the 30 s sample and every decision run readAndStep under the same semaphore.withPermits(1). Ended runs are recorded before peaks is captured for that decision, so the decision already uses them. kinds.set in started runs outside the semaphore, as it did on main, and it only adds.
  • Tests: the gate test "a light run that used 1000 MB …" is red on main (no learning, so 384 MB fits in 574 MB free). The 200 MB test is a guard and is meant to pass on main too.

State question (runs again, stops half-way, meets existing, old or empty state):

  • Runs again: each ended run is recorded once, because runPeaks.delete runs before the record and kinds.delete runs before runEnded.
  • Stops half-way, or a restart: peaks, kinds and runPeaks live in memory only. After a restart the gate starts again from the rule's start costs, and children still running count as writers with their live demand, as on main. This is lower than the learned cost until runs end, a gap the PR body names.
  • Empty or old state: an empty history gives the start cost exactly, so nothing changes until a run ends. No stored state is read, so there is no old format to meet.
  • Never-reporting children: a child that never shows a run has no peak and is dropped without recording. A child whose memory never reads (null) is skipped. A kinds or runPeaks entry for an ended child stays until the next decision, which bounds it and stays correct.

🤖 Generated with Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby

scuttletoby commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: Claude Opus 5.5 (lens sub-agent) · read at: ad8c5ae

blocker: none
major: none
minor: the "cost learned" log line reports afterMb before the rule's 400 % clamp. A light run that peaks at 2000 MB logs afterMb 2304, but the cost that counts is 1536 (costOf clamps it). A second run at 2100 MB logs again (2304 to 2432) while the real cost stays 1536. Logging the clamped cost, or only real changes, would make the log match what the gate does.
minor: learnedAgentMb and enforceCosts return the unclamped learned cost. Every caller today goes through costOf or runningKind, and both clamp. A future caller that reads learned[kind].mb directly would get more than the rule allows.

State question (runs again / stops half-way / old or empty state):

  • Server restart: agentPeaks, runPeaks and kinds are memory only and start empty. Costs go back to the start costs, and children that were already running count as writers with their live demand, as before. Nothing is kept, so a stop half-way cannot leave a wrong cost on disk.
  • A kind with no runs yet: peaks[kind] is missing, so the cost is the start cost. enforceCosts(rule, raises) with no peaks gives the old numbers.
  • A child that stops while a reading is in flight: readAndStep and the clean-up of kinds both run under the gate's semaphore, and the clean-up comes after the reading in withCapacity. A finished child's last reading is folded in first, then its peak is recorded once and runPeaks is cleared. A child with no reading at all records nothing. A scope that reads as gone, or a shared scope (ownScope gives undefined), reads as null and is never learned, so one shared process is never counted as one thread's peak.
  • Clean-up runs only on decisions, not on the 30 s timer. A finished child's peak waits in runPeaks until the next ask, and that ask cleans up before it computes costs, so it still decides with the new cost.
  • Can a cost that only rises lock a kind out for good? No. Each cost is capped at 400 % of its start cost (light 1536 MB, writer 3072 MB). The floor (floors.agent 2) still lets a kind start at unlearnedMb (the start cost) while fewer than 2 agents run, as long as that stays above the severe line. So a raised kind can still get runs, and 20 new runs push the big peak out of the window. Until then a busy machine can make it wait. That is the intended safe side, and the PR body says so.
  • A kind renamed or missing in the rule: runEnded drops any kind that is not in an agent group in CAPACITY_RULE. The rule is built in, so a rename ships with a restart, which empties the history. Old names cannot stay in the window.
  • OOM raises together with learned costs: raises multiply the learned cost, and costOf clamps the product at 400 %. An OOM run whose peak is also high raises its kind twice, but never past the clamp. Calm readings lower the raises again. The learned part ages out only through the 20-run window, as the PR says.
  • Thread reuse: kinds come only from delegate_task (new child threads). The route path passes no kind, so one kind's run peak cannot be carried into a run of another kind.

Tests: I tried to check that removing yield* runEnded(threadId, kind) turns "a light run that used 1000 MB makes the next light start owe 1152 MB" red, but the machine's capacity gate refused for 15 minutes in a row, so it never ran. From the code: recordAgentPeak is called only in runEnded. Without that call agentPeaks stays {}, the cost stays 384 and the ask is allowed, so the test (which expects a refusal at 1152) would fail. The new slotObserve.test.ts cases import recordAgentPeak and learnedAgentMb, which do not exist on main, so they are red there.

🤖 Generated with Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@scuttletoby scuttletoby added the fork:merge-ready Merge conveyor: lenses done, merge when green label Nov 28, 2026
@scuttletoby
Merge branch 'main' into fork/882-d5-learned-cost
5da0beb
@scuttletoby
scuttletoby merged commit 316d6e3 into main Nov 28, 2026
35 checks passed

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Nov 28, 2026
Dynamic agent slots: finish D4-D8 so slot counts come from the machine, not from instructions #882
Open
Dynamic slots D5: learned agent costs survive a restart (#882) #1226
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

fork:merge-ready Merge conveyor: lenses done, merge when green

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@scuttletoby
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.