fix: 收口上下文压缩生命周期边界
This commit is contained in:
@@ -2390,6 +2390,7 @@ function finishSessionRunSuccessfully(
|
||||
runToken: number,
|
||||
messages: RawMessage[],
|
||||
statuses: Record<string, OpencodeSessionStatus> = {},
|
||||
compactionGeneration?: number,
|
||||
): boolean {
|
||||
if (!isSessionRunCurrent(sessionId, runToken)) return false;
|
||||
flushSessionRunStreamBatch(set, sessionId, runToken);
|
||||
@@ -2397,6 +2398,19 @@ function finishSessionRunSuccessfully(
|
||||
set((state) => {
|
||||
const sendingSessionIds = withoutKey(state.sendingSessionIds, sessionId);
|
||||
const nextState = { ...state, sendingSessionIds };
|
||||
const currentTranscript = state.sessionTranscriptBySessionId[sessionId];
|
||||
const completedTranscript = compactionGeneration !== undefined
|
||||
&& state.runtimeGeneration === compactionGeneration
|
||||
? completeCompaction(
|
||||
getOrCreateSessionTranscript(state, sessionId),
|
||||
{ runID: String(runToken), generation: compactionGeneration },
|
||||
{
|
||||
runID: String(runToken),
|
||||
generation: compactionGeneration,
|
||||
completedAt: Date.now(),
|
||||
},
|
||||
)
|
||||
: currentTranscript;
|
||||
return {
|
||||
...getSessionMessagePatch(state, sessionId, messages),
|
||||
...dispatchSessionRunEvent(state, sessionId, {
|
||||
@@ -2413,6 +2427,14 @@ function finishSessionRunSuccessfully(
|
||||
sendingSessionId: getSendingSessionIdForSelection(nextState),
|
||||
loading: false,
|
||||
...errorState(null),
|
||||
...(completedTranscript && completedTranscript !== currentTranscript
|
||||
? {
|
||||
sessionTranscriptBySessionId: {
|
||||
...state.sessionTranscriptBySessionId,
|
||||
[sessionId]: completedTranscript,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
});
|
||||
invalidateSessionRun(sessionId);
|
||||
@@ -3051,6 +3073,7 @@ async function runSessionSubmission(
|
||||
runToken,
|
||||
messages,
|
||||
statuses,
|
||||
submission.kind === 'compact' ? runGeneration : undefined,
|
||||
);
|
||||
if (
|
||||
completed
|
||||
|
||||
Reference in New Issue
Block a user