Skip to content

fix(sandbox): pre-stage marketplace skills before workspace projection#2059

Merged
oss-maintainer merged 1 commit into
mainfrom
fix/prestage-skills-before-sandbox-projection
Jul 9, 2026
Merged

fix(sandbox): pre-stage marketplace skills before workspace projection#2059
oss-maintainer merged 1 commit into
mainfrom
fix/prestage-skills-before-sandbox-projection

Conversation

@chickenlj

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes a timing issue where .skills-cache/ was empty during sandbox workspace projection when using database-backed AgentSkillRepository (e.g. MySQL/PostgreSQL), because MarketplaceStager.stage() ran after sandbox.start()
  • Adds a beforeStartCallback on SandboxLifecycleMiddleware that fires after acquire but before sandbox.start(), allowing host-workspace resources to be materialised before projection
  • Extracts prestageMarketplaceSkills() from HarnessSkillMiddleware and wires it as the callback in HarnessAgent.Builder.build()

Closes #2042

Test plan

  • New SandboxLifecycleMiddlewareCallbackTest with 4 tests covering:
    • prestageMarketplaceSkills() materialises .skills-cache/ correctly
    • Staging is idempotent (safe to call twice)
    • Null stager is a no-op
    • Method-reference callback wiring works end-to-end
  • Existing SkillRuntimeTest and MarketplaceStagerExecBitTest pass
  • Full agentscope-harness module compiles cleanly

#2042)

When using a database-backed AgentSkillRepository in sandbox mode,
.skills-cache was empty at projection time because MarketplaceStager.stage()
ran during onSystemPrompt (inside the Flux.using body), which executes after
sandbox.start() (inside the Flux.using resource supplier).

Add a beforeStartCallback on SandboxLifecycleMiddleware that fires after
acquire but before sandbox.start(). Extract prestageMarketplaceSkills() from
HarnessSkillMiddleware so the callback can materialise .skills-cache on the
host workspace before projection hydrates it into the sandbox.

Closes #2042

Copilot AI 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.

Pull request overview

This PR addresses a sandbox timing issue where workspace projection could run before marketplace skill resources were staged into .skills-cache/, particularly impacting database-backed AgentSkillRepository implementations. It introduces a pre-start callback hook in SandboxLifecycleMiddleware and wires HarnessSkillMiddleware to pre-stage marketplace skills prior to sandbox startup.

Changes:

  • Add a beforeStartCallback hook to SandboxLifecycleMiddleware intended to run before sandbox.start() workspace projection.
  • Extract prestageMarketplaceSkills() into HarnessSkillMiddleware and wire it from HarnessAgent.Builder.build().
  • Add a new JUnit test class to validate .skills-cache/ materialization behavior and callback method-reference usage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/SandboxLifecycleMiddleware.java Adds a configurable callback hook intended to run before sandbox start/projection.
agentscope-harness/src/main/java/io/agentscope/harness/agent/middleware/HarnessSkillMiddleware.java Introduces prestageMarketplaceSkills() to stage marketplace resources ahead of sandbox start.
agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java Wires the new pre-start callback to call prestageMarketplaceSkills().
agentscope-harness/src/test/java/io/agentscope/harness/agent/middleware/SandboxLifecycleMiddlewareCallbackTest.java Adds tests around .skills-cache/ staging and (simulated) callback wiring.

Comment on lines +67 to +75
/**
* Registers a callback that runs after the sandbox session is acquired but before
* {@link io.agentscope.harness.agent.sandbox.Sandbox#start()} applies workspace projection.
* This allows callers to materialise resources on the host workspace (e.g.
* {@code .skills-cache/}) so that projection picks them up in the same call.
*
* @param callback receives the per-call {@link RuntimeContext}; may be {@code null} to clear
*/
public void setBeforeStartCallback(Consumer<RuntimeContext> callback) {
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

@oss-maintainer oss-maintainer merged commit 37bb6e7 into main Jul 9, 2026
12 checks passed
@oss-maintainer oss-maintainer deleted the fix/prestage-skills-before-sandbox-projection branch July 10, 2026 04:27
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.

Sandbox workspace projection runs before MarketplaceStager stages .skills-cache

3 participants