Registry Mirror
Skip to content

Conversation

@aditya-shantanu

Copy link
Copy Markdown
Collaborator

What this is

We keep saying Substrate's sweet spot is "agents that are idle most of the time" — but none of our benchmarks actually behave like one. Glutton hammers one resource at a time, and sweperf needs an external image with a replay trace. This adds a workload that acts like the thing we're building for: a coding agent working through a task.

Each locust user is one session. The actor gets told to do the kind of things a coding agent does — clone a repo, install deps, build, hit a failing test, fix it, write tests, refactor, package — twenty steps, each one costing the sandbox the CPU, memory, disk, and network the real action would. Between steps the "LLM is thinking," so the driver suspends the actor, and the next step's first request wakes it back up through the router. That parked wake (WakeFirstTouch in the stats) is the number this whole benchmark exists to measure.

The part I care most about: the entire workload is one table in internal/benchmarking/boomer/agentsession/script.go. Every step says in plain English what the agent is doing and what it costs. If you want to know what step 6 does to the sandbox, you read step 6. If you want a different workload, you edit the table — tests will catch you if you write a step that reads a file nothing wrote, or blow the actor's memory budget.

To act the steps out, glutton grew two RPCs: BurnCPU (compute-bound work) and Ingest (bytes that actually cross the network before hitting disk, so a "git clone" is a real download, not a local write).

How it went when we ran it

Validated on a fresh 2-node GKE cluster, micro-VM first, then gVisor on the same hardware. Smoke runs were clean on both classes (gVisor: 1340 requests over 7 full laps, zero failures, wake p50 1.4s; micro-VM: wake p50 2.1s). At 20 concurrent sessions with realistic think times, gVisor held 2.6% failures with wake p50 1.3s. Pushing past the knee (~7 concurrently-active sessions on 8 vCPUs) was also useful: it reproduced the ateom-socket-vanishing failure from #1133 and left six actors permanently wedged in DELETING — a live repro of #1665.

Two things the first live run taught us are already folded in: RAM refills are in-place so repeat laps don't transiently double the guest heap (512Mi micro-VM actors OOM'd without this — use 1Gi), and the driver replaces an actor after three failed steps in a row, because a CRASHED actor never comes back on its own.

Future changes

Right now the script is compiled in — changing what steps do means editing the table and rebuilding the image. That's deliberate for this PR (one reviewable, test-guarded source of truth), but the follow-up we've agreed on is to make the script runtime-configurable: named script variants selectable per run first, then accepting a full script as a file so operators can define workloads without touching Go. That lands as its own PR once this one is in.

@chw120 Chenyi Wang (chw120) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean design — the declarative table in script.go + budget/ordering tests make this very easy to follow. A few comments on agentsession.go, mostly about reusing the failure/hibernate handling we already have in glutton/lifecycle.go.

// hibernate suspends (or pauses, per LifecycleMode) the actor at the end of
// a step. Failures are recorded but not fatal: the next wake reports the
// resulting state.
func (u *sessionUser) hibernate(ctx context.Context) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If SuspendActor/PauseActor fails here, the actor may still be RUNNING on the next step. In implicit mode, the next wake ping will return in a few ms against an already-awake actor and get recorded as a WakeFirstTouch success, pulling p50/p99 down under load. In explicit mode, the next ResumeActor will hit FailedPrecondition.

Can we track hibernatePending like glutton/lifecycle.go does (or skip recording WakeFirstTouch when the previous hibernate failed)?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, I don't think implicit resume is super valuable because it has such high flake potential and doesn't add much complexity. It's something we should exercise. Not sure if it needs to be exercised everywhere though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Added hibernatePending: a failed suspend/pause is re-driven at the top of the next step before anything is woken, so WakeFirstTouch only ever records a real wake. Covered by TestRunStep_RetriesStrandedHibernate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this benchmark the parked wake is the measurement, though: WakeFirstTouch in implicit mode is the user-visible resume latency, which is the number the workload exists for. Explicit mode stays as the control. The flake you're describing (waking an already-awake actor) is what the hibernatePending fix above closes.

@maxsmythe Max Smythe (maxsmythe) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really cool! Will be interesting to figure out how to push some of these scripts locally to glutton so that network isn't require to enable every op, but this is definitely where I would like to see glutton go, generally.

Comment thread benchmarking/README.md Resolved
Comment thread benchmarking/README.md
gap gets ±20% jitter so sessions don't move in lockstep.
* `--resume-mode implicit|explicit` — implicit (default) lets the parked
first request wake the actor; explicit issues ResumeActor before traffic.
* `--lifecycle-mode suspend|pause` — durable suspend (default) or node-local

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe explicit "pause" may be going away soon

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the existing shared --lifecycle-mode flag; agentsession just honors it like glutton does, so it goes when pause goes. Happy to drop the README mention now if you'd rather.

// hibernate suspends (or pauses, per LifecycleMode) the actor at the end of
// a step. Failures are recorded but not fatal: the next wake reports the
// resulting state.
func (u *sessionUser) hibernate(ctx context.Context) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general, I don't think implicit resume is super valuable because it has such high flake potential and doesn't add much complexity. It's something we should exercise. Not sure if it needs to be exercised everywhere though.

// the shape of a download.
opIngest opKind = iota
// opBurnCPU spins the sandbox's CPU for a wall-clock duration.
opBurnCPU

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be some overlap with this PR, potential to consolidate?

#1875

Also it still needs review

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at it. Different shapes: UseCPU is a steady background duty cycle that persists across resumes, BurnCPU is a bounded burst inside a step. Both fit an agent (idle draw plus bursts of work). If 1875 lands first I'll rebase and have BurnCPU reuse its burner loop.

@chw120

Copy link
Copy Markdown
Collaborator

LGTM. Thanks Aditya for adding the workload.

Emulates a fleet of coding agents: each locust user drives one actor
through a scripted 20-step coding task (clone, build, fix a test,
refactor, package), where each step costs the sandbox the CPU, RAM,
disk, and network the real action would. Between steps the actor is
suspended for the step's LLM think time and woken by the next step's
parked request through the router, so the run measures the wake
latency oversubscription depends on.

The script is a single declarative table in
internal/benchmarking/boomer/agentsession/script.go; glutton gains
BurnCPU (compute-bound work) and Ingest (bytes over the network to
disk) so the existing actor binary can act out every step.
The first live micro-VM run showed lap-2 RAM refills OOM-killing the
workload: TRUNCATE reallocates the array, transiently doubling the
guest heap on top of ~110Mi of tmpfs files. Refill in place with
OVERWRITE instead, raise the documented actor memory to 1Gi (observed
guest peak ~320Mi), and teach the driver to delete and recreate an
actor after three consecutive failed steps — a CRASHED actor never
recovers on its own and would wedge its session for the whole run.
…iver

Review feedback on the initial workload:

- WakeFirstTouch timed the step's first real op, so steps that lead
  with a long burn or a large ingest inflated the headline wake
  number. A dedicated ping now precedes each step's ops and is the
  only thing recorded as WakeFirstTouch; in implicit mode it is also
  what triggers the parked wake.
- The ingest payload is pre-generated once per worker and shared;
  generating up to 32Mi of random bytes per op counted client-side
  work inside the step timings and stressed the GC at high VU counts.
- A failed step now retries on the next iteration instead of
  advancing, so one transient failure no longer cascades NotFounds
  down the rest of the script; failed explicit resumes count toward
  actor replacement so a CRASHED actor cannot wedge its session.
- The user gauge no longer double-decrements when a session fails to
  start, agentsession leaves the default template set (it needs 1Gi
  actors, the shared default is 256Mi), BurnCPU caps its goroutine
  count at 4x the CPU count, and the budget-test comments now say
  what the test actually bounds.
TestSandboxAssetPrewarmDownloads failed; the test is unrelated to this
change and fails intermittently across branches.
… the extra template

The agent-session driver handled lifecycle failures on its own: every
failed step counted toward a three-strike replacement, a failed suspend
left the actor awake so the next "wake" was booked as a few-millisecond
WakeFirstTouch success, and control-plane RPCs ran without a deadline, so a
server-side hang parked the VU for the rest of the run.

Move glutton's failure classification, concurrent-update retry, and crashed
check into boomerutil and use them from both drivers. A CRASHED, NotFound,
or FailedPrecondition actor is replaced at once, capacity and availability
errors do not count against the actor, and ResumeActor retries update
conflicts. A failed suspend or pause sets hibernatePending and is re-driven
at the top of the next step before anything is woken. Every control-plane
call now carries a 60s deadline.

BurnCPU runs for fixed wall time, so step latency hides CPU contention;
export the per-goroutine iteration rate as a histogram so throttling is
visible.

The agentsession ActorTemplate was the glutton template under another
name, and actor memory is already a deploy flag, so drop it together with
the --agentsession-template flag. Sessions use the glutton template,
deployed with --actor-memory 1Gi.
@chw120

Copy link
Copy Markdown
Collaborator

LGTM

@MushuEE Grant McCloskey (MushuEE) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

… race-free test queue

Give ClassifyLifecycleFailure an explicit default arm instead of falling
out of the switch, make the retry test's error queue safe under parallel
tests, and derive the script's size units from iota.

@maxsmythe Max Smythe (maxsmythe) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maxsmythe
Max Smythe (maxsmythe) added this pull request to the merge queue Sep 30, 2026
Merged via the queue into agent-substrate:main with commit bc3cbc5 Oct 1, 2026
10 checks passed
Shrutiya Mohan (shrutiyam-glitch) pushed a commit to shrutiyam-glitch/substrate that referenced this pull request Oct 1, 2026
…able per run (agent-substrate#2046)

## What this is

Follow-up to agent-substrate#1934, as discussed there: the agent-session script moves
out of Go and into YAML, so a workload can be read, edited, and selected
without touching the driver.

- The default script is now
`internal/benchmarking/boomer/agentsession/scripts/coding-session.yaml`,
embedded in the boomer worker. It was generated from the old Go table
and round-trips byte-for-byte on every op.
- `--agentsession-script <name>` picks a built-in variant (any
`scripts/<name>.yaml`). Resolved on the worker's first iteration (the
knob arrives with the first spawn message, after Init); a bad name is
logged and retried each iteration, so fixing the knob and re-swarming
recovers.
- Decoding is strict and runs the same invariants the old tests
enforced: unknown op kinds or fields, arguments a kind does not take,
reads before writes, walks before fills, duplicate steps, non-positive
think times.
- Each script declares `min_actor_memory`. The worker reads the glutton
template's memory limit at start and refuses to run against a smaller
actor, with a message naming `--actor-memory`. That replaces the
README's advice with a guard.
- README gains a "Writing an agent-session script" section with the
format and the op table.

## Not in this PR

Loading a script from a file on the worker (ConfigMap mount) is the next
PR, on top of this loader.

## Testing

`go test -race` on the benchmarking packages, boilerplate, gofmt, and
golangci-lint pass. New tests: every embedded script loads; default
script shape (20 steps, 1Gi floor, declared bytes under budget);
encode/decode round trip; 14 rejection cases; the template memory guard
in refuse, exact, and no-limit modes.

Co-authored-by: Aditya Shantanu <aditya-shantanu@users.noreply.github.com>
Lior Lieberman (LiorLieberman) pushed a commit to LiorLieberman/agent-substrate that referenced this pull request Oct 6, 2026
…sandbox prewarm worker joinable, fixing the race (agent-substrate#1940)

## Summary

Fixes the flaky `TestSandboxAssetPrewarmDownloads` (unit lane).

**Root cause:** the test patches `nodepath.StaticFilesDir` /
`prewarmMaxJitter` and restores them in `t.Cleanup`, but returns as soon
as the prewarmed asset appears on disk. The prewarm worker goroutine is
still running its tail at that point (pause-image pull) and reads
`nodepath.StaticFilesDir` in `downloadVerified` while the cleanup writes
it — a data race that `-race` turns into a hard failure whenever the CI
runner is slow enough for the two to overlap.

**Fix:** the worker was not joinable — after context cancellation
nothing could wait for it to exit. `startSandboxAssetPrewarm` now
returns the prewarmer; its worker closes a `done` channel on exit and
exposes `wait()`. The test registers `t.Cleanup(p.wait)` after the
globals-restore cleanup, so (LIFO, and `t.Context()` cancels first) the
order becomes: cancel → join worker → restore globals. `main.go` ignores
the new return value.

Closes agent-substrate#1939

## Evidence

Cross-PR failures at ~1.5% of runs over the last week, including twice
on `main` and once on the benchmarking-only agent-substrate#1934 — run links in agent-substrate#1939.
The race trace pins write (test cleanup, `sandbox_prewarm_test.go:360`)
against read (`sandbox_assets.go:285` inside the worker).

## Test plan

- [x] `go test -race -run TestSandboxAssetPrewarm -count=200
./cmd/atelet/` — clean
- [x] `go test -race ./cmd/atelet/` — full package clean
- [x] Confirmed the direct `&sandboxPrewarmer{...}` test constructors
never call `run()`, so the nil `done` channel is never closed there

---------

Co-authored-by: Aditya Shantanu <aditya-shantanu@users.noreply.github.com>
Adhita Selvaraj (swiftdiaries) pushed a commit to swiftdiaries/substrate that referenced this pull request Oct 6, 2026
…ll op (agent-substrate#2230)

## Summary

The coding-session script (agent-substrate#1934, agent-substrate#2046, agent-substrate#2047) covers an agent that
computes in bursts and is suspended whenever it is not computing. An
always-on personal assistant of the OpenClaw / Hermes Agent kind looks
different: a gateway that stays resident at over a gigabyte, answers a
few dozen chat messages a day in short clusters, runs a heartbeat turn
every half hour, fires scheduled jobs, and rewrites its memory at night.
Most of its awake wall time is spent waiting on the model.

This adds:

- **`dwell` op**: the actor stays resident and idle for `millis` without
any request, the way a gateway sits in a model round trip or a typing
gap. The driver sleeps; nothing is sent. Decoder, encoder and `execOp`
support, with tests (decode, rejects `parallel`, sends no request,
honors context cancellation).
- **`personal-assistant` script** (`scripts/personal-assistant.yaml`):
one lap is one day in real time, 61 steps named by time of day. 30 user
messages in 7 clusters, 26 heartbeats (skipped where the user is
active), hourly system-event crons folded into the on-the-hour
heartbeats, a morning briefing, four model-catalog refreshes, one
context compaction, one nightly memory sweep. Every model turn reads the
bootstrap files and the session store, burns CPU, ships its context out
through the router (`read_disk_data` of a 96Ki file), dwells for the
round trip, and appends WAL. Resident set 640Mi at start growing to
about 960Mi (catalog, browser, nightly sweep). Per lap: about 65
CPU-seconds, 440 s of resident idle, 150 MiB written. Think gaps are the
real gaps, so run it with a fractional `--agentsession-think-scale`
(0.02 plays a day in about 30 minutes).
- README: the op table row and a "Built-in script variants" subsection.

## Evidence

Per-event sizes come from an strace and RSS profile of OpenClaw 2026.9.8
(Node 24) on a GKE pod, driven through its gateway API by a scripted
OpenAI-compatible mock that returned real tool calls (memory search with
embeddings, read, write, web fetch, an automation), plus a reading of
the OpenClaw and Hermes Agent source, docs and issue trackers. Measured:
1.2 GiB resident after start, 1.45 to 1.54 GiB after one conversation
and never back down; a plain turn reads 5 to 7 MiB of SQLite, writes 1
to 4 MiB of WAL and ships a 50 to 110 KiB request that grows with the
session; a tool-loop turn reads 36 MiB, writes 9.6 MiB and makes three
model calls; a heartbeat is a chat turn with no user; idle is about 1%
of a core. CPU under strace is inflated 1.5 to 3x, so the script burns
0.5 s per plain turn where strace showed 0.6 to 1.0 s. Day shape (about
30 messages a day in clusters, heartbeats outnumbering user turns,
nightly consolidation, catalog refreshes) comes from the projects' docs
and first-person usage reports. The script header lists the figures; the
browser steps and the dwell durations are from field reports, not the
profile.

Two things the day makes visible: an assistant's heartbeats and crons
are internal timers, which cannot fire in a suspended sandbox, so each
of those turns is a wake something external must provide; and at this
resident size memory, not CPU, bounds instances per node.

## Test plan

- `go test ./internal/benchmarking/...` (new tests: dwell
decode/reject/no-request/cancel; the embedded-script test loads the new
variant)
- `./benchmarking/locust/deploy.sh --deploy --user-class agentsession`
then start a swarm with `agentsession_script=personal-assistant`,
`agentsession_think_scale=0.02`, `lifecycle_mode=pause` on a kind or GKE
cluster; one lap should complete in about 30 minutes with 61 `Step_*`
rows.

Co-authored-by: Aditya Shantanu <aditya-shantanu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/benchmarking kind/feature An enhancement / feature request or implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants