fix: scope observation to current turn

Require assistant natural language after the latest user message so a completed prompt cannot reuse historical replies when queuing the observation snapshot.
This commit is contained in:
2026-08-24 12:55:01 +08:00
parent 7a15b1b49c
commit 16f5c57f17
3 changed files with 65 additions and 7 deletions

View File

@@ -220,6 +220,45 @@ describe('local Agent session sync', () => {
expect(pushSessionDataMock).not.toHaveBeenCalled();
});
it('does not reuse an older assistant reply when the current turn has no reply', async () => {
const base = createProductSnapshot('conversation-1');
queueCodingConversationSessionSync({
...base,
nodes: [
{
kind: 'message',
id: 'old-user',
role: 'user',
status: 'complete',
blocks: [{ kind: 'text', id: 'old-question', text: '旧问题', status: 'complete' }],
},
{
kind: 'message',
id: 'old-assistant',
role: 'assistant',
status: 'complete',
blocks: [{ kind: 'text', id: 'old-answer', text: '旧回答', status: 'complete' }],
},
{
kind: 'message',
id: 'current-user',
role: 'user',
status: 'complete',
blocks: [{ kind: 'text', id: 'current-question', text: '新问题', status: 'complete' }],
},
],
run: {
status: 'idle',
runId: 'run-2',
settledAt: Date.parse('2026-08-24T08:01:00.000Z'),
terminalReason: 'completed',
},
});
await flushPendingAgentSessionSync();
expect(pushSessionDataMock).not.toHaveBeenCalled();
});
it('never uploads a pending snapshot under a different authenticated account', async () => {
queueAgentSessionSync('prj_1', 'ses_1', [
{ id: 'user-1', role: 'user', content: '账号 A 的问题' },