fix(sandbox): pre-stage marketplace skills before workspace projection#2059
Merged
oss-maintainer merged 1 commit intoJul 9, 2026
Merged
Conversation
#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
Contributor
There was a problem hiding this comment.
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
beforeStartCallbackhook toSandboxLifecycleMiddlewareintended to run beforesandbox.start()workspace projection. - Extract
prestageMarketplaceSkills()intoHarnessSkillMiddlewareand wire it fromHarnessAgent.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 Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.skills-cache/was empty during sandbox workspace projection when using database-backedAgentSkillRepository(e.g. MySQL/PostgreSQL), becauseMarketplaceStager.stage()ran aftersandbox.start()beforeStartCallbackonSandboxLifecycleMiddlewarethat fires after acquire but beforesandbox.start(), allowing host-workspace resources to be materialised before projectionprestageMarketplaceSkills()fromHarnessSkillMiddlewareand wires it as the callback inHarnessAgent.Builder.build()Closes #2042
Test plan
SandboxLifecycleMiddlewareCallbackTestwith 4 tests covering:prestageMarketplaceSkills()materialises.skills-cache/correctlySkillRuntimeTestandMarketplaceStagerExecBitTestpassagentscope-harnessmodule compiles cleanly