Repository navigation
placement: decode forwarded facts, here fallback, needs reader, factsCommand runner, facts read limits (#794, #805, #821) - #970
Conversation
…r, facts read limits (#794, #805, #821) - factsFromAnswer decodes a linked machine's t3_environment_read answer with P3's schema: neither field is no facts (null); a refused answer carries a problem and the engine refuses that machine, named too. - Rule engine: here without a host sample passes H2/H8 and is the last fallback; needs are read through readPlacementNeeds (a broken value fits no machine); labels use contracts' one canonical form. - factsCommand runner (not wired yet): re-checks the path on its own OS, no shell, no args, .exe only on Windows, 5 s limit, capped output. - Facts read: the host read has its own 2 s limit and runs beside the slot count; a test runs the real slot gate. - Docs: threat notes, clean-up wording, per-account limits; FORK_CHANGES links the P3 PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The here fallback keeps upstream's weight rule (manual or an unknown word stays out) and its 5 % free-memory limit when memory was measured. - factsCommand: a run cut at the output limit drops its last, maybe partial, line; a program a signal ends reads as "stopped by a signal". - The real-program test now proves the path ran whole with no arguments. - A real-gate test for a hung sampler with slots on; the README now says that case gives "not available" after 6 s, and that with slots off nothing checks again at launch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
lens: code · reviewer: lens agent (Opus) · read at: 13bfe5d 🤖 Generated with Claude Code |
Fixes #794, Fixes #805, Fixes #821
Placement follow-ups from the P2, P3 and P5 reviews (umbrella #883). This PR changes only fork-named files (
fork/,fork*,FORK_*, fork docs), so there are no new seams and no list change. Placement stays off; turning it on is #902, which this PR does not touch.#794 (rule engine input)
factsFromAnswer(apps/server/src/fork/environmentFacts.ts) maps it tonull, meaning "no facts", as P3 documents for an older build. A named machine then meets only the rules that need no facts. Test:environmentFacts.answer.test.ts, "neither field".whytext says it was picked only because nothing ranks. Upstream's own limits still hold for it:manualor an unknown weight word keeps it out, and so does 5 % free memory or less when memory was measured. With agent slots on, its gate checks again at launch; with slots off nothing does, as in upstream's own launch on this machine. A linked machine without a sample is still refused. Tests inforkPlacement.test.ts: "a sampler failure here does not stop all delegation", plus new H2 and H8 rows and the weight and memory cases.factsFromAnswerdecodes withResultFields. When the schema refuses an answer (wrong type, negative count, CPU above 1, nofactsAt, not an object), the facts carryproblem. H2 then refuses the machine with "The machine's facts are not valid: …", even when it is named. A bad answer never reads as busy or free.PlacementLabelalready decoded to the canonical form, andPlacementWeightis a literal union (packages/contracts/src/placement.ts). The last part was the second label function, merged under #805 item 2.#805 (P2 review)
readPlacementNeedsPlacementTask.needsis nowPlacementNeeds, and H6 andchoosePlacementread it throughreadPlacementNeeds. A broken value (or anything that is not a list) fits no machine, including a named machine and this machine, with the reason. Test: "a broken needs value fits no machine".canonicalPlacementLabelsandcanonicalLabelscanonicalLabelsnow calls contracts'canonicalPlacementLabels, the one P2 stores with, after dropping any value that is not a string (from another machine's answer). The contracts file is unchanged; see the seam note below. The test checks that both give the same result.apps/server/src/fork/factsCommand.ts. It checks the path againstHostProcess.Platformbefore running it. It runs the program as one path withargs: []throughProcessRunner(shell: false). On Windows only an.exeruns, becauseProcessRunnerwould use a shell for.cmdand.bat. Limits: 5 s timeout, output truncated at 16 KB, at most 64 labels. A run cut at the output limit drops its last line, which may be part of a label. A program that a signal ends reads as "stopped by a signal". Tests run a real program in a folder namedwith space;echo hacked: it printsargs-0(no arguments) andwhole-path($0is the full path), and both come back as labels. Wrong-OS paths are never run. Row P4 wires the runner into the facts read; nothing calls it yet.docs/fork/README.md,server.placement. Placement guards against mistakes, not against a determined agent with a shell.factsCommandruns with the server's rights. A linked machine's own report is taken as that machine's word, and a refused answer is refused.factsCommandkept in its read formreadPlacementForThisOs) turns such a value intooffwith a reason, and that view is never saved. The settings file keeps the person's text byte for byte;placementSettingsFile.test.tsassertsfile.placementequals what was written.readPlacementForThisOs; the runner checks again#821 (P3 review)
wait_listruns) and gets at most 6 s. A cheaper read was considered. The facts read now runs the host read and the slot count at the same time. With slots off,placementno longer waits for the host. With slots on, the gate's own count reads the same sample (see item 3). The gate'susageread is kept because it is the one sourcewait_listshows, and its clean-up is idempotent.HOST_READ_TIMEOUT(2 s). A hung sampler leaves outhostResources, andplacementstill comes. Tests: "a host read that hangs is given up at its own limit". With slots on, the gate's count reads the same sample for its memory floor, soplacementis "not available (the gate could not count)" after 6 s, never a guessed count. That is the gate's own answer at launch. Test: "a hung sampler with slots on" inenvironmentFacts.realGate.test.ts. The README says this.availableignores per-account limitsavailableandslotsFreecount only the machine limit and the memory floor; the account is checked at launch by the gate.environmentFacts.realGate.test.tsrunsSlotGate.layerOverwith only its inputs replaced (settings, running threads, host sample). It covers counts, full, below the floor, slots off, and a second run giving the same result.Tests that fail without the fix
Each fix was reverted in place, the new tests were run against it, and the files were then restored from the commit:
problemcheck in H2, removed the here exemption in H2, read needs raw instead of throughreadPlacementNeeds): 7 of 127 fail. These are the H2 "did not decode" and "here without a host sample" tests, H6 "broken needs", "a broken needs value fits no machine", "a sampler failure here does not stop all delegation", "missing, stale or partial facts never fit", and the labels test.factsFromAnswer(no decode): 7 fail. These are "a good answer … newer build's field ignored" and all six "reported as not valid" cases.factsCommand(removed the path check again and the.exerule): 4 fail. On linux, darwin and win32 a wrong-OS path "is never run", and "on Windows only an .exe runs".manualcase.factsCommand(kept the cut last line, and read a signal as "could not run"): 3 of 9 fail. These are "output cut at its limit", the stand-in signal case, and the realkill -9program.Checks run
All of these ran locally behind the machine's capacity gate:
packages/sharedforkPlacement.test.ts: 127 passedapps/serversrc/fork/plusSlotGate.test.ts: 61 files, 1320 passedapps/serverandpackages/sharedvp linton the changed filesvp fmt --check--config-refmain): "only the pinned seams"Review
One
codelens (Opus, high effort) reviewed the first commit. It found six points, and the second commit fixes all six:manualor unknown weight.placement. That is false with slots on; the docs are fixed and a test is added.$#and$0.It also noted that with slots off nothing checks again at launch; the comment and README now say so.
State question
factsFromAnswer,choosePlacementand the facts read are pure, or re-measure each time. Tests show that the same input gives the same output (the answer decode, the real gate read, two runs offactsCommand).factsCommandis run again on each read and leaves nothing behind.factsCommandpast 5 s), the result is "no host facts" or "not available" with a reason, never a guessed count. ThefactsCommandprocess is stopped at its timeout (timedOutResult). Output cut at its limit gives only the whole lines, and a program a signal ends is "not available".placementNeedsfits no machine. An emptyfactsCommandis available with no labels and nothing runs. This machine with no sampler is still a last-place fallback, so a sampler failure does not stop all delegation.General vs project
All of this is general fork code. Machine facts come from each machine's own settings (
placement.labels,placement.factsCommand,agentSlots) and from its live readings. Nothing machine- or project-specific is hard-coded. The only numbers are generic limits: 2 s, 5 s, 16 KB, 64 labels.Seam note
packages/contracts/src/placement.tsand its test are the fork's own files (P2, #798), but.github/fork-seams.jsonforkFilesdoes not list them. As a result, the seam check reads any change to them as an upstream edit. This PR leaves them alone. A future change to them needs a list-only pull request first that addspackages/contracts/src/placement*toforkFiles; upstream has no such file.Left for later rows (not in this PR)
runFactsCommandand thelabelssetting into the facts read.labelsis still[]there.🤖 Generated with Claude Code