ODS V3 Pre-Release: Public testing and refinement ahead of the official V3 launch. Turn your PC, Mac, or Linux box into a private AI server.
Python ai-agentsamdcomfyuidockerllama-cppllmlocal-ain8nnvidiaopen-webuiragself-hostedspeech-to-textstrix-halotext-to-speechworkflow-automation
{
"version": "2026.6.33",
"sourceSha256": "ae83457af1947f3eaf3e08f8fbde869a1c023a80acfbf0f27d3db887af1d36d3",
"patchedSha256": "2382052dd075b2eae2d6fee59d5485bc5b63a988286a1595cb9e122c0fd87d12",
"replacements": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
],
[
"currentAttemptAssistant = findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t});",
"// Yield context comes from this attempt's real model messages, before\n\t\t\t\t\t// Tool Search projects synthetic nested assistant calls into the transcript.\n\t\t\t\t\tcurrentAttemptAssistant = yieldDetected\n\t\t\t\t\t\t? snapshotSelection.messagesSnapshot.slice(Math.max(0, prePromptMessageCount)).findLast(message => message?.role === \"assistant\" && ![\"error\", \"aborted\"].includes(message.stopReason))\n\t\t\t\t\t\t: findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t\t});"
],
[
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) runAgentEndSideEffects({\n\t\t\t\t\tevent: {\n\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t},\n\t\t\t\t\tctx: {\n\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\thookRunner\n\t\t\t\t});",
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) {\n\t\t\t\t\tconst agentEndSideEffects = {\n\t\t\t\t\t\tevent: {\n\t\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx: {\n\t\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\thookRunner\n\t\t\t\t\t};\n\t\t\t\t\tconst emitAgentEnd = () => runAgentEndSideEffects(agentEndSideEffects);\n\t\t\t\t\t// A known pre-provider context precheck is an attempt boundary,\n\t\t\t\t\t// not the terminal outcome of the native recovery loop. Keep its\n\t\t\t\t\t// failure pending until a later attempt ends or recovery exits.\n\t\t\t\t\tif (!aborted && promptErrorSource === \"precheck\" && promptError && preflightRecovery\n\t\t\t\t\t\t&& preflightRecovery.source === void 0\n\t\t\t\t\t\t&& [\"compact_only\", \"compact_then_truncate\"].includes(preflightRecovery.route)\n\t\t\t\t\t\t&& typeof params.deferPreflightAgentEnd === \"function\") {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd(emitAgentEnd);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd?.();\n\t\t\t\t\t\temitAgentEnd();\n\t\t\t\t\t}\n\t\t\t\t}"
],
[
"\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);",
"\t\t// ODS: estimate the tool results the provider request will carry. The\n\t\t// stream projects them after this transform (per-result cap, aggregate\n\t\t// budget, older results reduced to a notice). Counting the raw\n\t\t// transcript instead compacted at a fraction of the real context.\n\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: params.projectToolResults?.(contextMessages) ?? contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);"
],
[
"\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;",
"\t\t\t// The provider stream sends tool results through this projection\n\t\t\t// (installProviderPromptHistoryTransform below); the loop guard measures\n\t\t\t// the same view. It passes no projection state, so measuring never\n\t\t\t// changes what the stream later sends.\n\t\t\tconst projectGuardToolResults = (messages) => truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudgetForGuard, toolResultMaxCharsForGuard, toolResultMaxCharsForGuard * PROMPT_TOOL_RESULT_AGGREGATE_CAP_MULTIPLIER).messages;\n\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;"
],
[
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t\t...midTurnPrecheckOptions"
],
[
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t...midTurnPrecheckOptions"
],
[
"/**\n* Idempotent cleanup: prune persisted image blocks from completed turns older\n* than {@link PRESERVE_RECENT_COMPLETED_TURNS}. The delay also reduces\n* prompt-cache churn, though prefix stability additionally depends on the\n* replay sanitizer being idempotent. Textual media markers are scrubbed on the\n* same boundary because detectAndLoadPromptImages treats them as fresh prompt\n* image references when old history is replayed into a later prompt.\n*/\nfunction pruneProcessedHistoryImages(messages) {\n\tconst pruneBeforeIndex = resolvePruneBeforeIndex(messages);\n\tif (pruneBeforeIndex < 0) return null;",
"// ODS: a Pixel preview screenshot is evidence for the run that took it. Before\n// the latest user message (the next owner turn, or a retry prompt), replace it\n// with the processed-image marker, whatever model the route serves now; its\n// receipt text stays. Owner images keep the three-turn rule below.\nconst PIXEL_PREVIEW_INSPECTION_TOOL = \"pixel_ods_workspace_preview_inspect\";\n// A Tool Search tool_call result names its child first (openclaw-image-envelope.json).\nconst PIXEL_PREVIEW_INSPECTION_ENVELOPE = JSON.stringify({ tool: {\n\tid: \"openclaw:pixel-ods:\" + PIXEL_PREVIEW_INSPECTION_TOOL,\n\tsource: \"openclaw\",\n\tsourceName: \"pixel-ods\",\n\tname: PIXEL_PREVIEW_INSPECTION_TOOL\n} });\nfunction isPixelPreviewInspectionResult(message) {\n\tif (message?.role !== \"toolResult\" || !Array.isArray(message.content)) return false;\n\tif (message.toolName === PIXEL_PREVIEW_INSPECTION_TOOL) return true;\n\tconst first = message.content[0];\n\treturn message.toolName === \"tool_call\" && first?.type === \"text\" && first.text === PIXEL_PREVIEW_INSPECTION_ENVELOPE;\n}\nfunction prunePixelPreviewScreenshotsBeforeLatestUser(messages) {\n\tconst latestUser = messages.findLastIndex((message) => message?.role === \"user\");\n\tlet prunedMessages = null;\n\tfor (let i = 0; i < latestUser; i++) {\n\t\tconst message = messages[i];\n\t\tif (!isPixelPreviewInspectionResult(message) || !message.content.some((block) => block?.type === \"image\")) continue;\n\t\tprunedMessages ??= messages.slice();\n\t\tprunedMessages[i] = cloneMessageWithContent(message, message.content.map((block) => block?.type === \"image\" ? {\n\t\t\ttype: \"text\",\n\t\t\ttext: PRUNED_HISTORY_IMAGE_MARKER\n\t\t} : block));\n\t}\n\treturn prunedMessages;\n}\nfunction pruneProcessedHistoryImages(messages) {\n\tconst runScoped = prunePixelPreviewScreenshotsBeforeLatestUser(messages);\n\treturn pruneProcessedTurnHistoryImages(runScoped ?? messages) ?? runScoped;\n}\n/**\n* Idempotent cleanup: prune persisted image blocks from completed turns older\n* than {@link PRESERVE_RECENT_COMPLETED_TURNS}. The delay also reduces\n* prompt-cache churn, though prefix stability additionally depends on the\n* replay sanitizer being idempotent. Textual media markers are scrubbed on the\n* same boundary because detectAndLoadPromptImages treats them as fresh prompt\n* image references when old history is replayed into a later prompt.\n*/\nfunction pruneProcessedTurnHistoryImages(messages) {\n\tconst pruneBeforeIndex = resolvePruneBeforeIndex(messages);\n\tif (pruneBeforeIndex < 0) return null;"
],
[
"async function assertSessionFileFence() {\n\t\tif (!fenceActive) return;\n\t\tconst current = await readSessionFileFingerprint(params.lockOptions.sessionFile);",
"async function assertSessionFileFence() {\n\t\tif (!fenceActive) return;\n\t\t// Do not yield between capture and comparison: an owned write can refresh the fence.\n\t\tconst current = readSessionFileFingerprintSync(params.lockOptions.sessionFile);"
],
[
"\t\tconst effectivePromptMode = params.toolsAllow?.length ? \"minimal\" : promptMode;",
"\t\t// ODS small-context owner chats retain the native safety/tool rules and\n\t\t// ODS hook contract, while omitting generic messaging/control-UI prose.\n\t\t// This is prompt layout only: tool policies and capabilities are unchanged.\n\t\tconst odsSmallContext = sessionAgentId === \"pixel\" && params.promptMode === void 0 && promptMode === \"full\"\n\t\t\t&& params.config?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true\n\t\t\t&& Number.isInteger(params.contextTokenBudget)\n\t\t\t&& params.contextTokenBudget >= 4096 && params.contextTokenBudget <= 8192;\n\t\tconst effectivePromptMode = params.toolsAllow?.length || odsSmallContext ? \"minimal\" : promptMode;"
]
],
"previousReplacements": {
"edf3d389cf098db7d2f9c8866579542d2aa0faf33730a4a2ab979712718c43e8": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
]
],
"9b42083e60143d03d10b0a966416a187b057356e2447d7b3502ac0ccd3bf2cec": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
]
],
"65fb7b9ed2fadfa3c0019c88484e77e355c6db4650feda7f39c43db99aaa2e61": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
]
],
"0439891d0b7e7528af4c5d6a81be609ade3cae08f5f75347c94478462512d4bd": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
]
],
"bf6963ed7992c373d9707f0ed6168ef87d063a7f48e062d83aae382d79c9d44a": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
],
[
"currentAttemptAssistant = findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t});",
"// Yield context comes from this attempt's real model messages, before\n\t\t\t\t\t// Tool Search projects synthetic nested assistant calls into the transcript.\n\t\t\t\t\tcurrentAttemptAssistant = yieldDetected\n\t\t\t\t\t\t? snapshotSelection.messagesSnapshot.slice(Math.max(0, prePromptMessageCount)).findLast(message => message?.role === \"assistant\" && ![\"error\", \"aborted\"].includes(message.stopReason))\n\t\t\t\t\t\t: findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t\t});"
]
],
"2e64e5eb0e35f5f363865d4f51bba54a599c9ac745241120b0a826e97613288e": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
],
[
"currentAttemptAssistant = findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t});",
"// Yield context comes from this attempt's real model messages, before\n\t\t\t\t\t// Tool Search projects synthetic nested assistant calls into the transcript.\n\t\t\t\t\tcurrentAttemptAssistant = yieldDetected\n\t\t\t\t\t\t? snapshotSelection.messagesSnapshot.slice(Math.max(0, prePromptMessageCount)).findLast(message => message?.role === \"assistant\" && ![\"error\", \"aborted\"].includes(message.stopReason))\n\t\t\t\t\t\t: findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t\t});"
],
[
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) runAgentEndSideEffects({\n\t\t\t\t\tevent: {\n\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t},\n\t\t\t\t\tctx: {\n\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\thookRunner\n\t\t\t\t});",
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) {\n\t\t\t\t\tconst agentEndSideEffects = {\n\t\t\t\t\t\tevent: {\n\t\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx: {\n\t\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\thookRunner\n\t\t\t\t\t};\n\t\t\t\t\tconst emitAgentEnd = () => runAgentEndSideEffects(agentEndSideEffects);\n\t\t\t\t\t// A known pre-provider context precheck is an attempt boundary,\n\t\t\t\t\t// not the terminal outcome of the native recovery loop. Keep its\n\t\t\t\t\t// failure pending until a later attempt ends or recovery exits.\n\t\t\t\t\tif (!aborted && promptErrorSource === \"precheck\" && promptError && preflightRecovery\n\t\t\t\t\t\t&& preflightRecovery.source === void 0\n\t\t\t\t\t\t&& [\"compact_only\", \"compact_then_truncate\"].includes(preflightRecovery.route)\n\t\t\t\t\t\t&& typeof params.deferPreflightAgentEnd === \"function\") {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd(emitAgentEnd);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd?.();\n\t\t\t\t\t\temitAgentEnd();\n\t\t\t\t\t}\n\t\t\t\t}"
]
],
"91b613c55a09f27df4058f568557ace6d70a2155dd58c3580ca2fe9085a6b39a": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
],
[
"currentAttemptAssistant = findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t});",
"// Yield context comes from this attempt's real model messages, before\n\t\t\t\t\t// Tool Search projects synthetic nested assistant calls into the transcript.\n\t\t\t\t\tcurrentAttemptAssistant = yieldDetected\n\t\t\t\t\t\t? snapshotSelection.messagesSnapshot.slice(Math.max(0, prePromptMessageCount)).findLast(message => message?.role === \"assistant\" && ![\"error\", \"aborted\"].includes(message.stopReason))\n\t\t\t\t\t\t: findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t\t});"
],
[
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) runAgentEndSideEffects({\n\t\t\t\t\tevent: {\n\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t},\n\t\t\t\t\tctx: {\n\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\thookRunner\n\t\t\t\t});",
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) {\n\t\t\t\t\tconst agentEndSideEffects = {\n\t\t\t\t\t\tevent: {\n\t\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx: {\n\t\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\thookRunner\n\t\t\t\t\t};\n\t\t\t\t\tconst emitAgentEnd = () => runAgentEndSideEffects(agentEndSideEffects);\n\t\t\t\t\t// A known pre-provider context precheck is an attempt boundary,\n\t\t\t\t\t// not the terminal outcome of the native recovery loop. Keep its\n\t\t\t\t\t// failure pending until a later attempt ends or recovery exits.\n\t\t\t\t\tif (!aborted && promptErrorSource === \"precheck\" && promptError && preflightRecovery\n\t\t\t\t\t\t&& preflightRecovery.source === void 0\n\t\t\t\t\t\t&& [\"compact_only\", \"compact_then_truncate\"].includes(preflightRecovery.route)\n\t\t\t\t\t\t&& typeof params.deferPreflightAgentEnd === \"function\") {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd(emitAgentEnd);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd?.();\n\t\t\t\t\t\temitAgentEnd();\n\t\t\t\t\t}\n\t\t\t\t}"
],
[
"\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);",
"\t\t// ODS: estimate the tool results the provider request will carry. The\n\t\t// stream projects them after this transform (per-result cap, aggregate\n\t\t// budget, older results reduced to a notice). Counting the raw\n\t\t// transcript instead compacted at a fraction of the real context.\n\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: params.projectToolResults?.(contextMessages) ?? contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);"
],
[
"\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;",
"\t\t\t// The provider stream sends tool results through this projection\n\t\t\t// (installProviderPromptHistoryTransform below); the loop guard measures\n\t\t\t// the same view. It passes no projection state, so measuring never\n\t\t\t// changes what the stream later sends.\n\t\t\tconst projectGuardToolResults = (messages) => truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudgetForGuard, toolResultMaxCharsForGuard, toolResultMaxCharsForGuard * PROMPT_TOOL_RESULT_AGGREGATE_CAP_MULTIPLIER).messages;\n\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;"
],
[
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t\t...midTurnPrecheckOptions"
],
[
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t...midTurnPrecheckOptions"
]
],
"670a1c0007f7fc2d3c623b3d0882e94d472513b60c43bf97b1d3ac3f586d2149": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
],
[
"currentAttemptAssistant = findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t});",
"// Yield context comes from this attempt's real model messages, before\n\t\t\t\t\t// Tool Search projects synthetic nested assistant calls into the transcript.\n\t\t\t\t\tcurrentAttemptAssistant = yieldDetected\n\t\t\t\t\t\t? snapshotSelection.messagesSnapshot.slice(Math.max(0, prePromptMessageCount)).findLast(message => message?.role === \"assistant\" && ![\"error\", \"aborted\"].includes(message.stopReason))\n\t\t\t\t\t\t: findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t\t});"
],
[
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) runAgentEndSideEffects({\n\t\t\t\t\tevent: {\n\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t},\n\t\t\t\t\tctx: {\n\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\thookRunner\n\t\t\t\t});",
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) {\n\t\t\t\t\tconst agentEndSideEffects = {\n\t\t\t\t\t\tevent: {\n\t\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx: {\n\t\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\thookRunner\n\t\t\t\t\t};\n\t\t\t\t\tconst emitAgentEnd = () => runAgentEndSideEffects(agentEndSideEffects);\n\t\t\t\t\t// A known pre-provider context precheck is an attempt boundary,\n\t\t\t\t\t// not the terminal outcome of the native recovery loop. Keep its\n\t\t\t\t\t// failure pending until a later attempt ends or recovery exits.\n\t\t\t\t\tif (!aborted && promptErrorSource === \"precheck\" && promptError && preflightRecovery\n\t\t\t\t\t\t&& preflightRecovery.source === void 0\n\t\t\t\t\t\t&& [\"compact_only\", \"compact_then_truncate\"].includes(preflightRecovery.route)\n\t\t\t\t\t\t&& typeof params.deferPreflightAgentEnd === \"function\") {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd(emitAgentEnd);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd?.();\n\t\t\t\t\t\temitAgentEnd();\n\t\t\t\t\t}\n\t\t\t\t}"
],
[
"\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);",
"\t\t// ODS: estimate the tool results the provider request will carry. The\n\t\t// stream projects them after this transform (per-result cap, aggregate\n\t\t// budget, older results reduced to a notice). Counting the raw\n\t\t// transcript instead compacted at a fraction of the real context.\n\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: params.projectToolResults?.(contextMessages) ?? contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);"
],
[
"\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;",
"\t\t\t// The provider stream sends tool results through this projection\n\t\t\t// (installProviderPromptHistoryTransform below); the loop guard measures\n\t\t\t// the same view. It passes no projection state, so measuring never\n\t\t\t// changes what the stream later sends.\n\t\t\tconst projectGuardToolResults = (messages) => truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudgetForGuard, toolResultMaxCharsForGuard, toolResultMaxCharsForGuard * PROMPT_TOOL_RESULT_AGGREGATE_CAP_MULTIPLIER).messages;\n\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;"
],
[
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t\t...midTurnPrecheckOptions"
],
[
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t...midTurnPrecheckOptions"
],
[
"/**\n* Idempotent cleanup: prune persisted image blocks from completed turns older\n* than {@link PRESERVE_RECENT_COMPLETED_TURNS}. The delay also reduces\n* prompt-cache churn, though prefix stability additionally depends on the\n* replay sanitizer being idempotent. Textual media markers are scrubbed on the\n* same boundary because detectAndLoadPromptImages treats them as fresh prompt\n* image references when old history is replayed into a later prompt.\n*/\nfunction pruneProcessedHistoryImages(messages) {\n\tconst pruneBeforeIndex = resolvePruneBeforeIndex(messages);\n\tif (pruneBeforeIndex < 0) return null;",
"// ODS: a Pixel preview screenshot is evidence for the run that took it. Before\n// the latest user message (the next owner turn, or a retry prompt), replace it\n// with the processed-image marker, whatever model the route serves now; its\n// receipt text stays. Owner images keep the three-turn rule below.\nconst PIXEL_PREVIEW_INSPECTION_TOOL = \"pixel_ods_workspace_preview_inspect\";\n// A Tool Search tool_call result names its child first (openclaw-image-envelope.json).\nconst PIXEL_PREVIEW_INSPECTION_ENVELOPE = JSON.stringify({ tool: {\n\tid: \"openclaw:pixel-ods:\" + PIXEL_PREVIEW_INSPECTION_TOOL,\n\tsource: \"openclaw\",\n\tsourceName: \"pixel-ods\",\n\tname: PIXEL_PREVIEW_INSPECTION_TOOL\n} });\nfunction isPixelPreviewInspectionResult(message) {\n\tif (message?.role !== \"toolResult\" || !Array.isArray(message.content)) return false;\n\tif (message.toolName === PIXEL_PREVIEW_INSPECTION_TOOL) return true;\n\tconst first = message.content[0];\n\treturn message.toolName === \"tool_call\" && first?.type === \"text\" && first.text === PIXEL_PREVIEW_INSPECTION_ENVELOPE;\n}\nfunction prunePixelPreviewScreenshotsBeforeLatestUser(messages) {\n\tconst latestUser = messages.findLastIndex((message) => message?.role === \"user\");\n\tlet prunedMessages = null;\n\tfor (let i = 0; i < latestUser; i++) {\n\t\tconst message = messages[i];\n\t\tif (!isPixelPreviewInspectionResult(message) || !message.content.some((block) => block?.type === \"image\")) continue;\n\t\tprunedMessages ??= messages.slice();\n\t\tprunedMessages[i] = cloneMessageWithContent(message, message.content.map((block) => block?.type === \"image\" ? {\n\t\t\ttype: \"text\",\n\t\t\ttext: PRUNED_HISTORY_IMAGE_MARKER\n\t\t} : block));\n\t}\n\treturn prunedMessages;\n}\nfunction pruneProcessedHistoryImages(messages) {\n\tconst runScoped = prunePixelPreviewScreenshotsBeforeLatestUser(messages);\n\treturn pruneProcessedTurnHistoryImages(runScoped ?? messages) ?? runScoped;\n}\n/**\n* Idempotent cleanup: prune persisted image blocks from completed turns older\n* than {@link PRESERVE_RECENT_COMPLETED_TURNS}. The delay also reduces\n* prompt-cache churn, though prefix stability additionally depends on the\n* replay sanitizer being idempotent. Textual media markers are scrubbed on the\n* same boundary because detectAndLoadPromptImages treats them as fresh prompt\n* image references when old history is replayed into a later prompt.\n*/\nfunction pruneProcessedTurnHistoryImages(messages) {\n\tconst pruneBeforeIndex = resolvePruneBeforeIndex(messages);\n\tif (pruneBeforeIndex < 0) return null;"
]
],
"c4400345f497ff7c12e748928728414648465605fa4c1f2519c05bbe01a6e558": [
[
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = 6e4;",
"const COMPACTION_RETRY_AGGREGATE_TIMEOUT_MS = resolveCompactionTimeoutMs(params.config);"
],
[
"\tlet heldLock = await acquireLock();\n\tconst activeWriteLock = new AsyncLocalStorage();",
"\tlet heldLock = await acquireLock();\n\tlet promptLockReacquisition;\n\tconst activeWriteLock = new AsyncLocalStorage();"
],
[
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tconst lock = await acquireLock();\n\t\t\ttry {\n\t\t\t\theldLock = lock;\n\t\t\t\tawait assertSessionFileFence();\n\t\t\t} catch (err) {\n\t\t\t\theldLock = void 0;\n\t\t\t\tawait lock.release();\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t},",
"\t\tasync reacquireAfterPrompt() {\n\t\t\tawait waitForHeldLockDrain();\n\t\t\t// Split-turn summaries share one session: acquire and verify its lock once.\n\t\t\tif (promptLockReacquisition) return await promptLockReacquisition;\n\t\t\tif (takeoverDetected || heldLock) return;\n\t\t\tpromptLockReacquisition = (async () => {\n\t\t\t\tconst lock = await acquireLock();\n\t\t\t\ttry {\n\t\t\t\t\theldLock = lock;\n\t\t\t\t\tawait assertSessionFileFence();\n\t\t\t\t} catch (err) {\n\t\t\t\t\theldLock = void 0;\n\t\t\t\t\tawait lock.release();\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\t\t\t})();\n\t\t\ttry {\n\t\t\t\tawait promptLockReacquisition;\n\t\t\t} finally {\n\t\t\t\tpromptLockReacquisition = void 0;\n\t\t\t}\n\t\t},"
],
[
"\t\t\t\tonBeforeLifecycleTerminal: () => {\n\t\t\t\t\tif (requiresCompletionRequiredAsyncTaskWait({\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\ttoolMetas: toolMetasForTerminal\n\t\t\t\t\t})) return;\n\t\t\t\t\tclearActiveEmbeddedRun(params.sessionId, queueHandle, params.sessionKey, params.sessionFile);\n\t\t\t\t},",
"\t\t\t\t// agent_end may precede overflow compaction and continuation in this same\n\t\t\t\t// attempt. Retain its abort handle until the identity-checked outer finally."
],
[
"\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {",
"\t\t\tconst persistedToolResultModelProjection = createPersistedToolResultModelProjection({agentId: sessionAgentId, config: params.config});\n\t\t\tsessionManager = guardSessionManager(SessionManager.open(params.sessionFile), {"
],
[
"\t\t\t\tonMessagePersisted: () => {\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();",
"\t\t\t\tonMessagePersisted: (message) => {\n\t\t\t\t\tpersistedToolResultModelProjection.capture(message);\n\t\t\t\t\tsessionLockController.refreshAfterOwnedSessionWrite();"
],
[
"function normalizeMessagesForLlmBoundary(messages, options) {",
"// Per-attempt projection of already-persisted tool feedback. Hooks run once.\nfunction createPersistedToolResultModelProjection({agentId, config} = {}) {\n\t// Persistence hooks on other agents/plugins keep their storage-only contract.\n\tconst enabled = agentId === \"pixel\" && config?.plugins?.enabled !== false &&\n\t\tconfig?.plugins?.entries?.[\"pixel-ods\"]?.enabled === true &&\n\t\t(!Array.isArray(config.plugins.allow) || config.plugins.allow.includes(\"pixel-ods\")) &&\n\t\t(!Array.isArray(config.plugins.deny) || !config.plugins.deny.includes(\"pixel-ods\"));\n\tconst projected = new Map();\n\tconst keyFor = (message) => message?.role === \"toolResult\" &&\n\t\ttypeof message.toolCallId === \"string\" && message.toolCallId.length > 0 &&\n\t\ttypeof message.toolName === \"string\" && message.toolName.length > 0 &&\n\t\tNumber.isSafeInteger(message.timestamp) && message.timestamp > 0\n\t\t? JSON.stringify([message.toolCallId, message.toolName, message.timestamp]) : void 0;\n\treturn {\n\t\tcapture(message) {\n\t\t\tif (!enabled) return;\n\t\t\tconst key = keyFor(message);\n\t\t\tif (!key) return;\n\t\t\t// Reused identities are ambiguous, even within one attempt.\n\t\t\tif (projected.has(key)) { projected.set(key, null); return; }\n\t\t\tif (projected.size >= 512) return;\n\t\t\tprojected.set(key, structuredClone(message));\n\t\t},\n\t\tapply(messages) {\n\t\t\tif (!enabled) return messages;\n\t\t\tconst counts = new Map();\n\t\t\tfor (const message of messages) { const key = keyFor(message); if (key) counts.set(key, (counts.get(key) ?? 0) + 1); }\n\t\t\tlet changed = false;\n\t\t\tconst result = messages.map(message => {\n\t\t\t\tconst key = keyFor(message), replacement = projected.get(key);\n\t\t\t\tif (!replacement || counts.get(key) !== 1) return message;\n\t\t\t\tchanged = true;\n\t\t\t\treturn structuredClone(replacement);\n\t\t\t});\n\t\t\treturn changed ? result : messages;\n\t\t}\n\t};\n}\nfunction normalizeMessagesForLlmBoundary(messages, options) {"
],
[
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(messages, contextTokenBudget,",
"const providerPromptHistoryTruncation = truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudget,"
],
[
"currentAttemptAssistant = findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t});",
"// Yield context comes from this attempt's real model messages, before\n\t\t\t\t\t// Tool Search projects synthetic nested assistant calls into the transcript.\n\t\t\t\t\tcurrentAttemptAssistant = yieldDetected\n\t\t\t\t\t\t? snapshotSelection.messagesSnapshot.slice(Math.max(0, prePromptMessageCount)).findLast(message => message?.role === \"assistant\" && ![\"error\", \"aborted\"].includes(message.stopReason))\n\t\t\t\t\t\t: findCurrentAttemptAssistantMessage({\n\t\t\t\t\t\t\tmessagesSnapshot,\n\t\t\t\t\t\t\tprePromptMessageCount\n\t\t\t\t\t\t});"
],
[
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) runAgentEndSideEffects({\n\t\t\t\t\tevent: {\n\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t},\n\t\t\t\t\tctx: {\n\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\thookRunner\n\t\t\t\t});",
"\t\t\t\tif (!beforeAgentFinalizeRevisionReason) {\n\t\t\t\t\tconst agentEndSideEffects = {\n\t\t\t\t\t\tevent: {\n\t\t\t\t\t\t\tmessages: messagesSnapshot,\n\t\t\t\t\t\t\tsuccess: !aborted && !promptError,\n\t\t\t\t\t\t\terror: promptError ? formatErrorMessage(promptError) : void 0,\n\t\t\t\t\t\t\tdurationMs: Date.now() - promptStartedAt\n\t\t\t\t\t\t},\n\t\t\t\t\t\tctx: {\n\t\t\t\t\t\t\trunId: params.runId,\n\t\t\t\t\t\t\ttrace: freezeDiagnosticTraceContext(diagnosticTrace),\n\t\t\t\t\t\t\tagentId: hookAgentId,\n\t\t\t\t\t\t\tsessionKey: params.sessionKey,\n\t\t\t\t\t\t\tsessionId: params.sessionId,\n\t\t\t\t\t\t\tworkspaceDir: params.workspaceDir,\n\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t...params.config ? { config: params.config } : {},\n\t\t\t\t\t\t\t...buildAgentHookContextChannelFields(params),\n\t\t\t\t\t\t\t...buildAgentHookContextIdentityFields({\n\t\t\t\t\t\t\t\ttrigger: params.trigger,\n\t\t\t\t\t\t\t\tsenderId: params.senderId,\n\t\t\t\t\t\t\t\tchatId: params.chatId,\n\t\t\t\t\t\t\t\tchannelContext: params.channelContext\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t\t\thookRunner\n\t\t\t\t\t};\n\t\t\t\t\tconst emitAgentEnd = () => runAgentEndSideEffects(agentEndSideEffects);\n\t\t\t\t\t// A known pre-provider context precheck is an attempt boundary,\n\t\t\t\t\t// not the terminal outcome of the native recovery loop. Keep its\n\t\t\t\t\t// failure pending until a later attempt ends or recovery exits.\n\t\t\t\t\tif (!aborted && promptErrorSource === \"precheck\" && promptError && preflightRecovery\n\t\t\t\t\t\t&& preflightRecovery.source === void 0\n\t\t\t\t\t\t&& [\"compact_only\", \"compact_then_truncate\"].includes(preflightRecovery.route)\n\t\t\t\t\t\t&& typeof params.deferPreflightAgentEnd === \"function\") {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd(emitAgentEnd);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tparams.deferPreflightAgentEnd?.();\n\t\t\t\t\t\temitAgentEnd();\n\t\t\t\t\t}\n\t\t\t\t}"
],
[
"\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);",
"\t\t// ODS: estimate the tool results the provider request will carry. The\n\t\t// stream projects them after this transform (per-result cap, aggregate\n\t\t// budget, older results reduced to a notice). Counting the raw\n\t\t// transcript instead compacted at a fraction of the real context.\n\t\tif (exceedsPreemptiveOverflowThreshold({\n\t\t\tmessages: params.projectToolResults?.(contextMessages) ?? contextMessages,\n\t\t\tmaxContextChars\n\t\t})) throw new Error(PREEMPTIVE_CONTEXT_OVERFLOW_MESSAGE);"
],
[
"\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;",
"\t\t\t// The provider stream sends tool results through this projection\n\t\t\t// (installProviderPromptHistoryTransform below); the loop guard measures\n\t\t\t// the same view. It passes no projection state, so measuring never\n\t\t\t// changes what the stream later sends.\n\t\t\tconst projectGuardToolResults = (messages) => truncateOversizedToolResultsInMessages(persistedToolResultModelProjection.apply(messages), contextTokenBudgetForGuard, toolResultMaxCharsForGuard, toolResultMaxCharsForGuard * PROMPT_TOOL_RESULT_AGGREGATE_CAP_MULTIPLIER).messages;\n\t\t\tconst midTurnPrecheckEnabled = params.config?.agents?.defaults?.compaction?.midTurnPrecheck?.enabled === true;"
],
[
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t\t...midTurnPrecheckOptions"
],
[
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\t...midTurnPrecheckOptions",
"\t\t\t\tcontextWindowTokens: contextTokenBudgetForGuard,\n\t\t\t\tprojectToolResults: projectGuardToolResults,\n\t\t\t\t...midTurnPrecheckOptions"
],
[
"/**\n* Idempotent cleanup: prune persisted image blocks from completed turns older\n* than {@link PRESERVE_RECENT_COMPLETED_TURNS}. The delay also reduces\n* prompt-cache churn, though prefix stability additionally depends on the\n* replay sanitizer being idempotent. Textual media markers are scrubbed on the\n* same boundary because detectAndLoadPromptImages treats them as fresh prompt\n* image references when old history is replayed into a later prompt.\n*/\nfunction pruneProcessedHistoryImages(messages) {\n\tconst pruneBeforeIndex = resolvePruneBeforeIndex(messages);\n\tif (pruneBeforeIndex < 0) return null;",
"// ODS: a Pixel preview screenshot is evidence for the run that took it. Before\n// the latest user message (the next owner turn, or a retry prompt), replace it\n// with the processed-image marker, whatever model the route serves now; its\n// receipt text stays. Owner images keep the three-turn rule below.\nconst PIXEL_PREVIEW_INSPECTION_TOOL = \"pixel_ods_workspace_preview_inspect\";\n// A Tool Search tool_call result names its child first (openclaw-image-envelope.json).\nconst PIXEL_PREVIEW_INSPECTION_ENVELOPE = JSON.stringify({ tool: {\n\tid: \"openclaw:pixel-ods:\" + PIXEL_PREVIEW_INSPECTION_TOOL,\n\tsource: \"openclaw\",\n\tsourceName: \"pixel-ods\",\n\tname: PIXEL_PREVIEW_INSPECTION_TOOL\n} });\nfunction isPixelPreviewInspectionResult(message) {\n\tif (message?.role !== \"toolResult\" || !Array.isArray(message.content)) return false;\n\tif (message.toolName === PIXEL_PREVIEW_INSPECTION_TOOL) return true;\n\tconst first = message.content[0];\n\treturn message.toolName === \"tool_call\" && first?.type === \"text\" && first.text === PIXEL_PREVIEW_INSPECTION_ENVELOPE;\n}\nfunction prunePixelPreviewScreenshotsBeforeLatestUser(messages) {\n\tconst latestUser = messages.findLastIndex((message) => message?.role === \"user\");\n\tlet prunedMessages = null;\n\tfor (let i = 0; i < latestUser; i++) {\n\t\tconst message = messages[i];\n\t\tif (!isPixelPreviewInspectionResult(message) || !message.content.some((block) => block?.type === \"image\")) continue;\n\t\tprunedMessages ??= messages.slice();\n\t\tprunedMessages[i] = cloneMessageWithContent(message, message.content.map((block) => block?.type === \"image\" ? {\n\t\t\ttype: \"text\",\n\t\t\ttext: PRUNED_HISTORY_IMAGE_MARKER\n\t\t} : block));\n\t}\n\treturn prunedMessages;\n}\nfunction pruneProcessedHistoryImages(messages) {\n\tconst runScoped = prunePixelPreviewScreenshotsBeforeLatestUser(messages);\n\treturn pruneProcessedTurnHistoryImages(runScoped ?? messages) ?? runScoped;\n}\n/**\n* Idempotent cleanup: prune persisted image blocks from completed turns older\n* than {@link PRESERVE_RECENT_COMPLETED_TURNS}. The delay also reduces\n* prompt-cache churn, though prefix stability additionally depends on the\n* replay sanitizer being idempotent. Textual media markers are scrubbed on the\n* same boundary because detectAndLoadPromptImages treats them as fresh prompt\n* image references when old history is replayed into a later prompt.\n*/\nfunction pruneProcessedTurnHistoryImages(messages) {\n\tconst pruneBeforeIndex = resolvePruneBeforeIndex(messages);\n\tif (pruneBeforeIndex < 0) return null;"
],
[
"async function assertSessionFileFence() {\n\t\tif (!fenceActive) return;\n\t\tconst current = await readSessionFileFingerprint(params.lockOptions.sessionFile);",
"async function assertSessionFileFence() {\n\t\tif (!fenceActive) return;\n\t\t// Do not yield between capture and comparison: an owned write can refresh the fence.\n\t\tconst current = readSessionFileFingerprintSync(params.lockOptions.sessionFile);"
]
]
}
}