WIP: feat(agent): send the game's performance statistics when a plan asks #113

Draft
gab9281 wants to merge 4 commits from gab9281/Beanstalk:feat/perf-statistics into main
Member

The farm's PCs run the same scenes the same way on many GPUs, but their frame times never reach the team's performance dashboards. With this PR, a test plan can ask for them: the farm's game starts then send Longshot's own performance statistics, the way a player's launcher does when Send performance statistics is ticked.

What

  • The plan asks. A new probe, [[probe]] kind = "perf_statistics" (plan schema 10), lets a PR's .farm/test.toml, a maintainer's /beanstalk plan words, or the planner (only when the PR asks) request the statistics. Plans without it send nothing. Agents now say plan_schema = 10, so a schema-10 plan only goes to agents that read it.
  • The volunteer can still say no. perf_statistics = false in policy.toml, or the new Settings tick (on by default), always wins. The agent reads it again just before sending. A local run never sends.
  • How the summaries get out.
    • The agent writes the launcher's tick into both sides' runtimes (longshot_perf.ini: send=1, keep_sent=0), so the game leaves a summary in perf_pending/ every 5 minutes of play and at exit.
    • The sandbox has no network. Once a variant's runs are over, the agent sends the summaries itself, outside the sandbox and after the measuring (Core/PerfStatistics.cs, JobPipeline.SendPerfAsync).
    • They go to the relay that perf_reports names in main's nx2/addresses.ini.
  • How they're labeled. Each summary goes as client: "Beanstalk", kept apart from the players' summaries. Each also carries an identifier: the job, its side, and the build variant and attempt when there are more than one (jb_0123456789abcdef-pr, …-baseline-v3, …-pr-a2). On the dashboards, Client = Beanstalk plus that Identifier shows one run on its own. The relay has taken this optional v2 label since Longshot-api #26 (merged and deployed). The dashboards default to Client = Longshot, the players.
  • No unlabeled frame costs. A plan with perf_statistics can't also have a gpu_passes or screenshot probe, a shot step, or a cold cache (driver_cold, cold). Those slow the frames, and the summary wouldn't say so. Both plan readers refuse such plans, on shared fixtures. A driver_warm scenario's unmeasured start sends nothing. docs/test-plan.md lists what stays unlabeled: [scenario.env] switches and build variants, which only the identifier names. One identifier covers a whole side; the summaries split it by map.
  • It never fails the job. A relay that is busy or away stops the send and is noted in the log. So is anything odd that PR code left in perf_pending/.

After: this PR, Settings' new tick

After: this PR. Settings gains the tick; before, there was none. Rendered from the app's own view, headless, with a throwaway agent home.

Security (CONTRIBUTING.md: this changes what the agent uploads)

Why upload this. The farm's frame times, by map and by GPU, are what the performance dashboards lack. A summary holds what a player's launcher already sends (Longshot's docs/user/performance-report.md): hardware and driver models, which the farm already reports; frame-time histograms and hitches by map; and Link's position to the nearest 100 units. Nothing comes from the volunteer's files, saves, user name or PC name. Inside the sandbox, the user and the hostname are both beanstalk.

perf_pending/ is written by PR code and read outside the sandbox. The agent:

  • reads only non-empty regular .json files: never through a link, never a FIFO or socket (opening a FIFO would wait for a writer forever), and never when perf_pending/ or the runtime folder is itself a link. It never writes the tick into a linked runtime folder either;
  • sends only a JSON object of at most 60 KiB (the game's kMaxBody) that still fits the relay's limit once relabeled. Anything else is dropped unsent. It always overwrites client and identifier;
  • sends at most 48 summaries per runtime, over https only, with no redirects, to the address in main's checkout. PR code can't change that address: every sandboxed step mounts Longshot read-only;
  • reads perf_pending/ only after every sandboxed process is gone (the session's process tree is killed, and bwrap's --die-with-parent), so nothing can swap a file between the check and the read.

Hardlinks to a volunteer's file can't be made from the sandbox. Each writable folder is a separate bind mount, and a hardlink can't cross a mount (EXDEV). The volunteer's home is never mounted.

Reviews and tests

  • Code review (/code-review high), 10 findings:
    • Fixed: the FIFO hang; no catch-all around the tick and the send; the warm-up start being sent; retries counted twice (the attempt now goes in the identifier); the opt-out read only at the job's start; local runs sending; size growing from escaping after relabel; and the log saying "did not answer" when the relay did.
    • Documented: one identifier covers a whole side.
    • Left as is: writing perf_statistics into policy.toml follows the hidden key's pattern.
  • Security review (/security-review high): no finding at or above the bar. Its one hardening suggestion, refusing a linked runtime folder, is in.
  • Agent checks: agent/tests/agent_core/PerfStatisticsChecks.cs has 56 checks. They cover the policy key and the plan gate; the tick; the relay address (https only); the relabel (no escaping growth, a duplicate key, empty, oversized, the relay's limit); the identifier, with variant and attempt; the send outcomes; and the files that must never be read: a symlink to a "volunteer's file", a FIFO, an empty file, a linked perf_pending/ or runtime folder, and a warm-up start's summaries. python3 -I -B agent/tests/test_agent_core.py --strict: 2277 checks pass. That includes the coordinator and the agent normalizing every plan fixture the same way, the 6 new ones too.
  • Coordinator: pytest passes the plan and planner tests, including test_perf_statistics and its refusals. Locally the full suite has 8 failures in tests/test_regression.py, and the same 8 fail on a clean origin/main here. CI is the judge.
  • Build: dotnet build agent/Beanstalk.Agent.slnx -c Release: 0 warnings, 0 errors.
  • End to end: the agent's own PerfStatistics.SendAsync sent a summary to the live relay. It arrived in Prometheus as client="Beanstalk", identifier="jb_e2echeck-pr", with 250 s of Kokiri Forest. A symlink planted next to it was neither read nor sent. Players' series stay without an identifier.

To test

A maintainer or volunteer with a farm PC: run a job whose .farm/test.toml adds

schema = 10
[[probe]]
kind = "perf_statistics"

The agent's log should end with performance statistics: N summaries sent to the team's Grafana. On Longshot performance, with Client = Beanstalk, the job's identifier should be listed under Identifier.

🤖 Generated with Claude Code

https://claude.ai/code/session_015KgSKnCVhRNx6p3Y8Zabk4

The farm's PCs run the same scenes the same way on many GPUs, but their frame times never reach the team's performance dashboards. With this PR, a test plan can ask for them: the farm's game starts then send Longshot's own performance statistics, the way a player's launcher does when **Send performance statistics** is ticked. ## What - **The plan asks.** A new probe, `[[probe]] kind = "perf_statistics"` (plan schema 10), lets a PR's `.farm/test.toml`, a maintainer's `/beanstalk plan` words, or the planner (only when the PR asks) request the statistics. Plans without it send nothing. Agents now say `plan_schema = 10`, so a schema-10 plan only goes to agents that read it. - **The volunteer can still say no.** `perf_statistics = false` in `policy.toml`, or the new Settings tick (on by default), always wins. The agent reads it again just before sending. A local `run` never sends. - **How the summaries get out.** - The agent writes the launcher's tick into both sides' runtimes (`longshot_perf.ini`: `send=1`, `keep_sent=0`), so the game leaves a summary in `perf_pending/` every 5 minutes of play and at exit. - The sandbox has no network. Once a variant's runs are over, the agent sends the summaries itself, outside the sandbox and after the measuring (`Core/PerfStatistics.cs`, `JobPipeline.SendPerfAsync`). - They go to the relay that `perf_reports` names in **main's** `nx2/addresses.ini`. - **How they're labeled.** Each summary goes as **`client: "Beanstalk"`**, kept apart from the players' summaries. Each also carries an **`identifier`**: the job, its side, and the build variant and attempt when there are more than one (`jb_0123456789abcdef-pr`, `…-baseline-v3`, `…-pr-a2`). On the dashboards, Client = Beanstalk plus that Identifier shows one run on its own. The relay has taken this optional v2 label since Longshot-api #26 (merged and deployed). The dashboards default to Client = Longshot, the players. - **No unlabeled frame costs.** A plan with `perf_statistics` can't also have a `gpu_passes` or `screenshot` probe, a `shot` step, or a cold cache (`driver_cold`, `cold`). Those slow the frames, and the summary wouldn't say so. Both plan readers refuse such plans, on shared fixtures. A `driver_warm` scenario's unmeasured start sends nothing. `docs/test-plan.md` lists what stays unlabeled: `[scenario.env]` switches and build variants, which only the identifier names. One identifier covers a whole side; the summaries split it by map. - **It never fails the job.** A relay that is busy or away stops the send and is noted in the log. So is anything odd that PR code left in `perf_pending/`. ![After: this PR, Settings' new tick](https://git.magicbean.dev/attachments/631210f1-7430-4d93-bb6f-ed2a10534dc5) After: this PR. Settings gains the tick; before, there was none. Rendered from the app's own view, headless, with a throwaway agent home. ## Security (CONTRIBUTING.md: this changes what the agent uploads) **Why upload this.** The farm's frame times, by map and by GPU, are what the performance dashboards lack. A summary holds what a player's launcher already sends (Longshot's `docs/user/performance-report.md`): hardware and driver models, which the farm already reports; frame-time histograms and hitches by map; and Link's position to the nearest 100 units. Nothing comes from the volunteer's files, saves, user name or PC name. Inside the sandbox, the user and the hostname are both `beanstalk`. **`perf_pending/` is written by PR code and read outside the sandbox.** The agent: - reads only non-empty regular `.json` files: never through a link, never a FIFO or socket (opening a FIFO would wait for a writer forever), and never when `perf_pending/` or the runtime folder is itself a link. It never writes the tick into a linked runtime folder either; - sends only a JSON object of at most 60 KiB (the game's `kMaxBody`) that still fits the relay's limit once relabeled. Anything else is dropped unsent. It always overwrites `client` and `identifier`; - sends at most 48 summaries per runtime, over https only, with no redirects, to the address in main's checkout. PR code can't change that address: every sandboxed step mounts Longshot read-only; - reads `perf_pending/` only after every sandboxed process is gone (the session's process tree is killed, and bwrap's `--die-with-parent`), so nothing can swap a file between the check and the read. **Hardlinks** to a volunteer's file can't be made from the sandbox. Each writable folder is a separate bind mount, and a hardlink can't cross a mount (EXDEV). The volunteer's home is never mounted. ## Reviews and tests - **Code review** (`/code-review high`), 10 findings: - Fixed: the FIFO hang; no catch-all around the tick and the send; the warm-up start being sent; retries counted twice (the attempt now goes in the identifier); the opt-out read only at the job's start; local runs sending; size growing from escaping after relabel; and the log saying "did not answer" when the relay did. - Documented: one identifier covers a whole side. - Left as is: writing `perf_statistics` into `policy.toml` follows the `hidden` key's pattern. - **Security review** (`/security-review high`): no finding at or above the bar. Its one hardening suggestion, refusing a linked runtime folder, is in. - **Agent checks:** `agent/tests/agent_core/PerfStatisticsChecks.cs` has 56 checks. They cover the policy key and the plan gate; the tick; the relay address (https only); the relabel (no escaping growth, a duplicate key, empty, oversized, the relay's limit); the identifier, with variant and attempt; the send outcomes; and the files that must never be read: a symlink to a "volunteer's file", a FIFO, an empty file, a linked `perf_pending/` or runtime folder, and a warm-up start's summaries. `python3 -I -B agent/tests/test_agent_core.py --strict`: 2277 checks pass. That includes the coordinator and the agent normalizing every plan fixture the same way, the 6 new ones too. - **Coordinator:** `pytest` passes the plan and planner tests, including `test_perf_statistics` and its refusals. Locally the full suite has 8 failures in `tests/test_regression.py`, and the same 8 fail on a clean `origin/main` here. CI is the judge. - **Build:** `dotnet build agent/Beanstalk.Agent.slnx -c Release`: 0 warnings, 0 errors. - **End to end:** the agent's own `PerfStatistics.SendAsync` sent a summary to the live relay. It arrived in Prometheus as `client="Beanstalk"`, `identifier="jb_e2echeck-pr"`, with 250 s of Kokiri Forest. A symlink planted next to it was neither read nor sent. Players' series stay without an identifier. ## To test A maintainer or volunteer with a farm PC: run a job whose `.farm/test.toml` adds ```toml schema = 10 [[probe]] kind = "perf_statistics" ``` The agent's log should end with `performance statistics: N summaries sent to the team's Grafana`. On Longshot performance, with Client = Beanstalk, the job's identifier should be listed under Identifier. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015KgSKnCVhRNx6p3Y8Zabk4
feat(agent): send the game's performance statistics from the farm's runs
Some checks failed
CI / Conventional Commit title (pull_request) Successful in 4s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
CI / Coordinator tests (pull_request) Has been cancelled
CI / Agent build and checks (pull_request) Has been cancelled
CI / Coordinator image (pull_request) Has been cancelled
6fa5525917
Each runtime gets the launcher's "Send performance statistics" tick
(longshot_perf.ini: send=1, keep_sent=0), so the game writes its
summaries, every 5 minutes of play and at exit, into perf_pending/. The
sandbox has no network, so they wait there; once a variant's runs are
over the agent sends them itself, outside the sandbox and the measuring,
to the relay main's nx2/addresses.ini names (perf_reports).

Each goes as client "Beanstalk", so the farm's runs stay apart from the
players' on the performance dashboards, with "run": the job, its side
and build variant (jb_...-pr), so one run can be looked at alone.

perf_pending/'s files are written by PR code and read outside the sandbox:
only regular .json files, never through a link (perf_pending/ itself
neither), each a JSON object of at most 60 KiB. A relay that is busy or
away stops the send and is said in the log, never the job's failure.

On by default; policy.toml's perf_statistics = false, or Settings' new
"Send performance statistics", turns it off. README, docs/using.md and
agent/README.md say what leaves the PC.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015KgSKnCVhRNx6p3Y8Zabk4
feat(agent): the run goes as the summary's identifier
Some checks failed
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 4s
CI / Coordinator tests (pull_request) Has been cancelled
CI / Agent build and checks (pull_request) Has been cancelled
CI / Coordinator image (pull_request) Has been cancelled
c00e601551
The relay's optional v2 field is "identifier" (Longshot-api #26), more
general than a run: the agent fills it with the job, its side and build
variant. Optional and unused by players; for now only Beanstalk sends one.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015KgSKnCVhRNx6p3Y8Zabk4
feat(plan): the perf_statistics probe, so a plan asks for the statistics
Some checks failed
CI / Conventional Commit title (pull_request) Successful in 4s
CI / Workflow lint (actionlint) (pull_request) Successful in 3s
CI / Coordinator tests (pull_request) Has been cancelled
CI / Agent build and checks (pull_request) Has been cancelled
CI / Coordinator image (pull_request) Has been cancelled
51191aa689
Plan schema 10. The farm's runs send the game's performance statistics
only when their plan has the perf_statistics probe (a .farm/test.toml, a
maintainer's /beanstalk plan words, or the planner when the pull request
asks); the volunteer's perf_statistics = false still wins. A plan can't
pair it with what slows the frames without the statistics saying so: a
gpu_passes or screenshot probe, a shot step, or a cold cache. Both
readers refuse those, on shared fixtures the agent's checks compare.

The agent says plan_schema 10, so a schema-10 plan goes only to agents
that read it.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015KgSKnCVhRNx6p3Y8Zabk4
fix(agent): what PR code leaves in the runtime never fails or stalls the job
Some checks failed
CI / Workflow lint (actionlint) (pull_request) Successful in 7s
CI / Conventional Commit title (pull_request) Successful in 8s
CI / Coordinator tests (pull_request) Failing after 1m27s
CI / Agent build and checks (pull_request) Successful in 45s
CI / Coordinator image (pull_request) Successful in 17s
eb14e92ff2
From the review of the statistics' send:
- an empty file, a FIFO or a socket in perf_pending/ is never opened (a
  FIFO's open waited for a writer forever; Linux gives it no other mark)
- the tick and the send can't fail the job: what goes wrong is logged
- a summary is written back with no escaping beyond JSON's own and sent
  only if it fits the relay (64 KiB); a key twice is dropped, not thrown
- a driver_warm scenario's unmeasured start sends nothing
- the identifier names the attempt past the first, so a job offered
  again doesn't add to its first attempt's numbers
- the policy is read again before sending: unticking "Send performance
  statistics" during a job sends none
- a local run sends none
- a runtime that is a link is never ticked or read

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015KgSKnCVhRNx6p3Y8Zabk4
Author
Member

After: this PR, Settings' new tick (the app's window, rendered headless with a throwaway agent home).

settings-perf.png

After: this PR, Settings' new tick (the app's window, rendered headless with a throwaway agent home). ![settings-perf.png](https://git.magicbean.dev/attachments/631210f1-7430-4d93-bb6f-ed2a10534dc5)
gab9281 changed title from WIP: feat(agent): send the game's performance statistics from the farm's runs to WIP: feat(agent): send the game's performance statistics when a plan asks 2026-11-20 15:24:57 +00:00
Some checks failed
CI / Workflow lint (actionlint) (pull_request) Successful in 7s
CI / Conventional Commit title (pull_request) Successful in 8s
CI / Coordinator tests (pull_request) Failing after 1m27s
CI / Agent build and checks (pull_request) Successful in 45s
CI / Coordinator image (pull_request) Successful in 17s
This pull request has changes conflicting with the target branch.
  • README.md
  • agent/Core/Hardware.cs
  • agent/Core/Plan.cs
  • agent/README.md
  • agent/tests/agent_core/PlanChecks.cs
  • agent/tests/agent_core/TagChecks.cs
  • agent/tests/fixtures/plans/bad-schema.toml
  • coordinator/beanstalk/plan.py
  • coordinator/beanstalk/planner.py
  • coordinator/tests/test_plan.py
  • docs/protocol.md
  • docs/test-plan.md
  • docs/using.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feat/perf-statistics:gab9281-feat/perf-statistics'
git switch 'gab9281-feat/perf-statistics'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Beanstalk!113
No description provided.