Skip to content

fix(core): make recursive mkdir a single write-side op (no per-component exists walk)#1532

Merged
NathanFlurry merged 1 commit into
mainfrom
fix/native-recursive-mkdir
Jun 25, 2026
Merged

fix(core): make recursive mkdir a single write-side op (no per-component exists walk)#1532
NathanFlurry merged 1 commit into
mainfrom
fix/native-recursive-mkdir

Conversation

@NathanFlurry

@NathanFlurry NathanFlurry commented Jun 25, 2026

Copy link
Copy Markdown
Member

Problem

AgentOs.mkdir(path, { recursive: true }) (_mkdirp) probed every ancestor with a read-side exists() before each mkdir:

for (const part of parts) {
  current += `/${part}`;
  if (!(await this.#kernel.exists(current))) {
    await this.#kernel.mkdir(current);
  }
}

On the native sidecar every read-side fs op (exists/stat/readFile) triggers a full shadow-tree reconciliation walk in secure-exec. So a per-component exists() loop makes mkdir -p /a/b/c/d cost O(components × whole-shadow-tree) — a major contributor to the session-creation latency seen on populated VMs (each mkdir step paying a multi-second walk).

Fix

kernel.mkdir already defaults to recursive on both the native sidecar and compat kernels, and creating an existing directory is a no-op, so a single write-side call is sufficient (write-side ops skip the walk):

await this.#kernel.mkdir(path);

Test

Adds a regression test (recursive mkdir issues one mkdir and zero exists() probes) asserting recursive mkdir issues exactly one mkdir and zero exists() probes, while preserving behavior (all intermediate dirs created and writable, idempotent on repeat).

Note: this is the client-side half. The underlying secure-exec bug — read-side fs ops unconditionally re-walking the entire shadow tree — is fixed separately in the secure-exec repo.

`AgentOs.mkdir(path, { recursive: true })` (_mkdirp) probed every ancestor
with a read-side `exists()` before each `mkdir`. On the native sidecar every
read-side fs op triggers a full shadow-tree reconciliation walk, so a
per-component `exists()` loop makes `mkdir -p` cost O(components * tree) and is
a major contributor to session-creation latency on populated VMs. The kernel
`mkdir` is already recursive and creating an existing directory is a no-op, so a
single call is sufficient.

Adds a regression test asserting recursive mkdir issues exactly one `mkdir` and
zero `exists()` probes, while preserving behavior (intermediate dirs created,
idempotent).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@railway-app
railway-app Bot temporarily deployed to agentos / agentos-pr-1532 June 25, 2026 12:09 Destroyed
@railway-app
railway-app Bot temporarily deployed to rivet-frontend / agentos-pr-1532 June 25, 2026 12:09 Destroyed
@railway-app

railway-app Bot commented Jun 25, 2026

Copy link
Copy Markdown

🚅 Deployed to the agentos-pr-1532 environment in agentos

Service Status Web Updated (UTC)
agentos 😴 Sleeping (View Logs) Web Jun 25, 2026 at 12:18 pm

🚅 Deployed to the agentos-pr-1532 environment in rivet-frontend

Service Status Web Updated (UTC)
agent-os 😴 Sleeping (View Logs) Jun 25, 2026 at 12:14 pm

@NathanFlurry
NathanFlurry merged commit b5f5288 into main Jun 25, 2026
3 of 4 checks passed
@NathanFlurry
NathanFlurry deleted the fix/native-recursive-mkdir branch June 25, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant