dsh-lcx-codex 0.6.0-pre.2 → 0.7.0-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -12,15 +12,15 @@ import { join } from "node:path";
12
12
  import { AsyncLocalStorage } from "node:async_hooks";
13
13
  import { getSupportedThinkingLevels } from "./pi-responses-runtime.js";
14
14
  import { fetchJsonWithRetry } from "./transport.js";
15
- import { DEFAULT_TOOL_UPDATES, planToolSurface, withoutDeferLoading } from "./tool-surface.js";
15
+ import { DEFAULT_TOOL_UPDATES, planToolSurface } from "./tool-surface.js";
16
16
  import { agentSessionId, agentUsesSession, compactionConfigState, compactionPatchCandidate, installCompactionPatch, patchCompactionConfig, patchToolResultPruner, readAgentRouteState, readSelectedAgentRouteState, recordAgentRouteEvent, resolveAgentService, resolveContextService, resolveScopedService, restoreCompactionConfig, restoreCompactionPatches, restoreToolResultPruner, sessionFor, sessionFromAgent, scopedToolRuntime, onScopedToolExecute, tokenMeterTotal, toolResultPrunerState, } from "./dsh-compat.js";
17
17
  import { InvocationPolicyScope } from "./invocation-policy-scope.js";
18
18
  import { providerDynamicHeaders } from "./provider-headers.js";
19
19
  import { resolveCatalogModel } from "./model-catalog.js";
20
- import { authenticatedGrokHeaders, authenticatedHeaders, currentRoute, generationControlsFromSession, grokPromptCacheSessionId, promptCacheKey, promptCacheRetention, promptCacheSessionId, resolveGrokResponsesRouteConfig, diagnoseResponsesRoute, markHostRecognizedModel, warmHostRecognizedModels, resolveResponsesRouteConfig, routeFingerprint, } from "./route.js";
21
- import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, DEFAULT_REQUEST_IMAGE_MAX_BYTES, assertAggregateImageBudget, hydrateNativeImageReferences, inputImageBase64Lengths, resolveRouteModelFacts, routeModelOverride, hasMidHistoryPromptSnapshot, responseInputItems, serializeDshMessages, } from "./dsh-responses.js";
20
+ import { authenticatedGrokHeaders, authenticatedHeaders, currentRoute, generationControlsFromSession, grokPromptCacheSessionId, promptCacheKey, promptCacheRetention, promptCacheSessionId, resolveGrokResponsesRouteConfig, diagnoseResponsesRoute, markHostRecognizedModel, warmHostRecognizedModels, resolveApiKey, resolveResponsesRouteConfig, routeFingerprint, } from "./route.js";
21
+ import { DEFAULT_MAX_REQUEST_IMAGE_BYTES, DEFAULT_REQUEST_IMAGE_PIXEL_BUDGET, DEFAULT_REQUEST_IMAGE_MAX_BYTES, assertAggregateImageBudget, hydrateNativeImageReferences, inputImageBase64Lengths, resolveRouteModelFacts, routeModelOverride, hasMidHistoryPromptSnapshot, responseInputItems, serializeDshMessages, splitSystemPrompt, } from "./dsh-responses.js";
22
22
  import { mergeFeatureHeader, requestNativeCompaction } from "./compact-v2.js";
23
- import { buildResponsesBody } from "./responses-request.js";
23
+ import { buildResponsesBody, configurationUpdateEffort } from "./responses-request.js";
24
24
  import { managedFailureChunk, streamResponsesRequest, } from "./responses-stream.js";
25
25
  import { assertSupportedCheckpointMessage, checkpointStateForMessage, compactCheckpointId, createNativeCheckpointBlock, nativeCheckpointChunks, portableMessagesForCheckpoint, stateRouteCompatible, } from "./native-checkpoint.js";
26
26
  import { HOSTED_SEARCH_OUTPUT, HOSTED_SEARCH_PARAMETERS, buildHostedSearchBody, hostedMediaPresentationMeta, normalizeHostedSearchArgs, parseHostedSearchResponse, renderHostedSearchResult, } from "./web-search-hosted.js";
@@ -37,6 +37,8 @@ const ADVANCED_HOSTED_TOOL = "websearch_gpt_advanced";
37
37
  const ALPHA_TOOL = "websearch_alpha";
38
38
  const hostedSearchRouteContext = new AsyncLocalStorage();
39
39
  const WEB_SEARCH_TIMEOUT_MS = 240_000;
40
+ // DSH 0.2.2 defaults to 800; its root export does not expose this constant.
41
+ const WEB_SEARCH_SUMMARY_MAX_CHARS = 800;
40
42
  const AUTO_COMPACTION_THRESHOLD_PERCENT = 90;
41
43
  const EMERGENCY_PRUNE_THRESHOLD_PERCENT = 95;
42
44
  function positiveInteger(value, fallback, maximum) {
@@ -188,6 +190,8 @@ function requestImageOptions(routeConfig, imageSupport, signal, imageMap, extra
188
190
  signal,
189
191
  imageMap,
190
192
  maxRequestImageBytes: routeConfig.maxRequestImageBytes,
193
+ maxRequestImages: routeConfig.maxRequestImages,
194
+ imageOffloadCountQuantum: routeConfig.imageOffloadCountQuantum,
191
195
  requestImagePixelBudget: routeConfig.requestImagePixelBudget,
192
196
  requestImageMaxBytes: routeConfig.requestImageMaxBytes,
193
197
  ...extra,
@@ -266,7 +270,7 @@ function createScopedGptWebSearchTool(ctx, state, getConfig, provider, fetchEnab
266
270
  section: () => () => { },
267
271
  },
268
272
  };
269
- applyWebSearchTool(composition, getConfig().webMaxResults, WEB_SEARCH_MAX_QUERIES, WEB_SEARCH_TIMEOUT_MS, fetchEnabled);
273
+ applyWebSearchTool(composition, getConfig().webMaxResults, WEB_SEARCH_MAX_QUERIES, WEB_SEARCH_SUMMARY_MAX_CHARS, WEB_SEARCH_TIMEOUT_MS, fetchEnabled);
270
274
  if (!definition)
271
275
  throw new Error("DSH web_search composition did not register a tool");
272
276
  const execute = definition.execute.bind(definition);
@@ -636,7 +640,6 @@ async function serializeNativeAware(rawMessages, route, routeConfig, ctx, option
636
640
  let messages = rawMessages;
637
641
  let tools = options.tools;
638
642
  let anchoredTools = false;
639
- let toolSurfaceCompat;
640
643
  if (options.toolSurface !== undefined) {
641
644
  const surface = planToolSurface({
642
645
  mode: routeConfig.toolUpdates ?? DEFAULT_TOOL_UPDATES,
@@ -649,7 +652,6 @@ async function serializeNativeAware(rawMessages, route, routeConfig, ctx, option
649
652
  messages = surface.messages;
650
653
  tools = surface.tools;
651
654
  anchoredTools = surface.anchored;
652
- toolSurfaceCompat = surface.compat;
653
655
  if (surface.fallbackReason !== undefined)
654
656
  reportToolSurfaceFallback(ctx, route, surface);
655
657
  }
@@ -663,117 +665,109 @@ async function serializeNativeAware(rawMessages, route, routeConfig, ctx, option
663
665
  let nativeTools;
664
666
  let nativeModel;
665
667
  let grammarToolInputProperties;
666
- let normal = [];
667
- /** Absolute `input` positions rendered from DSH prompt snapshots that a checkpoint supersedes. */
668
+ /** Absolute input positions rendered from prompt snapshots superseded by a checkpoint. */
668
669
  const supersededInstructionItems = [];
669
- const serializeOptions = (imageMapOverride = undefined, extra = {}) => requestImageOptions(routeConfig, imageSupport, options.signal, imageMapOverride, {
670
- route,
671
- tools,
672
- responsesCompat: toolSurfaceCompat === undefined
673
- ? routeConfig.responsesCompat
674
- : { ...routeConfig.responsesCompat, ...toolSurfaceCompat },
670
+ const serializeOptions = (extra = {}) => requestImageOptions(routeConfig, imageSupport, options.signal, undefined, {
671
+ route, tools,
672
+ responsesCompat: routeConfig.responsesCompat,
675
673
  systemPromptUpdate,
676
674
  ...(anchoredTools ? { toolUpdate: "addition-only" } : {}),
677
675
  ...(modelOverride === undefined ? {} : { model: modelOverride }),
678
676
  ...extra,
679
677
  });
680
- const firstMessage = messages[0];
681
- const systemHead = firstMessage?.role === "system" ? firstMessage : undefined;
682
- const surfaceMessages = systemHead ? messages.slice(1) : messages;
683
- const systemPrompt = systemHead?.content
684
- .filter((block) => block.type === "text")
685
- .map((block) => block.text)
686
- .join("") || undefined;
687
- const prelude = await serializeDshMessages([], ctx, serializeOptions(undefined, {
688
- systemPrompt,
689
- includeSystemPrompt: true,
690
- }));
691
- const ephemeralPreludeItemCount = prelude.input.length;
692
- input.push(...prelude.input);
693
- nativeTools = prelude.tools;
694
- nativeModel = prelude.model;
695
- grammarToolInputProperties = prelude.grammarToolInputProperties;
696
- /** Base64 length of images DSH cannot offload (hydrated checkpoint, portable replay). */
697
- let fixedImageBytes = 0;
698
- /** Base64 length of each offloadable surface image, oldest first, across all batches. */
699
- const surfaceImageBytes = [];
700
- const flush = async () => {
701
- if (!normal.length)
702
- return;
703
- const batch = normal;
704
- normal = [];
705
- const serialized = await serializeDshMessages(batch, ctx, serializeOptions());
706
- surfaceImageBytes.push(...inputImageBase64Lengths(serialized.input));
707
- // Every batch derives its request tools from the same immediate declarations; a difference would
708
- // change the cached prefix between batches of one request.
709
- if (anchoredTools && JSON.stringify(serialized.tools) !== JSON.stringify(nativeTools))
710
- throw Object.assign(new Error("LCX anchored tool declarations diverged between serialization batches"), { code: "LCX_RESPONSES_INVALID_INPUT" });
711
- nativeTools = serialized.tools ?? nativeTools;
712
- nativeModel = serialized.model ?? nativeModel;
713
- grammarToolInputProperties =
714
- serialized.grammarToolInputProperties ?? grammarToolInputProperties;
715
- const restored = restoreGrokNativeReplay(serialized.input, batch.filter(isPersistedMessage), options.grokNativeReplayRoute);
716
- const base = input.length;
717
- supersededInstructionItems.push(...locateSupersededItems(serialized.input, restored, serialized.supersededInstructionItems).map((position) => base + position));
718
- input.push(...restored);
719
- mergeMap(imageMap, serialized.imageMap);
720
- };
721
- for (const message of surfaceMessages ?? []) {
678
+ const { systemPrompt, messages: surfaceMessages } = splitSystemPrompt(options.system, messages);
679
+ // Resolve the descriptor before selecting effort. This conversion has no tool-bearing transcript.
680
+ const descriptor = await serializeDshMessages([], ctx, serializeOptions({ tools: undefined }));
681
+ const configurationUpdateEffort = await options.configurationUpdate?.(descriptor.model);
682
+ const nonce = `lcx-request-boundary:${globalThis.crypto.randomUUID()}:`;
683
+ const marker = (id) => ({
684
+ role: "user", content: [{ type: "text", text: nonce + id }],
685
+ });
686
+ // Checkpoint bodies are already serialized. Hold their positions while ONE Pi conversion handles
687
+ // the entire tool-bearing surface; Pi alone owns declarations, removals and incremental notices.
688
+ const transcript = [];
689
+ const replacements = new Map();
690
+ for (const message of surfaceMessages) {
722
691
  assertSupportedCheckpointMessage(message);
723
- const state = session && isPersistedMessage(message) && compactCheckpointId(message)
724
- ? await checkpointStateForMessage(ctx, session, message)
725
- : undefined;
726
- if (state && session) {
727
- const checkpointId = compactCheckpointId(message);
728
- if (!checkpointId) {
729
- normal.push(message);
730
- continue;
731
- }
732
- await flush();
733
- if (stateRouteCompatible(state, route, ctx)) {
734
- const nativeOutput = state.nativeOutput;
735
- const hydratedMap = new Map();
736
- const hydrated = await hydrateNativeImageReferences(nativeOutput, ctx, requestImageOptions(routeConfig, imageSupport, options.signal, hydratedMap));
737
- const hydratedItems = responseInputItems(hydrated);
738
- for (const bytes of inputImageBase64Lengths(hydratedItems))
739
- fixedImageBytes += bytes;
740
- input.push(...hydratedItems);
741
- mergeMap(imageMap, hydratedMap);
742
- }
743
- else {
744
- const portable = await portableMessagesForCheckpoint(ctx, session, checkpointId, { maxChars: routeConfig.portableReplayMaxChars });
745
- // Shadowed history is superseded by the head DSH re-rendered when the compaction began its new
746
- // series, so its old system messages stay ordinary context instead of regaining instruction
747
- // authority behind the current prompt.
748
- const serialized = await serializeDshMessages(portable, ctx,
749
- // Portable history is plain context: it carries no developer updates, and deferred declarations are
750
- // only meaningful to the anchored surface itself.
751
- serializeOptions(undefined, {
752
- systemPromptUpdate: undefined,
753
- toolUpdate: undefined,
754
- tools: tools?.map((tool) => withoutDeferLoading(tool)),
755
- }));
756
- for (const bytes of inputImageBase64Lengths(serialized.input))
757
- fixedImageBytes += bytes;
758
- input.push(...serialized.input);
759
- mergeMap(imageMap, serialized.imageMap);
760
- }
692
+ const checkpointId = session && isPersistedMessage(message) ? compactCheckpointId(message) : undefined;
693
+ const state = checkpointId && session && isPersistedMessage(message) ? await checkpointStateForMessage(ctx, session, message) : undefined;
694
+ if (!state || !session || !checkpointId) {
695
+ transcript.push(message);
696
+ continue;
697
+ }
698
+ let items;
699
+ if (stateRouteCompatible(state, route, ctx)) {
700
+ const hydratedMap = new Map();
701
+ items = responseInputItems(await hydrateNativeImageReferences(state.nativeOutput, ctx, requestImageOptions(routeConfig, imageSupport, options.signal, hydratedMap)));
702
+ mergeMap(imageMap, hydratedMap);
703
+ }
704
+ else {
705
+ const portable = await portableMessagesForCheckpoint(ctx, session, checkpointId, {
706
+ maxChars: routeConfig.portableReplayMaxChars,
707
+ });
708
+ // Shadowed history is plain context. Its old tools and prompt snapshots cannot re-declare
709
+ // the current series' surface or regain instruction authority on a different route.
710
+ const serialized = await serializeDshMessages(portable, ctx, serializeOptions({
711
+ systemPromptUpdate: undefined, toolUpdate: undefined, tools: undefined,
712
+ // Fixed replay images cannot be offloaded by the surface owner; check the assembled request below.
713
+ maxRequestImageBytes: Number.MAX_SAFE_INTEGER, maxRequestImages: Number.MAX_SAFE_INTEGER,
714
+ }));
715
+ items = serialized.input;
716
+ mergeMap(imageMap, serialized.imageMap);
717
+ }
718
+ const id = String(replacements.size);
719
+ replacements.set(id, items);
720
+ transcript.push(marker(id));
721
+ }
722
+ const serialized = await serializeDshMessages(transcript, ctx, serializeOptions({
723
+ systemPrompt, includeSystemPrompt: true, tracePrelude: true,
724
+ ...(configurationUpdateEffort === undefined ? {} : { configurationUpdateEffort }),
725
+ }));
726
+ const surfaceImageBytes = inputImageBase64Lengths(serialized.input);
727
+ nativeTools = serialized.tools;
728
+ nativeModel = serialized.model;
729
+ grammarToolInputProperties = serialized.grammarToolInputProperties;
730
+ mergeMap(imageMap, serialized.imageMap);
731
+ const restored = restoreGrokNativeReplay(serialized.input, surfaceMessages.filter(isPersistedMessage), options.grokNativeReplayRoute);
732
+ const snapshotPositions = new Set(locateSupersededItems(serialized.input, restored, serialized.supersededInstructionItems));
733
+ const ephemeralPreludeItemCount = serialized.preludeItemCount;
734
+ const seen = new Set();
735
+ for (const [position, item] of restored.entries()) {
736
+ const text = isRecord(item) && item.role === "user" && Array.isArray(item.content) && item.content.length === 1
737
+ && isRecord(item.content[0]) ? item.content[0].text : undefined;
738
+ if (typeof text === "string" && text.startsWith(nonce)) {
739
+ const id = text.slice(nonce.length);
740
+ if (seen.has(id) || !replacements.has(id))
741
+ throw Object.assign(new Error("LCX could not trace a request boundary"), { code: "LCX_RESPONSES_INVALID_INPUT" });
742
+ seen.add(id);
743
+ input.push(...replacements.get(id));
761
744
  continue;
762
745
  }
763
- normal.push(message);
746
+ if (snapshotPositions.has(position))
747
+ supersededInstructionItems.push(input.length);
748
+ input.push(item);
764
749
  }
765
- await flush();
750
+ if (ephemeralPreludeItemCount < 0 || seen.size !== replacements.size || JSON.stringify(input).includes(nonce))
751
+ throw Object.assign(new Error("LCX could not remove request boundary markers"), { code: "LCX_RESPONSES_INVALID_INPUT" });
752
+ const assembledImages = inputImageBase64Lengths(input);
766
753
  assertAggregateImageBudget({
767
754
  maxBytes: Number.isSafeInteger(routeConfig.maxRequestImageBytes) && Number(routeConfig.maxRequestImageBytes) > 0
768
755
  ? Number(routeConfig.maxRequestImageBytes)
769
756
  : DEFAULT_MAX_REQUEST_IMAGE_BYTES,
770
- fixedBytes: fixedImageBytes,
757
+ fixedBytes: assembledImages.reduce((sum, bytes) => sum + bytes, 0) - surfaceImageBytes.reduce((sum, bytes) => sum + bytes, 0),
758
+ fixedCount: assembledImages.length - surfaceImageBytes.length,
759
+ maxImages: routeConfig.maxRequestImages,
760
+ countQuantum: routeConfig.imageOffloadCountQuantum,
771
761
  surfaceBytes: surfaceImageBytes,
772
762
  });
773
763
  if (!nativeModel)
774
764
  throw Object.assign(new Error("LCX could not resolve the Pi Responses model descriptor"), { code: "LCX_RESPONSES_MODEL_UNAVAILABLE" });
765
+ // Pi ends the input with the request's own level, after everything else it serializes.
766
+ if (configurationUpdateEffort !== undefined)
767
+ input.push({ type: "configuration_update", reasoning: { effort: configurationUpdateEffort } });
775
768
  return {
776
769
  input,
770
+ configurationUpdateEffort,
777
771
  ephemeralPreludeItemCount,
778
772
  supersededInstructionItems,
779
773
  imageMap,
@@ -800,11 +794,12 @@ async function* remoteCompactionStream(options, routeConfig, ctx, next) {
800
794
  try {
801
795
  const prepared = await serializeNativeAware(history, route, routeConfig, ctx, {
802
796
  signal: options.signal,
797
+ system: options.system,
803
798
  tools: options.tools && [...options.tools],
804
799
  toolSurface: { history: options.toolHistory },
805
800
  });
806
801
  const cacheSessionId = promptCacheSessionId(route, routeConfig, ctx);
807
- const headers = await authenticatedHeaders(ctx, routeConfig, cacheSessionId, cacheSessionId === undefined ? null : route.sessionId, providerDynamicHeaders(routeConfig.provider, options.messages), route.sessionId || undefined);
802
+ const headers = await authenticatedHeaders(ctx, routeConfig, cacheSessionId, cacheSessionId === undefined ? null : route.sessionId, providerDynamicHeaders(routeConfig.provider, options.messages), route.sessionId || undefined, options);
808
803
  const generation = generationControlsFromSession(sessionFor(ctx, route.sessionId), route);
809
804
  const result = await requestNativeCompaction({
810
805
  baseURL: routeConfig.baseURL,
@@ -1102,12 +1097,14 @@ async function* managedResponsesStream(options, routeConfig, ctx) {
1102
1097
  throw Object.assign(new Error("LCX Responses does not support GenerateOptions.stop"), { code: "LCX_RESPONSES_UNSUPPORTED_OPTION" });
1103
1098
  const prepared = await serializeNativeAware(options.messages, route, routeConfig, ctx, {
1104
1099
  signal: options.signal,
1100
+ system: options.system,
1105
1101
  tools: options.tools && [...options.tools],
1106
1102
  toolSurface: { history: options.toolHistory },
1103
+ configurationUpdate: (model) => configurationUpdateEffort(model, options.reasoningEffort, () => resolveApiKey(ctx, routeConfig)),
1107
1104
  });
1108
1105
  assertSupportedReasoningEffort(options.reasoningEffort, prepared.modelFacts);
1109
1106
  const cacheSessionId = promptCacheSessionId(route, routeConfig, ctx);
1110
- const headers = await authenticatedHeaders(ctx, routeConfig, cacheSessionId, cacheSessionId === undefined ? null : route.sessionId, providerDynamicHeaders(routeConfig.provider, options.messages), route.sessionId || undefined);
1107
+ const headers = await authenticatedHeaders(ctx, routeConfig, cacheSessionId, cacheSessionId === undefined ? null : route.sessionId, providerDynamicHeaders(routeConfig.provider, options.messages), route.sessionId || undefined, options);
1111
1108
  const body = buildResponsesBody({
1112
1109
  model: prepared.model,
1113
1110
  input: prepared.input,
@@ -1119,6 +1116,7 @@ async function* managedResponsesStream(options, routeConfig, ctx) {
1119
1116
  reasoningEffort: options.reasoningEffort,
1120
1117
  temperature: options.temperature,
1121
1118
  maxTokens: options.maxTokens,
1119
+ ...(prepared.configurationUpdateEffort === undefined ? {} : { configurationUpdateEffort: prepared.configurationUpdateEffort }),
1122
1120
  });
1123
1121
  const nativeReplay = inputHasNativeState(prepared.input);
1124
1122
  if (nativeReplay) {
@@ -1137,6 +1135,7 @@ async function* managedResponsesStream(options, routeConfig, ctx) {
1137
1135
  timeoutMs: routeConfig.timeoutMs,
1138
1136
  maxAttempts: 1,
1139
1137
  maxResponseBytes: routeConfig.maxResponseBytes,
1138
+ ...(prepared.configurationUpdateEffort === undefined ? {} : { providerThinkingLevel: prepared.configurationUpdateEffort }),
1140
1139
  onFailure: (info) => logStreamFailure(ctx, "gpt", info),
1141
1140
  });
1142
1141
  }
@@ -1155,6 +1154,7 @@ async function* managedGrokNativeSearchStream(options, routeConfig, nativeSearch
1155
1154
  const declaredToolNames = new Set(visibleTools?.map((tool) => tool.name) ?? []);
1156
1155
  const prepared = await serializeNativeAware(projected.messages, route, routeConfig, ctx, {
1157
1156
  signal: options.signal,
1157
+ system: options.system,
1158
1158
  tools: visibleTools,
1159
1159
  grokNativeReplayRoute: nativeReplayRoute,
1160
1160
  });
@@ -1295,7 +1295,7 @@ function installInjected(ctx, configInput) {
1295
1295
  ctx.on("session/event", (session, event) => {
1296
1296
  recordAgentRouteEvent(session, event);
1297
1297
  // DSH 0.2 session/selectModel appends model/selection before the next
1298
- // prompt assembly projects tools (dsh-api-session-controller/lib/index.js:320).
1298
+ // prompt assembly projects tools (dsh-api-session-controller `selectModel`).
1299
1299
  if (event.type === "model/selection" || event.type === "request/header")
1300
1300
  for (const agent of managedAgents)
1301
1301
  if (agentUsesSession(agent, session))
@@ -222,8 +222,9 @@ export async function activeCompactionId(ctx, session) {
222
222
  * one, as developer/system or even as user text, would keep a stale full prompt (for example plan-mode
223
223
  * policy that has since been switched off) in front of the model after the compaction.
224
224
  *
225
- * Only items the serializer traced back to such snapshots (`supersededItemIndices`, absolute positions
226
- * in `input`) are removed. Any other retained developer/system item is genuine client context and
225
+ * Only items traced to such snapshots or Pi tool-update notices (`supersededItemIndices`, absolute positions
226
+ * in `input`) are removed. Tool notices belong to the old series, whose declarations retention drops.
227
+ * Any other retained developer/system item is genuine client context and
227
228
  * stays. The ephemeral prelude is removed by the caller's slice, and the retention budget is computed
228
229
  * over what is actually kept.
229
230
  */