Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
860a334
test(serve): reproduce encoded subagent id failure
carffuca Aug 8, 2026
6df743f
fix(serve): support encoded subagent task ids
carffuca Aug 8, 2026
1713e9a
test(serve): cover oversized encoded subagent ids
carffuca Aug 8, 2026
2ba6d37
fix(serve): bound encoded virtual session ids
carffuca Aug 8, 2026
0945d22
test(serve): reject lossy virtual agent ids
carffuca Aug 8, 2026
977e6d8
fix(serve): preserve virtual agent id round trips
carffuca Aug 8, 2026
b69cf27
test(serve): cover virtual agent id length limit
carffuca Aug 8, 2026
2ba3bbc
test(serve): cover virtual session id boundaries
carffuca Aug 9, 2026
4c2c421
fix(serve): validate canonical virtual session ids
carffuca Aug 9, 2026
9750746
test(serve): pin virtual session id length limit
carffuca Aug 9, 2026
a4c7df2
test(serve): cover reserved ids through resolve
carffuca Aug 10, 2026
1c27914
refactor(serve): share virtual id part length limit
carffuca Aug 10, 2026
d425d1f
Merge branch 'main' into fix/virtual-subagent-session-id-parts
qwen-code-dev-bot Aug 11, 2026
6688f96
test(serve): pin parent charset and encoded slash coverage
qwen-code-dev-bot Aug 11, 2026
53265f2
refactor(serve): sync virtual subagent id length limits (#8717)
qwen-code-dev-bot Aug 11, 2026
a91880c
test(serve): pin parse-side parent id length limit (#8717)
qwen-code-dev-bot Aug 11, 2026
3d0f6e0
refactor(serve): rename subagent route param to subagentRef (#8717)
qwen-code-dev-bot Aug 11, 2026
44f0e4c
test(serve): pin parse-side total session id cap (#8717)
qwen-code-dev-bot Aug 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions packages/cli/src/serve/routes/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import {
deleteBranch,
} from '../server/git-branch-ops.js';
import {
MAX_VIRTUAL_SESSION_ID_PART_LENGTH,
parseVirtualSubagentSessionId,
type VirtualSubagentSessions,
} from '../virtual-subagent-sessions.js';
Expand Down Expand Up @@ -2392,8 +2393,8 @@ export function registerSessionRoutes(
app.post('/session/:id/load', mutate(), restoreSessionHandler('load'));
app.post('/session/:id/resume', mutate(), restoreSessionHandler('resume'));

app.get('/session/:id/subagents/:toolCallId', async (req, res) => {
const route = 'GET /session/:id/subagents/:toolCallId';
app.get('/session/:id/subagents/:subagentRef', async (req, res) => {
const route = 'GET /session/:id/subagents/:subagentRef';
const sessionId = requireSessionId(req, res);
if (!sessionId) return;
if (!virtualSubagentSessions) {
Expand All @@ -2404,11 +2405,14 @@ export function registerSessionRoutes(
});
return;
}
const toolCallId = req.params['toolCallId'];
if (!toolCallId || toolCallId.length > 500) {
const subagentRef = req.params['subagentRef'];
if (
!subagentRef ||
subagentRef.length > MAX_VIRTUAL_SESSION_ID_PART_LENGTH
) {
res.status(400).json({
error: '`toolCallId` must be a non-empty tool call id',
code: 'invalid_tool_call_id',
error: '`subagentRef` must be a non-empty subagent reference',
code: 'invalid_subagent_ref',
});
return;
}
Expand All @@ -2424,14 +2428,14 @@ export function registerSessionRoutes(
const resolved = await virtualSubagentSessions.resolve(
runtime,
sessionId,
toolCallId,
subagentRef,
);
if (!resolved) {
res.status(404).json({
error: 'Subagent session not found',
code: 'session_not_found',
sessionId,
toolCallId,
subagentRef,
});
return;
}
Expand All @@ -2442,10 +2446,10 @@ export function registerSessionRoutes(
});

app.post(
'/session/:id/subagents/:toolCallId/cancel',
'/session/:id/subagents/:subagentRef/cancel',
mutate(),
async (req, res) => {
const route = 'POST /session/:id/subagents/:toolCallId/cancel';
const route = 'POST /session/:id/subagents/:subagentRef/cancel';
const sessionId = requireSessionId(req, res);
if (!sessionId) return;
if (!virtualSubagentSessions) {
Expand All @@ -2456,11 +2460,14 @@ export function registerSessionRoutes(
});
return;
}
const toolCallId = req.params['toolCallId'];
if (!toolCallId || toolCallId.length > 500) {
const subagentRef = req.params['subagentRef'];
if (
!subagentRef ||
subagentRef.length > MAX_VIRTUAL_SESSION_ID_PART_LENGTH
) {
res.status(400).json({
error: '`toolCallId` must be a non-empty tool call id',
code: 'invalid_tool_call_id',
error: '`subagentRef` must be a non-empty subagent reference',
code: 'invalid_subagent_ref',
});
return;
}
Expand All @@ -2476,14 +2483,14 @@ export function registerSessionRoutes(
const resolved = await virtualSubagentSessions.resolve(
runtime,
sessionId,
toolCallId,
subagentRef,
);
if (!resolved) {
res.status(404).json({
error: 'Subagent session not found',
code: 'session_not_found',
sessionId,
toolCallId,
subagentRef,
});
return;
}
Expand Down
105 changes: 61 additions & 44 deletions packages/cli/src/serve/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8785,53 +8785,70 @@ describe('createServeApp', () => {
]);
});

it('resolves and cancels a virtual subagent through its routes', async () => {
const bridge = fakeBridge({
cancelSessionTaskImpl: async () => ({ cancelled: true }),
});
const resolveSpy = vi
.spyOn(VirtualSubagentSessions.prototype, 'resolve')
.mockResolvedValue({
sessionId: createVirtualSubagentSessionId('s-1', 'agent-1'),
taskId: 'agent-1',
title: 'Investigate',
status: 'running',
it.each([
['agent%3A8', 'agent:8'],
['agent%2F8', 'agent/8'],
])(
'resolves and cancels a virtual subagent through its routes: %s',
async (encodedSubagentRef, subagentRef) => {
const taskId = `general-purpose-${subagentRef}`;
const bridge = fakeBridge({
cancelSessionTaskImpl: async () => ({ cancelled: true }),
});
const tokenOpts: ServeOptions = { ...baseOpts, token: 'secret' };
const app = createServeApp(
{ ...tokenOpts, workspace: WS_BOUND },
undefined,
{ bridge },
);
const resolveSpy = vi
.spyOn(VirtualSubagentSessions.prototype, 'resolve')
.mockResolvedValue({
sessionId: createVirtualSubagentSessionId('s-1', taskId),
taskId,
title: 'Investigate',
status: 'running',
});
const tokenOpts: ServeOptions = { ...baseOpts, token: 'secret' };
const app = createServeApp(
{ ...tokenOpts, workspace: WS_BOUND },
undefined,
{ bridge },
);

try {
const resolveRes = await request(app)
.get('/session/s-1/subagents/tool-1')
.set('Host', `127.0.0.1:${tokenOpts.port}`)
.set('Authorization', 'Bearer secret');
const cancelRes = await request(app)
.post('/session/s-1/subagents/tool-1/cancel')
.set('Host', `127.0.0.1:${tokenOpts.port}`)
.set('Authorization', 'Bearer secret');
try {
const resolveRes = await request(app)
.get(`/session/s-1/subagents/${encodedSubagentRef}`)
.set('Host', `127.0.0.1:${tokenOpts.port}`)
.set('Authorization', 'Bearer secret');
const cancelRes = await request(app)
.post(`/session/s-1/subagents/${encodedSubagentRef}/cancel`)
.set('Host', `127.0.0.1:${tokenOpts.port}`)
.set('Authorization', 'Bearer secret');

expect(resolveRes.status).toBe(200);
expect(resolveRes.headers['cache-control']).toBe('no-store');
expect(resolveRes.body).toMatchObject({
taskId: 'agent-1',
status: 'running',
});
expect(cancelRes.status).toBe(200);
expect(cancelRes.body).toEqual({ cancelled: true });
expect(resolveSpy).toHaveBeenCalledTimes(2);
expect(resolveSpy.mock.calls[0]?.slice(1)).toEqual(['s-1', 'tool-1']);
expect(resolveSpy.mock.calls[1]?.slice(1)).toEqual(['s-1', 'tool-1']);
expect(bridge.cancelSessionTaskCalls).toEqual([
{ sessionId: 's-1', taskId: 'agent-1', taskKind: 'agent' },
]);
} finally {
resolveSpy.mockRestore();
}
});
expect(resolveRes.status).toBe(200);
expect(resolveRes.headers['cache-control']).toBe('no-store');
expect(resolveRes.body).toMatchObject({
taskId,
status: 'running',
});
expect(cancelRes.status).toBe(200);
expect(cancelRes.body).toEqual({ cancelled: true });
expect(resolveSpy).toHaveBeenCalledTimes(2);
expect(resolveSpy.mock.calls[0]?.slice(1)).toEqual([
's-1',
subagentRef,
]);
expect(resolveSpy.mock.calls[1]?.slice(1)).toEqual([
's-1',
subagentRef,
]);
expect(bridge.cancelSessionTaskCalls).toEqual([
{
sessionId: 's-1',
taskId,
taskKind: 'agent',
},
]);
} finally {
resolveSpy.mockRestore();
}
},
);

it('requires the parent runtime for virtual heartbeat and detach', async () => {
const primaryBridge = fakeBridge();
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/serve/server/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ export const legacySessionTelemetryRoutes = [
},
{
method: 'GET',
path: '/session/:id/subagents/:toolCallId',
path: '/session/:id/subagents/:subagentRef',
attribution: 'handler_resolved',
route: 'GET /session/:id/subagents/:toolCallId',
route: 'GET /session/:id/subagents/:subagentRef',
},
{
method: 'POST',
path: '/session/:id/subagents/:toolCallId/cancel',
path: '/session/:id/subagents/:subagentRef/cancel',
attribution: 'handler_resolved',
route: 'POST /session/:id/subagents/:toolCallId/cancel',
route: 'POST /session/:id/subagents/:subagentRef/cancel',
},
{
method: 'GET',
Expand Down
Loading
Loading