Skip to content

Improvements for devbox robustness - #4775

Open
michaeljguarino wants to merge 28 commits into
masterfrom
devbox-robustness-pass
Open

michaeljguarino wants to merge 28 commits into
masterfrom
devbox-robustness-pass

Conversation

@michaeljguarino

@michaeljguarino michaeljguarino commented Dec 1, 2026 •

Copy link
Copy Markdown
Member
  • Proper crash detection
  • handle some grpc edge cases

KAS load & capacity

KAS CPU spiked with 20–30 devboxes active on one runner, and users were disrupted while the worker pool caught up.

  • Batched delta pushes. The gateway sends every box's deltas in one PushInstanceDeltas per 200ms. Before, each box sent its own every 50ms, so at about 25 active agents KAS proxied roughly 500 unary calls a second.
  • No resume storms. A wake is reported to console as provisioning ("resuming"), and a failed wake as suspended with its error. Viewer pings and resume_if_suspended calls stop re-requesting resumes while a wake is slow or failing. Console also debounces ping-driven resumes (resume_requested_at, 2 minutes). The UI shows "Resuming…".
  • Autoscaler sees waiting resumes. Every instance turned away for lack of room is recorded as demand, zoned or not, and keeps waiting up to ReadyTimeout instead of giving up after a minute. The operator counts zoneless demand for single-pool runners and watches the demand ConfigMaps, so scale-up starts within seconds. New spareInstancesPercent (default 10%), and the spareInstances floor is raised to 2.
  • KAS caches positive tunnel lookups per cluster for 5s, instead of a Redis scan on every control call.

Note: atenet-router calls ResumeActor on every routed request, even to running actors. That's in Substrate and isn't changed here.

Questions and approvals survive crashes

A box killed for exceeding its memory limit is reverted, and its pending questions and approvals expired with nobody told.

  • An expired question or approval stays answerable. The answer goes to its thread as a new prompt that names the question and the choice, waking the box if needed, and is recorded under a row lock. A replayed expiry can't undo it.
  • Question forms list the (Recommended) option first, and multi-select questions render as checkboxes instead of an empty text box.

Memory cap inside the box

The daemon builds a cgroup tree at boot, via sudo devbox-daemon cgroup-setup. The daemon sits in devbox/daemon, and devbox/workload is capped at 88% of guest RAM, with leaves for agent CLIs, terminals, the browser and Docker (--cgroup-parent). Processes start directly in their leaf (clone3 with CLONE_INTO_CGROUP), so every command a harness forks is capped without the harness knowing. At the cap the kernel reclaims page cache, then kills the largest process instead of the box being OOM-killed and reverted.

  • No memory.high. Without swap it throttled a test allocator indefinitely instead of killing it.
  • Safe fallback. It's only set up when the daemon is PID 1. Any failure leaves the box uncapped as before, and DEVBOX_NO_WORKLOAD_CAP opts out.
  • AGENTS.md now names heavy jobs, says to run them one at a time, and states the cap and what hitting it looks like.

Test Plan

  • Go: gateway (including new tests for cross-box delta batching and the resuming/failed-wake reports), actors (demand for zoneless resumes), operator autoscaler unit tests and devbox envtests, KAS (control lookup cache), daemon cgroup package (Prepare against a fake cgroupfs, delegation, fallback paths). All daemon packages pass except daemon/proc's TestDeprioritizeLowersAProcess, which this PR doesn't touch.
  • Elixir: devboxes_test, devboxes/ingest_test and devboxes/threads_test pass: 136 tests, covering the resume debounce, provisioning → suspended, late answers to expired questions and approvals (including a subagent's), and replay protection.
  • UI: DevboxInteractionCard and devboxIdle tests (expired cards, recommended-first, multi-select, "Resuming…"); biome, oxlint and tsc --build are clean.
  • Live check of the cap in a devbox: with a 512 MiB test cap, dev started a process directly in the leaf, and a 1.5 GB allocator was killed in under a second while the daemon and box were unaffected (memory.events recorded one oom_kill). The box's cgroups were restored afterwards.
  • Not run here: the operator's Ginkgo suite can't start its test API server in this sandbox. It fails the same way on the base branch.

Test environment: https://console.plrldemo.onplural.sh/cd/clusters/1fb8bed1-20a9-4ddd-b5f8-5a68f314cc79/services/501cb8b2-3ce2-440b-93d7-722e5929295d/components

Checklist

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have deployed the agent to a test environment and verified that it works as expected (required only when changing agent code).

Plural Flow: console

🤖 Generated with Claude Code

@michaeljguarino
michaeljguarino requested a review from a team as a code owner December 1, 2026 22:02
@michaeljguarino michaeljguarino added the enhancement New feature or request label Dec 1, 2026
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this (and set kas to the same sha tag)

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deployment PR created: https://github.com/pluralsh/plrl-up-demos/pull/3903 — Console and KAS are both pinned to sha-751479c.

@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The changes reach devbox lifecycle, Console state, runner capacity, and several API workflows.

Fix the reset-confirmation race before merging; it can leave restored thread updates permanently missing.

Findings

  1. P1 Skipped resets lose restored updates ▶

Summary

Improves devbox crash recovery, resume reporting, capacity tracking, and memory limits.

  • The gateway checks box health and repairs state after crashes.
  • The gateway combines box updates and KAS reuses recent tunnel lookups.
  • The daemon caps workload processes inside each devbox.
  • Slow devbox wakes stop triggering repeated resume requests.
  • People can answer expired devbox questions and approvals.
  • Devbox question forms put recommended choices first and show multi-selects as checkboxes.
  • Runner autoscaling counts waiting resumes as demand and keeps more spare boxes.
  • PR automation rules reject invalid and overly large patterns.
  • AI evidence collection handles services with no matching results.
  • Console API errors show clearer messages for common failures.

Reviews (3) · Last reviewed commit: "Leave instances still being adopted to a..." · Reviewed by Greptile

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this (and set the kubernetes-agent, kas, tag to the same sha)

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deployment PR created: https://github.com/pluralsh/plrl-up-demos/pull/3907 — Console, kubernetes-agent, and KAS are pinned to sha-c2f26dc.

@plural-copilot
plural-copilot Bot requested a review from a team as a code owner December 2, 2026 05:09
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this (and set kas to the same img tag)

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GitOps deployment PR has been created: https://github.com/pluralsh/plrl-up-demos/pull/3913

Console and KAS are both pinned to sha-3d0ecd0.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this (and set the kas image too)

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Follow-up: https://github.com/pluralsh/plrl-up-demos/pull/3914 updates both Console and KAS to sha-1991579 from this source PR head.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deployment promotion created: https://github.com/pluralsh/plrl-up-demos/pull/3917

This pins the Console image to sha-ad665e3 and is annotated for mgmt/apps reconciliation.

@michaeljguarino

Copy link
Copy Markdown
Member Author

@greptileai

michaeljguarino and others added 11 commits December 2, 2026 21:05
* Proper crash detection
* handle some grpc edge cases
* gateway: push every box's deltas in one PushInstanceDeltas per 200ms rather
  than one per box every 50ms, cutting the unary calls KAS proxies
* gateway: report a wake to console as provisioning ("resuming"), and a failed
  one as suspended with its error, so viewer pings and resume_if_suspended
  calls stop re-requesting resumes during a slow or failed wake
* console: debounce ping-driven resumes (resume_requested_at, 2 minutes) and
  allow provisioning -> suspended; show "Resuming…" in the UI
* actors: record demand for every instance waiting for room, zoned or not,
  and wait out ReadyTimeout instead of giving up after a minute
* operator: count zoneless demand for the single pool, add
  spareInstancesPercent (default 10) and raise the spareInstances floor to 2,
  and watch the demand ConfigMaps so scale-up starts within seconds
* kas: cache positive tunnel lookups per cluster for 5s instead of a Redis
  scan on every control call
* ui: list an option marked "(Recommended)" first in question forms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A box killed for exceeding its memory limit is reverted, and the daemon
expires every pending interaction: the agent process waiting on the reply
is gone. The question used to vanish with it.

* console: answering an expired interaction sends the answer to its thread
  as a new prompt (waking the box if needed), naming the question and the
  choice, and records it as answered under the row's lock; a subagent's goes
  to the thread that started it
* ingest: a replayed expiry never downgrades an answered interaction
* ui: expired requests keep their form or approval buttons with a note that
  the answer goes to the thread; expired approvals and subagent requests get
  a card too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A box that fills its memory is killed on the host and reverted to its last
snapshot, losing running turns, background jobs and unanswered questions:
nothing inside the guest pushed back first.

The daemon now builds a cgroup tree at boot (as root, through
`sudo devbox-daemon cgroup-setup`): itself in devbox/daemon, and a
devbox/workload group capped at 88% of the guest's memory, with leaves for
agent CLIs, terminals, the browser and Docker containers. Processes start
directly in their leaf (clone3 CLONE_INTO_CGROUP), so every command a harness
forks is capped without the harness knowing about cgroups. At the cap the
kernel reclaims page cache and then kills the largest process, not the box.

There's no memory.high: without swap, anonymous memory above it can't be
reclaimed and the kernel throttles instead of killing, which stalled a test
allocator indefinitely. Verified in a live box: a 1.5 GB allocator under a
512 MiB cap was killed within a second, the daemon and box unaffected.

* dockerd gets --cgroup-parent when the tree exists
* AGENTS.md's resources section names heavy jobs, says to run them one at a
  time, and states the cap and what hitting it does
* set up only when the daemon is PID 1; any failure leaves the box uncapped as
  before (DEVBOX_NO_WORKLOAD_CAP opts out)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude-agent-acp sends an AskUserQuestion with multiSelect as an array
property whose items list the choices (anyOf). The interaction card only read
enum and oneOf, so these questions rendered as an empty text box. They're now
checkboxes, recommended choice first, submitted as a list, with required,
minItems and maxItems checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* TestDeltasOfEveryBoxShareOnePush wrote to the second instance's forwarder
  before it existed: running() returns once the instance is RUNNING (set just
  before its forwarder starts) and once any forwarder subscribed, which the
  first instance's already satisfies. Wait for both forwarders.
* make sync in js/documentation for spareInstancesPercent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The AI cron analyzes stale services once Service.stable/1 lets them through
(10 minutes after their last update). A service its cluster never synced has
no component_status yet, and Evidence.Service.changed?/1 split it as a string:
String.split(nil, "/") crashed the memoizer task (FunctionClauseError), e.g.
for new bootstrap services on a cluster whose agent hadn't connected. Latent
since #3526.

* changed?/1 only parses a string component_status; nil or an unparseable
  one counts as changed, so the service is analyzed (why isn't it syncing?)
* service, cluster and service-component evidence no longer error-log
  {:ok, nil} from a component insight: that's Memoizer's "nothing to analyze"

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A user invoking a PR automation whose regex was `(image: (.*)` got
"unknown error": pull requests apply the automation's regexes with Go's RE2
in `plural pr template`, the failure came back as the CLI's output
(%Tee{}), and the REST fallback controller turned anything that wasn't a
string, atom or changeset into a bare "unknown error". The automation
itself had been accepted, so every pull request it created would fail.

* REST: the fallback describes errors the way the GraphQL error handler
  does (now ErrorHandler.message/1), so a failed template returns the CLI's
  message, without color codes
* console: saving a PR automation validates updates.regexes, updates.files
  and regex_replacements[].regex: they must compile, and PCRE-only syntax
  RE2 rejects (lookarounds, atomic groups, backreferences) is refused; a
  templated regex with template markers is left to pull request time
* CRD: CEL rules compile the same fields with RE2 (CEL's matches), so an
  invalid PrAutomation is rejected on apply. The rules use 'a' rather than
  '' for the probe string: gofmt rewrites '' in doc comments to a curly
  quote, which would break them. Verified against envtest 1.28.3 and 1.35.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
michaeljguarino and others added 5 commits December 2, 2026 21:05
* drop the console-side changeset validation: `plural pr template` now
  validates every regex up front with Go's RE2 (pluralsh/plural-cli),
  and its error reaches API callers through the fallback controller
* CRD rules read as what they check, type('a'.matches(r)) == bool: CEL has
  no "valid regex" function, and matches errors on a pattern that doesn't
  compile, which rejects the resource
* the CRD skips patterns with template markers wherever the CLI renders
  them first: regexReplacements[].regex (the CLI templates it whatever
  `templated` says) and files; regexes aren't templated, so always checked

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cause of the user report: a PR automation's configuration field had
validation regex `(image: (.*)`. Pr.Validation matched inputs with
~r/#{r}/, and interpolating into the sigil compiles at runtime with
Regex.compile!, which raised Regex.CompileError inside createPullRequest.
safe_resolver rescued it, and Console.GraphQl.Exception's fallback for an
unknown exception is "unknown error (check the logs for more details)".
Reproduced in a test against the old code before fixing it.

* Pr.Validation compiles the pattern with Regex.compile and returns an error
  naming the field, the pattern and why it's invalid
* Configuration rejects a validation regex that doesn't compile on save, so
  a new automation can't hold one (console evaluates this regex itself, with
  Elixir's engine, so this is the right place to check it)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The health loop adopts an actor running under a suspended instance once it
has been seen running for a HealthInterval, timed from the first check that
saw that state. The test made exactly one pass after advancing the clock, so
a background actor check that read the actor before it woke, applied late,
restarted that timer and the pass rightly declined to adopt: "timed out
waiting for running" in CI. Reproduced by injecting such a late check.

It now passes once per interval until the actor is adopted, as the live loop
does, still after asserting one sighting isn't enough.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Greptile: if console took the "resuming" report but missed every retry of
the failure report, it stayed at provisioning/"resuming" for good. Heartbeats
don't carry the status, the health loop saw the actor correctly suspended,
and an explicit resume of a "resuming" instance answers without reaching the
gateway, so the user couldn't recover.

reportSuspended keeps a report console didn't acknowledge pending, and the
health loop resends it each pass (retryReport, like retryReset) until console
takes it. A newer status supersedes it, and it keeps its generation, so a
late resend can't undo a newer status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
master (#4770) retries adoption until Substrate answers and marks the
instance adopting until it has seen the actor, keeping backstops and
Suspend/Resume away from it meanwhile. The health loop reconciled records
with actors without regard to that, so it could act on a just-loaded
instance whose record is stale. healthPass and checkActor now skip an
adopting instance, as the other backstops do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@plural-copilot
plural-copilot Bot force-pushed the devbox-robustness-pass branch from 53288a1 to 33a8497 Compare December 2, 2026 21:07
@michaeljguarino

Copy link
Copy Markdown
Member Author

@greptileai

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

Comment on lines +300 to +305
if !g.report(ctx, req) {
return false
}
inst.mu.Lock()
if inst.reverts == reverts {
inst.rec.IndexReset = false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Skipped resets lose restored updates

resetIndexLocked can clear IndexReset even though console skipped the reset. While retryReset sends generation N, a concurrent resume can report RUNNING with generation N+1. If N arrives later, console treats it as stale and returns success without resetting anything.

g.report treats that reply as confirmation and clears the flag. The forwarder then sends and acknowledges restored events that console drops because their revisions are too low. Keep the reset pending until console confirms it actually applied, or serialize reset reports with status reports.

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deployment GitOps PR created: https://github.com/pluralsh/plrl-up-demos/pull/3922 — it updates the Console main image to sha-33a8497 and is annotated for Plural Service: mgmt/apps.

michaeljguarino and others added 3 commits December 2, 2026 21:28
A user's service failed with "error preparing kustomize overlay: lstat
/tmp/manifestsXXXX/kustomize-postrender: no such file or directory" for one
chart while the same setup worked for another. The agent reads the overlay
(and luaFile/luaFolder) from the service tarball's root, but for a chart
from a helm repository (or another git repository) Services.tarstream only
splices in part of the service's own repository:

* with luaScript, all of it (so the overlay came along by accident)
* with valuesFiles, only those files: the overlay was dropped
* otherwise, nothing: the chart alone

tarstream now also splices in the post-render overlay, the lua folder and
the lua file from the service's repository, with or without values files
(folder names normalized, "." meaning the whole repository). The digest also
keeps the repository when a post-render overlay is set, so editing the
overlay in git redeploys the service.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It waited a fixed 3s and then required two reconciles, which DeQueueJitter
(1s) spaces apart; on a loaded CI runner that budget ran out ("Should be
true" at controller_supervisor_test.go:90). Wait for the two reconciles with
assert.Eventually and a generous deadline instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fork's plural/main branch is upstream main plus the privileged actor,
RootfsUpperDisks and BLOCK external volume patches. Sync the CRDs, Envoy
configs and SandboxConfigs from it, and mirror upstream's
automountServiceAccountToken: false on atenet-egress and rustfs.

The microvm SandboxConfig now pins a rootfs-upper-disk asset that atelet
fetches on every node, so microvm-assets embeds Substrate's
upper-disk.ext4.zst and stages it with the Kata and Cloud Hypervisor
assets. It stays optional for SandboxConfigs that don't pin it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deployment PR created: https://github.com/pluralsh/plrl-up-demos/pull/3928

It pins the demo Console image to sha-eff9ca7 and is annotated for Plural Service: mgmt/apps.

michaeljguarino and others added 7 commits December 2, 2026 16:12
A DevboxRunner can set home.volumeMode: Block (microvm pools on Block
storage only). The operator then asks Substrate for a BLOCK external
volume, which ateworker-microvm attaches as a virtio-blk disk, so home
writes go through the guest's page cache instead of virtiofsd's.

devbox-disk-prep creates device-mapper slots (ate-blk-<n>) that Substrate
grants to microVM workers with /dev/kvm. --block-slots=auto sizes them to
the node's CSI attach limit, so slots never run out before attachments do.
devbox-block publishes a home by loading the CSI device into a free slot
and resets the slot on unpublish.

Runners that don't set volumeMode keep filesystem homes, and existing
instances keep their revision.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The docs check ran in the test job that build-image needs, so a stale api.md held up the image. It is now its own job, and it also checks the docs site's copy.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	go/deployment-operator/pkg/devbox/gateway/tunnel/tunnel.go
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deployment requested and acknowledged. GitOps promotion: https://github.com/pluralsh/plrl-up-demos/pull/3946 (Console image tag sha-9a69a78; Plural Service: mgmt/apps).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant