Skip to content

fix(oss,cos): list session ids that contain slashes intact - #4246

Open
chxi113 wants to merge 3 commits into
agentscope-ai:mainfrom
chxi113:fix/oss-cos-list-session-ids-nested-slot
Open

chxi113 wants to merge 3 commits into
agentscope-ai:mainfrom
chxi113:fix/oss-cos-list-session-ids-nested-slot

Conversation

@chxi113

@chxi113 chxi113 commented Nov 18, 2026 •

Copy link
Copy Markdown

AgentScope-Java Version

2.1.0-SNAPSHOT; verified at commit d149469f on top of main @ 2d70942c.

Description

Background

OssAgentStateStore and CosAgentStateStore build an object key as
<keyPrefix><userId>/<sessionId>/<stateKey><suffix> and then decode a stored id back by cutting
the key at its first / (OssAgentStateStore.java:225, CosAgentStateStore.java:222). Any
session id containing a slash is therefore listed truncated — and the framework produces such ids
itself:

  • SessionSandboxStateStore.slotSessionId() (agentscope-harness) packs the isolation scope, the
    agent id and the value into the session id, because AgentStateStore only offers a
    (userId, sessionId, key) slot model and the sandbox store always passes userId = null:
    sandbox/session/<sessionId>, sandbox/user/<agentId>/<userId>, sandbox/agent/<agentId>,
    sandbox/global. Every one of them contains /.
  • HarnessAgent wires that store to the application-configured AgentStateStore, so a
    sandbox-backed agent on OSS/COS writes those ids on every persisted sandbox state
    (SandboxManager load/save), and the default scope is USER.

Concretely, with the default keyPrefix = agentscope/state/ and agent coder:

stored session id listed before this PR listed after
sandbox/user/coder/alice sandbox sandbox/user/coder/alice
sandbox/user/coder/bob (collapsed into the same sandbox entry) sandbox/user/coder/bob
sandbox/user/translator/alice (collapsed into the same sandbox entry) sandbox/user/translator/alice
sess-a sess-a sess-a

So AgentStateStore#listSessionIds returns an id that was never stored, and distinct sessions of
distinct users/agents become indistinguishable. That is user-visible through the admin starter
(GET /v1/admin/sessions → SessionOperations.java:75 → listSessionIds(null)), and it is worse
than a display problem: delete(userId, sessionId) in both stores removes objects by key
prefix
, so one delete driven by that listing removes every sandbox slot sharing the truncated
prefix — silently destroying sandbox resume state for all users and agents.

Reads, writes and exists() address the full prefix and never re-parse it, which is why the two
backends otherwise behave correctly and this went unnoticed.

Changes

  • Decode the session id at the last / instead of the first, in both stores. What follows the
    last slash is always the state file name (<stateKey>.json / .list.json / .hash), so a
    stored id round-trips exactly, slash-free ids are unaffected, and the behaviour now matches the
    other backends: JsonFileAgentStateStore encodes the whole id into one directory segment and
    decodes it back (safeSegment/decodeSegment), and JdbcAgentStateStore strips an anchored
    user prefix without parsing the id.
  • This is the remaining piece of the same class of defect in the object-storage backends: the core
    slot-key mis-split was fixed in fix(core): persist agent state under the caller's identity #3335 and the JDBC/PostgreSQL path-separator rejection was
    relaxed for exactly these sandbox slot ids in fix(jdbc): allow sandbox-shaped slot ids containing path separators #3233, but neither pass reviewed how OSS/COS
    decode keys back into ids.
  • No signature, key layout, serialized state or documented contract changes; the stores now
    return what the listSessionIds Javadoc already promises.

How to test

mvn -B -T1C -pl agentscope-extensions/agentscope-extensions-oss,\
agentscope-extensions/agentscope-extensions-cos -am test spotless:check \
  -Dtest='OssAgentStateStoreTest,CosAgentStateStoreTest' -Dsurefire.failIfNoSpecifiedTests=false

Both new cases fail against the previous decoder with the exact malformed listing:

OssAgentStateStoreTest.listSessionIds_keepsIdsContainingSlashes:165
  expected: <[sess-a, sandbox/user/agent-a/slot-1]> but was: <[sess-a, sandbox]>
CosAgentStateStoreTest.listSessionIds_keepsIdsContainingSlashes:173
  expected: <[sess-a, sandbox/user/agent-a/slot-1]> but was: <[sess-a, sandbox]>

After the change both modules are green, including spotless:check, and the full module suites
pass: mvn -B -T1C -pl <oss>,<cos> test → OSS 63 tests, COS 21 tests, 0 failures, 0 errors. No
network, credentials or live object storage is involved — the tests mock the SDK client the same
way the existing cases in these classes do.

Tests

Test Asserts
OssAgentStateStoreTest.listSessionIds_keepsIdsContainingSlashes a slash-bearing sandbox slot key and a slash-free key listed under the anonymous namespace are returned intact, not truncated at the first /
CosAgentStateStoreTest.listSessionIds_keepsIdsContainingSlashes the same contract for the COS backend

The pre-existing listSessionIds_extractsIds cases in both classes keep passing unchanged,
pinning that slash-free ids behave exactly as before.

Known residual (out of scope)

  • Both stores still resolve a session id to a prefix. An id that is a strict directory prefix
    of another — sandbox/user/coder vs sandbox/user/coder/alice — matches both on delete, and
    listSessionIds cannot tell a session's own objects from a nested id's objects. Making the slot
    model unambiguous means changing the key layout, which would orphan existing data; this PR only
    stops the listing from inventing ids.
  • A userId containing / shares one namespace with another user (e.g. u1 listing u1 + /x),
    the same non-injective namespace issue recorded for the core slot key in [Bug]: ReActAgent slot key collides when userId contains '/' #3337. Fixing it needs a
    cross-store key-format decision.
  • Full-repository clean verify was not run; the change is confined to two extension modules with
    no signature change, so cross-module verification is left to CI.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions (no public API changed; the decoding rule is documented at the changed line)
  • Related documentation has been updated (N/A — checked docs/v2/{en,zh}/integration/session/*: no page documents a slash restriction on session ids, and this restores the documented listSessionIds contract)
  • Code is ready for review

OssAgentStateStore and CosAgentStateStore decoded a stored object key back
into a session id at its first '/', so any id containing a slash was listed
truncated. The harness produces such ids itself: SessionSandboxStateStore
packs the isolation scope, the agent id and the value into the session id
("sandbox/user/<agentId>/<userId>"), so every sandbox slot listed as the
single bogus entry "sandbox" and the admin session listing hid the real
slots. Since delete(userId, sessionId) removes objects by key prefix, one
delete driven by that listing wipes every sandbox slot sharing the
truncated prefix.

Reads, writes and exists() address the full prefix and were unaffected,
which is why these backends looked healthy. Cut at the last '/' instead:
what follows it is always the state file name, so a stored id round-trips
exactly as AgentStateStore#listSessionIds documents, matching
JsonFileAgentStateStore (safeSegment/decodeSegment) and the prefix-anchored
JDBC listing, and consistent with the decision to relax path-separator
validation in the JDBC and PostgreSQL stores.

Tests: listSessionIds_keepsIdsContainingSlashes in both modules fails
against the old decoder with
expected: <[sess-a, sandbox/user/agent-a/slot-1]> but was: <[sess-a, sandbox]>.
Both module suites and spotless:check pass (63 + 21 tests).
xzxiaoshan added a commit that referenced this pull request Nov 20, 2026
…#4274)

## Background

Swept the last 125 PRs (#4272→#4075) for single-OS CI failures under
`mvn -B -T1C clean verify` (one build OS red, the other green on the
same commit = flake suspect). Cross-PR repeats and main's own red run on
2026-11-19 (ubuntu, run 44516464414) pinpoints four still-broken test
classes; all fixes are test-side only (no `src/main` changes).

## Fixes and evidence

| Test class | Victims | Signature | Fix |
|---|---|---|---|
| `RocketMqExecutionTest` | #4182, #4192, #4103 + main run 44516464414
(2026-11-19, ubuntu) | `turn reaches SUCCEEDED did not become true
within 10s` while the turn kept progressing (modelCalls complete, acks
climbing, lastFailure=none) — deadline breakthrough under starvation,
not a lost turn | shared `waitUntil` deadline 10s→30s (repo tier
#3726/#3774) |
| `AgentScopeAdapterTest` | #4204 (same-commit re-run green = confirmed
flake), #4191, #4246 | `Timed out observing Turn` at 6.7–8.5s elapsed;
resume/recovery one step from terminal | `turn.await(5s)`→30s at all 3
sibling sites via `TURN_DEADLINE`, outer `get` budgets +5s margin |
| `WorkerRuntimeTest` | #4219, #4224, #4255 (windows) | (a) `Worker
lease lost` after 2.4s — 1s claim leases expired between claim and
release; (b) `renewed.await(5s)` missed at 6.5s while the recovery lane
was healthy; (c) `Interrupted sleep interrupted` —
`WorkerRuntime.process()` interrupts the calling thread on lease-renewal
failure and manual `tick()` runs it on the test thread | (a) claim
leases 1s→30s (staleness under test still comes from `release(ZERO)` +
re-claim); (b) latches 5s→30s; (c) raw `Thread.sleep`→interrupt-proof
`pause()` at 5 sites, mirroring the #4176 fix for the same signature in
`ProcessRecoveryTest` |
| `ChatSessionsTest.await` (shared with `ChatControllerTest`) | #4233,
#4182 (stuck-RUNNING at 40.8s/46.4s), #4268, #4163 (poll threw `Durable
database transaction failed`) | two surfaces of one cause: every
snapshot poll opens a writing sqlite transaction contending with the
runtime's own writes, and windows runners starve turns past 30s (same
file already measured 56.6s starvation and uses 120s elsewhere, #3726) |
deadline 30s→120s (aligned tier) + tolerate transient `UNAVAILABLE`
store exceptions while polling; persistent failure rethrows at the
deadline, FAILED-turn fast-fail unchanged |
| `CommandExecutorTest.missingExitCodeIsUnknown` | local -T2C full-repo
stress (2026-11-19; pristine-main baseline of the same class green) |
the 2s network budget fired on scheduler starvation before the instant
fake response was processed, misclassifying the failure as a deadline
miss instead of a missing exit code (2.97s elapsed) | budget 2s→30s for
this non-deadline-semantics test; the two deadline-semantics tests keep
their tight budgets |

## Constraint compliance

- Happy path zero cost: every change only extends failure-path deadlines
or hardens helpers; no new sleeps, no weakened assertions.
- Minimal widening anchored to measured data (each comment cites victims
+ measured values); 30s follows the repo's established deflake tier,
120s follows this file's own previously measured starvation tier.
- Structural hardening preferred: `pause()` helper, transient-lock
retry, lease decoupling from the tested invariant.
- No `src/main` changes.

## Observed but deliberately not fixed here

-
`ProcessRecoveryTest.replacementCollectsOriginalResultWithoutRepeatingEffect`
(#4214: `expected: 2 but was: 3`): recovery-semantics race (model re-run
without effect re-run after abrupt halt) — a product question for the
durable recovery work, not a deadline flake.
-
`JevEvidenceProcessorTest.filterFailureIsWithheldButRankFailureFollowsScoredEvidence`
(#4265: delivered `[]` on a 25×-slowed runner): root cause not
established; single occurrence.
- Already fixed upstream, victims predate the fix:
`AgentScopeAgentExecutorInputRequiredTest` (#4157/#4187/#4152 all
predate #4176's `BaseReActAgentRunner` change), `InboxMiddlewareTest`
(#4093 predates #3738), `HarnessAgentSubagentStreamEventsTest` (#4183
predates #2917).
- `SkillBoxTest$UploadContainment` quartet (#4201/#4202/#4212/#4229):
test does not exist on main (fork stack only); deterministic cross-drive
path bug, not load flakiness.
- #4184/#4185: both-OS compile breaks from dependency major bumps
(dependabot), out of scope.

Also applied during review: sibling sites with the identical measured
mechanism were widened in the same pass — the remaining 1s fixture claim
leases in `WorkerRuntimeTest` (fenced begin/update/release sequences,
same #4219 signature), the start/PAUSED 5s budgets in the same
`AgentScopeAdapterTest` method as the victims, and the 5s/4s observe
budgets in
`completeLocalBackendRunsNativeAgentWhileManagedObserverIsBlocked`.

## Test plan

- [x] Full local `mvn -B -T2C clean verify` green (stricter than CI's
-T1C). Locally excluded, each verified to fail identically on pristine
main on this machine (Windows/git-bash) while passing on CI:
`JsonFileAgentStateStoreTest` (symlink permissions), the
`agentscope-extensions-durable-sandbox` trio plus
`ToolInSandboxExampleTest`/`SandboxRoundTripTest` (sandbox shell heredoc
incompatible with local git-bash python3), and the
`AgentScopeAdapterTest`/`ProcessRecoveryTest`/`HarnessExternalToolProcessRecoveryTest`
trio (durable-adapter classes whose Windows runs are skipped on CI; the
same named tests fail on pristine main locally).
- [ ] CI green on both OS.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants