fix: harden long conversation continuity
Memind CI / Test, build, and release guards (push) Successful in 1m28s

This commit is contained in:
john
2026-07-27 21:39:34 +08:00
parent 5ae166fc44
commit 48c61a3279
16 changed files with 1635 additions and 94 deletions
+60
View File
@@ -3,8 +3,10 @@ import test from 'node:test';
import {
reconcileSessionEventRequestContext,
resolvePostAgentRunChatState,
shouldIgnoreZeroActivityFinish,
shouldKeepStreamingAfterRunError,
shouldPromoteSessionIdToStreaming,
shouldScheduleMissingActiveRequestGrace,
} from './chat-agent-run-gate.mjs';
test('resolvePostAgentRunChatState keeps idle when Finish beat agent-run gate', () => {
@@ -85,6 +87,64 @@ test('shouldPromoteSessionIdToStreaming skips re-streaming after Finish', () =>
assert.equal(shouldPromoteSessionIdToStreaming('streaming'), true);
});
test('zero-token Finish cannot unlock a composer with an active request', () => {
assert.equal(
shouldIgnoreZeroActivityFinish({
eventType: 'Finish',
hasActiveRequest: true,
tokenState: {
inputTokens: 0,
outputTokens: 0,
totalTokens: 0,
accumulatedInputTokens: 0,
accumulatedOutputTokens: 0,
accumulatedTotalTokens: 0,
},
}),
true,
);
assert.equal(
shouldIgnoreZeroActivityFinish({
eventType: 'Finish',
hasActiveRequest: true,
tokenState: { inputTokens: 8, outputTokens: 2, totalTokens: 10 },
}),
false,
);
assert.equal(
shouldIgnoreZeroActivityFinish({
eventType: 'Finish',
hasActiveRequest: false,
tokenState: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
}),
false,
);
});
test('missing ActiveRequests cannot unlock while the Portal agent-run is pending', () => {
assert.equal(
shouldScheduleMissingActiveRequestGrace({
allowMissingGrace: true,
agentRunPending: true,
}),
false,
);
assert.equal(
shouldScheduleMissingActiveRequestGrace({
allowMissingGrace: true,
agentRunPending: false,
}),
true,
);
assert.equal(
shouldScheduleMissingActiveRequestGrace({
allowMissingGrace: false,
agentRunPending: false,
}),
false,
);
});
test('reconcileSessionEventRequestContext adopts Goose request id while agent-run gate waits', () => {
assert.deepEqual(
reconcileSessionEventRequestContext({