Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions packages/cli/src/acp-integration/acpAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15331,6 +15331,53 @@ describe('QwenAgent MCP SSE/HTTP support', () => {
await agentPromise;
});

it('resolves sessionTurnIndex settings per request, not from the this.settings cache', async () => {
const readTurnIndexPage = vi.fn().mockResolvedValue({
sessionId: VALID_SESSION_ID,
records: [],
hasMore: false,
gaps: [],
startTime: 'start',
lastUpdated: 'end',
});
vi.mocked(SessionTranscriptReader).mockImplementation(
() =>
({
readTurnIndexPage,
}) as unknown as InstanceType<typeof SessionTranscriptReader>,
);
const { agent, agentPromise } =
await bootCoreSettingsAgent(makeCoreSettings());

// Multi-workspace daemon shape: the live session and `this.settings`
// belong to the boot workspace; the turn-index request names another cwd
// whose own settings must pin the transcript read. Routing through the
// stale cache would scan the wrong runtime root (#10095 bug class).
const perRequestSettings = makeCoreSettings();
vi.mocked(loadSettings).mockClear();
vi.mocked(loadSettings).mockReturnValue(perRequestSettings);
vi.mocked(runWithAcpRuntimeOutputDir).mockClear();

await expect(
agent.extMethod(SERVE_STATUS_EXT_METHODS.sessionTurnIndex, {
cwd: '/tmp/workspace-a',
sessionId: VALID_SESSION_ID,
}),
).resolves.toBeDefined();

expect(loadSettings).toHaveBeenCalledWith('/tmp/workspace-a');
expect(runWithAcpRuntimeOutputDir).toHaveBeenCalledTimes(1);
expect(vi.mocked(runWithAcpRuntimeOutputDir).mock.calls[0]![0]).toBe(
perRequestSettings,
);
expect(vi.mocked(runWithAcpRuntimeOutputDir).mock.calls[0]![1]).toBe(
'/tmp/workspace-a',
);

mockConnectionState.resolve();
await agentPromise;
});

it('still scans the transcript when the pre-read flush fails', async () => {
const sessionId = '11111111-1111-1111-1111-111111111111';
const innerConfig = await setupSessionMocks(sessionId);
Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/acp-integration/acpAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4580,9 +4580,10 @@ class QwenAgent implements Agent {
* caller's decision at this level: callers that already hold deliberately
* scoped settings (workspace MCP discovery, live-session scope checks,
* session creation) pass them in. Per-request session-management handlers
* (list, delete, rename, transcript page, settled turn status, and the
* non-live branch of loadUpdates) must not make that decision themselves —
* they use `runWithPinnedRuntimeBaseDirForRequest` below. Session load and
* (list, delete, rename, transcript page, transcript turn index, settled
* turn status, and the non-live branch of loadUpdates) must not make that
* decision themselves — they use `runWithPinnedRuntimeBaseDirForRequest`
* below. Session load and
* resume resolve the request's settings at the call site deliberately,
* under profiler instrumentation, because they adopt those settings for
* the session afterwards.
Expand Down
Loading