Skip to content

fix(agents): preserve sandbox skills during concurrent runs - #181807

Open
yinx65588-boop wants to merge 1 commit into
openclaw:mainfrom
yinx65588-boop:fix/sandbox-skill-catalog-retention
Open

yinx65588-boop wants to merge 1 commit into
openclaw:mainfrom
yinx65588-boop:fix/sandbox-skill-catalog-retention

Conversation

@yinx65588-boop

@yinx65588-boop yinx65588-boop commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #122554

What Problem This Solves

Fixes sandboxed agents reading another run's skill instructions, or losing advertised skills, when concurrent runs refresh a shared skills directory.

User Impact

An active run keeps its advertised instructions and companion files until its tools and asynchronous cleanup finish. Eligible copies remain readable by a non-host container user without changing source permissions. No configuration changes or migration are required. Sandbox owner/security review is appropriate for this change.

Why This Change Was Made

Publish a retained catalog below the existing mounted directory and prepare the prompt from that exact catalog. Reuse the existing disposable sandbox result and asynchronous work owner; native staging locks preserve live catalogs and permit cleanup after a process dies. Settled turns keep their session's prompt locations. An ordinary copy failure omits that skill with a warning; required library selections still fail. Preparation copies each run's catalog rather than relying on mutable shared copies.

This builds on the investigation and unmerged implementation in #122679 by @eightHundreds, including its unresolved copy-failure, SDK-lifetime and abandoned-directory findings.

Evidence

  • Exact reviewed PR head: full build and shipped CLI/Docker proof passed on 4b85835fc16692ebc86b491913b1f6f989df7a79, checked out directly without applying a patch. Four real agent turns completed through the built CLI and Gateway with actual Docker reads. The pinned workflow and controlled fixture reproduce the run; the HTTP model is synthetic and isolated to loopback.
  • Real baseline reproduction: the first sandbox's advertised path reads the later run's replacement instructions.
  • Shipped Gateway/CLI and Docker comparison: B and C finish while A is paused. Baseline A reads C's instructions and companion; repaired A retains its originals. Independent Docker UID 65534 probes read all four catalogs, including copies of a 0700/0600 source whose permissions stay unchanged. The model transport is synthetic, loopback-only, with no paid provider calls.
  • 163 focused regressions and four type graphs: context, publication, killed-process recovery, delayed cleanup, prompt stability, native dispatch and CLI controls pass; production/test types and changed-file lint/format pass. That run stops on six stale mock baseline rows, removed and verified in the next evidence link.
  • Final mock and line-cap guards: pass, with exactly six obsolete baseline rows deleted. Its other 17 file patches are byte-identical to the validated candidate.
  • Generated-file Git discovery regression: the existing Git-discovery test first exposes generated ownership files; the runtime-owned ignore fix passes 24 materializer/custody tests, targeted types, lint and guards.
  • Independent Codex review of the final patch and coupled source modules completed in two passes with no actionable P0–P2 findings; source-consistency checks passed. This was source review, separate from the execution evidence above.

Exact-head result, verified against the downloaded artifact and source stamp:

Source: 4b85835fc16692ebc86b491913b1f6f989df7a79
A pauses; B and C finish; A resumes: OriginalAlpha retained
B: ReplacementBeta; C: ReplacementGamma; D: PrivateDelta
Independent Docker UID 65534: all four instructions and companions readable
Original private source: directory 0700, SKILL.md 0600, unchanged
Model requests: 8; fixture failures: 0; paid provider calls: 0
Production build and shipped proof: success

The final change retains the existing mount, SDK disposer and async-work owner. The additional catalog publication/custody code is necessary to keep both instructions and companion files alive; production +394/-10, tests +362/-3, docs +6, and six obsolete mock-baseline rows removed.

Linux/Docker is exercised. Live SSH/OpenShell transport concurrency and Windows execution are not covered by this proof.

Repository automation note: Auto response on this PR fails in the unchanged Barnacle isPrivilegedActor code (Cannot read properties of undefined (reading 'owner')). The same failure on an unrelated PR confirms it also occurs outside this change; it is separate from the sandbox validation above.

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime docker Docker and sandbox tooling agents Agent runtime and tooling size: L labels Oct 23, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@yinx65588-boop
yinx65588-boop marked this pull request as ready for review October 23, 2026 18:08
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Maintainer security review required

This external contributor PR changes sensitive security components. A maintainer must review these changes before merging.

Current SHA: 4b85835fc16692ebc86b491913b1f6f989df7a79

These sensitive security changes were made:

  • src/agents/embedded-agent-runner/sandbox-skills.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/context.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.
  • src/agents/sandbox/skill-catalog.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

After reviewing the changes, post a new PR comment containing only approval commands, each on its own line:

/allow-security-sensitive-change

A later push requires a fresh approval comment.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR publishes retained per-run skill catalogs and keeps their instructions and companion files until execution cleanup settles.

Example: Run A advertises OriginalAlpha, then runs B and C publish ReplacementBeta and ReplacementGamma in the same Docker sandbox.

  • Before: A can read C's replacement instructions or encounter missing files.
  • After: A retains OriginalAlpha and its companion file while B and C use their own catalogs.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Strong shipped Docker evidence supports the intended local fix, but the introduced remote missing-path regression blocks merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Submitted live output and the inspected pinned workflow exercise the exact-head built CLI, Gateway, concurrent agent turns, and real Docker reads with a controlled loopback model transport. A retains OriginalAlpha after B/C completion, UID 65534 reads each instruction and companion, and private source modes remain unchanged. Raw artifact access is blocked by the reviewer environment's allowlist; that limitation does not invalidate the supplied Docker evidence.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Concurrent sandboxed agents can lose eligible skill instructions or read another run's replacement files.
Reason: The local Docker repair restores documented readable skill behavior, but the linked issue also includes remote refresh failures; until those are addressed, the relationship to #122554 should remain Related rather than Closes.

Merge readiness

⛔ Blocked before merge - 3 items remain

This PR addresses a concrete concurrency bug, but remote sandbox integration needs correction before merge.

Priority: P1
Reviewed head: 4b85835fc16692ebc86b491913b1f6f989df7a79

Before merge

  • Deliver new catalogs to reused remote sandboxes before advertising them (P1) - This selects per-session catalogs for SSH as well as Docker, but the remote backend still uploads the workspace only during first bootstrap. With backend ssh, workspaceAccess none or ro, and scope agent, run session A once and then start session B on the same runtime: B advertises a different skills/.openclaw-catalogs/run-.../skills/... path, while ensureRuntimeInner returns because the remote runtime exists and refreshRemoteSkillsWorkspace returns because access is not rw. The advertised file therefore exists only on the host and B's read fails with file not found. An existing remote runtime after upgrading has the same problem because publicationNamespace changes between processes. Integrate catalog publication with the remote delivery owner and cover reused none/ro runtimes rather than assuming the host directory is mounted.
  • Await maintainer action - A maintainer must approve the corrected current revision through the enforced security-sensitive review gate before merge.
  • Explain or restore the original intent of Sandbox-readable skill paths and remote delivery - 3b6bcbf: Materialize eligible skills into sandbox-readable roots and thread their delivery through Docker, SSH, filesystem bridges, prompts, and compaction.

Findings

  • [P1] Deliver new catalogs to reused remote sandboxes before advertising them — src/agents/sandbox/context.ts:154-157

Provenance

  • Sandbox-readable skill paths and remote delivery changes intended behavior without addressing why it exists (3b6bcbf: Materialize eligible skills into sandbox-readable roots and thread their delivery through Docker, SSH, filesystem bridges, prompts, and compaction.)

Tests

  • Missing end-to-end proof: The supplied shipped Docker proof does not exercise newly advertised catalogs against reused SSH runtimes or remote state retained across an upgrade.
Agent review details

How this fits together

Sandbox preparation materializes eligible host skills, maps their locations into the sandbox, and supplies the agent prompt; execution owners release those files after asynchronous work settles.

flowchart LR
  A[Eligible source skills] --> B[Workspace materializer]
  B --> C[Retained run catalog]
  C --> D[Sandbox transport]
  C --> E[Prompt snapshot]
  E --> F[Agent tool reads]
  D --> F
  F --> G[Execution cleanup]
Loading

Technical review

Best possible solution:

Keep execution-owned catalogs in the existing materializer and make remote delivery publish and retain each advertised catalog before tools can read it.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the shared refresh/read interleaving, supported by the linked official-release reports and submitted baseline reproduction; source inspection also establishes the introduced reused-SSH missing-path failure, without executing target code.

Is this the best way to solve the issue?

Retaining instructions and companion files through the existing execution owner is appropriate, and the added lifecycle and recovery machinery serves distinct failures; the cutover is incomplete because remote transports do not consume the new catalog lifecycle.

Full review comments:

  • [P1] Deliver new catalogs to reused remote sandboxes before advertising them — src/agents/sandbox/context.ts:154-157
    This selects per-session catalogs for SSH as well as Docker, but the remote backend still uploads the workspace only during first bootstrap. With backend ssh, workspaceAccess none or ro, and scope agent, run session A once and then start session B on the same runtime: B advertises a different skills/.openclaw-catalogs/run-.../skills/... path, while ensureRuntimeInner returns because the remote runtime exists and refreshRemoteSkillsWorkspace returns because access is not rw. The advertised file therefore exists only on the host and B's read fails with file not found. An existing remote runtime after upgrading has the same problem because publicationNamespace changes between processes. Integrate catalog publication with the remote delivery owner and cover reused none/ro runtimes rather than assuming the host directory is mounted.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e96c7041019b.

Provenance checked

  • Unchanged-tree reuse changes intended behavior with a stated reason (232281f: Avoid rediscovery and recursive copies when the watched skill snapshot is unchanged.)
  • Generated skill Git visibility keeps the original intent (5004720: Exclude generated skill copies from ordinary Git discovery while preserving tracked and project-file visibility.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +384, Tests +359, Docs +6, Other -6. Total +743 across 18 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 394 10 +384
Tests 8 362 3 +359
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 6 -6
Total 18 762 19 +743

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #122554
Summary: This PR is a local retained-catalog repair candidate for the canonical concurrency report; remote publication remains overlapping work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported concurrency defect disrupts sandboxed automation, and the patch introduces missing advertised skill paths in supported SSH setups.
  • merge-risk: 🚨 compatibility: Existing remote runtimes with workspaceAccess none or ro can survive an upgrade while lacking every newly advertised catalog path.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 23, 2026, 2:30 PM ET / 18:30 UTC.

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

agents Agent runtime and tooling docker Docker and sandbox tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-review-required security-sensitive-changed size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Concurrent sandboxed runs race on shared materialized skills dir and omit skills from <available_skills>

1 participant