Repository navigation
fix(serve): support reserved characters in virtual subagent ids #8717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
860a334
6df743f
1713e9a
2ba6d37
0945d22
977e6d8
b69cf27
2ba3bbc
4c2c421
9750746
a4c7df2
1c27914
d425d1f
6688f96
53265f2
a91880c
3d0f6e0
44f0e4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,8 @@ import { replayTranscriptRecordPage } from '../acp-integration/session/history-r | |||||||||||||||||||||||||||||||||
| import type { WorkspaceRuntime } from './workspace-registry.js'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const PREFIX = 'subagent.'; | ||||||||||||||||||||||||||||||||||
| const MAX_VIRTUAL_SESSION_ID_PART_LENGTH = 500; | ||||||||||||||||||||||||||||||||||
| const MAX_VIRTUAL_SESSION_ID_LENGTH = 2_000; | ||||||||||||||||||||||||||||||||||
| const POLL_INTERVAL_MS = 250; | ||||||||||||||||||||||||||||||||||
| const TARGET_RETENTION_MS = 60_000; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -204,38 +206,61 @@ function decodePart(value: string): string | undefined { | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| function isValidVirtualSessionPart(value: string): boolean { | ||||||||||||||||||||||||||||||||||
| return /^[a-zA-Z0-9_-]{1,500}$/.test(value); | ||||||||||||||||||||||||||||||||||
| function isValidVirtualParentSessionId(value: string): boolean { | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| value.length > 0 && | ||||||||||||||||||||||||||||||||||
| value.length <= MAX_VIRTUAL_SESSION_ID_PART_LENGTH && | ||||||||||||||||||||||||||||||||||
| /^[a-zA-Z0-9_-]+$/.test(value) | ||||||||||||||||||||||||||||||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks — agreed this would be useful regression coverage for the parent-session ID trust boundary. The production validator already enforces the strict parent charset, so this is not a current correctness fix. Since this PR has already gone through several review rounds, I’m going to defer this test-only hardening to a follow-up rather than widen the bugfix further. |
||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| function isValidVirtualAgentId(value: string): boolean { | ||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| value.length > 0 && | ||||||||||||||||||||||||||||||||||
| value.length <= MAX_VIRTUAL_SESSION_ID_PART_LENGTH && | ||||||||||||||||||||||||||||||||||
| decodePart(encodePart(value)) === value | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+219
to
+227
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] On the parse path the "lossless round-trip" check is vacuous — Failure scenario:
Suggested change
中文说明在解析路径上,"无损往返" 校验是空转的: — DeepSeek/deepseek-v4-flash via Qwen Code /review (v0.21.8)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 4c2c421. Parsing now re-encodes and compares both the parent and agent components with their original Base64URL parts, so only canonical spellings are accepted. The regression tests cover padded aliases for each component as well as a |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export function createVirtualSubagentSessionId( | ||||||||||||||||||||||||||||||||||
| parentSessionId: string, | ||||||||||||||||||||||||||||||||||
| agentId: string, | ||||||||||||||||||||||||||||||||||
| ): string { | ||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||
| !isValidVirtualSessionPart(parentSessionId) || | ||||||||||||||||||||||||||||||||||
| !isValidVirtualSessionPart(agentId) | ||||||||||||||||||||||||||||||||||
| !isValidVirtualParentSessionId(parentSessionId) || | ||||||||||||||||||||||||||||||||||
| !isValidVirtualAgentId(agentId) | ||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||
| throw new Error('Virtual subagent session ids require valid id parts'); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return `${PREFIX}${encodePart(parentSessionId)}.${encodePart(agentId)}`; | ||||||||||||||||||||||||||||||||||
| const sessionId = `${PREFIX}${encodePart(parentSessionId)}.${encodePart(agentId)}`; | ||||||||||||||||||||||||||||||||||
| if (sessionId.length > MAX_VIRTUAL_SESSION_ID_LENGTH) { | ||||||||||||||||||||||||||||||||||
| throw new Error('Virtual subagent session id exceeds 2000 characters'); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+239
to
+244
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The new encoded-length cap branch throws the same "Virtual subagent session ids require valid id parts" message as the invalid-parts branch — Failure scenario: a bridge agent task ID in the ~374–500 multibyte range passes every
Suggested change
中文说明新增的编码后总长度上限分支与无效部件分支抛出了相同的 "Virtual subagent session ids require valid id parts" 错误信息,混淆了两种失败模式:部件确实非法,与部件各自合法但编码后组合长度超过 2,000 字符。触发场景:约 374–500 个多字节字符的 agent task ID 能通过 — DeepSeek/deepseek-v4-flash via Qwen Code /review (v0.21.8)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 4c2c421. The encoded-length branch now reports a distinct |
||||||||||||||||||||||||||||||||||
| return sessionId; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export function parseVirtualSubagentSessionId( | ||||||||||||||||||||||||||||||||||
| sessionId: string, | ||||||||||||||||||||||||||||||||||
| ): VirtualSubagentSessionKey | undefined { | ||||||||||||||||||||||||||||||||||
| if (!sessionId.startsWith(PREFIX) || sessionId.length > 2_000) { | ||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||
| !sessionId.startsWith(PREFIX) || | ||||||||||||||||||||||||||||||||||
| sessionId.length > MAX_VIRTUAL_SESSION_ID_LENGTH | ||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| const parts = sessionId.slice(PREFIX.length).split('.'); | ||||||||||||||||||||||||||||||||||
| if (parts.length !== 2) return undefined; | ||||||||||||||||||||||||||||||||||
| const parentSessionId = decodePart(parts[0]!); | ||||||||||||||||||||||||||||||||||
| const agentId = decodePart(parts[1]!); | ||||||||||||||||||||||||||||||||||
| const parentPart = parts[0]!; | ||||||||||||||||||||||||||||||||||
| const agentPart = parts[1]!; | ||||||||||||||||||||||||||||||||||
| const parentSessionId = decodePart(parentPart); | ||||||||||||||||||||||||||||||||||
| const agentId = decodePart(agentPart); | ||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||
| !parentSessionId || | ||||||||||||||||||||||||||||||||||
| !agentId || | ||||||||||||||||||||||||||||||||||
| !isValidVirtualSessionPart(parentSessionId) || | ||||||||||||||||||||||||||||||||||
| !isValidVirtualSessionPart(agentId) | ||||||||||||||||||||||||||||||||||
| !isValidVirtualParentSessionId(parentSessionId) || | ||||||||||||||||||||||||||||||||||
| !isValidVirtualAgentId(agentId) || | ||||||||||||||||||||||||||||||||||
| encodePart(parentSessionId) !== parentPart || | ||||||||||||||||||||||||||||||||||
| encodePart(agentId) !== agentPart | ||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] R2-1: No test chains a reserved-character task ID through the real
VirtualSubagentSessions.resolve()— the reserved-char round-trip tests below callcreateVirtualSubagentSessionId/parseVirtualSubagentSessionIddirectly, the server route test mocksresolve, and every real-resolveunit test uses plain IDs only (fork-agent-1,general-purpose-call-1, ...). — Failure scenario: a future change at theresolve()call site that re-restricts or transformstask.idbefore ID creation (e.g. reintroducing a per-part charset filter) silently ships this PR's exact bug — HTTP 500 foragent:8-style provider IDs — while every current test stays green (verified by probe: a strict charset gate injected ontask.idleft all existing tests green; adding the missing chain test failed with the originalvalid id partserror).Suggested fix — add one real-
resolvecase with a reserved-char id, e.g. a sibling of'resolves an out-of-band fork by agent task id'where the bridge task'sidisgeneral-purpose-agent:8, asserting the resolvedsessionIdparses back to that agent ID:中文说明
没有测试把含保留字符的 task ID 经由真实的
VirtualSubagentSessions.resolve()串到createVirtualSubagentSessionId:下方的保留字符往返测试直接调用 create/parse,server 路由测试 mock 了resolve,而所有真实resolve单测只用普通 ID(fork-agent-1、general-purpose-call-1等)。— 失败场景:未来在resolve()调用点对task.id重新收紧或变换(例如重新引入按部件的字符集过滤),会在所有现有测试保持绿色的情况下悄悄复发本 PR 修复的 bug——agent:8这类 provider ID 返回 HTTP 500(已用探针验证:在task.id上注入严格字符集门槛后全部现有测试仍为绿色;补上缺失的链路测试则以原始的valid id parts报错失败)。建议修复——为真实
resolve补一个含保留字符 ID 的用例,例如在'resolves an out-of-band fork by agent task id'旁新增一个 bridge taskid为general-purpose-agent:8的用例,断言解析出的sessionId能 parse 回该 agent ID。— qwen3.8-max via Qwen Code /review (v0.21.8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in a4c7df2. The existing out-of-band resolve test is now parameterized with
general-purpose-agent:8and asserts that thesessionIdreturned by the realVirtualSubagentSessions.resolve()path parses back to the same task ID. I also verified the test's efficacy by temporarily reintroducing a strict charset gate at the resolve call site: only the new reserved-ID case failed with the originalvalid id partserror. The focused suite passes 19/19 on the final code.