← Engineering blog

A coding agent’s memory outlives its machine

Suppose a coding agent has edited three files, found a failing test, and paused for your answer. When you say “continue,” it remembers the patch. If its temporary machine has expired, that memory describes files that no longer exist.

Our Mainbrella provider for Open SWE has to handle that gap. It can create a Linux workspace and reconnect to it later, but it refuses to substitute a fresh machine when the old one is gone. Resuming a patch on an empty disk is a lousy recovery strategy.

The provider is in the October 8 commit of our fork. It gets machine identity right, but reviewing it through Open SWE’s caller exposed two unfinished parts: short commands consume retained job records, and an inherited file-deletion helper fails before it reaches the machine. Those are worth fixing before handing it a long coding session.

An assistant records a half-built mechanical project in a notebook while the actual parts sit on its workbench.
The same assistant returns holding the unchanged notebook, but the workbench has been cleared of its project.

The workspace belongs to a conversation

Open SWE takes an engineering request from GitHub, Slack, or its dashboard and works toward a pull request. It investigates the repository, changes code, runs checks, and responds to feedback. Deep Agents supplies its planning and file tools, while LangGraph keeps execution and conversation state between turns.

A follow-up in the same thread can depend on an uncommitted edit, installed packages, and the checkout that produced the last test failure. Open SWE records a sandbox ID in the thread’s metadata so it can reconnect to that work. Independent conversations can have independent workspaces.

We added Mainbrella to the existing provider registry using the project’s httpx2 dependency. The adapter sends asynchronous commands and binary file transfers over HTTP, so there’s no additional provider SDK to install. Open SWE’s file tools keep using the backend interface they already know.

Those tools assume they’re talking to the machine containing the thread’s work. Open SWE’s thread lifecycle already reports an error when it can’t reach a working sandbox. Our adapter reports that error too.

The slot can belong to another job

Consider our paused patch in container slot c1. The machine expires, then another job starts in the same slot. Looking up “c1” will find a running computer. It won’t find the computer that ran our test.

To tell the two machines apart, the adapter includes the slot and exact creation timestamp in its ID:

mainbrella:c1@2026-10-08T12:00:00.000Z

The timestamp identifies a generation: this particular incarnation of the slot. Reconnection checks the account’s container list for the same slot, timestamp, and running status. Commands and file transfers also send both values, so a machine that expires between the initial check and a later write can’t redirect that write into its replacement.

The thread retains its patch history through a pause. Below it, generation A expires and slot c1 is reused by generation B. A follow-up still addressed to A is rejected at B.

Accept any running c1

The agent has its old test result and a different filesystem. It may mistake missing work for a change in the repository, or start editing another job’s workspace.

Require the recorded generation

The adapter raises an error when that generation is missing, stopped, or replaced. The caller has to recover the missing work before resuming.

The generation check protects another job’s files; it can’t recover yours. This provider doesn’t automatically save or restore Mainbrella workspaces, and Open SWE’s LangSmith snapshot settings don’t apply to it. Push commits or export files before expiration. Unexported guest files are discarded when the machine stops.

Recover the machine without repeating the work

A lost HTTP reply doesn’t necessarily mean a lost machine. During creation, the adapter generates one idempotency key and reuses it for transport failures and HTTP 503 responses within a 120-second attempt. It keeps the image and size selection too, allowing the backend to find the original creation without consuming another start.

It doesn’t simply pick a running container from the account list. The creation receipt names the slot and generation it reserved; the adapter waits for that exact creation to be running and confirmed in the list. If the attempt remains ambiguous at its deadline, the exception includes the creation key for reconciliation. That key belongs to this attempt; starting the factory again generates a new one.

Appending a line to a file has no equivalent creation receipt. Replay that command after losing the response and the file may get the line twice. The adapter doesn’t replay foreground commands or file writes. The caller has to figure out whether the operation failed or only its reply disappeared.

For commands with longer timeouts, the adapter starts a managed job and polls its retained result. If the caller cancels that wait, the adapter requests cancellation of the job before passing the interruption back. But the cleanup block only takes effect once the initial POST has returned a job ID. Cancel during that request and the job may keep running until its deadline, because the backend doesn’t cancel jobs when a client disconnects.

A blanket “retry on network error” policy would undo that care. Looking up a reserved machine or a known job is safe to repeat. Arbitrary shell text isn’t.

The 60-second default that became five minutes

The adapter uses foreground execution for timeouts up to 60 seconds. Longer timeouts, up to 900 seconds, use managed jobs. That choice matters because Mainbrella retains at most 32 managed-job records per generation for one hour from admission, including jobs that have finished. Trying to start job 33 before a record expires returns 429 execution_history_limit.

The adapter’s own 60-second default would keep an ordinary git status out of that history. But Open SWE doesn’t call it with the default left alone. Open SWE’s per-thread proxy supplies 300 seconds when the caller omits a timeout. The adapter receives an explicit five-minute allowance and chooses managed execution even if the command finishes immediately.

Same short command, different path
CallerTimeout receivedExecution
Adapter directly; timeout omitted60 secondsForeground; no retained job
Open SWE thread proxy; timeout omitted300 secondsManaged; retains a job record
Thread proxy; explicit 60 seconds60 secondsForeground; no retained job

A local probe through the proxy confirmed that routing. A session can burn through all 32 records on quick shell calls without ever running a long job. Five minutes sounds like a generous default until it prevents command 33 from starting. We need to fix that policy before this path is ready for sustained work, and falling back from a timed-out foreground command to a managed job would risk running the command twice.

There’s a second inheritance trap. Most asynchronous file helpers in the installed Deep Agents BaseSandbox call the adapter’s async primitives, but deletion falls back to running the synchronous delete method in a worker thread. That method calls execute, which this async-only adapter deliberately rejects. Calling adelete reproduced a NotImplementedError before any HTTP request. File deletion through that helper needs its own async implementation; shell deletion remains available.

Both bugs slipped past the provider’s mocked HTTP tests because those tests called the adapter directly. The timeout comes from its caller; deletion comes from its parent class. Testing each method in isolation missed the way Open SWE uses them. Both problems are present in the reviewed commit. Our checks used mocked HTTP responses and local caller probes, without a live Open SWE agent run.

Prepare the image for Open SWE

The default catalog image is Python because the inherited file tools run python3 helpers inside the guest. A Node project still needs Python for those tools. Custom images should include Python, bash, git, and GNU coreutils, plus the project’s runtimes and Open SWE’s expected tools such as gh and rg. A workspace setup script can supply missing tools; the Python catalog image by itself isn’t a complete coding-agent environment.

Open SWE reapplies global Git identity when a run resumes, which needs a usable home directory. Mainbrella’s execution environment inherits only PATH, so the adapter restores HOME from the guest user’s account when it’s absent. Commands start in /workspace.

There are also hard limits to plan around: binary transfers and command output are capped at 1 MiB; a timeout preserves partial output and reports exit code 124; truncation retains its flag. A command’s timeout never extends the machine’s hard deadline. The adapter waits for command results; it doesn’t expose a live terminal or automatically add the platform’s other APIs as agent tools.

Try it on a disposable patch

Use the fork and commit linked above, with the existing Open SWE development setup. The base uv sync install includes what this provider needs. Add these values to Open SWE’s environment, using a key from the Mainbrella deployment you intend to call:

SANDBOX_TYPE="mainbrella"
MAINBRELLA_API_KEY="mb_..."
MAINBRELLA_CATALOG_ID="python"
MAINBRELLA_SANDBOX_SIZE="small"

An optional MAINBRELLA_IMAGE_ID selects a custom image instead of the catalog. MAINBRELLA_API_URL defaults to the hosted HTTPS API and accepts loopback HTTP for a local backend. Authentication and compute allowance are separate: the target deployment must also grant active access. The customization guide records the provider’s configuration, and the API contract describes retained-job limits.

Start with work you can afford to lose. Push the patch or explicitly save the workspace before stopping the machine, then check what a resumed conversation can reach. Until the timeout policy and deletion helper are fixed, this fork needs more adapter work before it gets a valuable repository.