Skip to content

fix(harness): preserve explicit sandbox snapshot specs - #2363

Open
March-77 wants to merge 3 commits into
agentscope-ai:mainfrom
March-77:agent/preserve-sandbox-snapshot-spec
Open

March-77 wants to merge 3 commits into
agentscope-ai:mainfrom
March-77:agent/preserve-sandbox-snapshot-spec

Conversation

@March-77

@March-77 March-77 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.1-SNAPSHOT

Description

Background

Filesystem-specific snapshotSpec(...) overrides stored the value only in each subclass. The base SandboxFilesystemSpec.snapshotSpecOverride therefore remained null, allowing HarnessAgent to replace an explicit filesystem snapshot configuration with the DistributedStore default.

Changes

  • Synchronize the base explicit snapshot override from all five production covariant setters: Docker, Daytona, Kubernetes, AgentRun, and E2B.
  • Preserve each subclass's existing snapshot field and fluent return type.
  • Add a harness regression test proving an explicit LocalSnapshotSpec takes precedence over a distributed store's NoopSnapshotSpec.
  • Add module-local regression tests for AgentRun, Daytona, E2B, and Kubernetes so each covariant setter is directly covered.

Fixes #2254

Testing

Passed:

mvn -pl agentscope-harness -Dtest=HarnessAgentDistributedSandboxTest test
mvn -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-daytona,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-agentrun,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b test
mvn -pl agentscope-harness,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-daytona,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-agentrun,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b spotless:check
mvn -pl agentscope-harness,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-daytona,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-agentrun,agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b -DskipTests package

The four extension modules now pass 52 tests in total (24 Kubernetes, 17 AgentRun, 1 Daytona, and 10 E2B).

A full agentscope-harness module test run executed 649 tests with 0 assertion failures, but Maven reported 5 unrelated Windows JUnit temporary-directory cleanup errors (DirectoryNotEmptyException).

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions (no new public API; inherited method documentation remains applicable)
  • Related documentation has been updated (not applicable; no documented behavior or API surface changed)
  • Code is ready for review (opened as a draft)

@CLAassistant

CLAassistant commented Jul 22, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@March-77
March-77 marked this pull request as ready for review July 23, 2026 03:36
@oss-maintainer

This comment was marked as abuse.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Looks good.


Automated review by "github-manager-bot"

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/extensions agentscope-extensions (general) area/harness agentscope-harness (test/runtime support) labels Aug 11, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a critical bug where a user's explicitly-set SandboxSnapshotSpec on any sandbox filesystem subclass (AgentRun, Daytona, E2B, Kubernetes, Docker) was silently overwritten by the HarnessAgent builder with the distributed store's default snapshot spec. The fix makes each subclass override call super.snapshotSpec() to propagate the override marker to the parent class. Test coverage is strong: 4 new unit tests + 1 integration test.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a critical bug where a user's explicitly-set SandboxSnapshotSpec on any sandbox filesystem subclass (AgentRun, Daytona, E2B, Kubernetes, Docker) was silently overwritten by the HarnessAgent builder with the distributed store's default snapshot spec. The fix makes each subclass override call super.snapshotSpec() to propagate the override marker to the parent class. Test coverage is strong: 4 new unit tests + 1 integration test.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This PR fixes a critical bug where a user's explicitly-set SandboxSnapshotSpec on any sandbox filesystem subclass (AgentRun, Daytona, E2B, Kubernetes, Docker) was silently overwritten by the HarnessAgent builder with the distributed store's default snapshot spec. The fix makes each subclass override call super.snapshotSpec() to propagate the override marker to the parent class. Test coverage is strong: 4 new unit tests + 1 integration test.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@March-77

Copy link
Copy Markdown
Contributor Author

Rechecked the current status: all checks are passing, the PR is mergeable/clean, the existing approval remains valid, and there are no unresolved review threads. When convenient, could a maintainer please merge this PR? Thank you!

@March-77
March-77 force-pushed the agent/preserve-sandbox-snapshot-spec branch from ca908bb to 11c98cc Compare September 22, 2026 16:49

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Re-review at 11c98cc3 (previous pass: APPROVED on 335005a3, 2026-07-24). The branch was squashed onto current main, so this pass looks at the whole change again.

The fix is minimal, correct, and consistent across every sandbox spec in the tree. Each concrete spec now declares @Override on snapshotSpec(SandboxSnapshotSpec) and calls super.snapshotSpec(snapshotSpec) before assigning its own field, so the inherited SandboxFilesystemSpec.snapshotSpecOverride is actually populated. Without that, HarnessAgent (if (sandboxFilesystemSpec.getSnapshotSpecOverride() == null) { ... distributedStore.sandboxSnapshotSpec() }) could not distinguish "operator chose a snapshot spec" from "default", and a distributed store would silently replace an explicit NoopSnapshotSpec / provider-specific spec. Covering all five implementations (agentrun, daytona, e2b, kubernetes, docker in harness) in one change is the right call — a partial sweep would have left the same bug in whichever provider was skipped.

The covariant return types (AgentRunFilesystemSpec snapshotSpec(...)) keep the fluent chain provider-typed, and snapshotSpec() (the protected no-arg accessor) still reads the subclass field, so no behavior changes for non-distributed builds. Tests assert both the fluent return identity and the two accessors per provider, and HarnessAgentDistributedSandboxTest covers the precedence that the fix is about. CI is green on Linux and Windows and license/cla is signed.

Findings

  • [Info] The subclass fields (private SandboxSnapshotSpec snapshotSpec) now duplicate state that the base class already tracks in snapshotSpecOverride, and the two must be kept in sync by hand. Either delegate the accessor (protected SandboxSnapshotSpec snapshotSpec() { return getSnapshotSpecOverride(); }) or drop the local field in a follow-up, so a future provider spec cannot reintroduce the drift this PR fixes.

No blocking issue. Merging is a maintainer decision.


Automated review by github-manager-bot

@oss-maintainer

Copy link
Copy Markdown
Collaborator

⚠️ Merge conflict detected

This PR has conflicts with the main branch and cannot be merged. Please rebase or merge main into your branch and resolve the conflicts:

git fetch origin
git checkout agent/preserve-sandbox-snapshot-spec
git rebase origin/main
# resolve conflicts, then:
git push --force-with-lease

This is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved.


Automated notification by github-manager-bot

xzxiaoshan added a commit that referenced this pull request Nov 26, 2026
…#4435)

## Background

Swept the last 125 PRs (#4434→#4239), every single-OS-failed CI run
since 2026-11-19 and the main-branch push runs for `mvn -B -T1C clean
verify` failures (one build OS red and the other green on the same
commit = flake suspect). Four test classes still fail on current main:
three fail on windows-latest only, and the fourth sits at its deadline
on both OSes. All fixes are test-side only (no `src/main` changes).

## Fixes and evidence

| Test class | Victims | Signature | Fix |
|---|---|---|---|
| `HarnessAgentStructuredOutputStreamEventsTest` | #4296, #4349, #4071,
main run 44879286932 (2026-11-20 to 11-23), all windows-latest |
`streamEvents(...).block(10s)` timed out at 10.2-11.3s per call; the
class takes 3.7-9.6s on windows-latest when green and 1-1.5s on ubuntu |
ephemeral `InMemoryThreadJournalStore` in the three workspace-backed
tests (the fourth already used one) |
| `HarnessAgentOverflowRecoveryTest` | #4042, #4426 (2026-11-26), both
windows-latest; the journal rows were added by #4399 on 11-25 | row
`[3]` (journal=true) crossed `block(30s)` at 36.3-38.1s and row `[4]`
passed with 33.8s; the same rows take 0.4-1.3s on ubuntu, and main's own
run 45595615922 needed 61s for the class on windows-latest | ephemeral
`InMemoryThreadJournalStore` in `newAgent` |
| `DashScopeMultiModalEmbeddingTest` | #4413 (2026-11-25),
windows-latest | the first SDK request in the fork hit the 5s latch
(7.29s elapsed); the class takes 1.4-4.2s on windows-latest even when
green | first-request latch 5s→15s |
| `AnthropicAutoConfigurationTest` | #2363, run 45137197507
(2026-11-23), windows-latest | the first gateway test crossed
`block(10s)` at 15.66s; the other three take under 1s, and this one
already takes 5-11s on windows-latest and 9-12s on ubuntu when green |
block 10s→30s |

The first two share one cause: since #4154 the default workspace journal
is `SqliteJournalStorage` on Windows, which opens a JDBC connection per
storage operation and commits every CAS as a durable transaction (DELETE
journal, synchronous EXTRA). A journaled turn issues about 20 such
writes at roughly 8ms each on a fast local disk. Neither class asserts
journal persistence, so they now use the ephemeral backend the
repository already documents for tests. Locally on Windows the
overflow-recovery class dropped from 17.9s to 5.6s and the
structured-output class from 3.2s to 1.6s.

## Constraint compliance

- Happy path zero cost: the journal swap removes work, the two
relaxations only move failure deadlines, and no sleeps or weakened
assertions were added.
- Structural hardening first: the journal swap is structural. For the
two cold-start waits the structural alternative, a warm-up request
before the timed section, would add a request to every run, so the
deadline was relaxed instead.
- Minimal widening anchored to measured data: each relaxation is 3x the
deadline that was crossed, and every comment cites its victims and
measured values.
- No `src/main` changes.

## Observed but deliberately not fixed here

-
`WorkerRuntimeTest.saturatedStartsDoNotBlockRecoveryAndDrainPreservesActiveLeases`
(#4294, windows-latest, 36.19s at the `renewed` latch): with the test's
4s worker lease a heartbeat delayed by more than 2.7s finds the lease
already expired and fails with `Worker lease lost` instead of arriving
late, so widening the latch (as #4274 did to 30s) cannot help. That
latch is the only place asserting the runtime renews leases, and a
longer lease would delay the first heartbeat by lease/3, so the fix
needs a design decision.
-
`SubagentFactoryDeclarationTest.declaredFactory_persistSessionIsolatesUsers`
(main run 45172445003, 2026-11-23, 31.45s) and
`ChatControllerTest.httpUsesExplicitCreationAndTargetedIdempotentControls`
(main run 44566773929 and #4255, both 2026-11-19): no recurrence since.
- Two windows-latest hangs that ended at the 2h job timeout:
`AgentSpawnToolPermissionTest` (#4305, run 44760439728) and
`AgentSpawnToolPlanModeTest` (main run 45739005058 on the current head).
Both classes wait with unbounded `.block()`; the root cause is not
established, and the 30-minute Surefire fork timeout in the root pom did
not end either run.
- The cost of the Windows default journal itself (one JDBC connection
and one durable transaction per storage operation) is a production
concern that deserves its own `src/main` change.
- Already fixed upstream, victims predate the fix:
`JevEvidenceProcessorTest` (13 runs, fixed by #4346),
`ChatSessionsTest`, `RocketMqExecutionTest` and `AgentScopeAdapterTest`
(fixed by #4274).

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

area/extensions agentscope-extensions (general) area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: filesystem重写snapshotSpec不生效

4 participants