Commit 56dce1e
authored
fix(cloud-agent-next): use lastIndexOf for DO name sessionId extraction (#1112)
## Summary
The `CloudAgentSession` constructor parsed the Durable Object name using
`split(':')[1]` to extract the session ID. The DO name format is
`userId:sessionId` (e.g. `oauth/google:12345:agent_abc`). When the
userId itself contains a colon (as with all OAuth provider IDs like
`oauth/google:XXXXX`), splitting on the first colon incorrectly
extracted the OAuth numeric ID (`12345`) instead of the actual session
ID (`agent_abc`). This caused a `SessionId mismatch` error that blocked
**all** session creation for OAuth-authenticated users.
The fix switches from `split(':')[1]` to `lastIndexOf(':')` + `slice()`,
so the session ID is always extracted from after the final colon
regardless of how many colons appear in the userId.
## Verification
- [x] `pnpm run typecheck` — passed (tsgo + wrapper)
- [x] `pnpm run test` — 650 unit tests passed
- [x] `pnpm run test:integration` — 30 integration tests passed
(including 3 new tests for this fix)
## Visual Changes
N/A
## Reviewer Notes
- The bug only affects users whose `userId` contains a colon — all
`oauth/*` provider IDs have this format. Users with plain UUID-style IDs
were unaffected.
- The new integration test in
`test/integration/session/session-id-parsing.test.ts` covers: OAuth
userId with colon, plain userId without colon, and metadata correctness
verification.
- `CloudAgentSession.ts:174-177` is the only location where the DO name
is parsed into a sessionId.2 files changed
Lines changed: 79 additions & 2 deletions
File tree
- cloud-agent-next
- src/persistence
- test/integration/session
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
174 | 176 | | |
175 | | - | |
| 177 | + | |
| 178 | + | |
176 | 179 | | |
177 | 180 | | |
178 | 181 | | |
| |||
Lines changed: 74 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
0 commit comments