Skip to content

Commit b754236

Browse files
fix: add .catch() to all fire-and-forget saveSessionState calls
Replaced 6 'void saveSessionState(state, logger)' calls with 'saveSessionState(state, logger).catch(() => {})' in hooks.ts and inject.ts. Root cause: with dynamic STORAGE_DIR, fire-and-forget saves now write to test temp dirs. When tests delete the temp dir, pending writes fail with ENOENT, triggering unhandledRejection. The .catch() handler silently absorbs these errors — consistent with the existing pattern in state.ts:56. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 17954a0 commit b754236

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎lib/hooks.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function runMajorGC(
158158
agedOutTokens,
159159
maxBlockAge,
160160
})
161-
void saveSessionState(state, logger)
161+
saveSessionState(state, logger).catch(() => {})
162162
}
163163

164164
if (!state.modelContextLimit) return
@@ -202,7 +202,7 @@ function runMajorGC(
202202
currentTokens,
203203
threshold: config.gc.majorGcThresholdPercent,
204204
})
205-
void saveSessionState(state, logger)
205+
saveSessionState(state, logger).catch(() => {})
206206
}
207207
}
208208

@@ -246,14 +246,14 @@ export function createChatMessageTransformHandler(
246246
const activeBlockCountBefore = state.prune.messages.activeBlockIds.size // [FIX Bug 4]
247247
syncCompressionBlocks(state, logger, output.messages)
248248
if (state.prune.messages.activeBlockIds.size !== activeBlockCountBefore) { // [FIX Bug 4]
249-
void saveSessionState(state, logger) // [FIX Bug 4] persist deactivations
249+
saveSessionState(state, logger).catch(() => {}) // [FIX Bug 4] persist deactivations
250250
}
251251
syncToolCache(state, config, logger, output.messages)
252252
buildToolIdList(state, output.messages)
253253
runMajorGC(state, config, logger, output.messages)
254254
const batchResult = runBatchCleanup(state, config, logger, output.messages)
255255
if (batchResult.mergedCount > 0) {
256-
void saveSessionState(state, logger)
256+
saveSessionState(state, logger).catch(() => {})
257257
}
258258
prune(state, logger, config, output.messages)
259259
// [FIX Bug 2] assign refs to newly created synthetic messages from prune/filterCompressedRanges

‎lib/messages/inject/inject.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const injectCompressNudges = (
9191
state.nudges.turnNudgeAnchors.clear()
9292
state.nudges.iterationNudgeAnchors.clear()
9393
state.nudges.lastPerMessageNudgeTokens = currentTokens
94-
void saveSessionState(state, logger)
94+
saveSessionState(state, logger).catch(() => {})
9595
return
9696
}
9797

@@ -229,7 +229,7 @@ export const injectCompressNudges = (
229229
}
230230

231231
if (anchorsChanged) {
232-
void saveSessionState(state, logger)
232+
saveSessionState(state, logger).catch(() => {})
233233
}
234234
}
235235

0 commit comments

Comments
 (0)