Repository navigation
test: run the e2b host-directory tests on POSIX hosts only, and take a race out of ToolConfirmationCoordinatorTest (#4460) - #4461
Conversation
…scope-ai#4453) `SkillBoxTest$UploadContainment.preservesLegacyNamesWithRelativeNonNormalizedWorkDirectory` started with `Path.of("").toAbsolutePath().relativize(tempDir)`. A relative path cannot cross drives, and on the Windows runner the checkout is on `D:` while `java.io.tmpdir` is on `C:`, so that line threw `'other' has different root` before `SkillBox` was called. Since the backport of agentscope-ai#3787 (`508d5e27`) it has failed the Windows job of every `2.0.x` PR and got the Ubuntu job cancelled. The directory the test relativizes is now created under the module's `target/`, which is on the drive a relative path is resolved against, and is removed afterwards. What the test asserts and the code it exercises are unchanged: with `SkillUtil.resolveContainedPath` no longer normalizing its base directory, this is the one test in the class that fails.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
The CI of this PR is green on both systems: The PR is stacked: #4454 (core), then #4456 (harness), then this one. Merged in that order, each is left with its own commits only. Once they are on |
…agentscope-ai#4455) Three Windows path problems kept the harness module red on the Windows job of every `2.0.x` PR, 18 tests in all, so that module and everything after it was never tested by CI on this branch. `SandboxWorkspaceRoot.normalize` accepted only roots that start with `/`. The in-memory sandbox used by the tests reports a host directory as its root, which is a drive path on Windows. A drive path is accepted now, on every host; relative, drive-relative and UNC roots are still rejected. `ProjectAwareOverlay.isWorkspacePath` relied on `Path.isAbsolute()` to tell an absolute path from a relative one. On a Windows host a path with a leading separator is not absolute for it, so `/MEMORY.md`, the spelling the `CompositeFilesystem` hands its backends, was matched against the workspace prefixes as if it were relative. It was then written to the workspace layer, which bypasses the project writer and its rejection. A leading separator now counts as absolute wherever the code runs. `MemoryFlushSandboxIndependenceTest` relativized the temp directory from the working directory, which cannot cross drives, as in agentscope-ai#4453. Tests: `SandboxWorkspaceRootTest` and `ProjectAwareOverlayTest` each gain a case that holds on every host.
… test `LocalFilesystemPersonalAssistantExampleTest.localFilesystem_filesPersistAcrossCalls` asserts that MEMORY.md is unchanged after the second call. With memory hooks on, the flush that runs in the background after a call can consolidate into MEMORY.md, so that assertion depended on whether the flush had finished. Repeating the scenario 50 times on unmodified `2.0.x` changed MEMORY.md once, to the stub model's reply. The test is about files persisting across calls, not about memory, so it now disables memory hooks. With them disabled, 50 repetitions did not change MEMORY.md.
…a race out of ToolConfirmationCoordinatorTest (agentscope-ai#4460) Two tests in `agentscope-extensions-sandbox-e2b` use a directory under `@TempDir` as the in-sandbox workspace root, so that they can read the files on disk. `E2bSandboxClient` requires a root that starts with `/`, which is right for a sandbox that is always Linux. A host directory only passes for an in-sandbox path on a POSIX host, so the two tests failed on Windows. They are enabled on Linux and macOS now. `ToolConfirmationCoordinatorTest.replacementTurnLeaseCannotReleaseOldTicketAndMayReuseToolUseId` re-stubbed `controlPlaneClient.managedExecutionScope` while threads started by its own requests were still calling that mock. Mockito can attribute a stubbing made in that window to one of those calls. The stubbing is then lost, and the test either failed with `CannotStubVoidMethodWithReturnValue` or saw a ticket built from the old scope. The stubbing is made once now, before any request, and switched through an `AtomicReference`.
539a4c9 to
26d5ae9
Compare
|
About the codecov report above: its first version reported one partially covered line in The operand turned out to be redundant, so it is gone (see #4456): a drive path that gets that far matches no workspace prefix either way. With the new run the report says that all modified and coverable lines are covered, and the CI is green on both systems. |
…ader on 2.0.x (#2888) (#4452) Fixes #2888 on `2.0.x`, where the call still exists. `main` no longer has it. ## Problem A session that only has v1 keys (`memory_messages` / `toolkit_activeGroups`) is reconstructed by `LegacyStateLoader` on first load. Legacy keys carry no permission context, and `ReActAgent.loadOrCreateAgentStateForSlot` calls the three-argument overload, which passes `null`. The reconstructed state therefore gets the default context although the builder configured one, mode and rules alike. The fresh-state branch of the same method does use the builder's context. On `2.0.x` this shows through `getAgentState(userId, sessionId)` and `getAgentState(ctx)`, which return the state as loaded. A `call()` is not affected: `activateSlotForContext` applies the builder's context the first time it activates a slot. ## Fix `permCtx` is forwarded to the four-argument overload, the shape of #2886 and #3221. Nothing else changes: a state that already exists is still loaded as it was persisted. ## Tests `ReActAgentLegacyPermissionContextTest` (new, 4 cases). `LegacyStateLoaderTest` already covers the loader's four-argument overload; nothing covered the caller. | Case | Unmodified `2.0.x` | With the fix | | --- | --- | --- | | the legacy session is reconstructed with the builder's context (mode and deny rule), keeping the conversation and the tool groups | fails: `expected ... mode=BYPASS, denyRules={shell=[...]}` but was `mode=DEFAULT` with no rules | passes | | without a builder context the default is kept | passes | passes | | an existing state keeps its own context | passes | passes | | a `call()` applies the builder's context on first activation | passes | passes | The last two pass before and after on purpose: they bound the change. A variant of the fix that also overwrites the context of an existing state fails the third case (`expected: <EXPLORE> but was: <BYPASS>`). ## Verification The full `agentscope-core` suite was run before and after the change on Windows and in a Linux container. The failing lists are identical; the only difference is the 4 added tests. | Environment | Before | After | Failing before and after | | --- | --- | --- | --- | | Windows | 3237 run, 0 F + 3 E | 3241 run, 0 F + 3 E | 2 × `DangerousPathBypassTest.symlink*` (no symlink privilege), `SkillBoxTest$UploadContainment.preservesLegacyNamesWithRelativeNonNormalizedWorkDirectory` | | Linux container (`maven:3.9-eclipse-temurin-17`) | 3242 run, 0 F + 0 E | 3246 run, 0 F + 0 E | none | **CI.** The first run of this PR was red for reasons that lay in the base branch: since the backports of 2026-11-13, every PR against `2.0.x` failed the Windows job, at first in `agentscope-core`, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into `2.0.x` on 2026-11-27; the harness part went in with #4461. The current run of this PR, on top of them, is green on both systems. The local before/after runs recorded above were made before the fixes existed, which is why the "before" column lists failures that the branch no longer has.
…2918) (#4450) Fixes #2918 on `2.0.x`, where the code involved still exists. This is the final state of #3386, which targeted `main` and was closed when #3441 removed that code there. ## Problem With a remote filesystem, session history silently stays on the local disk. `ObjectStoreTranscriptStore`, the default transcript store whenever a filesystem is present, writes each segment through the `AbstractFilesystem` under `{tenant}/{agentId}/{sessionId}/events/...`, with a default tenant of `default`. `RemoteFilesystemSpec` routes `agents/{agentId}/sessions/` to the remote store. The two never match, so `CompositeFilesystem` sends every segment to the default backend. There is a second mismatch behind the first one. The route is keyed on the builder's `agentId`. The transcript middleware is registered on the inner `ReActAgent`, so it keys the transcript on the agent's display name. Where the two differ, even a correctly prefixed segment would miss the route. ## Fix - `SessionTranscriptWriter` builds the ref as `agents/{agentId}/sessions/{sessionId}` for the store the builder installs by default, so segment keys hit the sessions route. The builder creates that store through the new `ObjectStoreTranscriptStore.onSessionsRoute(filesystem)`, and only a store created that way is keyed on the route. A store supplied through `transcriptStore(...)`, whatever its class, keeps the layout it was configured with. - The ref uses the id the routes were built with. `HarnessAgent` passes `resolvedAgentId` through a new `TranscriptMiddleware` constructor argument to the writer. Callers that do not pass it keep using their own agent id. - The Javadoc of `transcriptStore`, `transcriptTenant`, `TranscriptStore` and `TranscriptRef` says which store uses which layout: `transcriptTenant` applies to every supplied store, and the default store's layout has no tenant segment. **Scoped after review.** The first version keyed every `ObjectStoreTranscriptStore` on the route, because the writer tested the class. A store supplied explicitly would have been re-keyed as well, from `{rootPrefix}{tenant}/{agentId}/{sessionId}` to `{rootPrefix}agents/{agentId}/sessions/{sessionId}`: segments already written under its tenant prefix would no longer be listed, and tenants sharing a backend with the same agent and session ids would have shared one namespace. The default store is the only one re-keyed now. ## Tests `SessionTranscriptStoreRoutingTest` (new, 10 cases). The default store, built the way the builder builds it: - segments reach the store behind the sessions route when the routing id differs from the caller's display name; - the same when no routing id is given and the caller's id is the routed one; - a blank routing id is treated like none; - a `TranscriptMiddleware` built with the three-argument constructor, which passes no routing id, keys the segments on the agent's name; - end to end: a built `HarnessAgent` with `agentId("agent-qa")`, a different display name and a `RemoteFilesystemSpec` puts its segments into the store under `agents/agent-qa/...`, nothing under the display name, and no `events` directory on the local disk. What must not change: - a `TranscriptMiddleware` built with the one-argument constructor, which has no transcript store, writes the local session log and nothing else; - a store that is not an `ObjectStoreTranscriptStore` keeps the tenant layout; - a supplied `ObjectStoreTranscriptStore` keeps its prefix and the tenant layout, behind the same routes: `tenants/acme/team-a/agent-a/session-1/events`, where the previous head wrote `tenants/acme/agents/agent-a/sessions/session-1/events`; - two tenants on one supplied store keep separate namespaces, with the same agent and session ids: the previous head wrote both into one directory on the route; - end to end: the same agent as above, built with `transcriptStore(new ObjectStoreTranscriptStore(...))` and a tenant, keeps the tenant layout and puts nothing on the sessions route: the previous head's segments reached the store of the route. On unmodified `2.0.x` the two route tests and the end-to-end test of the default store fail, and the tenant-layout test passes before and after. The three supplied-store cases fail on the previous head, `287609b5`. Where the other cases stand is placed by the mutants below, since they need the store factory and cannot run on unmodified code. Each piece of the fix was then broken on its own: | Broken piece | Caught by | | --- | --- | | writer keeps the tenant layout for every store | the two route tests and the end-to-end test of the default store | | writer keys every `ObjectStoreTranscriptStore` on the route (the code before the scoping) | the three supplied-store cases | | builder installs a plain store instead of the one on the route | `segmentsOfABuiltAgentReachTheSessionsRouteOfItsAgentId` | | factory does not mark the store as on the route | the five default-store cases | | `isOnSessionsRoute()` answers false for every store | the five default-store cases | | `isOnSessionsRoute()` answers true for every store | the three supplied-store cases | | the one-argument constructor marks a supplied store as on the route | `segmentsOfABuiltAgentWithASuppliedStoreKeepTheTenantLayout` | | the three-argument constructor marks a supplied store as on the route | `aStoreSuppliedToTheBuilderKeepsItsPrefixAndTheTenantLayout`, `tenantsOfASuppliedStoreKeepSeparateNamespaces` | | writer ignores the routing id | `segmentsHitTheSessionsRouteOfTheRoutingId`, end to end | | writer falls back to the tenant when no routing id is given | `segmentsHitTheSessionsRouteOfTheCallersIdWhenNoRoutingIdIsGiven` | | writer does not treat a blank routing id as absent | `aBlankRoutingId_fallsBackToTheCallersId` | | `HarnessAgent` passes the display name instead of `resolvedAgentId` | end to end | | `HarnessAgent` does not thread the id | end to end | | `TranscriptMiddleware` does not hand the id to the writer | end to end | | the three-argument constructor of the middleware passes the tenant on as routing id | `aMiddlewareWithoutARoutingId_keysTheSegmentsOnTheAgentsName` | All are caught. The three that break the threading between `HarnessAgent` and the writer are caught by the end-to-end test alone, which is why it is there. `withRuntimeContext` and `withFilesystem` carry the mark over to their copies; nothing reads it from a copy, so no test can tell and no mutant is listed. Every line this PR adds to production code is covered on Linux, branches included. ## Segments written before this change They are not migrated. They were written to the default backend, which is the local disk of the node that wrote them; that is the bug. The local context file remains the primary copy on that node. Nothing reads the old segment files afterwards, since the store lists, compacts and deletes by ref and the ref now points at the new layout, so they stay in place until the workspace is removed. Only the default store is affected. A supplied store writes where it always did. ## Verification The full `agentscope-harness` suite was run before and after the change on Windows and in a Linux container. The failing lists are identical; the only difference is the added tests. The Windows numbers are from before the last two commits, which add tests and scope the change to the default store; the current head passes the Windows job in CI. | Environment | Before | After | Failing before and after | | --- | --- | --- | --- | | Windows | 1619 run, 5 F + 12 E | 1623 run, 5 F + 12 E (1629 with the last two commits, green in CI) | Windows path checks (`Sandbox workspace root must be an absolute path`), 2 × `MemoryConsolidatorCommitGateTest`, `MemoryFlushSandboxIndependenceTest` | | Linux container (`maven:3.9-eclipse-temurin-17`) | 1619 run, 3 F + 1 E | 1629 run, 3 F + 1 E | 3 × `BaseSandboxFilesystemTest.edit_*` (`python3: not found` in the image), `MarketplaceStagerOrphanGcTest.unreadableEntryDoesNotFailStage` | No existing test depends on the old key layout of the default store. **CI.** The first run of this PR was red for reasons that lay in the base branch: since the backports of 2026-11-13, every PR against `2.0.x` failed the Windows job, at first in `agentscope-core`, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into `2.0.x` on 2026-11-27; the harness part went in with #4461. The runs since, including the one on the current head, are green on both systems. One Windows run in between, on `108fae28`, stopped on `HttpSelfRegistrationTest` in `agentscope-extensions-aistio`: the shutdown race of that module (#3132), unrelated to this change; the next run passed. The local before/after runs recorded above were made before the fixes existed, which is why the "before" column lists failures that the branch no longer has.
Fixes #4460
Stacked on #4456, which is stacked on #4454. The first three commits are those PRs'; the last one is this PR's. Only tests change in it.
Problem
With #4454 and #4456 applied, the Windows job of a
2.0.xPR fails inagentscope-extensions-sandbox-e2b:To see what is behind that module without one CI run per layer, I ran the whole reactor on a Windows machine with
-Dmaven.test.failure.ignore=true: 96 modules, 11301 tests, 7 errors. Four need the symlink privilege that the machine does not have. Two are the ones above. The last one is a flaky test that is not about Windows.Fix
The two e2b tests
Both use a directory under
@TempDiras the in-sandbox workspace root, so that they can read the materialized files on disk.E2bSandboxClient.normalizeWorkspaceRootrequires a root that starts with/. That is right for a sandbox that is always Linux, so I left it as it is. A host directory only looks like an in-sandbox path on a POSIX host, so the two tests are now enabled on Linux and macOS only, with the reason next to them.mainhas the same tests and its Windows job is green, becausemain'sE2bSandbox.alignWorkspaceRootdoes not validate the saved root while the2.0.xbackport does.ToolConfirmationCoordinatorTest.replacementTurnLeaseCannotReleaseOldTicketAndMayReuseToolUseIdThe test re-stubbed
controlPlaneClient.managedExecutionScope("session-a")in the middle of the test, after its first request had started threads that keep calling that mock (hitl-upload-*callsappendSessionEvent). A stubbing made in that window can be attributed to one of those calls instead, and is then lost. The test fails in one of two ways, depending on where the background call lands:CannotStubVoidMethodWithReturnValuenamingappendSessionEvent:when(...)took the background call as the one to stub;expected: "attempt-b" but was: "attempt-a": the stubbing was lost, and the second request built its ticket from the old scope. The ticket printed at that point confirms it: a new ticket (continuationLeaseId=instance-b, the new input) withattemptId=attempt-a.Switching that one line to
doReturn(...).when(...)only removed the first failure and left the second, since the window is between registering the answer and the call that is meant to be stubbed. The stubbing is made once now, before any request, as an answer that reads anAtomicReference, and the test switches the reference. It is the only place in the class where a stub is made after a request.Repetitions of the test method in one JVM, on Windows:
CannotStubVoidMethodWithReturnValuedoReturn(...).when(...)expected: "attempt-b" but was: "attempt-a"Verification
Only the tests named above changed, so those were run on both systems:
E2b*TestToolConfirmationCoordinatorTestBefore the change the e2b module had the 2 errors above on Windows. Spotless is clean.
Effect on CI
The CI of this PR is the first complete and green run for a PR against
2.0.xsince the backports of 2026-11-13: bothbuild (windows-latest)andbuild (ubuntu-latest)pass. Until #4454 the Windows job failed inagentscope-coreand the Ubuntu job was cancelled; with #4454 it failed inagentscope-harness; with #4456, in the e2b module.