Repository navigation
fix(harness): omit host facts from sandbox runtime prompt - #4112
Merged
jujn merged 5 commits intoNov 25, 2026
Merged
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Contributor
Author
2 of 3 tasks
xzxiaoshan
added a commit
that referenced
this pull request
Nov 12, 2026
#4149) ## Summary Scanned the last 5 pages of PRs (#3941–#4147, 125 PRs): 14 had red CI, and 9 of those failed on exactly one OS while the other OS stayed green on the same commit — the classic `-T1C` parallel-build starvation signature (the both-OS failures were compile/spotless issues and are out of scope). This PR fixes every distinct flaky test class found that way, plus two narrowly-scoped hardenings the fixes depend on. | Test / class | Failed OS | Victim PRs | Evidence | Fix | |---|---|---|---|---| | `AguiMvcControllerTest#eventStreamSignals…` | ubuntu ×2 | #4112, #4143 | 5s latch deadline hit while sibling tests in the class ran 5–9s under the same load | shared 30s await constant (all waits in the class share the same executor starvation exposure) | | `SubagentRunIdChainTest` (both methods) | windows ×3 | #4091, #4025, #4142 | blocking read starved just past 10s (10.04–10.84s elapsed); same test 0.414s on ubuntu | block budget 10s → 30s | | `InboxMiddlewareTest#notificationReaches…` | ubuntu ×2 | #3991, #4093 | assertion matched the memory-consolidation prompt instead of the reasoning request | `MockModel` recordings made thread-safe (see below) | | `GatewayEventsWebSocketTest#sameOrigin…` | windows ×2 | #4072, #4094 | ~0.1s clean close with no frames; job log shows the preceding 403'd upstream upgrade left a dying pooled socket (`Connection prematurely closed BEFORE opening handshake is complete`) that the next proxied socket reused | stand-in control plane now answers rejected upgrades with `Connection: close` so the gateway pool discards the socket | | `TurnLeaseServiceTest#heartbeatErrors…` | windows | #4075 | `await(70ms) isFalse` anchored to when the starved test thread resumes, not to lease acquisition | bounds re-anchored to elapsed-time-since-acquisition (fires within 2s, not before 120ms; deadline 150ms, ticks 50ms) | | `SandboxConnectorRedirectTest#commandWaits…` | windows | #4058 | capability probe inherited the 200ms command-transport budget and died at 199ms before any command was submitted | probe budget floor (see CommandExecutor below) | | `GracefulShutdownManager` singleton leak | local | found during verification | `resetForTesting()` reset every field except `config`, so a `PT0.1S` config leaked across tests and failed `defaultConfig` whenever filesystem class order placed it after `shutdownTimeoutSignal` | reset now also restores `GracefulShutdownConfig.DEFAULT` | ## Shared test-util fix `MockModel` recorded calls from whichever thread drives the agent — the turn thread and background memory maintenance — into a plain `ArrayList` plus unsynchronized `int`/`last*` fields. Two concurrent adds race the `elementData[size] / size++` update and can silently drop an entry; that is exactly the #4093/#3991 signature (the reasoning request vanished, only the post-call consolidation request survived). Recordings are now a `CopyOnWriteArrayList` with `AtomicInteger`/`volatile` siblings — order-preserving, atomic per add, stable to iterate while a call is in flight. Complements the iteration fix proposed in #4133. ## Non-test changes (called out explicitly) - **`CommandExecutor`** — the `/capabilities` pre-flight probe now uses `max(configured per-attempt, 2s)` for its budgets. Strictly a widening: identical for default (60s) and ≥2s configurations; only sub-2s configs change, and only for the probe — command exchanges keep the configured budget. Side benefit: the old code passed the same 200ms as the shared exchange deadline, which made the intended `CAPABILITY_MAX_ATTEMPTS = 3` retry dead code; the floor lets the retry actually run. The test-only alternative (raising the test's 200ms config and the server delays to match) would add ~1.5–2s of real test wall time, so the 2-line production fix is the smaller change. - **`GracefulShutdownManager.resetForTesting`** — one added line restoring `config` to default, inside a method documented "Intended for testing and demo purposes only" (no production callers; production code never calls `setConfig`). ## Constraint compliance - **No happy-path slowdown:** every widened number is a failure-path deadline only; all awaits/latches return the moment the signal arrives, and no sleeps were added (`TurnLeaseServiceTest` actually drops a forced 70ms wait). - **Minimal widenings, anchored to measurements:** 5s→30s (deadline hit twice; repo precedent from #3726 for CI-starvation waits), 10s→30s (3× the observed 10.04–10.84s), probe floor 2s (10× the 199ms miss), TurnLease window [120ms, 2s] (bug population ~50ms vs legitimate ≥150ms). ## Test plan - [x] Full reactor `mvn -B -T2C clean verify` green locally (4m38s wall clock; all seven fixed areas' suites green) - [x] `JsonFileAgentStateStoreTest` (8 symlink cases) excluded locally only — pre-existing Windows-symlink-privilege limitation, reproduced identically on a pristine `main` baseline, unrelated to this diff - [ ] CI on both OSes Follow-up noted during review: the production control-plane hub behind `/api/v1/events` lives outside this repo; if it also answers rejected upgrades with a keep-alive 403 and closes, the gateway can still poison a subsequent proxied socket in production — worth checking against the real hub separately.
…host-facts-upstream # Conflicts: # agentscope-harness/src/test/java/io/agentscope/harness/agent/middleware/WorkspaceContextMiddlewareSandboxPromptTest.java # docs/v2/en/docs/harness/workspace.md # docs/v2/zh/docs/harness/workspace.md
jujn
approved these changes
Nov 25, 2026
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.
AgentScope-Java Version
2.1.0-SNAPSHOT (base:
mainat 874c9cb)Description
Fixes #4111
Background
Under a pure sandbox execution backend,
WorkspaceContextMiddlewareunconditionally rendered host facts in
## Runtime Environment:Those facts are not actionable inside a sandbox and contradicted the
## Workspaceparagraph, which said that host paths do not establish thesandbox working directory. The model was frequently misled into using host
paths, host shell syntax, or host temporary directories.
Changes
SESSION_CONTEXT_SECTION_TEMPLATEinto a host-facts template and anidentity-only
SESSION_CONTEXT_SECTION_SANDBOX_TEMPLATE.buildSessionContextSectionnow receives the activeAbstractFilesystemandselects the identity-only template when the surface is a pure sandbox:
fs instanceof AbstractSandboxFilesystem && !(fs instanceof OverlayFilesystem) && !(fs instanceof LocalFilesystemWithShell). Such prompts contain only## Runtime Environment,You are the <name> agent., and non-emptyenvironmentMemory.LocalFilesystemWithShell), plain local,and
CompositeFilesystembranches keep host facts.directLocalShellIsDescribedAsHostExecutionsoa local shell cannot be mistaken for a remote sandbox.
WorkspaceContextMiddlewareSandboxPromptTestto assert sandbox promptsomit host facts, keep the agent identity and non-empty
environmentMemory,and that direct local shell prompts still carry host facts.
## Workspaceopening sentence as a positive statement:file and shell paths follow the configured execution backend; use that
backend's shell syntax, installed runtimes, and temporary paths. The
"host paths above do not establish its working directory" clause is removed.
Sandbox root:, routed backend notes, and artifact delivery guidance areunchanged. Token estimation still uses the rendered section.
docs/v2/en/docs/harness/workspace.mdanddocs/v2/zh/docs/harness/workspace.mdto explain that sandbox surfaces omithost facts, that host facts serve local and remote-template-fallback
deployments, and that the sandbox root comes only from metadata still valid
for the current call.
How to test
Targeted tests:
Result: 46 tests, 0 failures, 0 errors.
Formatting:
Result: BUILD SUCCESS.
Full harness module suite:
mvn -T1C -pl agentscope-harness testResult: 1624 tests, 0 failures, 0 errors, 12 skipped.
Note: a full reactor
mvn -T1C -pl agentscope-harness -am testcurrently hitspre-existing, unrelated
agentscope-corefailures(
SkillBoxTest$SkillBoxUploadSecurityGate#testMaterializesValidResourcesUnderSkillIdAndBlocksEscapingOnesresource ordering and
GracefulShutdownTest$StateAndConfigTests#defaultConfigstatic-state leak). They reproduce independently of this change.
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test) — theagentscope-harnessmodule passes (1624 tests); the full reactor currently hits pre-existing, unrelatedagentscope-corefailures (see note above)