Skip to content

fix(harness): key transcript segments on the sessions route on 2.0.x (#2918) - #4450

Merged
juruoO-o merged 5 commits into
agentscope-ai:2.0.xfrom
aiyili:fix/transcript-segment-key-route-20x
Dec 2, 2026
Merged

juruoO-o merged 5 commits into
agentscope-ai:2.0.xfrom
aiyili:fix/transcript-segment-key-route-20x

Conversation

@aiyili

@aiyili aiyili commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

…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

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

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.
@juruoO-o

juruoO-o commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

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 instanceof ObjectStoreTranscriptStore, so it also changes keys for an explicitly supplied transcriptStore(new ObjectStoreTranscriptStore(...)). Those deployments may already have readable segments under the configured tenant prefix, and multiple tenants sharing a backend with the same agent/session IDs would now share the same segment namespace. Please preserve the explicit store’s existing tenant layout and add a regression for it.

@aiyili

aiyili commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, and the Javadoc was the accurate one: the writer's instanceof ObjectStoreTranscriptStore was wider than what the description says. I'll scope the route-aligned keys to the store the builder installs itself, keep {rootPrefix}{tenant}/{agentId}/{sessionId}/events/... for every store supplied through transcriptStore(...), and add regressions for both — including two tenants sharing one backend with the same agent and session ids.

…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.
@aiyili

aiyili commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Done in 108fae28.

What changed

  • HarnessAgent.Builder installs its default store through the new ObjectStoreTranscriptStore.onSessionsRoute(filesystem). That is now the only store keyed as agents/{agentId}/sessions/{sessionId}: SessionTranscriptWriter asks isOnSessionsRoute() instead of testing the class.
  • Every store supplied through transcriptStore(...) keeps its key, {rootPrefix}{tenant}/{agentId}/{sessionId}/events/..., whatever its class. That includes the way a built agent keys the tenant layout on the agent's name, which predates [Bug]: 当前 main 默认 ObjectStoreTranscriptStore 的 segment key 不匹配 RemoteFilesystemSpec 路由,session 历史无法写入远程/MySQL #2918 and is left as it is.
  • The Javadoc of transcriptStore, transcriptTenant, TranscriptStore and TranscriptRef says which store uses which layout.

Regressions (SessionTranscriptStoreRoutingTest, 10 cases now; the three below fail on 287609b5):

Case Before Now
aStoreSuppliedToTheBuilderKeepsItsPrefixAndTheTenantLayout: a supplied store with prefix tenants/acme, behind the same routes tenants/acme/agents/agent-a/sessions/session-1/events tenants/acme/team-a/agent-a/session-1/events
tenantsOfASuppliedStoreKeepSeparateNamespaces: one store, two tenants, the same agent and session both written into one directory on the route shared/team-a/agent-a/session-1/events and shared/team-b/agent-a/session-1/events
segmentsOfABuiltAgentWithASuppliedStoreKeepTheTenantLayout: through the builder, with a RemoteFilesystemSpec the segments reached the store of the route nothing on the route; team-a/Agent QA Display/s-1/events in the workspace

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 segmentsOfABuiltAgentReachTheSessionsRouteOfItsAgentId alone; a constructor marking a supplied store, by the cases that use that constructor. All seven mutants are caught.

The full agentscope-harness suite in a Linux container went from 1626 to 1629 tests with the same four environmental failures. CI on the current head is green on both systems; one Windows run in between stopped on HttpSelfRegistrationTest in agentscope-extensions-aistio, the shutdown race of #3132, unrelated to this change.

One thing I noticed and left alone, since it predates this PR: SessionTree uploads the segments of any ObjectStoreTranscriptStore through the agent's workspace filesystem (transcriptStoreForMirror calls withFilesystem), while syncFromRemote reads through the store's own filesystem. For a supplied store over another backend, those are not the same place.

@juruoO-o juruoO-o 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.

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.

@juruoO-o
juruoO-o merged commit ad8e214 into agentscope-ai:2.0.x Dec 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants