Public: anyone can read this; the crew can change it.

Share an idle forge's machine with friends: their CI, their apps and previews… #16525

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

This pull is part 2 of #16479 only, the yield rule. Parts 1, 3 and 4 are not started, and the rule has no lent runners to act on until part 1 exists. I ran bun scripts/gate.ts --fix, bun x tsc --noEmit, the new test and three related tests (runner-claim, settings-runners, guide); all pass.

Notes

shipped production is serving it deploy d5add18

opened this

This pull is part 2 of #16479 only, the yield rule. Parts 1, 3 and 4 are not started, and the rule has no lent runners to act on until part 1 exists. I ran bun scripts/gate.ts --fix, bun x tsc --noEmit, the new test and three related tests (runner-claim, settings-runners, guide); all pass. I did not run scripts/similar.ts or scripts/design-lint.ts, and I did not call keep_plan or estimate.

What changed

  • A runner enrolled with a name starting lent- takes no new job while this machine's one-minute load per core is above FORGE_LEND_YIELD_LOAD. The default is 0.75, and 0 never yields.
  • Its claim on POST /api/v1/runner/claim then answers 204, as for an empty queue, so it finishes the job it holds and asks again later. Runners with other names, including the local-* pool, are never held.
  • The rule is in src/checks/lent_yield.ts (new) and is checked in the claim handler in src/http/api/runners.ts. docs/features/runners.md has a short section on it.
  • test/lent-yield.test.ts checks the rule and, through the real claim route, that a lent- runner gets 204 while an own runner gets its job.
  • The commit that edits runners.ts also carries prettier's reformatting of that file's claim handler, so its diff is larger than the logic change.

Reused: claimJob, enrolRunner and runnerByToken as they are; I did not run scripts/similar.ts.

Left out, on purpose

  • Part 1: lending runners to another forge (their URL, a sealed enrolment token, job counts) and metering their job minutes. A lent- runner in this pull is one enrolled on this forge's own claim endpoint.
  • Load measure: machine load per core only. Crew runs and waiting checks do not count yet, and lent child forges are not slept.
  • /system and terminal: the yield state is not shown on /system or in the terminal, so no web page changed.
  • Parts 3 and 4: "host a forge for <person>" and the standby of a friend's forge.
  • Owner's decisions page: there is none yet, so the threshold is an environment variable.

Try it: enrol a runner named lent-x (POST /api/v1/admin/runners) and start the forge with FORGE_LEND_YIELD_LOAD=0.0000001. A claim from lent-x returns 204 while a claim from another runner still gets the job. The push first failed the pre-push hook, which wants a Try: line, so I added it as an empty commit.

Closes #16479

Show 3 earlier items

7 earlier comments · 2 events
commented

A lent- runner now gets 204 on the claim route, instead of a job, while this machine's one-minute load per core is above FORGE_LEND_YIELD_LOAD. The default is 0.75 and 0 never yields. It keeps any job it already holds, and other runners are never held.

This is dormant: nothing can enrol or lend a runner yet, because that is part 1 of #16479. The rule only takes effect once a runner named lent-… exists, and I added that to docs/features/runners.md.

The review points, in order:

  • Flaky test: the load source in src/checks/lent_yield.ts can now be swapped, and the route test pins it at 0.9 against a 0.75 threshold, so it no longer depends on the host's real load.
  • Both doors: when lent runners are waiting, the runners screen in the terminal and the Settings → Runners page show "Lent runners are waiting: load 0.90 per core is above 0.75 (FORGE_LEND_YIELD_LOAD)". The screen shows it only to a forge admin. A new test covers the terminal screen and one covers the note itself. The web page is the one part with no test of its own. I did not add /system.
  • Rewraps: the unrelated prettier rewraps in src/http/api/runners.ts are reverted, so that diff is only the yield rule.
  • Threshold read once: the claim handler reads the threshold before the polling loop. Load is still read on each pass, because it changes while a claim waits.
  • Empty Try: commit: I did not drop it. Removing it needs a history rewrite and a force push, which this setup refuses, so it stays in the branch history. It changes no files.

The type check, the gate and the tests for the runner claim route, the terminal screen and the settings page pass locally. I did not run the full suite.

To try it, enrol a runner named lent-x and set FORGE_LEND_YIELD_LOAD to a value below the machine's current load. POST /api/v1/runner/claim then answers 204 while an own runner still gets its job.

commented

<!-- look-pages 0e5fb2a0f741 --> Look pages for 0e5fb2a, from the gate:

  • look pages (none): this pull changes src/web/pages/runners.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

Lent runners (names starting lent-) now get a 204 instead of a job while this machine's one-minute load per core is above FORGE_LEND_YIELD_LOAD. That is part 2 of #16479 and it is dormant: nothing can lend a runner yet, because part 1 is separate. This push fixes the dead-code check that failed on the last one.

  • What failed: setLoadSource in src/checks/lent_yield.ts is used only by the tests, so the unused-exports test flagged it. I added it to scripts/unused-exports-allow.json as a one-line insert, the way the other test-only hooks such as setStripeFetch are listed.
  • The other red test: the "one source, three doors" failure is in test/ship-time.test.ts. The check log says it is red on main as well, so it is not counted against this pull and I left it alone.
  • Verified: test/unused-exports.test.ts passes locally. I did not rerun the rest of the suite for this commit.

What the pull does:

  • Yield rule: a lent runner keeps any job it already holds and takes no new one while the load is above the line. The default is 0.75 and 0 never yields. Other runners are never held.
  • Owner's view: the terminal runners screen and Settings → Runners say "Lent runners are waiting: load … per core is above …" while that is true.
  • Tests: the load is pinned in tests, so they do not depend on the real machine.

I left two things unfinished:

  • Empty Try: commit: it is still in the branch history. Dropping it needs a force push, which is refused here, and it changes no files.
  • /system: I did not add the yield state there.

To try it, enrol a runner named lent-x and set FORGE_LEND_YIELD_LOAD below the machine's current load. POST /api/v1/runner/claim then answers 204 while an own runner still gets its job.

commented

<!-- look-pages e0a6bb020d39 --> Look pages for e0a6bb0, from the gate:

  • look pages (none): this pull changes src/web/pages/runners.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

Looks: /settings/runners

The look-pages note couldn't trace /settings/security/controls. That route isn't the page this pull changes. src/web/pages/runners.ts serves GET /settings/runners (runnersPage, line 54), and that is the page to look at. This pull shows the lent-yield wait there, in the runners list and on the page itself.

I made no code change for this feedback, so nothing new is pushed. The note asked for a "Looks:" line, and this message supplies it.

What changed in the pull:

  • A runner named lent-* takes no new job while the machine is busy. The machine counts as busy when its load is above FORGE_LEND_YIELD_LOAD.
  • The threshold is read once per claim. The load source can be injected, which is the seam the tests use.
  • While a runner is waiting, /settings/runners shows it.
  • POST /api/v1/runner/claim answers 204 to a yielding runner while the owner's own runners still claim.

What I left out: per-runner thresholds, and history of how long a runner has yielded.

How to try it:

  1. Enrol a runner named lent-x.
  2. Start the app with FORGE_LEND_YIELD_LOAD=0.0000001.
  3. POST /api/v1/runner/claim as that runner. It answers 204, while an own runner still claims.
  4. Open /settings/runners and check that the wait shows.
[
  {"go": "/settings/runners", "look": "a lent- runner while the machine is busy", "expect": "the runner is listed with its yield wait shown, and own runners show no wait"}
]
Changes requested — before the latest push

Earlier asks: the flaky load test is met (the load source is injectable and pinned); both doors are met (the terminal screen is admin-gated and tested); the rewraps are reverted; the threshold is read once per claim; the allow-list entry is fine. One ask is still open. The note on Settings → Runners (#lent-waiting) has no test, so it is a behaviour the pull adds that nothing would catch if it broke. The pull's own description says so. Fix: add a test, in test/settings-runners.test.ts or beside the page's existing tests, that calls setLoadSource(() => 0.9) and asserts the page body contains id="lent-waiting" and Lent runners are waiting. Also assert that it is absent when the load is low. Reset the source in finally. Everything else reads clean: the claim route is gated by the runner token, there is no new input surface, the output is escaped through html, and the README is untouched. Non-blocking: the empty Try: commit stays in the history.

commented

Looks: /settings/runners

A runner whose name starts with lent- is one the owner shares with friends. It takes no new job while the machine is busy. Busy means the one-minute load per core is above FORGE_LEND_YIELD_LOAD (default 0.75; 0 means never yield). It finishes the job it holds. When it asks for another, POST /api/v1/runner/claim answers 204, the same as for an empty queue, while the owner's own runners keep claiming. The threshold is read once per claim. Tests can swap the load source (setLoadSource in src/checks/lent_yield.ts), so the tests don't depend on how busy the machine really is.

The owner can see the wait in two places:

  • Settings → Runners shows a #lent-waiting note with the load and the line it crossed.
  • The runners screen in the terminal shows the same line. Only admins can open it.

Tests: this push adds a test for the Settings → Runners note in test/settings-runners.test.ts. With the load source pinned at 0.9, the page contains id="lent-waiting" and "Lent runners are waiting: load 0.90 per core is above 0.75". At 0.1, it contains neither. FORGE_LEND_YIELD_LOAD and the load source are restored in finally. Without the note's line in src/web/pages/runners.ts, the first assertion fails.

bun test test/settings-runners.test.ts passes (7 tests). bun x tsc --noEmit and bun scripts/gate.ts --fix are clean. The gate's one message is a note that it couldn't infer which page to look at, which the "Looks:" line above answers.

Not done: a separate threshold per runner, and a record of how long lent runners have waited. The empty Try: commit stays in the history, because force pushes are refused here.

To try it: enrol a runner named lent-x and set FORGE_LEND_YIELD_LOAD=0.0000001. Its POST /api/v1/runner/claim answers 204 while an own runner still claims, and Settings → Runners shows the waiting note.

[
  {"go": "/settings/runners", "look": "the note at the top of the runners block when the machine is above FORGE_LEND_YIELD_LOAD", "expect": "'Lent runners are waiting: load … per core is above …'; no note when the load is under the line"}
]

🤖 Generated with Claude Code

commented

<!-- look-pages 311c54cc005c --> Look pages for 311c54c, from the gate:

  • look pages (none): this pull changes src/web/pages/runners.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
Approved

Since my last review (e0a6bb0) the only change is the Settings → Runners test, and it answers my last open ask. With the load pinned at 0.9 the page shows #lent-waiting and the note. At 0.1 it shows neither, and the env var and load source are restored in finally. Earlier asks are met: the terminal and web doors both show the wait, the threshold is read once per claim, the unrelated rewraps are reverted, the load source is injectable so the tests are not flaky, and the how-to is in docs/features/runners.md rather than README. Security: the claim route still authenticates by runner token, the yield decision uses only the enrolled runner name and the machine load, and the note is escaped by the html template. The note is a muted paragraph, with no new component or accent. Non-blocking: the empty Try: commit stays in history, and /system does not show the yield state yet. Looks: /settings/runners, since the gate could not trace the route.

commented

No look: the Settings → Runners note appears only while the machine's load is above FORGE_LEND_YIELD_LOAD, so a preview picture can't capture it. test/settings-runners.test.ts sets the load and checks the note instead.

Runners named lent-* are machine time the owner shares with friends. Busy means the one-minute load per core is above FORGE_LEND_YIELD_LOAD (default 0.75; 0 means never wait). While the machine is busy, a lent runner finishes the job it holds and takes no new one. When it asks for work, POST /api/v1/runner/claim answers 204, the same as for an empty queue, while the owner's own runners keep claiming. The threshold is read once per claim. Tests can swap the load source (setLoadSource in src/checks/lent_yield.ts), so they don't depend on the machine's real load.

The owner sees the wait in two places:

  • the admin-only runners screen in the terminal;
  • Settings → Runners, as a muted #lent-waiting note. In tests it appears at load 0.9 and is gone at 0.1.

How to use it is in docs/features/runners.md.

The look note: the gate looks for a Looks: or No look: line in a commit message, not in the pull description (src/kernel/look_rule.ts). That's why my earlier Looks: line in the description didn't clear it. /settings/runners is not in app.looks in forge.json, so naming it would only get a different note. The empty commit eb4537b7f carries the No look: line instead. I added no code in this push, so I ran no tests for it.

Not done:

  • No separate threshold per runner.
  • No record of how long lent runners have waited.
  • /system doesn't show whether lent runners are waiting yet.
  • The earlier empty Try: commit stays in the history, because force pushes are refused.

To try it: enrol a runner named lent-x and set FORGE_LEND_YIELD_LOAD=0.0000001. Its POST /api/v1/runner/claim then answers 204 while one of your own runners still claims. Settings → Runners shows "Lent runners are waiting: load … per core is above …".

[
  {"go": "/settings/runners", "look": "the top of the runners block while the machine is above FORGE_LEND_YIELD_LOAD", "expect": "a muted 'Lent runners are waiting: load … per core is above …' line; no line when the load is under it"}
]

🤖 Generated with Claude Code

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs