@cortexkit/opencode-magic-context 0.49.13 → 0.49.15
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/dist/auto-search-worker.js +1 -1
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-azqk0vfd.js → context-0m46day0.js} +133 -17
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/verify.d.ts +22 -3
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +2 -0
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/hooks/magic-context/apply-operations.d.ts +3 -1
- package/dist/hooks/magic-context/apply-operations.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +2 -2
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner.d.ts +4 -0
- package/dist/hooks/magic-context/compartment-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/degraded-pass-refusal.d.ts +2 -0
- package/dist/hooks/magic-context/degraded-pass-refusal.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-drop-eligibility.d.ts +14 -0
- package/dist/hooks/magic-context/pending-drop-eligibility.d.ts.map +1 -0
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +1 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-hnm8raee.js → index-1vc7jrkg.js} +2 -2
- package/dist/{index-wj6ht7nm.js → index-42vcjcwe.js} +52 -17
- package/dist/{index-b16gpywn.js → index-944w16m0.js} +2 -2
- package/dist/{index-wz6mzzb1.js → index-mc1cqza6.js} +3 -3
- package/dist/{index-2jr1smmh.js → index-snp5wbge.js} +99 -11
- package/dist/{index-v13skev1.js → index-thvnpfsv.js} +1 -1
- package/dist/{index-sj89f3b0.js → index-ts1hjk1h.js} +100 -15
- package/dist/{index-aw1bh90w.js → index-xn6q9pg6.js} +2 -2
- package/dist/{index-qkd9zz0p.js → index-yxycg7fs.js} +1 -1
- package/dist/index.js +13 -13
- package/dist/{message-index-seaqpb7c.js → message-index-a6gztaqx.js} +3 -3
- package/dist/{message-index-bounded-vm64mqpq.js → message-index-bounded-vtgpq6b4.js} +3 -3
- package/dist/migration-worker.js +1 -1
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{read-session-chunk-ax05f7gr.js → read-session-chunk-3ae3nfdn.js} +2 -2
- package/dist/{recomp-orchestrator-dmbeadwt.js → recomp-orchestrator-nwzcfhx4.js} +6 -6
- package/dist/{search-5yd5ytzs.js → search-deajrd90.js} +4 -4
- package/dist/{storage-tags-yygfb9c8.js → storage-tags-s5bg1ahx.js} +1 -1
- package/dist/{transform-postprocess-phase-72v86syx.js → transform-postprocess-phase-ne3z1zmt.js} +6 -6
- package/dist/v2/auto-search-worker.js +1 -1
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-w055w17c.js → context-4qczzck7.js} +265 -32
- package/dist/v2/hidden-completion.d.ts +23 -3
- package/dist/v2/hidden-completion.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/hidden-child.d.ts +19 -0
- package/dist/v2/hooks/hidden-child.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-wepg5723.js → message-index-bounded-rxxznd34.js} +3 -3
- package/dist/v2/{message-index-gcmd0ng0.js → message-index-f947qtbz.js} +3 -3
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
- package/dist/v2/{read-session-chunk-hr3w5bjk.js → read-session-chunk-rq9nx1nn.js} +2 -2
- package/dist/v2/{recomp-orchestrator-ca7qt75a.js → recomp-orchestrator-5zhxtwha.js} +5 -5
- package/dist/v2/{search-c86dcv14.js → search-n8wqxb1j.js} +4 -4
- package/dist/v2/{server-xh7jar6k.js → server-cfbr1s2x.js} +2 -2
- package/dist/v2/{server-b81w6sw3.js → server-dd0tz6cn.js} +99 -11
- package/dist/v2/{server-t4prcjc1.js → server-e298hswg.js} +1 -1
- package/dist/v2/{server-m97brnat.js → server-ehyava47.js} +2 -2
- package/dist/v2/{server-n8ch9683.js → server-kmbarfmn.js} +1 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{storage-tags-a2gq6dw7.js → storage-tags-hcc2adpf.js} +1 -1
- package/dist/v2/store-reader.d.ts +27 -1
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{wrapup-orchestrator-e1a2w6jh.js → wrapup-orchestrator-65pwye0d.js} +5 -5
- package/dist/{wrapup-orchestrator-2051r6qm.js → wrapup-orchestrator-28xzsj5q.js} +7 -7
- package/package.json +1 -1
- /package/dist/{index-fwefky9w.js → index-mht7bq0z.js} +0 -0
- /package/dist/v2/{server-bxpwy6fy.js → server-atbc19ab.js} +0 -0
|
@@ -195,6 +195,8 @@ import {
|
|
|
195
195
|
HIDDEN_CURATE_AGENT,
|
|
196
196
|
hiddenAgentFor,
|
|
197
197
|
hiddenToolLoop,
|
|
198
|
+
HIDDEN_RUN_DISPOSED_REASON,
|
|
199
|
+
noteChildOfDisposedInstance,
|
|
198
200
|
hiddenChildPermissions,
|
|
199
201
|
registerHiddenChildAgents,
|
|
200
202
|
hiddenToolCallRefusal,
|
|
@@ -281,7 +283,7 @@ import {
|
|
|
281
283
|
startCompartmentAgent,
|
|
282
284
|
setRecompStarting2,
|
|
283
285
|
setRecompTerminal2
|
|
284
|
-
} from "./server-
|
|
286
|
+
} from "./server-dd0tz6cn.js";
|
|
285
287
|
import {
|
|
286
288
|
resolveHistorianModel2
|
|
287
289
|
} from "./server-8cd2j99z.js";
|
|
@@ -306,7 +308,7 @@ import {
|
|
|
306
308
|
openDatabaseAsync,
|
|
307
309
|
isDatabasePersisted,
|
|
308
310
|
getDatabasePersistenceError
|
|
309
|
-
} from "./server-
|
|
311
|
+
} from "./server-kmbarfmn.js";
|
|
310
312
|
import {
|
|
311
313
|
setHomeProjectPermission,
|
|
312
314
|
shouldSkipHomeProjectMemory,
|
|
@@ -351,6 +353,7 @@ import {
|
|
|
351
353
|
HYGIENE_PROVIDER_UNITS_VERSION,
|
|
352
354
|
sessionDecisionCalibration,
|
|
353
355
|
transitionSessionHygieneUnits,
|
|
356
|
+
readEpochFloorSnapshot,
|
|
354
357
|
getProtectionWindowForSession,
|
|
355
358
|
withReplayEnvelopeSnapshot,
|
|
356
359
|
invalidateReplayEnvelopeSnapshot,
|
|
@@ -509,7 +512,7 @@ import {
|
|
|
509
512
|
readRawSessionMessageById2,
|
|
510
513
|
readSessionChunk2,
|
|
511
514
|
readRawSessionSeedTail2
|
|
512
|
-
} from "./server-
|
|
515
|
+
} from "./server-ehyava47.js";
|
|
513
516
|
import {
|
|
514
517
|
embedPauseBySession,
|
|
515
518
|
embedRunStateBySession,
|
|
@@ -601,12 +604,13 @@ import {
|
|
|
601
604
|
isMessageIndexReconciledThrough2,
|
|
602
605
|
indexMessagesAfterOrdinal2,
|
|
603
606
|
sweepOrphanedOpenCodeMessageIndexes2
|
|
604
|
-
} from "./server-
|
|
607
|
+
} from "./server-e298hswg.js";
|
|
605
608
|
import {
|
|
606
609
|
stableStringify,
|
|
607
610
|
getTemporalDecisions,
|
|
608
611
|
observeTemporalDecisions,
|
|
609
612
|
freezeTemporalDecisions,
|
|
613
|
+
tagRevisionKey,
|
|
610
614
|
tagIdentityRevisionKey
|
|
611
615
|
} from "./server-pwv4ezb0.js";
|
|
612
616
|
import {
|
|
@@ -701,7 +705,7 @@ import {
|
|
|
701
705
|
adoptNullOwnerToolTag2,
|
|
702
706
|
getCandidateToolOwners2,
|
|
703
707
|
pickNearestPriorOwner2
|
|
704
|
-
} from "./server-
|
|
708
|
+
} from "./server-atbc19ab.js";
|
|
705
709
|
import"./server-51779zs2.js";
|
|
706
710
|
import {
|
|
707
711
|
isRawCompactionSummaryInfo2,
|
|
@@ -879,7 +883,7 @@ import {
|
|
|
879
883
|
resolveMemoriesByIdsForSearch2,
|
|
880
884
|
unifiedSearch2,
|
|
881
885
|
formatSearchResults2
|
|
882
|
-
} from "./server-
|
|
886
|
+
} from "./server-cfbr1s2x.js";
|
|
883
887
|
import {
|
|
884
888
|
resolvePromptContext2
|
|
885
889
|
} from "./server-fmsr7v69.js";
|
|
@@ -3024,6 +3028,20 @@ function resolveTodowriteAvailability(sessionId) {
|
|
|
3024
3028
|
}
|
|
3025
3029
|
|
|
3026
3030
|
// src/hooks/magic-context/degraded-pass-refusal.ts
|
|
3031
|
+
function describeDegradedPassFailure(site, cause) {
|
|
3032
|
+
const details = [site];
|
|
3033
|
+
const seen = new Set;
|
|
3034
|
+
while (cause !== undefined && cause !== null && !seen.has(cause)) {
|
|
3035
|
+
seen.add(cause);
|
|
3036
|
+
const current = cause;
|
|
3037
|
+
const detail = typeof current.site === "string" ? current.site : typeof current.message === "string" ? current.message : String(cause);
|
|
3038
|
+
if (!details.includes(detail))
|
|
3039
|
+
details.push(detail);
|
|
3040
|
+
cause = current.cause;
|
|
3041
|
+
}
|
|
3042
|
+
return `Magic Context could not safely prepare this turn [${userFacingFailureCode("transform_pass_degraded")}] (${details.join(": ")}). This request was not sent.`;
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3027
3045
|
class DegradedPassRefusalError extends Error {
|
|
3028
3046
|
site;
|
|
3029
3047
|
code = "DEGRADED_PASS_REFUSAL";
|
|
@@ -3031,7 +3049,7 @@ class DegradedPassRefusalError extends Error {
|
|
|
3031
3049
|
estimatedTokens;
|
|
3032
3050
|
contextLimitTokens;
|
|
3033
3051
|
constructor(site, options) {
|
|
3034
|
-
super(
|
|
3052
|
+
super(describeDegradedPassFailure(site, options?.cause), {
|
|
3035
3053
|
cause: options?.cause
|
|
3036
3054
|
});
|
|
3037
3055
|
this.site = site;
|
|
@@ -5733,12 +5751,12 @@ function buildTriggerInMemoryTail(db, sessionId, messages) {
|
|
|
5733
5751
|
function getProactiveCompartmentTriggerPercentage(executeThresholdPercentage) {
|
|
5734
5752
|
return Math.max(0, executeThresholdPercentage - PROACTIVE_TRIGGER_OFFSET_PERCENTAGE);
|
|
5735
5753
|
}
|
|
5736
|
-
function estimateProjectedPostDropPercentage(db, sessionId, usage, activeTags, keepReasoningTokens, clearedReasoningThroughTag, canClearReasoning, liveBudgetCutoff) {
|
|
5754
|
+
function estimateProjectedPostDropPercentage(db, sessionId, usage, activeTags, keepReasoningTokens, clearedReasoningThroughTag, canClearReasoning, liveBudgetCutoff, eligiblePendingDropTagIds) {
|
|
5737
5755
|
const totalActiveBytes = activeTags.reduce((sum, tag) => sum + tag.byteSize + tag.reasoningByteSize, 0);
|
|
5738
5756
|
if (totalActiveBytes === 0)
|
|
5739
5757
|
return null;
|
|
5740
5758
|
let droppableBytes = 0;
|
|
5741
|
-
const pendingDrops = getPendingOps(db, sessionId).filter((op) => op.operation === "drop");
|
|
5759
|
+
const pendingDrops = getPendingOps(db, sessionId).filter((op) => op.operation === "drop" && eligiblePendingDropTagIds?.has(op.tagId) === true);
|
|
5742
5760
|
const pendingDropTagIds = new Set(pendingDrops.map((op) => op.tagId));
|
|
5743
5761
|
if (pendingDrops.length > 0) {
|
|
5744
5762
|
droppableBytes += activeTags.filter((tag) => pendingDropTagIds.has(tag.tagNumber)).reduce((sum, tag) => sum + tag.byteSize + tag.reasoningByteSize, 0);
|
|
@@ -5867,7 +5885,7 @@ function getUnsummarizedTailInfo(db, sessionId, triggerBudget, usage, executeThr
|
|
|
5867
5885
|
function formatProjectedPostDropPercentage(value) {
|
|
5868
5886
|
return value === null ? "none" : `${value.toFixed(1)}%`;
|
|
5869
5887
|
}
|
|
5870
|
-
function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPercentage, executeThresholdPercentage, triggerBudget, keepReasoningTokens, commitClusterTrigger, preloadedActiveTags, contextLimit, inMemoryTail, taggerFloorOverride, reasoningProjection, reclaimRide) {
|
|
5888
|
+
function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPercentage, executeThresholdPercentage, triggerBudget, keepReasoningTokens, commitClusterTrigger, preloadedActiveTags, contextLimit, inMemoryTail, taggerFloorOverride, reasoningProjection, reclaimRide, eligiblePendingDropTagIds) {
|
|
5871
5889
|
if (sessionMeta.compartmentInProgress) {
|
|
5872
5890
|
sessionLog2(sessionId, `compartment trigger: skipped — historian already in progress (usage=${usage.percentage.toFixed(1)}%)`);
|
|
5873
5891
|
return { shouldFire: false };
|
|
@@ -5931,7 +5949,7 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
5931
5949
|
return { shouldFire: false };
|
|
5932
5950
|
}
|
|
5933
5951
|
const canClearReasoning = reasoningProjection?.canClearReasoning ?? modelAcceptsEmptyContent(reasoningProjection?.providerID);
|
|
5934
|
-
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff);
|
|
5952
|
+
const projectedPostDropPercentage = estimateProjectedPostDropPercentage(db, sessionId, usage, preloadedActiveTags ?? getActiveTagsBySession2(db, sessionId), keepReasoningTokens, sessionMeta.clearedReasoningThroughTag, canClearReasoning, reasoningProjection?.budgetCutoff, eligiblePendingDropTagIds);
|
|
5935
5953
|
const relativePostDropTarget = executeThresholdPercentage * POST_DROP_TARGET_RATIO;
|
|
5936
5954
|
const rideLabel = reclaimRide ? reclaimRideLabel(reclaimRide) : "ride=none";
|
|
5937
5955
|
const dropsCanLand = reclaimRide !== undefined && hasReclaimRide(reclaimRide);
|
|
@@ -6857,6 +6875,76 @@ function resolveHistoryBudgetTokens(historyBudgetPercentage, contextUsage, execu
|
|
|
6857
6875
|
}) / 100) * historyBudgetPercentage);
|
|
6858
6876
|
}
|
|
6859
6877
|
|
|
6878
|
+
// src/hooks/magic-context/pending-drop-eligibility.ts
|
|
6879
|
+
function pendingDropVeto(tagNumber, target, protectedTagIds) {
|
|
6880
|
+
if (protectedTagIds.has(tagNumber))
|
|
6881
|
+
return "protected";
|
|
6882
|
+
if (target?.thinkingDropProtected)
|
|
6883
|
+
return "active_thinking";
|
|
6884
|
+
return null;
|
|
6885
|
+
}
|
|
6886
|
+
function capturePendingDropEligibility(targets, protectedTagIds) {
|
|
6887
|
+
const eligible = new Set;
|
|
6888
|
+
for (const [number, target] of targets) {
|
|
6889
|
+
if (pendingDropVeto(number, target, protectedTagIds))
|
|
6890
|
+
continue;
|
|
6891
|
+
if (target.drop) {
|
|
6892
|
+
if (target.canDrop?.() === true)
|
|
6893
|
+
eligible.add(number);
|
|
6894
|
+
} else {
|
|
6895
|
+
const content = target.getContent?.();
|
|
6896
|
+
if (typeof content === "string" && content.length > `[dropped §${number}§]`.length)
|
|
6897
|
+
eligible.add(number);
|
|
6898
|
+
}
|
|
6899
|
+
}
|
|
6900
|
+
return eligible;
|
|
6901
|
+
}
|
|
6902
|
+
function pendingDropEligibilityKey(db, sessionId, input, protectionInputs) {
|
|
6903
|
+
const digests = input.map((message) => message.contentDigest?.() ?? null);
|
|
6904
|
+
if (digests.some((digest) => digest === null))
|
|
6905
|
+
return null;
|
|
6906
|
+
const revision = db.prepare("SELECT value FROM schema_migrations_meta WHERE key = ?").get(tagRevisionKey(sessionId));
|
|
6907
|
+
if (!revision?.value)
|
|
6908
|
+
return null;
|
|
6909
|
+
return JSON.stringify([
|
|
6910
|
+
input.map((message, index) => [
|
|
6911
|
+
message.id,
|
|
6912
|
+
message.role,
|
|
6913
|
+
message.synthetic,
|
|
6914
|
+
digests[index]
|
|
6915
|
+
]),
|
|
6916
|
+
revision.value,
|
|
6917
|
+
readEpochFloorSnapshot(db, sessionId),
|
|
6918
|
+
sessionDecisionCalibration(db, sessionId).toolsRatio,
|
|
6919
|
+
loadProtectedTailMeta(db, sessionId),
|
|
6920
|
+
[...getMergedReasoningStrippedIds(db, sessionId)].sort(),
|
|
6921
|
+
[...getReasoningRemovalState(db, sessionId).messageIds].sort(),
|
|
6922
|
+
protectionInputs
|
|
6923
|
+
]);
|
|
6924
|
+
}
|
|
6925
|
+
function createPendingDropEligibilityCache() {
|
|
6926
|
+
const sessions = new Map;
|
|
6927
|
+
return {
|
|
6928
|
+
read(sessionId, key) {
|
|
6929
|
+
const previous = sessions.get(sessionId);
|
|
6930
|
+
if (key === null || previous?.key !== key) {
|
|
6931
|
+
sessions.delete(sessionId);
|
|
6932
|
+
return;
|
|
6933
|
+
}
|
|
6934
|
+
return previous.eligible;
|
|
6935
|
+
},
|
|
6936
|
+
record(sessionId, key, eligible) {
|
|
6937
|
+
sessions.delete(sessionId);
|
|
6938
|
+
if (key === null)
|
|
6939
|
+
return;
|
|
6940
|
+
const oldest = sessions.keys().next().value;
|
|
6941
|
+
if (sessions.size >= 64 && oldest !== undefined)
|
|
6942
|
+
sessions.delete(oldest);
|
|
6943
|
+
sessions.set(sessionId, { key, eligible: new Set(eligible) });
|
|
6944
|
+
}
|
|
6945
|
+
};
|
|
6946
|
+
}
|
|
6947
|
+
|
|
6860
6948
|
// src/hooks/magic-context/apply-operations.ts
|
|
6861
6949
|
var RECENT_TOOL_SKELETON_WINDOW = 20;
|
|
6862
6950
|
function buildReplacementContent(tagId) {
|
|
@@ -6977,7 +7065,7 @@ function renderConvertedToolSkeletons(targets, converted) {
|
|
|
6977
7065
|
}
|
|
6978
7066
|
return didMutate;
|
|
6979
7067
|
}
|
|
6980
|
-
function applyPendingOperations(sessionId, db, targets, protectedTagIds, preloadedTags, preloadedPendingOps, syntheticPendingOps = [], editMarkerTagIds = new Set, onTagReduced, onBatchComplete) {
|
|
7068
|
+
function applyPendingOperations(sessionId, db, targets, protectedTagIds, preloadedTags, preloadedPendingOps, syntheticPendingOps = [], editMarkerTagIds = new Set, onTagReduced, onBatchComplete, onEligibilitySnapshot) {
|
|
6981
7069
|
let didMutateMessage = false;
|
|
6982
7070
|
let diagnostics;
|
|
6983
7071
|
const reject = (reason) => {
|
|
@@ -6992,6 +7080,7 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
|
|
|
6992
7080
|
}).immediate();
|
|
6993
7081
|
{
|
|
6994
7082
|
const pendingOps = preloadedPendingOps ?? getPendingOps(db, sessionId);
|
|
7083
|
+
onEligibilitySnapshot?.(capturePendingDropEligibility(targets, protectedTagIds));
|
|
6995
7084
|
const tags = preloadedTags ?? getTagsByNumbers2(db, sessionId, [
|
|
6996
7085
|
...new Set([
|
|
6997
7086
|
...pendingOps.map((op) => op.tagId),
|
|
@@ -7022,13 +7111,10 @@ function applyPendingOperations(sessionId, db, targets, protectedTagIds, preload
|
|
|
7022
7111
|
removePendingOp(db, sessionId, pendingOp.tagId);
|
|
7023
7112
|
continue;
|
|
7024
7113
|
}
|
|
7025
|
-
if (protectedTagIds.has(pendingOp.tagId)) {
|
|
7026
|
-
reject("protected");
|
|
7027
|
-
continue;
|
|
7028
|
-
}
|
|
7029
7114
|
const target = targets.get(pendingOp.tagId);
|
|
7030
|
-
|
|
7031
|
-
|
|
7115
|
+
const veto = pendingDropVeto(pendingOp.tagId, target, protectedTagIds);
|
|
7116
|
+
if (veto) {
|
|
7117
|
+
reject(veto);
|
|
7032
7118
|
continue;
|
|
7033
7119
|
}
|
|
7034
7120
|
const isToolTag = tagTypeById.get(pendingOp.tagId) === "tool";
|
|
@@ -9996,7 +10082,7 @@ async function runPostTransformPhase(args) {
|
|
|
9996
10082
|
pendingOpsDidMutate = applyPendingOperations(args.sessionId, args.db, newTargets, new Set([
|
|
9997
10083
|
...args.contextUsage.percentage >= 95 ? [] : args.protectedTagIds,
|
|
9998
10084
|
...protectedToolTags
|
|
9999
|
-
]), undefined, pendingOps, [], new Set, (reduction) => droppedTokenReductions.push(reduction));
|
|
10085
|
+
]), undefined, pendingOps, [], new Set, (reduction) => droppedTokenReductions.push(reduction), undefined, args.onPendingDropEligibility);
|
|
10000
10086
|
if (pendingOpsDidMutate) {
|
|
10001
10087
|
droppedCount += pendingOps.length;
|
|
10002
10088
|
for (const pendingOp of pendingOps) {
|
|
@@ -17759,6 +17845,13 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
17759
17845
|
return snapshot !== null && hasRunnableCompartmentWindow(snapshot);
|
|
17760
17846
|
}
|
|
17761
17847
|
async function awaitCompartmentRun(activeRun, reason) {
|
|
17848
|
+
await Promise.resolve();
|
|
17849
|
+
if (activeRun.inlineJoinTimedOutBudgetMs !== undefined && !activeRun.settled) {
|
|
17850
|
+
historianJoinTimedOut = true;
|
|
17851
|
+
historianJoinBudgetMs = activeRun.inlineJoinTimedOutBudgetMs;
|
|
17852
|
+
sessionLog2(args.sessionId, "transform: compartment inline join budget already exhausted for this run — not waiting again");
|
|
17853
|
+
return "timed_out";
|
|
17854
|
+
}
|
|
17762
17855
|
sessionLog2(args.sessionId, reason);
|
|
17763
17856
|
const timeoutMs = resolveHistorianInlineJoinBudget(args.historianTimeoutMs);
|
|
17764
17857
|
historianJoinBudgetMs = timeoutMs;
|
|
@@ -17774,6 +17867,7 @@ async function runCompartmentPhaseImpl(args) {
|
|
|
17774
17867
|
clearTimeout(timer);
|
|
17775
17868
|
}
|
|
17776
17869
|
if (result === "timeout") {
|
|
17870
|
+
activeRun.inlineJoinTimedOutBudgetMs = timeoutMs;
|
|
17777
17871
|
historianJoinTimedOut = true;
|
|
17778
17872
|
sessionLog2(args.sessionId, `transform: compartment await timed out after ${timeoutMs}ms — proceeding without waiting`);
|
|
17779
17873
|
return "timed_out";
|
|
@@ -18052,6 +18146,7 @@ function createTransform(deps) {
|
|
|
18052
18146
|
memorySyncRequestedSessions: deps.rustMemorySyncRequestedSessions
|
|
18053
18147
|
}) : undefined;
|
|
18054
18148
|
let entryReuse;
|
|
18149
|
+
const pendingDropEligibility = createPendingDropEligibilityCache();
|
|
18055
18150
|
const projectEntry = createLkgEntryProjector({
|
|
18056
18151
|
onReuse: (stats) => {
|
|
18057
18152
|
entryReuse = stats;
|
|
@@ -18622,6 +18717,18 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18622
18717
|
prewarmTagOwners(db, sessionId, ownerRatio);
|
|
18623
18718
|
const tagOwnersReady = isTagOwnerSummaryReady2(db, sessionId, ownerRatio);
|
|
18624
18719
|
let triggerBoundarySnapshot;
|
|
18720
|
+
let dropProjectionEmergency = contextUsageEarly.percentage >= 95;
|
|
18721
|
+
const dropProjectionKey = () => pendingDropEligibilityKey(db, sessionId, lkgInput, {
|
|
18722
|
+
currentTurnId,
|
|
18723
|
+
model: modelForBudget,
|
|
18724
|
+
protectedTokens: deps.protectedTokens,
|
|
18725
|
+
protectedTokenTierOverrides: deps.protectedTokenTierOverrides,
|
|
18726
|
+
protectedTools: deps.protectedTools,
|
|
18727
|
+
keepReasoningTokens: deps.keepReasoningTokens,
|
|
18728
|
+
usableSoft: windowGeometry?.usableSoft ?? boundaryContextLimit,
|
|
18729
|
+
emergency: dropProjectionEmergency,
|
|
18730
|
+
clearedReasoningThroughTag: sessionMeta?.clearedReasoningThroughTag
|
|
18731
|
+
});
|
|
18625
18732
|
if (fullFeatureMode && !compactionOff && historianRunnable && tagOwnersReady && !sessionMeta.compartmentInProgress) {
|
|
18626
18733
|
const tTrigger = performance.now();
|
|
18627
18734
|
try {
|
|
@@ -18634,7 +18741,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18634
18741
|
force: contextUsageEarly.percentage >= forceMaterializationPercentage && (contextUsageEarly.percentage >= 95 || getEmergencyInputSample(db, sessionId) === 0),
|
|
18635
18742
|
explicitFlush: deps.pendingMaterializationSessions.has(sessionId),
|
|
18636
18743
|
publishedHistory: isCacheBusting
|
|
18637
|
-
});
|
|
18744
|
+
}, pendingDropEligibility.read(sessionId, dropProjectionKey()));
|
|
18638
18745
|
if (triggerResult.shouldFire) {
|
|
18639
18746
|
sessionLog2(sessionId, `compartment trigger: firing (reason=${triggerResult.reason})`);
|
|
18640
18747
|
updateSessionMeta(db, sessionId, { compartmentInProgress: true });
|
|
@@ -18940,6 +19047,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18940
19047
|
const protectedTagIds = protectedTagNumbers;
|
|
18941
19048
|
const protectedCutoff = protectionWindow.cutoff;
|
|
18942
19049
|
const tPostProcess = performance.now();
|
|
19050
|
+
dropProjectionEmergency = thinkingFitRetries.has(sessionId) || contextUsage.percentage >= 95;
|
|
18943
19051
|
const postTransformResult = await runPostTransformPhase({
|
|
18944
19052
|
opencode2: deps.storeGeneration === "v2",
|
|
18945
19053
|
normalizeRecoveryTail,
|
|
@@ -18997,6 +19105,7 @@ Historian previously failed ${historianFailureState.failureCount} time(s), so Ma
|
|
|
18997
19105
|
lastHeuristicsTurnId: deps.lastHeuristicsTurnId,
|
|
18998
19106
|
keepReasoningTokens: resolveKeepReasoningTokens(deps.keepReasoningTokens, currentModelKeyForBoundary),
|
|
18999
19107
|
protectedTagIds,
|
|
19108
|
+
onPendingDropEligibility: (eligible) => pendingDropEligibility.record(sessionId, dropProjectionKey(), eligible),
|
|
19000
19109
|
protectedTagNumbers,
|
|
19001
19110
|
protectedCutoff,
|
|
19002
19111
|
protectedCount: protectionWindow.status.protectedCount,
|
|
@@ -22617,7 +22726,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22617
22726
|
const db = readDatabase();
|
|
22618
22727
|
if (!db)
|
|
22619
22728
|
return { ok: false, error: "db unavailable" };
|
|
22620
|
-
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-
|
|
22729
|
+
const { runManagedRecomp } = await importPluginModule(() => import("./recomp-orchestrator-5zhxtwha.js"));
|
|
22621
22730
|
const { sendIgnoredMessage } = await importPluginModule(() => import("./send-session-notification-8ghn9tnv.js"));
|
|
22622
22731
|
log2(`[rpc] recomp requested for session ${sessionId}`);
|
|
22623
22732
|
if (!args.client && !args.hiddenCompletionExecutor) {
|
|
@@ -22702,7 +22811,7 @@ function registerRpcHandlers(rpcServer, args) {
|
|
|
22702
22811
|
const db = readDatabase();
|
|
22703
22812
|
if (!db)
|
|
22704
22813
|
return { ok: false, error: "db unavailable" };
|
|
22705
|
-
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-
|
|
22814
|
+
const { runManagedWrapup } = await importPluginModule(() => import("./wrapup-orchestrator-65pwye0d.js"));
|
|
22706
22815
|
const model = liveSessionState.liveModelBySession.get(sessionId);
|
|
22707
22816
|
const contextLimit = model ? resolveContextLimit(model.providerID, model.modelID, { db, sessionID: sessionId }) : 128000;
|
|
22708
22817
|
const ctx = {
|
|
@@ -25506,6 +25615,25 @@ function subagentTemperature(model, metadata, temperature, log) {
|
|
|
25506
25615
|
}
|
|
25507
25616
|
|
|
25508
25617
|
// src/v2/hidden-completion.ts
|
|
25618
|
+
var DEFAULT_DISPOSE_DRAIN_MS = 2000;
|
|
25619
|
+
async function settleWithin(work, ms) {
|
|
25620
|
+
let timer;
|
|
25621
|
+
try {
|
|
25622
|
+
await Promise.race([
|
|
25623
|
+
work.then(() => {
|
|
25624
|
+
return;
|
|
25625
|
+
}, () => {
|
|
25626
|
+
return;
|
|
25627
|
+
}),
|
|
25628
|
+
new Promise((resolve) => {
|
|
25629
|
+
timer = setTimeout(resolve, Math.max(0, ms));
|
|
25630
|
+
})
|
|
25631
|
+
]);
|
|
25632
|
+
} finally {
|
|
25633
|
+
if (timer)
|
|
25634
|
+
clearTimeout(timer);
|
|
25635
|
+
}
|
|
25636
|
+
}
|
|
25509
25637
|
var POLL_INTERVAL_MS = 200;
|
|
25510
25638
|
function modelKey(model) {
|
|
25511
25639
|
return `${model.providerID}/${model.modelID}`;
|
|
@@ -25553,7 +25681,7 @@ function toolResultText(result) {
|
|
|
25553
25681
|
`);
|
|
25554
25682
|
return text.length > 0 ? text : undefined;
|
|
25555
25683
|
}
|
|
25556
|
-
function toolLoopMessages(attempt) {
|
|
25684
|
+
function toolLoopMessages(attempt, rows) {
|
|
25557
25685
|
const messages = attempt.observedMessages ?? [];
|
|
25558
25686
|
const results = new Map;
|
|
25559
25687
|
for (const message of messages) {
|
|
@@ -25571,10 +25699,28 @@ function toolLoopMessages(attempt) {
|
|
|
25571
25699
|
});
|
|
25572
25700
|
}
|
|
25573
25701
|
}
|
|
25574
|
-
|
|
25702
|
+
const transcript = rows ? rows.map((row) => ({ role: "assistant", content: row.data.content ?? [] })) : messages;
|
|
25703
|
+
return transcript.flatMap((message) => {
|
|
25575
25704
|
if (message.role !== "assistant")
|
|
25576
25705
|
return [];
|
|
25577
25706
|
const parts = message.content.flatMap((part) => {
|
|
25707
|
+
if (part.type === "text" && typeof part.text === "string")
|
|
25708
|
+
return [{ type: "text", text: part.text }];
|
|
25709
|
+
if (part.type === "tool" && typeof part.name === "string" && typeof part.state === "object" && part.state !== null) {
|
|
25710
|
+
const state = part.state;
|
|
25711
|
+
const output = state.status === "completed" ? toolResultText({ value: state.content }) : undefined;
|
|
25712
|
+
return [
|
|
25713
|
+
{
|
|
25714
|
+
type: "tool",
|
|
25715
|
+
tool: part.name,
|
|
25716
|
+
state: {
|
|
25717
|
+
status: state.status,
|
|
25718
|
+
input: state.input,
|
|
25719
|
+
...output === undefined ? {} : { output }
|
|
25720
|
+
}
|
|
25721
|
+
}
|
|
25722
|
+
];
|
|
25723
|
+
}
|
|
25578
25724
|
if (part.type !== "tool-call" || typeof part.id !== "string" || typeof part.name !== "string")
|
|
25579
25725
|
return [];
|
|
25580
25726
|
const result = results.get(part.id);
|
|
@@ -25651,6 +25797,9 @@ function isProviderFailure(error) {
|
|
|
25651
25797
|
}
|
|
25652
25798
|
async function awaitAssistantRow(openReader, readSessionError, localFailure, childID, afterSeq, deadline, signal) {
|
|
25653
25799
|
for (;; ) {
|
|
25800
|
+
const refusedBefore = localFailure();
|
|
25801
|
+
if (refusedBefore)
|
|
25802
|
+
throw refusedBefore;
|
|
25654
25803
|
const { assistant, idle } = withReader(openReader, (reader) => ({
|
|
25655
25804
|
assistant: reader.latestAssistant(childID),
|
|
25656
25805
|
idle: reader.latestIdle(childID)
|
|
@@ -25726,6 +25875,9 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25726
25875
|
const generation = options.generation ?? "opencode2";
|
|
25727
25876
|
const roleTails = new Map;
|
|
25728
25877
|
const note = options.log ?? log2;
|
|
25878
|
+
let disposed;
|
|
25879
|
+
const openRuns = new Set;
|
|
25880
|
+
const inFlight = new Set;
|
|
25729
25881
|
const removeSession = host.removeSession;
|
|
25730
25882
|
if (!removeSession)
|
|
25731
25883
|
throw new Error("Magic Context requires OpenCode 2.0.22 session.remove");
|
|
@@ -25762,7 +25914,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25762
25914
|
const entry = rows.find((row) => row && typeof row === "object" && row.providerID === model.providerID && row.id === model.modelID);
|
|
25763
25915
|
if (!entry)
|
|
25764
25916
|
return model;
|
|
25765
|
-
if (entry.variants && typeof entry.variants === "object" && Object.hasOwn(entry.variants, model.variant))
|
|
25917
|
+
if (Array.isArray(entry.variants) ? entry.variants.some((variant) => variant?.id === model.variant) : entry.variants && typeof entry.variants === "object" && Object.hasOwn(entry.variants, model.variant))
|
|
25766
25918
|
return model;
|
|
25767
25919
|
const key = `${model.providerID}/${model.modelID}:${model.variant}`;
|
|
25768
25920
|
if (!warnedVariants.has(key)) {
|
|
@@ -25820,10 +25972,17 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25820
25972
|
return {
|
|
25821
25973
|
capabilities: V2_HIDDEN_EXECUTOR_CAPABILITIES,
|
|
25822
25974
|
async open(identity) {
|
|
25975
|
+
if (disposed)
|
|
25976
|
+
throw disposed;
|
|
25823
25977
|
const role = roleFor(identity);
|
|
25824
|
-
const
|
|
25978
|
+
const releaseStore = options.holdStore?.() ?? (() => {});
|
|
25979
|
+
let releaseRole;
|
|
25825
25980
|
let openedChild;
|
|
25981
|
+
let opened;
|
|
25826
25982
|
try {
|
|
25983
|
+
releaseRole = await acquireRole(role);
|
|
25984
|
+
if (disposed)
|
|
25985
|
+
throw disposed;
|
|
25827
25986
|
await options.ensureAgent?.();
|
|
25828
25987
|
const head = await resolveHead(identity);
|
|
25829
25988
|
const active = await lifecycle.open(identity, role, head);
|
|
@@ -25836,17 +25995,25 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25836
25995
|
role,
|
|
25837
25996
|
child: active,
|
|
25838
25997
|
releaseRole,
|
|
25998
|
+
releaseStore,
|
|
25839
25999
|
failed: false,
|
|
25840
26000
|
unsettledFailure: false,
|
|
25841
26001
|
retired: false
|
|
25842
26002
|
};
|
|
25843
26003
|
runs.set(handle, run);
|
|
26004
|
+
opened = run;
|
|
26005
|
+
openRuns.add(run);
|
|
26006
|
+
if (disposed)
|
|
26007
|
+
noteChildOfDisposedInstance(active.id);
|
|
25844
26008
|
await switchChildModel(run, head);
|
|
25845
26009
|
return handle;
|
|
25846
26010
|
} catch (error) {
|
|
25847
26011
|
if (openedChild)
|
|
25848
26012
|
lifecycle.retire(openedChild, "hidden-run-open-failed");
|
|
25849
|
-
|
|
26013
|
+
if (opened)
|
|
26014
|
+
openRuns.delete(opened);
|
|
26015
|
+
releaseRole?.();
|
|
26016
|
+
releaseStore();
|
|
25850
26017
|
throw error;
|
|
25851
26018
|
}
|
|
25852
26019
|
},
|
|
@@ -25854,6 +26021,15 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25854
26021
|
const run = runs.get(handle);
|
|
25855
26022
|
if (!run)
|
|
25856
26023
|
throw new Error("Unknown hidden completion run");
|
|
26024
|
+
const refuseDisposed = () => {
|
|
26025
|
+
if (!disposed)
|
|
26026
|
+
return;
|
|
26027
|
+
run.failed = true;
|
|
26028
|
+
run.unsettledFailure = true;
|
|
26029
|
+
retire(run, "plugin-instance-disposed");
|
|
26030
|
+
throw disposed;
|
|
26031
|
+
};
|
|
26032
|
+
refuseDisposed();
|
|
25857
26033
|
if (request.signal?.aborted) {
|
|
25858
26034
|
await interruptAndRetire(run, "aborted-before-prompt");
|
|
25859
26035
|
throw new Error("Hidden completion prompt aborted");
|
|
@@ -25891,6 +26067,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25891
26067
|
handle.childSessionId = run.child.id;
|
|
25892
26068
|
}
|
|
25893
26069
|
await switchChildModel(run, requested);
|
|
26070
|
+
refuseDisposed();
|
|
25894
26071
|
const baseline = withReader(options.openReader, (reader) => reader.latestSequence(run.child.id));
|
|
25895
26072
|
const marker = `mc:hidden:${crypto.randomUUID()}:${crypto.randomUUID()}`;
|
|
25896
26073
|
run.completion = undefined;
|
|
@@ -25958,6 +26135,28 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
25958
26135
|
interruptAndRetire(run, "prompt-timeout").finally(() => abortReject(new Error("Hidden completion prompt timed out")));
|
|
25959
26136
|
}, Math.max(0, deadline - Date.now()));
|
|
25960
26137
|
request.signal?.addEventListener("abort", onAbort, { once: true });
|
|
26138
|
+
let settle;
|
|
26139
|
+
const entry = {
|
|
26140
|
+
cancel: async (refusal) => {
|
|
26141
|
+
attempt.refusal ??= refusal;
|
|
26142
|
+
noteChildOfDisposedInstance(run.child.id);
|
|
26143
|
+
try {
|
|
26144
|
+
await interruptAndRetire(run, "plugin-instance-disposed");
|
|
26145
|
+
} catch (error) {
|
|
26146
|
+
note(`[magic-context] hidden child ${run.child.id} could not be interrupted on dispose: ${errorText(error)}`);
|
|
26147
|
+
} finally {
|
|
26148
|
+
abortReject(refusal);
|
|
26149
|
+
}
|
|
26150
|
+
},
|
|
26151
|
+
reject: (refusal) => {
|
|
26152
|
+
attempt.refusal ??= refusal;
|
|
26153
|
+
abortReject(refusal);
|
|
26154
|
+
},
|
|
26155
|
+
settled: new Promise((resolve) => {
|
|
26156
|
+
settle = resolve;
|
|
26157
|
+
})
|
|
26158
|
+
};
|
|
26159
|
+
inFlight.add(entry);
|
|
25961
26160
|
try {
|
|
25962
26161
|
await Promise.race([
|
|
25963
26162
|
host.prompt({ sessionID: run.child.id, text: marker }),
|
|
@@ -26008,7 +26207,7 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
26008
26207
|
run.completion = {
|
|
26009
26208
|
text,
|
|
26010
26209
|
tokenLog: runTokenLog(tokens, run.identity.maxOutputTokens, row.data.finish),
|
|
26011
|
-
...hiddenToolLoop(run.identity) ? { messages: toolLoopMessages(attempt) } : {},
|
|
26210
|
+
...hiddenToolLoop(run.identity) ? { messages: toolLoopMessages(attempt, steps) } : {},
|
|
26012
26211
|
reasoning: text ? null : assistantReasoning(row),
|
|
26013
26212
|
usage: reportedUsage ? usage : meter(system, promptText(request), text ?? ""),
|
|
26014
26213
|
lengthCapped: ["length", "max_tokens"].includes(row.data.finish ?? ""),
|
|
@@ -26037,6 +26236,8 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
26037
26236
|
clearInterval(budgetPoll);
|
|
26038
26237
|
request.signal?.removeEventListener("abort", onAbort);
|
|
26039
26238
|
options.hook.releaseAttempt(marker);
|
|
26239
|
+
inFlight.delete(entry);
|
|
26240
|
+
settle();
|
|
26040
26241
|
}
|
|
26041
26242
|
},
|
|
26042
26243
|
async collect(handle) {
|
|
@@ -26060,9 +26261,27 @@ async function createV2HiddenCompletionExecutor(host, options) {
|
|
|
26060
26261
|
}
|
|
26061
26262
|
} finally {
|
|
26062
26263
|
runs.delete(handle);
|
|
26264
|
+
openRuns.delete(run);
|
|
26063
26265
|
run.releaseRole();
|
|
26266
|
+
run.releaseStore();
|
|
26064
26267
|
}
|
|
26065
26268
|
await lifecycle.finish(run.child, run.retired);
|
|
26269
|
+
},
|
|
26270
|
+
async dispose() {
|
|
26271
|
+
disposed ??= new HiddenCompletionRefusal("hidden_instance_disposed", HIDDEN_RUN_DISPOSED_REASON, true);
|
|
26272
|
+
const refusal = disposed;
|
|
26273
|
+
for (const run of openRuns)
|
|
26274
|
+
noteChildOfDisposedInstance(run.child.id);
|
|
26275
|
+
const entries = [...inFlight];
|
|
26276
|
+
if (entries.length === 0)
|
|
26277
|
+
return;
|
|
26278
|
+
note(`[magic-context] plugin instance disposed with ${entries.length} hidden run(s) in flight; cancelling them`);
|
|
26279
|
+
const bound = options.disposeDrainMs ?? DEFAULT_DISPOSE_DRAIN_MS;
|
|
26280
|
+
const deadline = Date.now() + bound;
|
|
26281
|
+
await settleWithin(Promise.allSettled(entries.map((entry) => entry.cancel(refusal))), bound);
|
|
26282
|
+
for (const entry of entries)
|
|
26283
|
+
entry.reject(refusal);
|
|
26284
|
+
await settleWithin(Promise.allSettled(entries.map((entry) => entry.settled)), deadline - Date.now());
|
|
26066
26285
|
}
|
|
26067
26286
|
};
|
|
26068
26287
|
}
|
|
@@ -30272,7 +30491,8 @@ function currentManifest(text) {
|
|
|
30272
30491
|
return start < 0 ? text : text.slice(start);
|
|
30273
30492
|
}
|
|
30274
30493
|
function parseMapMemoriesCompletion(text, completion, expectedIds) {
|
|
30275
|
-
|
|
30494
|
+
const source = /<mappings\b/i.test(text) ? text : assistantText2(completion.messages ?? []) || text;
|
|
30495
|
+
return validateMapMemoriesManifest(currentManifest(source), expectedIds);
|
|
30276
30496
|
}
|
|
30277
30497
|
function validateClientMapMemories(messages, expectedIds) {
|
|
30278
30498
|
if (hasLengthCappedOutput(messages)) {
|
|
@@ -32384,6 +32604,7 @@ var VERIFY_BATCH_SIZE = 5;
|
|
|
32384
32604
|
var VERIFY_TOKENS_PER_MEMORY = 1e5;
|
|
32385
32605
|
var VERIFY_RUN_TOKEN_BUDGET = 2500000;
|
|
32386
32606
|
var VERIFY_RUN_SLICE_MS = 240000;
|
|
32607
|
+
var VERIFY_IN_FLIGHT_GRACE_MS = 120000;
|
|
32387
32608
|
function verifyBatchTokenBudget(size, configured) {
|
|
32388
32609
|
return Math.min(configured ?? Number.MAX_SAFE_INTEGER, size * VERIFY_TOKENS_PER_MEMORY);
|
|
32389
32610
|
}
|
|
@@ -32470,7 +32691,15 @@ async function runVerifyWithCooldown(args) {
|
|
|
32470
32691
|
const runTokenBudget = Math.min(args.tokenBudget ?? VERIFY_RUN_TOKEN_BUDGET, VERIFY_RUN_TOKEN_BUDGET);
|
|
32471
32692
|
try {
|
|
32472
32693
|
for (let i = 0;i < batches.length; i += 1) {
|
|
32473
|
-
const
|
|
32694
|
+
const now = Date.now();
|
|
32695
|
+
const startCutoff = Math.min(args.deadline, sliceDeadline);
|
|
32696
|
+
const hardStop = Math.min(args.deadline, sliceDeadline + VERIFY_IN_FLIGHT_GRACE_MS);
|
|
32697
|
+
const remainingMs = Math.max(0, hardStop - now);
|
|
32698
|
+
if (now >= startCutoff) {
|
|
32699
|
+
result.stopReason = "deadline";
|
|
32700
|
+
log2(`[dreamer] ${args.forceBroad ? "verify-broad" : "verify"}: stopping before batch ${i + 1}/${batches.length} — the run deadline passed ${now - startCutoff}ms ago`);
|
|
32701
|
+
break;
|
|
32702
|
+
}
|
|
32474
32703
|
if (remainingMs < VERIFY_BATCH_FLOOR_MS) {
|
|
32475
32704
|
result.stopReason = "deadline";
|
|
32476
32705
|
log2(`[dreamer] ${args.forceBroad ? "verify-broad" : "verify"}: stopping before batch ${i + 1}/${batches.length} — remaining budget ${remainingMs}ms is below the ${VERIFY_BATCH_FLOOR_MS}ms batch floor`);
|
|
@@ -50970,6 +51199,7 @@ function persistV2UsageReading(args) {
|
|
|
50970
51199
|
class V2LkgAdmissionReplay extends Error {
|
|
50971
51200
|
}
|
|
50972
51201
|
var HIDDEN_SESSION_ERROR_GRACE_MS = 50;
|
|
51202
|
+
var STORE_POOL_DISPOSE_WAIT_MS = 1000;
|
|
50973
51203
|
function isBlockingV2TransformError(error) {
|
|
50974
51204
|
return error instanceof EmergencyFailClosedError || error instanceof UnresolvedHistoryBoundaryError || error instanceof UnmanagedOverWindowError || error instanceof DegradedPassRefusalError || isFailClosedBlockingError(error);
|
|
50975
51205
|
}
|
|
@@ -51317,7 +51547,8 @@ async function registerContext(context) {
|
|
|
51317
51547
|
ensureAgent: () => hiddenAgentsReady ??= context.agent.reload(),
|
|
51318
51548
|
modelCatalog: () => Promise.resolve(context.model.list()),
|
|
51319
51549
|
historianTemperature: () => config.historian?.temperature,
|
|
51320
|
-
openReader: openStoreReader
|
|
51550
|
+
openReader: openStoreReader,
|
|
51551
|
+
holdStore: () => readerPool.hold()
|
|
51321
51552
|
});
|
|
51322
51553
|
};
|
|
51323
51554
|
const dreamerAtBoot = config.dreamer;
|
|
@@ -52348,6 +52579,7 @@ ${baseline}
|
|
|
52348
52579
|
}, 0));
|
|
52349
52580
|
return {
|
|
52350
52581
|
async dispose() {
|
|
52582
|
+
await hiddenCompletionExecutor?.dispose();
|
|
52351
52583
|
rpcStopped = true;
|
|
52352
52584
|
rpcServer.stop();
|
|
52353
52585
|
transform?.disposeRust();
|
|
@@ -52361,7 +52593,8 @@ ${baseline}
|
|
|
52361
52593
|
release();
|
|
52362
52594
|
rawProviders.clear();
|
|
52363
52595
|
restoredRows.clear();
|
|
52364
|
-
readerPool.
|
|
52596
|
+
if (!await readerPool.closeWhenIdle(STORE_POOL_DISPOSE_WAIT_MS))
|
|
52597
|
+
log2(`[magic-context] v2 store reader pool still held by ${readerPool.holdCount()} hidden run(s) at dispose; it closes when they finish`);
|
|
52365
52598
|
clearSyntheticCandidates(context);
|
|
52366
52599
|
}
|
|
52367
52600
|
};
|