Skip to content

ui-sdk: equal directory timestamps let a moved outside hardlink qualify a writable workspace #4471

Open

Description

@schlessera

Context

scanOnce in packages/ui-sdk/src/server/worker-sandbox.ts:307 records directory inode, mtimeNs and ctimeNs (line 319), then the stamp loop at :360-366 treats unchanged values as proof that no entry moved during the walk. A fast rename can retain both directory timestamps. A policy hardlink moved from an unvisited child into the already-listed workspaces root is then counted nowhere, and resolveWorkspacesMount at :502 incorrectly returns writable. Since PR #4444 (main a3395c4b2) the alias scan runs only when the session opted in to code changes (codeChanges = true); default turns get workspaces read-only without scanning, which narrows but does not remove the exposure.

The existing test at packages/ui-sdk/tests/worker-sandbox.test.ts:231, “an alias moved during the walk is still found,” detected this during PR #4314's full unit selection. At filing, both the test and production file were byte-identical to origin/main 7e861bdb3. PR #4444 has since changed both files (the code-changes opt-in and a readOnlyPath field in the refusal), but not the stamp comparison, so the defect is unchanged at a3395c4b2; the test now calls resolveWorkspacesMount(f.brain, undefined, true) and expects readOnlyPath.

On origin/main 7e861bdb3, using its own test preload in a separate Ubuntu 24.04 VM checkout, the unchanged test failed 87 of 100 repetitions. A second diagnostic run sampled the directory metadata immediately around the injected rename: 85 of 100 observations retained both mtimeNs and ctimeNs, and those same 85 scans returned writable and failed MOVED_ALIAS. No native runtime or provider was used by this filtered predicate test.

Out of scope

No #4314 native test isolation changes, workflow budget changes, default workspace policy redesign, or new filesystem extension interface. This issue is filed without a milestone as a separately reproduced main failure.

Scope

Repair the existing alias walk's detection of entry changes when timestamp equality is insufficient. Restrict the uncertain workspace mount read-only, using the current refusal path. Preserve contained hardlink and ordinary writable-area behavior.

Acceptance criteria

  • The moved-alias case refuses the workspace even when directory mtimeNs and ctimeNs remain unchanged across the rename.
  • Add deterministic proof of that timestamp-equality case; do not stabilize the test with a sleep that hides the production race.
  • Preserve the existing wholly contained-hardlink positive and the byte-name, symlink-swap and outside-link negatives.
  • Mutating away the new change detection makes the named case fail with MOVED_ALIAS, rather than a module-load or setup failure.

Verification

Baseline reproduction: bun run test packages/ui-sdk/tests/worker-sandbox.test.ts -t 'an alias moved during the walk' --rerun-each 100 at the main commit above, with main's own preload. The repro depends on the kernel's timestamp granularity (it was observed on an Ubuntu 24.04 VM); a kernel with fine-grained directory timestamps may not reproduce it, which is why the fix needs a deterministic proof that does not rely on the race. Run the whole worker-sandbox file and appropriate checks after the fix. Preserve the workflow gates and budgets.

Contract impact

No CLI/MCP/schema contract change expected. This repairs the existing workspace integrity guarantee.

2026-11-23 triage at main a3395c4: re-verified the stamp comparison is unchanged after PR #4444 and refreshed drifted citations by anchor. Priority set from p1 to p2: no milestone or schedule commits this, and the exposure needs a code-changes session, a pre-existing hardlink to a file outside workspaces and a rename inside one timestamp tick. A bounded local rerun was not possible in the triage checkout (dependencies not installed), so the VM evidence above stands as the reproduction.

Activity

  1. added
    type: fixSomething is broken and must behave the way it is documented.
    area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.
    priority: p1Scheduled into the current or next milestone.
    securityAuth, isolation, egress, secrets, or anything in the threat model.
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    and removed
    priority: p1Scheduled into the current or next milestone.
    on Nov 22, 2026
  2. schlessera commented on Nov 23, 2026

    @schlessera
    OwnerAuthor

    Triage changed the priority from p1 to p2. priority: p1 means scheduled into the current or next milestone, and this issue has no milestone. Since PR #4444, the alias scan only runs for sessions that opt in to code changes. The race also needs a hardlink to a file outside workspaces that already exists and a rename inside one timestamp tick. It stays security and agent-ready. If a maintainer schedules it into a milestone, raise it back to p1.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.securityAuth, isolation, egress, secrets, or anything in the threat model.type: fixSomething is broken and must behave the way it is documented.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions