Repository navigation
fix(harness): key transcript segments on the sessions route on 2.0.x (#2918) - #4450
Conversation
…gentscope-ai#2918) The default `ObjectStoreTranscriptStore` wrote each segment through the `AbstractFilesystem` under `{tenant}/{agentId}/{sessionId}/events/...`, while `RemoteFilesystemSpec` routes `agents/{agentId}/sessions/` to the remote store. The two never matched, so every segment went to the default backend and session history stayed on the local disk. `SessionTranscriptWriter` now builds the ref as `agents/{agentId}/sessions/{sessionId}` for that store, keyed on the id the routes were built with. That id differs from the display name the transcript middleware used, because the middleware is registered on the inner `ReActAgent`; `HarnessAgent` passes `resolvedAgentId` through `TranscriptMiddleware` to the writer. Other `TranscriptStore` implementations keep the tenant layout. This is the final state of agentscope-ai#3386, which targeted `main` and was closed when agentscope-ai#3441 removed that code there. Tests: `SessionTranscriptStoreRoutingTest` covers the writer with and without a routing id, the tenant layout of other stores, and a built `HarnessAgent` whose `agentId` differs from its display name.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…nd a blank routing id codecov reported three added lines without coverage in agentscope-ai#4450: the one- and three-argument constructors of `TranscriptMiddleware`, which no test called, and the blank branch of the routing-id check in `SessionTranscriptWriter`. - The one-argument constructor leaves no transcript store, so only the local session log is written. - The three-argument constructor passes no routing id, so the segments are keyed on the agent's name. - A blank routing id is treated like none.
|
Please scope the route-aligned keys to the workspace-backed store that Harness creates by default. The builder Javadoc says the change is for that default store, but the writer checks |
|
Agreed, and the Javadoc was the accurate one: the writer's |
…er is given The route-aligned keys of agentscope-ai#2918 reached every `ObjectStoreTranscriptStore`, because the writer tested the class. A store supplied through `transcriptStore(...)` was re-keyed as well: segments written under its configured prefix and tenant were no longer listed, and tenants sharing a backend with the same agent and session ids were collapsed into one namespace. The builder now installs its default store through `ObjectStoreTranscriptStore.onSessionsRoute(filesystem)`, and only a store built that way is keyed on the sessions route. The constructors keep the tenant layout, `{rootPrefix}{tenant}/{agentId}/{sessionId}/events/...`, for stores a caller supplies itself. The Javadoc of `transcriptStore`, `transcriptTenant`, `TranscriptStore` and `TranscriptRef` says which store uses which layout. Three cases in `SessionTranscriptStoreRoutingTest` pin it: a supplied store keeps its prefix and the tenant layout; two tenants on one store keep separate namespaces; a built agent with a supplied store keeps the tenant layout and puts nothing on the sessions route. They fail on the previous head.
…entscope-extensions-aistio
|
Done in What changed
Regressions (
The five cases of the default store build it the way the builder does, so they still pin #2918. Each piece broken on its own: testing the class again is caught by the three new cases; installing a plain store, by The full One thing I noticed and left alone, since it predates this PR: |
juruoO-o
left a comment
There was a problem hiding this comment.
The builder-created workspace store now uses the sessions route, while existing caller-configured stores retain their key prefix and tenant layout. I checked the writer and mirror wiring and the same-agent, same-session, two-tenant regression against 2.0.x. Ubuntu and Windows CI passed.
Fixes #2918 on
2.0.x, where the code involved still exists. This is the final state of #3386, which targetedmainand 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 theAbstractFilesystemunder{tenant}/{agentId}/{sessionId}/events/..., with a default tenant ofdefault.RemoteFilesystemSpecroutesagents/{agentId}/sessions/to the remote store. The two never match, soCompositeFilesystemsends 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 innerReActAgent, 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
SessionTranscriptWriterbuilds the ref asagents/{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 newObjectStoreTranscriptStore.onSessionsRoute(filesystem), and only a store created that way is keyed on the route. A store supplied throughtranscriptStore(...), whatever its class, keeps the layout it was configured with.HarnessAgentpassesresolvedAgentIdthrough a newTranscriptMiddlewareconstructor argument to the writer. Callers that do not pass it keep using their own agent id.transcriptStore,transcriptTenant,TranscriptStoreandTranscriptRefsays which store uses which layout:transcriptTenantapplies to every supplied store, and the default store's layout has no tenant segment.Scoped after review. The first version keyed every
ObjectStoreTranscriptStoreon 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:
TranscriptMiddlewarebuilt with the three-argument constructor, which passes no routing id, keys the segments on the agent's name;HarnessAgentwithagentId("agent-qa"), a different display name and aRemoteFilesystemSpecputs its segments into the store underagents/agent-qa/..., nothing under the display name, and noeventsdirectory on the local disk.What must not change:
TranscriptMiddlewarebuilt with the one-argument constructor, which has no transcript store, writes the local session log and nothing else;ObjectStoreTranscriptStorekeeps the tenant layout;ObjectStoreTranscriptStorekeeps its prefix and the tenant layout, behind the same routes:tenants/acme/team-a/agent-a/session-1/events, where the previous head wrotetenants/acme/agents/agent-a/sessions/session-1/events;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.xthe 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:
ObjectStoreTranscriptStoreon the route (the code before the scoping)segmentsOfABuiltAgentReachTheSessionsRouteOfItsAgentIdisOnSessionsRoute()answers false for every storeisOnSessionsRoute()answers true for every storesegmentsOfABuiltAgentWithASuppliedStoreKeepTheTenantLayoutaStoreSuppliedToTheBuilderKeepsItsPrefixAndTheTenantLayout,tenantsOfASuppliedStoreKeepSeparateNamespacessegmentsHitTheSessionsRouteOfTheRoutingId, end to endsegmentsHitTheSessionsRouteOfTheCallersIdWhenNoRoutingIdIsGivenaBlankRoutingId_fallsBackToTheCallersIdHarnessAgentpasses the display name instead ofresolvedAgentIdHarnessAgentdoes not thread the idTranscriptMiddlewaredoes not hand the id to the writeraMiddlewareWithoutARoutingId_keysTheSegmentsOnTheAgentsNameAll are caught. The three that break the threading between
HarnessAgentand the writer are caught by the end-to-end test alone, which is why it is there.withRuntimeContextandwithFilesystemcarry 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-harnesssuite 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.Sandbox workspace root must be an absolute path), 2 ×MemoryConsolidatorCommitGateTest,MemoryFlushSandboxIndependenceTestmaven:3.9-eclipse-temurin-17)BaseSandboxFilesystemTest.edit_*(python3: not foundin the image),MarketplaceStagerOrphanGcTest.unreadableEntryDoesNotFailStageNo 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.xfailed the Windows job, at first inagentscope-core, and had its Ubuntu job cancelled. Those causes are fixed by #4454 and #4461, merged into2.0.xon 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, on108fae28, stopped onHttpSelfRegistrationTestinagentscope-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.