fix(cli): filter subagent sessions from resume history (#19698)

This commit is contained in:
Abhi
2026-02-21 12:41:27 -05:00
committed by GitHub
parent dfd7721e69
commit d2d345f41a
7 changed files with 116 additions and 9 deletions

View File

@@ -445,9 +445,76 @@ describe('SessionSelector', () => {
const sessionSelector = new SessionSelector(config);
const sessions = await sessionSelector.listSessions();
// Should list the session with gemini message
expect(sessions.length).toBe(1);
expect(sessions[0].id).toBe(sessionIdGeminiOnly);
});
it('should not list sessions marked as subagent', async () => {
const mainSessionId = randomUUID();
const subagentSessionId = randomUUID();
// Create test session files
const chatsDir = path.join(tmpDir, 'chats');
await fs.mkdir(chatsDir, { recursive: true });
// Main session - should be listed
const mainSession = {
sessionId: mainSessionId,
projectHash: 'test-hash',
startTime: '2024-01-01T10:00:00.000Z',
lastUpdated: '2024-01-01T10:30:00.000Z',
messages: [
{
type: 'user',
content: 'Hello world',
id: 'msg1',
timestamp: '2024-01-01T10:00:00.000Z',
},
],
kind: 'main',
};
// Subagent session - should NOT be listed
const subagentSession = {
sessionId: subagentSessionId,
projectHash: 'test-hash',
startTime: '2024-01-01T11:00:00.000Z',
lastUpdated: '2024-01-01T11:30:00.000Z',
messages: [
{
type: 'user',
content: 'Internal subagent task',
id: 'msg1',
timestamp: '2024-01-01T11:00:00.000Z',
},
],
kind: 'subagent',
};
await fs.writeFile(
path.join(
chatsDir,
`${SESSION_FILE_PREFIX}2024-01-01T10-00-${mainSessionId.slice(0, 8)}.json`,
),
JSON.stringify(mainSession, null, 2),
);
await fs.writeFile(
path.join(
chatsDir,
`${SESSION_FILE_PREFIX}2024-01-01T11-00-${subagentSessionId.slice(0, 8)}.json`,
),
JSON.stringify(subagentSession, null, 2),
);
const sessionSelector = new SessionSelector(config);
const sessions = await sessionSelector.listSessions();
// Should only list the main session
expect(sessions.length).toBe(1);
expect(sessions[0].id).toBe(mainSessionId);
});
});
describe('extractFirstUserMessage', () => {

View File

@@ -276,6 +276,12 @@ export const getAllSessionFiles = async (
return { fileName: file, sessionInfo: null };
}
// Skip subagent sessions - these are implementation details of a tool call
// and shouldn't be surfaced for resumption in the main agent history.
if (content.kind === 'subagent') {
return { fileName: file, sessionInfo: null };
}
const firstUserMessage = extractFirstUserMessage(content.messages);
const isCurrentSession = currentSessionId
? file.includes(currentSessionId.slice(0, 8))