@cortexkit/pi-magic-context 0.49.48 → 0.49.50
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 +5 -5
- package/dist/chunk-embedding-write-worker.js +12 -12
- package/dist/{compaction-marker-candidates-17a21jfn.js → compaction-marker-candidates-9yhrstyb.js} +2 -2
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-nyjs3dfh.js → compartment-chunk-embedding-wg7emg3z.js} +7 -7
- package/dist/embedding-backfill-fbhpk2yy.js +27 -0
- package/dist/embedding-worker-process.js +1 -1
- package/dist/embedding-worker.js +5 -5
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/{index-bbffazv6.js → index-06rdy9h6.js} +11 -9
- package/dist/{index-h1rtbjrp.js → index-38bm78h4.js} +25 -21
- package/dist/{index-tsg6swzr.js → index-38pf5bqw.js} +6 -4
- package/dist/{index-w26zvs1q.js → index-46wk0td0.js} +1 -1
- package/dist/{index-vnygvrad.js → index-4j5442b0.js} +7 -7
- package/dist/{index-806brt0p.js → index-4ss8c8ky.js} +10 -10
- package/dist/{index-bbbp8zs1.js → index-6d0bby9d.js} +2 -2
- package/dist/{index-000fthre.js → index-7y60kyea.js} +1 -1
- package/dist/{index-gzk7d940.js → index-aec63gtj.js} +3 -0
- package/dist/{index-6748dkmx.js → index-ch3rvpjg.js} +2 -2
- package/dist/{index-0wtm7g7f.js → index-j0eagxkz.js} +1 -1
- package/dist/{index-gwm5x42c.js → index-jexm22qn.js} +3 -3
- package/dist/{index-yacs388s.js → index-jxm4bvm4.js} +1 -1
- package/dist/{index-pja6ggeq.js → index-jy9fq8gp.js} +11 -11
- package/dist/{index-4sa1rx3h.js → index-ndg15t3x.js} +4 -4
- package/dist/{index-j1kkx3f3.js → index-pkg07s54.js} +2 -2
- package/dist/{index-bhj8kymt.js → index-qcsjj9m0.js} +3 -3
- package/dist/{index-gwvahsdz.js → index-qm139qq2.js} +2 -2
- package/dist/{index-rcenqffj.js → index-r6dj8rm9.js} +27 -11
- package/dist/{index-3g9fnq6y.js → index-szn2tac8.js} +1 -1
- package/dist/{index-zwbgxt01.js → index-ty2m0s0s.js} +6 -5
- package/dist/{index-2kmwjq42.js → index-xssjy4z9.js} +1 -1
- package/dist/{index-6pk49fc3.js → index-xx1911hb.js} +1 -1
- package/dist/{index-cq71g4dk.js → index-yjgkjkjs.js} +1 -1
- package/dist/{index-zybqfwfv.js → index-ywvhr524.js} +4 -4
- package/dist/{index-gymgz20n.js → index-yxeg8zaa.js} +23 -20
- package/dist/{index-d107f484.js → index-zc6fdyx7.js} +4 -4
- package/dist/{index-mp0gh04g.js → index-zxm7ckvc.js} +2 -2
- package/dist/index.js +194 -122
- package/dist/{logger-2j70hhz4.js → logger-hhgpkbx1.js} +1 -1
- package/dist/{message-fts-rowid-map-ff4qg3e4.js → message-fts-rowid-map-tec2x7qe.js} +4 -4
- package/dist/{message-index-bounded-f0bk44ch.js → message-index-bounded-wg71m86d.js} +10 -10
- package/dist/{message-time-backfill-x45573rs.js → message-time-backfill-krre2qnb.js} +2 -2
- package/dist/migration-worker.js +9 -9
- package/dist/{project-embedding-registry-ysaezfqw.js → project-embedding-registry-hpca84nz.js} +12 -12
- package/dist/raw-ordinal-warmup-worker.js +8 -8
- package/dist/{read-session-chunk-6nt4dzkk.js → read-session-chunk-dmpabgvh.js} +8 -8
- package/dist/{read-session-raw-nttnwy8p.js → read-session-raw-75dcxtdy.js} +2 -2
- package/dist/{render-yn7fgmg7.js → render-71rpjt3g.js} +17 -17
- package/dist/{safe-notification-target-jk69jxwp.js → safe-notification-target-8s1xg0q9.js} +2 -2
- package/dist/{search-archive-pcf0za02.js → search-archive-w12r0c45.js} +10 -10
- package/dist/{search-yvcam5gm.js → search-m61nenns.js} +20 -20
- package/dist/{storage-tags-s0zqj0m0.js → storage-tags-ahhwtfdq.js} +4 -4
- package/dist/subagent-entry.js +26 -26
- package/dist/tag-snapshot-worker-pi.js +11 -11
- package/dist/{v2-archive-reader-accb2tjp.js → v2-archive-reader-5n1w78zj.js} +1 -1
- package/package.json +1 -1
- package/dist/embedding-backfill-er9jc4xf.js +0 -27
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
log2,
|
|
16
16
|
sessionLog2,
|
|
17
17
|
flushLogger2
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-yxeg8zaa.js";
|
|
19
19
|
import {
|
|
20
20
|
sanitizeDiagnosticText,
|
|
21
21
|
hasShareabilitySensitiveText
|
|
@@ -153,7 +153,7 @@ import {
|
|
|
153
153
|
registerTodoStateLifecycle,
|
|
154
154
|
syncCtxMemoryToolEnabled,
|
|
155
155
|
registerMagicContextTools
|
|
156
|
-
} from "./index-
|
|
156
|
+
} from "./index-38bm78h4.js";
|
|
157
157
|
import"./index-4knyh1kt.js";
|
|
158
158
|
import {
|
|
159
159
|
canonicalModelIdentity,
|
|
@@ -171,7 +171,7 @@ import {
|
|
|
171
171
|
DEFAULT_HISTORIAN_TIMEOUT_MS,
|
|
172
172
|
DREAM_TASK_PROMOTION_DEFAULTS,
|
|
173
173
|
LIVE_RELOAD_CONFIG_PATHS
|
|
174
|
-
} from "./index-
|
|
174
|
+
} from "./index-aec63gtj.js";
|
|
175
175
|
import {
|
|
176
176
|
FAIL_CLOSED_DOCTOR_COMMAND,
|
|
177
177
|
formatFailClosedBlockingMessage,
|
|
@@ -191,7 +191,7 @@ import {
|
|
|
191
191
|
resolveProjectIdentityForSession,
|
|
192
192
|
beginBootQuietPeriod,
|
|
193
193
|
scheduleAfterBootQuiet
|
|
194
|
-
} from "./index-
|
|
194
|
+
} from "./index-xx1911hb.js";
|
|
195
195
|
import {
|
|
196
196
|
detectThinkingBindingMismatch,
|
|
197
197
|
detectLatestTurnThinkingMismatch,
|
|
@@ -356,7 +356,7 @@ import {
|
|
|
356
356
|
getRawSessionTagKeysThrough2,
|
|
357
357
|
getLegacyProtectedTailStartOrdinal2,
|
|
358
358
|
readSessionChunk2
|
|
359
|
-
} from "./index-
|
|
359
|
+
} from "./index-4j5442b0.js";
|
|
360
360
|
import {
|
|
361
361
|
UNKNOWN_FIT_RATIO,
|
|
362
362
|
hasMeasuredDecisionCalibration,
|
|
@@ -445,7 +445,7 @@ import {
|
|
|
445
445
|
getToolTagNumberByOwner2,
|
|
446
446
|
getNullOwnerToolTag2,
|
|
447
447
|
adoptNullOwnerToolTag2
|
|
448
|
-
} from "./index-
|
|
448
|
+
} from "./index-qcsjj9m0.js";
|
|
449
449
|
import {
|
|
450
450
|
textMentionsRecentCommit,
|
|
451
451
|
hasMeaningfulUserText2,
|
|
@@ -457,7 +457,7 @@ import {
|
|
|
457
457
|
estimateTokens,
|
|
458
458
|
estimateFixedPromptTokens,
|
|
459
459
|
normalizeText
|
|
460
|
-
} from "./index-
|
|
460
|
+
} from "./index-7y60kyea.js";
|
|
461
461
|
import {
|
|
462
462
|
inRootAsyncContext2,
|
|
463
463
|
Database2,
|
|
@@ -477,7 +477,7 @@ import {
|
|
|
477
477
|
observeTemporalDecisions,
|
|
478
478
|
freezeTemporalDecisions,
|
|
479
479
|
tagIdentityRevisionKey
|
|
480
|
-
} from "./index-
|
|
480
|
+
} from "./index-jxm4bvm4.js";
|
|
481
481
|
import {
|
|
482
482
|
piHarnessKindFromExecutable,
|
|
483
483
|
getErrorMessage,
|
|
@@ -495,7 +495,7 @@ import {
|
|
|
495
495
|
openCurrentDatabase,
|
|
496
496
|
openDatabaseAsync,
|
|
497
497
|
closeDatabase
|
|
498
|
-
} from "./index-
|
|
498
|
+
} from "./index-06rdy9h6.js";
|
|
499
499
|
import {
|
|
500
500
|
LkgRecoveryFenceError,
|
|
501
501
|
clearLkgFenceProcessState,
|
|
@@ -612,7 +612,7 @@ import {
|
|
|
612
612
|
getSourceContents,
|
|
613
613
|
recordSubagentInvocation,
|
|
614
614
|
getLatestHistorianInvocationId
|
|
615
|
-
} from "./index-
|
|
615
|
+
} from "./index-jy9fq8gp.js";
|
|
616
616
|
import {
|
|
617
617
|
resolveOpenCodeDbPath,
|
|
618
618
|
assertOpenCodeStoreGeneration,
|
|
@@ -630,12 +630,12 @@ import {
|
|
|
630
630
|
} from "./index-x2n261wp.js";
|
|
631
631
|
import {
|
|
632
632
|
RAW_SUMMARY_TEXT_MAX_CHARS2
|
|
633
|
-
} from "./index-
|
|
633
|
+
} from "./index-szn2tac8.js";
|
|
634
634
|
import"./index-nvh6d3bz.js";
|
|
635
635
|
import {
|
|
636
636
|
formatSynapseLaneDescriptor
|
|
637
|
-
} from "./index-
|
|
638
|
-
import"./index-
|
|
637
|
+
} from "./index-qm139qq2.js";
|
|
638
|
+
import"./index-6d0bby9d.js";
|
|
639
639
|
import {
|
|
640
640
|
buildCanonicalChunkTextFromFts2,
|
|
641
641
|
buildCompartmentSummaryFallbackText2,
|
|
@@ -645,7 +645,7 @@ import {
|
|
|
645
645
|
replaceCompartmentChunkEmbeddings2,
|
|
646
646
|
deleteChunkEmbedBackoffForSession2,
|
|
647
647
|
chunkWindowSourceKey2
|
|
648
|
-
} from "./index-
|
|
648
|
+
} from "./index-ndg15t3x.js";
|
|
649
649
|
import {
|
|
650
650
|
recordSessionProjectIdentity,
|
|
651
651
|
GIT_SWEEP_LEASE_RENEWAL_MS,
|
|
@@ -654,7 +654,7 @@ import {
|
|
|
654
654
|
markGitSweepSuccessAndRelease,
|
|
655
655
|
parkGitSweepNonIndexable,
|
|
656
656
|
releaseGitSweepLease
|
|
657
|
-
} from "./index-
|
|
657
|
+
} from "./index-zxm7ckvc.js";
|
|
658
658
|
import {
|
|
659
659
|
embedPauseBySession,
|
|
660
660
|
embedRunStateBySession,
|
|
@@ -670,7 +670,7 @@ import {
|
|
|
670
670
|
clearCompressionDepthRange,
|
|
671
671
|
cleanSearchText,
|
|
672
672
|
matchedSearchSnippet
|
|
673
|
-
} from "./index-
|
|
673
|
+
} from "./index-ywvhr524.js";
|
|
674
674
|
import {
|
|
675
675
|
rememberV1HiddenRun
|
|
676
676
|
} from "./index-6x556c2q.js";
|
|
@@ -688,7 +688,7 @@ import {
|
|
|
688
688
|
expandWorkspaceIdentitySetWithAliases,
|
|
689
689
|
sourceNameForMemory,
|
|
690
690
|
computeWorkspaceEpochFingerprint
|
|
691
|
-
} from "./index-
|
|
691
|
+
} from "./index-zc6fdyx7.js";
|
|
692
692
|
import {
|
|
693
693
|
configureContextDatabasePragmas2
|
|
694
694
|
} from "./index-fapenpch.js";
|
|
@@ -713,7 +713,7 @@ import {
|
|
|
713
713
|
createPrimer,
|
|
714
714
|
updatePrimerSupport,
|
|
715
715
|
updatePrimerAnswer
|
|
716
|
-
} from "./index-
|
|
716
|
+
} from "./index-46wk0td0.js";
|
|
717
717
|
import {
|
|
718
718
|
setEmbeddingSessionBusy2,
|
|
719
719
|
isEmbeddingHostBusy2
|
|
@@ -747,7 +747,7 @@ import {
|
|
|
747
747
|
} from "./index-q1yc6bs0.js";
|
|
748
748
|
import {
|
|
749
749
|
getCachedLocalEmbeddingPooling
|
|
750
|
-
} from "./index-
|
|
750
|
+
} from "./index-38pf5bqw.js";
|
|
751
751
|
import {
|
|
752
752
|
describeShadowBackfillWriteRefusal2,
|
|
753
753
|
contentSha2562,
|
|
@@ -765,10 +765,10 @@ import {
|
|
|
765
765
|
embedSessionCompartmentChunks2,
|
|
766
766
|
getEmbeddingCoverageStatus2,
|
|
767
767
|
getAutoEmbeddingSessionCoverage2
|
|
768
|
-
} from "./index-
|
|
768
|
+
} from "./index-r6dj8rm9.js";
|
|
769
769
|
import {
|
|
770
770
|
cosineSimilarity
|
|
771
|
-
} from "./index-
|
|
771
|
+
} from "./index-ty2m0s0s.js";
|
|
772
772
|
import {
|
|
773
773
|
USER_FACING_FAILURES,
|
|
774
774
|
renderUserFacingFailure,
|
|
@@ -802,8 +802,8 @@ import {
|
|
|
802
802
|
scheduleClearAndReindex,
|
|
803
803
|
clearSessionTracking,
|
|
804
804
|
createAutoSearchDiagnostics
|
|
805
|
-
} from "./index-
|
|
806
|
-
import"./index-
|
|
805
|
+
} from "./index-4ss8c8ky.js";
|
|
806
|
+
import"./index-xssjy4z9.js";
|
|
807
807
|
import {
|
|
808
808
|
DREAMER_PRIMER_INVESTIGATOR_ALLOWED_TOOLS,
|
|
809
809
|
buildHiddenAgentRegistrations,
|
|
@@ -830,11 +830,11 @@ import {
|
|
|
830
830
|
drainPiTagSnapshotSession,
|
|
831
831
|
assertPiTagSnapshotReady,
|
|
832
832
|
ensurePiTagSnapshotReady
|
|
833
|
-
} from "./index-
|
|
834
|
-
import"./index-
|
|
833
|
+
} from "./index-pkg07s54.js";
|
|
834
|
+
import"./index-yjgkjkjs.js";
|
|
835
835
|
import"./index-1cvyaw9a.js";
|
|
836
|
-
import"./index-
|
|
837
|
-
import"./index-
|
|
836
|
+
import"./index-jexm22qn.js";
|
|
837
|
+
import"./index-ch3rvpjg.js";
|
|
838
838
|
import {
|
|
839
839
|
__toESM
|
|
840
840
|
} from "./index-22jkk6wg.js";
|
|
@@ -857,7 +857,7 @@ import {
|
|
|
857
857
|
import {
|
|
858
858
|
logSlowWriteTransaction,
|
|
859
859
|
WriteTransactionSteps
|
|
860
|
-
} from "./index-
|
|
860
|
+
} from "./index-j0eagxkz.js";
|
|
861
861
|
import {
|
|
862
862
|
setStoragePrivatePermissionEnforcement,
|
|
863
863
|
ensureStorageDirectorySync,
|
|
@@ -866,7 +866,7 @@ import {
|
|
|
866
866
|
} from "./index-81nthk8j.js";
|
|
867
867
|
|
|
868
868
|
// src/index.ts
|
|
869
|
-
import { AsyncLocalStorage as
|
|
869
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
870
870
|
import { createRequire as createRequire2 } from "node:module";
|
|
871
871
|
import { join as join16, resolve as resolve3 } from "node:path";
|
|
872
872
|
|
|
@@ -3589,7 +3589,7 @@ function startHostStallProfilerSwitch() {
|
|
|
3589
3589
|
// package.json
|
|
3590
3590
|
var package_default = {
|
|
3591
3591
|
name: "@cortexkit/pi-magic-context",
|
|
3592
|
-
version: "0.49.
|
|
3592
|
+
version: "0.49.50",
|
|
3593
3593
|
type: "module",
|
|
3594
3594
|
description: "Pi and OMP coding agent extension for Magic Context — cross-session memory and context management",
|
|
3595
3595
|
main: "dist/index.js",
|
|
@@ -4867,7 +4867,6 @@ class HiddenCompletionRefusal extends Error {
|
|
|
4867
4867
|
}
|
|
4868
4868
|
}
|
|
4869
4869
|
// ../plugin/src/features/magic-context/dreamer/provider-output-failure.ts
|
|
4870
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4871
4870
|
import { createHash as createHash3 } from "node:crypto";
|
|
4872
4871
|
var MAX_NEAR_ZERO_OUTPUT_TOKENS = 32;
|
|
4873
4872
|
|
|
@@ -4875,52 +4874,18 @@ class DreamerProviderOutputFailureError extends Error {
|
|
|
4875
4874
|
fingerprint;
|
|
4876
4875
|
outputTokens;
|
|
4877
4876
|
reasoningTokens;
|
|
4878
|
-
quotaResetAt;
|
|
4879
4877
|
transient = true;
|
|
4880
|
-
constructor(fingerprint, outputTokens, reasoningTokens, responseText
|
|
4878
|
+
constructor(fingerprint, outputTokens, reasoningTokens, responseText) {
|
|
4881
4879
|
const preview = responseText.trim().replace(/\s+/g, " ").slice(0, 160);
|
|
4882
|
-
super(
|
|
4880
|
+
super(`dreamer provider-outage completion (output_tokens=${outputTokens}, reasoning_tokens=${reasoningTokens}): ${JSON.stringify(preview)}`);
|
|
4883
4881
|
this.fingerprint = fingerprint;
|
|
4884
4882
|
this.outputTokens = outputTokens;
|
|
4885
4883
|
this.reasoningTokens = reasoningTokens;
|
|
4886
|
-
this.quotaResetAt = quotaResetAt;
|
|
4887
4884
|
this.name = "DreamerProviderOutputFailureError";
|
|
4888
4885
|
}
|
|
4889
4886
|
}
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
return primaryQuotas.getStore() ? run() : primaryQuotas.run(new Map, run);
|
|
4893
|
-
}
|
|
4894
|
-
function rememberPrimaryQuota(model, error) {
|
|
4895
|
-
const quotas = primaryQuotas.getStore();
|
|
4896
|
-
if (!quotas || model === "primary" || !(error instanceof DreamerProviderOutputFailureError) || error.quotaResetAt === undefined || error.quotaResetAt <= Date.now())
|
|
4897
|
-
return null;
|
|
4898
|
-
const cached = new DreamerProviderOutputFailureError(error.fingerprint, error.outputTokens, error.reasoningTokens, "", error.quotaResetAt);
|
|
4899
|
-
cached.message = error.message;
|
|
4900
|
-
quotas.set(model, cached);
|
|
4901
|
-
return error;
|
|
4902
|
-
}
|
|
4903
|
-
function primaryQuotaFailure(model) {
|
|
4904
|
-
const quotas = primaryQuotas.getStore();
|
|
4905
|
-
const error = quotas?.get(model);
|
|
4906
|
-
if (!error)
|
|
4907
|
-
return null;
|
|
4908
|
-
if (error.quotaResetAt === undefined || error.quotaResetAt <= Date.now()) {
|
|
4909
|
-
quotas?.delete(model);
|
|
4910
|
-
return null;
|
|
4911
|
-
}
|
|
4912
|
-
const failure = new DreamerProviderOutputFailureError(error.fingerprint, error.outputTokens, error.reasoningTokens, "", error.quotaResetAt);
|
|
4913
|
-
failure.message = error.message;
|
|
4914
|
-
return failure;
|
|
4915
|
-
}
|
|
4916
|
-
function quotaResetAt(responseText, now) {
|
|
4917
|
-
const notice = /^All [1-9]\d* account\(s\) rate-limited for [\w.-]+\. Quota resets in ((?:\d+[hms] ?)+)\. Add more accounts with `opencode auth login` or wait and retry\.$/.exec(responseText.trim());
|
|
4918
|
-
if (!notice)
|
|
4919
|
-
return;
|
|
4920
|
-
const units = { h: 3600000, m: 60000, s: 1000 };
|
|
4921
|
-
const duration = [...notice[1].matchAll(/(\d+)([hms])/g)].reduce((sum, match) => sum + Number(match[1]) * units[match[2]], 0);
|
|
4922
|
-
const resetAt = now + duration;
|
|
4923
|
-
return duration > 0 && Number.isSafeInteger(resetAt) && resetAt < 8640000000000000 ? resetAt : undefined;
|
|
4887
|
+
function isAccountPoolQuotaNotice(responseText) {
|
|
4888
|
+
return /^All [1-9]\d* account\(s\) rate-limited for [\w.-]+\. Quota resets in (?:\d+[hms] ?)+\. Add more accounts with `opencode auth login` or wait and retry\.$/.test(responseText.trim());
|
|
4924
4889
|
}
|
|
4925
4890
|
function finiteTokenCount(value) {
|
|
4926
4891
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
|
|
@@ -4952,7 +4917,7 @@ function latestAssistantCompletion(messages) {
|
|
|
4952
4917
|
}
|
|
4953
4918
|
return latest;
|
|
4954
4919
|
}
|
|
4955
|
-
function providerOutputFailureFromInvalidManifest(messages, responseText
|
|
4920
|
+
function providerOutputFailureFromInvalidManifest(messages, responseText) {
|
|
4956
4921
|
const completion = latestAssistantCompletion(messages);
|
|
4957
4922
|
if (completion?.finish?.toLowerCase() !== "stop")
|
|
4958
4923
|
return null;
|
|
@@ -4962,11 +4927,10 @@ function providerOutputFailureFromInvalidManifest(messages, responseText, now =
|
|
|
4962
4927
|
const normalized = responseText.trim().replace(/\s+/g, " ").toLowerCase();
|
|
4963
4928
|
if (!normalized)
|
|
4964
4929
|
return null;
|
|
4965
|
-
|
|
4966
|
-
if (resetAt === undefined && completion.outputTokens > MAX_NEAR_ZERO_OUTPUT_TOKENS)
|
|
4930
|
+
if (!isAccountPoolQuotaNotice(responseText) && completion.outputTokens > MAX_NEAR_ZERO_OUTPUT_TOKENS)
|
|
4967
4931
|
return null;
|
|
4968
4932
|
const fingerprint = createHash3("sha256").update(normalized).digest("hex").slice(0, 16);
|
|
4969
|
-
return new DreamerProviderOutputFailureError(fingerprint, completion.outputTokens, completion.reasoningTokens, responseText
|
|
4933
|
+
return new DreamerProviderOutputFailureError(fingerprint, completion.outputTokens, completion.reasoningTokens, responseText);
|
|
4970
4934
|
}
|
|
4971
4935
|
|
|
4972
4936
|
// ../plugin/src/v2/hooks/hidden-child.ts
|
|
@@ -5112,6 +5076,94 @@ function toModelEntry(spec) {
|
|
|
5112
5076
|
return spec;
|
|
5113
5077
|
}
|
|
5114
5078
|
|
|
5079
|
+
// ../plugin/src/shared/hidden-model-cooldown.ts
|
|
5080
|
+
var MAX_SKIP_MS = 7 * 24 * 60 * 60 * 1000;
|
|
5081
|
+
var MIN_SKIP_MS = 60000;
|
|
5082
|
+
var RETRY_LATER_REASON = "provider said to retry later";
|
|
5083
|
+
|
|
5084
|
+
class HiddenModelCooldowns {
|
|
5085
|
+
now;
|
|
5086
|
+
entries = new Map;
|
|
5087
|
+
constructor(now = () => Date.now()) {
|
|
5088
|
+
this.now = now;
|
|
5089
|
+
}
|
|
5090
|
+
record(model, error) {
|
|
5091
|
+
if (!model?.includes("/"))
|
|
5092
|
+
return;
|
|
5093
|
+
const now = this.now();
|
|
5094
|
+
const delay = retryDelay(error, now);
|
|
5095
|
+
if (delay === undefined || !Number.isFinite(delay) || delay <= MIN_SKIP_MS)
|
|
5096
|
+
return;
|
|
5097
|
+
this.entries.set(model, {
|
|
5098
|
+
model,
|
|
5099
|
+
until: now + Math.min(delay, MAX_SKIP_MS),
|
|
5100
|
+
reason: RETRY_LATER_REASON
|
|
5101
|
+
});
|
|
5102
|
+
}
|
|
5103
|
+
succeeded(model) {
|
|
5104
|
+
if (model)
|
|
5105
|
+
this.entries.delete(model);
|
|
5106
|
+
}
|
|
5107
|
+
live() {
|
|
5108
|
+
const now = this.now();
|
|
5109
|
+
for (const [model, entry] of this.entries) {
|
|
5110
|
+
if (entry.until <= now)
|
|
5111
|
+
this.entries.delete(model);
|
|
5112
|
+
}
|
|
5113
|
+
return [...this.entries.values()];
|
|
5114
|
+
}
|
|
5115
|
+
startIndex(models, log) {
|
|
5116
|
+
const live = new Map(this.live().map((entry) => [entry.model, entry]));
|
|
5117
|
+
let start = models.findIndex((model) => !live.has(model));
|
|
5118
|
+
if (start < 0) {
|
|
5119
|
+
start = 0;
|
|
5120
|
+
for (let i = 1;i < models.length; i++) {
|
|
5121
|
+
if ((live.get(models[i])?.until ?? Infinity) < (live.get(models[start])?.until ?? Infinity))
|
|
5122
|
+
start = i;
|
|
5123
|
+
}
|
|
5124
|
+
}
|
|
5125
|
+
const logged = new Set;
|
|
5126
|
+
for (const model of models.slice(0, start)) {
|
|
5127
|
+
const entry = live.get(model);
|
|
5128
|
+
if (entry && !logged.has(model)) {
|
|
5129
|
+
log(`skipping ${model} until ${new Date(entry.until).toISOString()}: provider said to retry later`);
|
|
5130
|
+
logged.add(model);
|
|
5131
|
+
}
|
|
5132
|
+
}
|
|
5133
|
+
return start;
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
function retryDelay(error, now, depth = 0) {
|
|
5137
|
+
if (!isRecord(error) || depth > 4)
|
|
5138
|
+
return;
|
|
5139
|
+
const data = typeof error.statusCode === "number" || typeof error.status === "number" ? error : isRecord(error.data) ? error.data : error;
|
|
5140
|
+
const status = data.statusCode ?? data.status;
|
|
5141
|
+
if (status === 412 || status === 429 || status === 503) {
|
|
5142
|
+
if (typeof data.retryAfterMs === "number")
|
|
5143
|
+
return data.retryAfterMs;
|
|
5144
|
+
const headers = data.responseHeaders;
|
|
5145
|
+
if (isRecord(headers)) {
|
|
5146
|
+
const value = Object.entries(headers).find(([name]) => name.toLowerCase() === "retry-after")?.[1];
|
|
5147
|
+
if (typeof value === "string") {
|
|
5148
|
+
const text = value.trim();
|
|
5149
|
+
if (/^\d+$/.test(text))
|
|
5150
|
+
return Number(text) * 1000;
|
|
5151
|
+
if (/^(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2} GMT|(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), \d{2}-[A-Z][a-z]{2}-\d{2} \d{2}:\d{2}:\d{2} GMT|(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) [A-Z][a-z]{2} [ \d]\d \d{2}:\d{2}:\d{2} \d{4})$/.test(text))
|
|
5152
|
+
return Date.parse(text) - now;
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
}
|
|
5156
|
+
return retryDelay(error.hostError ?? error.cause, now, depth + 1);
|
|
5157
|
+
}
|
|
5158
|
+
var hiddenModelCooldowns = new HiddenModelCooldowns;
|
|
5159
|
+
function selectHiddenModelStart(primary, fallbacks = [], note) {
|
|
5160
|
+
if (!primary)
|
|
5161
|
+
return { primary, fallbacks };
|
|
5162
|
+
const chain = [primary, ...fallbacks];
|
|
5163
|
+
const start = hiddenModelCooldowns.startIndex(chain.map((entry) => toModelEntry(entry)?.model ?? ""), note);
|
|
5164
|
+
return { primary: chain[start], fallbacks: chain.slice(start + 1) };
|
|
5165
|
+
}
|
|
5166
|
+
|
|
5115
5167
|
// ../plugin/src/shared/model-suggestion-retry.ts
|
|
5116
5168
|
var ABORT_CALL_TIMEOUT_MS = 3000;
|
|
5117
5169
|
function copyPromptArgs(args, body) {
|
|
@@ -5350,14 +5402,11 @@ function throwWithPromptFailure(legacyError, failedAttempts, args, timeoutMs, tr
|
|
|
5350
5402
|
const error = legacyError instanceof Error ? legacyError : new Error(extractMessage(legacyError));
|
|
5351
5403
|
const last = failedAttempts.at(-1);
|
|
5352
5404
|
const failureClass = last?.failureClass ?? "unknown";
|
|
5353
|
-
const
|
|
5354
|
-
if (quota && error !== quota && !error.message.includes(quota.message))
|
|
5355
|
-
error.message = `${quota.message}; ${error.message}`;
|
|
5356
|
-
const providerError = failureClass === "provider_error" || quota ? sanitizeDiagnosticText(`${quota ? `${quota.message}; ` : ""}${shortErr(last?.error ?? legacyError)}`).slice(0, 500) : null;
|
|
5405
|
+
const providerError = failureClass === "provider_error" ? sanitizeDiagnosticText(shortErr(last?.error ?? legacyError)).slice(0, 500) : null;
|
|
5357
5406
|
promptFailureDetails.set(error, {
|
|
5358
5407
|
failureClass,
|
|
5359
5408
|
modelAttempted: last?.attempt.label ?? null,
|
|
5360
|
-
modelsTried: failedAttempts.
|
|
5409
|
+
modelsTried: failedAttempts.map((failure) => failure.attempt.label),
|
|
5361
5410
|
providerError,
|
|
5362
5411
|
timeoutMs: failureClass === "provider_timeout" ? timeoutMs : null,
|
|
5363
5412
|
childSessionId: transport ? transport.childSessionId ?? null : args.path.id || null,
|
|
@@ -5374,6 +5423,8 @@ async function attemptOnce(client, args, timeoutMs, signal, callContext, label,
|
|
|
5374
5423
|
await promptWithTimeout(client, attemptArgs, timeoutMs, signal, transport, firstOutputTimeoutMs);
|
|
5375
5424
|
return;
|
|
5376
5425
|
} catch (error) {
|
|
5426
|
+
if (!signal?.aborted && !isPromptTimeoutError(error))
|
|
5427
|
+
hiddenModelCooldowns.record(label, error);
|
|
5377
5428
|
if (isNonRetryable(error, signal) || !allowModelSuggestions)
|
|
5378
5429
|
throw error;
|
|
5379
5430
|
const suggestion = parseModelSuggestion(error);
|
|
@@ -5414,7 +5465,19 @@ function createChainClock(options, timeoutMs) {
|
|
|
5414
5465
|
}
|
|
5415
5466
|
};
|
|
5416
5467
|
}
|
|
5468
|
+
function cooldownStart(args, options) {
|
|
5469
|
+
const model = args.body.model;
|
|
5470
|
+
if (!model)
|
|
5471
|
+
return { args, options };
|
|
5472
|
+
const selected = selectHiddenModelStart({ model: `${model.providerID}/${model.modelID}`, qualifier: args.body.variant }, options.fallbackModels, log2);
|
|
5473
|
+
const { variant: _variant, ...body } = args.body;
|
|
5474
|
+
return {
|
|
5475
|
+
args: copyPromptArgs(args, { ...body, ...modelBodyField(selected.primary) }),
|
|
5476
|
+
options: { ...options, fallbackModels: selected.fallbacks }
|
|
5477
|
+
};
|
|
5478
|
+
}
|
|
5417
5479
|
async function promptSyncWithModelSuggestionRetry(client, args, options = {}) {
|
|
5480
|
+
({ args, options } = cooldownStart(args, options));
|
|
5418
5481
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
5419
5482
|
const callContext = options.callContext ?? "subagent";
|
|
5420
5483
|
const fallbacks = options.fallbackModels ?? [];
|
|
@@ -5486,6 +5549,8 @@ async function attemptAndValidate(client, args, timeoutMs, signal, callContext,
|
|
|
5486
5549
|
try {
|
|
5487
5550
|
output = await raceWithSignal(options.fetchOutput(args, attempt), options.signal);
|
|
5488
5551
|
} catch (error) {
|
|
5552
|
+
if (!signal?.aborted && !isPromptTimeoutError(error))
|
|
5553
|
+
hiddenModelCooldowns.record(attempt.label, error);
|
|
5489
5554
|
throw {
|
|
5490
5555
|
error,
|
|
5491
5556
|
failureClass: classifyPromptFailure(error, "output", signal),
|
|
@@ -5497,7 +5562,7 @@ async function attemptAndValidate(client, args, timeoutMs, signal, callContext,
|
|
|
5497
5562
|
const text = extractLatestAssistantText(messages);
|
|
5498
5563
|
if (text) {
|
|
5499
5564
|
const failure = providerOutputFailureFromInvalidManifest(messages, text);
|
|
5500
|
-
if (failure
|
|
5565
|
+
if (failure && isAccountPoolQuotaNotice(text))
|
|
5501
5566
|
throw failure;
|
|
5502
5567
|
}
|
|
5503
5568
|
if (!extractLatestAssistantText(output)) {
|
|
@@ -5506,11 +5571,14 @@ async function attemptAndValidate(client, args, timeoutMs, signal, callContext,
|
|
|
5506
5571
|
const error = new Error(`Host recorded assistant error: ${describeAssistantError(assistantFailure.error)}`);
|
|
5507
5572
|
Object.assign(error, {
|
|
5508
5573
|
name: "DreamerProviderOutputFailureError",
|
|
5509
|
-
transient: true
|
|
5574
|
+
transient: true,
|
|
5575
|
+
hostError: assistantFailure.error
|
|
5510
5576
|
});
|
|
5577
|
+
hiddenModelCooldowns.record(attempt.label, assistantFailure.error);
|
|
5511
5578
|
throw error;
|
|
5512
5579
|
}
|
|
5513
5580
|
}
|
|
5581
|
+
hiddenModelCooldowns.succeeded(attempt.label);
|
|
5514
5582
|
const validated = await options.validateOutput(output, attempt);
|
|
5515
5583
|
return { output, validated, attempt };
|
|
5516
5584
|
} catch (error) {
|
|
@@ -5525,6 +5593,7 @@ async function attemptAndValidate(client, args, timeoutMs, signal, callContext,
|
|
|
5525
5593
|
}
|
|
5526
5594
|
}
|
|
5527
5595
|
async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
5596
|
+
({ args, options } = cooldownStart(args, options));
|
|
5528
5597
|
const timeoutMs = options.timeoutMs ?? 300000;
|
|
5529
5598
|
const callContext = options.callContext ?? "subagent";
|
|
5530
5599
|
const fallbacks = options.fallbackModels ?? [];
|
|
@@ -5535,23 +5604,9 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
5535
5604
|
const failedAttempts = [];
|
|
5536
5605
|
let firstError = null;
|
|
5537
5606
|
let lastError = null;
|
|
5538
|
-
const cooledPrimary = primaryQuotaFailure(explicitPrimaryLabel);
|
|
5539
5607
|
const clock = createChainClock(options, timeoutMs);
|
|
5540
5608
|
const primaryStartedAt = Date.now();
|
|
5541
5609
|
try {
|
|
5542
|
-
if (cooledPrimary)
|
|
5543
|
-
throw {
|
|
5544
|
-
error: cooledPrimary,
|
|
5545
|
-
failureClass: "provider_error",
|
|
5546
|
-
attempt: {
|
|
5547
|
-
label: explicitPrimaryLabel,
|
|
5548
|
-
attemptIndex: 0,
|
|
5549
|
-
isFallback: false,
|
|
5550
|
-
totalAttempts,
|
|
5551
|
-
model: baseBody.model,
|
|
5552
|
-
skipped: true
|
|
5553
|
-
}
|
|
5554
|
-
};
|
|
5555
5610
|
const budget = clock.budget(0);
|
|
5556
5611
|
return await attemptAndValidate(client, baseArgs, budget.timeoutMs, options.signal, callContext, {
|
|
5557
5612
|
label: explicitPrimaryLabel,
|
|
@@ -5566,19 +5621,13 @@ async function promptSyncWithValidatedOutputRetry(client, args, options) {
|
|
|
5566
5621
|
clock.settle(failure.error, primaryStartedAt);
|
|
5567
5622
|
firstError = failure.error;
|
|
5568
5623
|
lastError = failure.error;
|
|
5569
|
-
if (failure.error instanceof DreamerProviderOutputFailureError && failure.error.quotaResetAt !== undefined)
|
|
5570
|
-
failure.error.message = failure.error.message.replace(/^provider quota exhausted/, "primary quota exhausted");
|
|
5571
|
-
const quota = !cooledPrimary && rememberPrimaryQuota(explicitPrimaryLabel, failure.error);
|
|
5572
|
-
if (quota)
|
|
5573
|
-
log2(`[${callContext}] ${quota.message}; skipping ${explicitPrimaryLabel} for this run until reset`);
|
|
5574
5624
|
if (isNonRetryable(failure.error, options.signal)) {
|
|
5575
5625
|
throwWithPromptFailure(failure.error, failedAttempts, args, timeoutMs, options.transport);
|
|
5576
5626
|
}
|
|
5577
5627
|
if (fallbacks.length === 0) {
|
|
5578
5628
|
throwWithPromptFailure(failure.error, failedAttempts, args, timeoutMs, options.transport);
|
|
5579
5629
|
}
|
|
5580
|
-
|
|
5581
|
-
log2(`[${callContext}] primary (${explicitPrimaryLabel}) failed validation/prompt: ${shortErr(failure.error)}; ${fallbacks.length} fallback(s) configured, subject to remaining budget`);
|
|
5630
|
+
log2(`[${callContext}] primary (${explicitPrimaryLabel}) failed validation/prompt: ${shortErr(failure.error)}; ${fallbacks.length} fallback(s) configured, subject to remaining budget`);
|
|
5582
5631
|
}
|
|
5583
5632
|
for (let i = 0;i < fallbacks.length; i += 1) {
|
|
5584
5633
|
const fallback = toModelEntry(fallbacks[i]);
|
|
@@ -9825,7 +9874,7 @@ function createV1HiddenCompletionExecutor(client, db, directory) {
|
|
|
9825
9874
|
preferResponseOnMissingData: true
|
|
9826
9875
|
});
|
|
9827
9876
|
const assistantFailure = extractLatestAssistantFailure(messages);
|
|
9828
|
-
const hostError = hostErrors.get(handle.id);
|
|
9877
|
+
const hostError = assistantFailure?.error ?? hostErrors.get(handle.id);
|
|
9829
9878
|
if (assistantFailure || hostError !== undefined) {
|
|
9830
9879
|
const finish = assistantFailure?.finish ? ` (finish=${assistantFailure.finish})` : "";
|
|
9831
9880
|
const error = new Error(`Historian host recorded an assistant error${finish}: ${describeAssistantFailure(assistantFailure?.error ?? hostError)}`, hostError === undefined ? undefined : { cause: hostError });
|
|
@@ -9874,6 +9923,8 @@ function historianReasoningBudgetDiagnostic(outputTokens, tokens) {
|
|
|
9874
9923
|
return `historian ran out of output budget while reasoning (length-capped at ${outputTokens} tokens, no text${tokens ? `; ${formatRunTokenLog(tokens)}` : ""}) — set historian.maxTokens or route historian.model to a low-reasoning lane/variant`;
|
|
9875
9924
|
}
|
|
9876
9925
|
async function runValidatedHistorianPass(args) {
|
|
9926
|
+
const selected = selectHiddenModelStart(args.model, args.fallbackModels, (message) => sessionLog2(args.parentSessionId, message));
|
|
9927
|
+
args = { ...args, model: selected.primary, fallbackModels: selected.fallbacks };
|
|
9877
9928
|
const firstRun = await runHistorianPrompt({
|
|
9878
9929
|
...args,
|
|
9879
9930
|
dumpLabel: `${args.dumpLabelBase}-initial`,
|
|
@@ -10132,6 +10183,7 @@ async function runHistorianPrompt(args) {
|
|
|
10132
10183
|
}
|
|
10133
10184
|
}
|
|
10134
10185
|
completion = await executor.collect(handle, 50);
|
|
10186
|
+
hiddenModelCooldowns.succeeded(handle.attemptedModel ?? toModelEntry(modelOverride)?.model);
|
|
10135
10187
|
const lengthCapped = completion.lengthCapped;
|
|
10136
10188
|
const tokens = {
|
|
10137
10189
|
...runTokenLog(undefined, args.maxOutputTokens),
|
|
@@ -10168,6 +10220,7 @@ async function runHistorianPrompt(args) {
|
|
|
10168
10220
|
const dumpPath = dumpHistorianResponse(parentSessionId, sessionDirectory, dumpLabel ?? "historian-response", result);
|
|
10169
10221
|
return { ok: true, result, dumpPath, invocationId: invocationId ?? undefined };
|
|
10170
10222
|
} catch (modelError) {
|
|
10223
|
+
hiddenModelCooldowns.record(handle?.attemptedModel ?? toModelEntry(modelOverride)?.model, modelError);
|
|
10171
10224
|
const desc = describeError(modelError);
|
|
10172
10225
|
sessionLog2(parentSessionId, `historian prompt failed: ${desc.brief} promptLength=${prompt.length}${desc.stackHead ? ` stackHead="${desc.stackHead}"` : ""}`);
|
|
10173
10226
|
recordInvocation({
|
|
@@ -12641,6 +12694,7 @@ function writeDocsProposal(projectDir, output, budget, expected, head) {
|
|
|
12641
12694
|
const result = validateDocsProposal(projectDir, output, budget, expected);
|
|
12642
12695
|
const dir = proposalDir(projectDir);
|
|
12643
12696
|
mkdirSync2(join8(dir, "superseded"), { recursive: true });
|
|
12697
|
+
ensureCortexKitArtifactGitignore(projectDir);
|
|
12644
12698
|
const stamp = `${new Date().toISOString().replace(/[:.]/g, "-")}-${Math.random().toString(36).slice(2, 8)}`;
|
|
12645
12699
|
const path = join8(dir, `${stamp}.md`);
|
|
12646
12700
|
const body = `# Docs update proposal
|
|
@@ -17333,9 +17387,6 @@ function closeBroadCycle(args, cycleStartAt) {
|
|
|
17333
17387
|
});
|
|
17334
17388
|
}
|
|
17335
17389
|
async function runVerify(args) {
|
|
17336
|
-
return withDreamerModelCooldown(() => runVerifyWithCooldown(args));
|
|
17337
|
-
}
|
|
17338
|
-
async function runVerifyWithCooldown(args) {
|
|
17339
17390
|
const runStartedAt = Date.now();
|
|
17340
17391
|
const result = {
|
|
17341
17392
|
verified: 0,
|
|
@@ -19518,9 +19569,6 @@ function recordTransientFailure(db, projectIdentity, due, finishedAt, error, sch
|
|
|
19518
19569
|
var LEASE_WAIT_POLL_MS = 2000;
|
|
19519
19570
|
var MANUAL_RUN_LEASE_WAIT_MS = 60000;
|
|
19520
19571
|
async function runDomainGroup(deps, group, cb) {
|
|
19521
|
-
return withDreamerModelCooldown(() => runDomainGroupWithCooldown(deps, group, cb));
|
|
19522
|
-
}
|
|
19523
|
-
async function runDomainGroupWithCooldown(deps, group, cb) {
|
|
19524
19572
|
const { db, projectIdentity, executor } = deps;
|
|
19525
19573
|
const leaseKey = leaseKeyFor(group[0].config.task, projectIdentity);
|
|
19526
19574
|
const holderId = crypto.randomUUID();
|
|
@@ -24633,6 +24681,7 @@ var pendingDecisionBySession = new Map;
|
|
|
24633
24681
|
var pendingPiDecisionBySession = new Map;
|
|
24634
24682
|
var lastBoundMessageIdBySession = new Map;
|
|
24635
24683
|
var scheduledWriteTokensBySession = new Map;
|
|
24684
|
+
var scheduledWriteWaitersBySession = new Map;
|
|
24636
24685
|
var systemHashChangedSessions = new Set;
|
|
24637
24686
|
var piSystemHashChangedSessions = new Set;
|
|
24638
24687
|
var unbustedPassBySession = new Map;
|
|
@@ -24757,8 +24806,12 @@ function deleteScheduledWriteToken(sessionId, token) {
|
|
|
24757
24806
|
if (!tokens)
|
|
24758
24807
|
return;
|
|
24759
24808
|
tokens.delete(token);
|
|
24760
|
-
if (tokens.size === 0)
|
|
24809
|
+
if (tokens.size === 0) {
|
|
24761
24810
|
scheduledWriteTokensBySession.delete(sessionId);
|
|
24811
|
+
for (const resolve of scheduledWriteWaitersBySession.get(sessionId) ?? [])
|
|
24812
|
+
resolve();
|
|
24813
|
+
scheduledWriteWaitersBySession.delete(sessionId);
|
|
24814
|
+
}
|
|
24762
24815
|
}
|
|
24763
24816
|
function findNewestPiAssistantEntryIdAfter(entries, snapshotNewestAssistantEntryId) {
|
|
24764
24817
|
if (!Array.isArray(entries))
|
|
@@ -25776,10 +25829,6 @@ var NON_EMERGENCY_MAX_CAP = 250000;
|
|
|
25776
25829
|
var FORCE80_MAX_CAP = 500000;
|
|
25777
25830
|
var FORCE95_MAX_CAP = 750000;
|
|
25778
25831
|
var NORMAL_HYSTERESIS_TOKENS = 256;
|
|
25779
|
-
var MIN_FORCE_ELIGIBLE_TOKENS_CAP = 1000;
|
|
25780
|
-
function deriveMinForceEligibleTokens(scaledN) {
|
|
25781
|
-
return Math.min(MIN_FORCE_ELIGIBLE_TOKENS_CAP, Math.max(1, Math.floor(scaledN / 8)));
|
|
25782
|
-
}
|
|
25783
25832
|
function clampPercentage(value) {
|
|
25784
25833
|
if (!Number.isFinite(value))
|
|
25785
25834
|
return 0;
|
|
@@ -26024,6 +26073,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
26024
26073
|
priorBoundaryOrdinal: ctx.priorBoundaryOrdinal,
|
|
26025
26074
|
migrationFloorActive: ctx.migrationFloorActive,
|
|
26026
26075
|
emergencyTailScale: ctx.emergencyTailScale,
|
|
26076
|
+
recovery: ctx.recovery,
|
|
26027
26077
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
26028
26078
|
cacheNamespace: ctx.cacheNamespace,
|
|
26029
26079
|
createdAt,
|
|
@@ -26068,6 +26118,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
26068
26118
|
priorBoundaryOrdinal: ctx.priorBoundaryOrdinal,
|
|
26069
26119
|
migrationFloorActive: false,
|
|
26070
26120
|
emergencyTailScale: ctx.emergencyTailScale,
|
|
26121
|
+
recovery: ctx.recovery,
|
|
26071
26122
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
26072
26123
|
cacheNamespace: ctx.cacheNamespace,
|
|
26073
26124
|
createdAt,
|
|
@@ -26183,6 +26234,7 @@ function resolveProtectedTailBoundary(ctx) {
|
|
|
26183
26234
|
priorBoundaryOrdinal: ctx.priorBoundaryOrdinal,
|
|
26184
26235
|
migrationFloorActive: ctx.migrationFloorActive,
|
|
26185
26236
|
emergencyTailScale: ctx.emergencyTailScale,
|
|
26237
|
+
recovery: ctx.recovery,
|
|
26186
26238
|
liftLivePromptFloor: ctx.liftLivePromptFloor === true ? true : undefined,
|
|
26187
26239
|
providerShapeVersion: ctx.providerShapeVersion,
|
|
26188
26240
|
cacheNamespace: ctx.cacheNamespace,
|
|
@@ -26261,6 +26313,7 @@ function resolveBoundaryContext(args) {
|
|
|
26261
26313
|
protectedTailPolicyVersion: meta.protectedTailPolicyVersion,
|
|
26262
26314
|
migrationFloorActive,
|
|
26263
26315
|
emergencyTailScale: args.emergencyTailScale,
|
|
26316
|
+
recovery: args.recovery,
|
|
26264
26317
|
liftLivePromptFloor: args.liftLivePromptFloor,
|
|
26265
26318
|
providerShapeVersion: args.providerShapeVersion ?? "opencode-v1",
|
|
26266
26319
|
cacheNamespace: args.cacheNamespace ?? `opencode:${args.sessionId}`,
|
|
@@ -26441,9 +26494,11 @@ function hasRunnableCompartmentWindow(snapshot) {
|
|
|
26441
26494
|
return false;
|
|
26442
26495
|
if (snapshot.eligibleEndOrdinal <= snapshot.offset)
|
|
26443
26496
|
return false;
|
|
26497
|
+
if (snapshot.recovery || snapshot.usagePercentage >= 95 || snapshot.mode === "manual-wrapup" || snapshot.mode === "manual-full-recomp")
|
|
26498
|
+
return true;
|
|
26444
26499
|
const forceMaterializationPercentage = escalationBands(snapshot.executeThresholdPercentage).forceMaterializationPercentage;
|
|
26445
26500
|
if (snapshot.usagePercentage >= forceMaterializationPercentage || snapshot.emergencyTailScale) {
|
|
26446
|
-
return snapshot.
|
|
26501
|
+
return snapshot.summaryRemovedEligibleTokens >= snapshot.contextLimit * 0.02;
|
|
26447
26502
|
}
|
|
26448
26503
|
return snapshot.eligibleEndOrdinal > snapshot.offset;
|
|
26449
26504
|
}
|
|
@@ -26856,9 +26911,13 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
26856
26911
|
}
|
|
26857
26912
|
return { shouldFire: false };
|
|
26858
26913
|
}
|
|
26914
|
+
const recovery = getOverflowState(db, sessionId).needsEmergencyRecovery;
|
|
26915
|
+
if (tailInfo.boundarySnapshot && recovery) {
|
|
26916
|
+
tailInfo.boundarySnapshot = { ...tailInfo.boundarySnapshot, recovery: true };
|
|
26917
|
+
}
|
|
26859
26918
|
if (tailInfo.boundarySnapshot && shouldWaitForNewHistorianHistory(tailInfo.boundarySnapshot, {
|
|
26860
26919
|
usagePercentage: usage.percentage,
|
|
26861
|
-
emergency:
|
|
26920
|
+
emergency: recovery
|
|
26862
26921
|
})) {
|
|
26863
26922
|
sessionLog2(sessionId, "compartment trigger: waiting for new history after no forward progress");
|
|
26864
26923
|
return { shouldFire: false };
|
|
@@ -26900,13 +26959,14 @@ function checkCompartmentTrigger(db, sessionId, sessionMeta, usage, _previousPer
|
|
|
26900
26959
|
executeThresholdPercentage,
|
|
26901
26960
|
usage,
|
|
26902
26961
|
usageSource: "live",
|
|
26903
|
-
emergencyTailScale: scale
|
|
26962
|
+
emergencyTailScale: scale,
|
|
26963
|
+
recovery
|
|
26904
26964
|
});
|
|
26905
26965
|
});
|
|
26906
26966
|
if (hasRunnableCompartmentWindow(scaledBoundary)) {
|
|
26907
26967
|
return { shouldFire: true, reason: "force_band", boundarySnapshot: scaledBoundary };
|
|
26908
26968
|
}
|
|
26909
|
-
sessionLog2(sessionId, "compartment trigger: force_band skipped —
|
|
26969
|
+
sessionLog2(sessionId, "compartment trigger: force_band skipped — no protected head meets summary admission after emergency tail scale");
|
|
26910
26970
|
return { shouldFire: false };
|
|
26911
26971
|
}
|
|
26912
26972
|
const clusterEnabled = commitClusterTrigger?.enabled ?? true;
|
|
@@ -27964,9 +28024,9 @@ function resolveUnknownUsageFromWireEstimate(input) {
|
|
|
27964
28024
|
}
|
|
27965
28025
|
|
|
27966
28026
|
// ../plugin/src/hooks/magic-context/transform-stage-logger.ts
|
|
27967
|
-
import { AsyncLocalStorage
|
|
28027
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
27968
28028
|
var SLOW_STAGE_MS = 100;
|
|
27969
|
-
var passes = new
|
|
28029
|
+
var passes = new AsyncLocalStorage;
|
|
27970
28030
|
async function withTransformTimingSummary(run) {
|
|
27971
28031
|
const pass = {
|
|
27972
28032
|
stages: [],
|
|
@@ -30449,7 +30509,10 @@ async function runPiHistorian(deps) {
|
|
|
30449
30509
|
}) : { ok: true };
|
|
30450
30510
|
if (!validation.ok && validation.reason === "stale_snapshot" && refreshBoundarySnapshot) {
|
|
30451
30511
|
try {
|
|
30452
|
-
const refreshed =
|
|
30512
|
+
const refreshed = {
|
|
30513
|
+
...refreshBoundarySnapshot(boundarySnapshot),
|
|
30514
|
+
recovery: boundarySnapshot.recovery || forceDrainQuota
|
|
30515
|
+
};
|
|
30453
30516
|
if (hasRunnableCompartmentWindow(refreshed)) {
|
|
30454
30517
|
sessionLog2(sessionId, `historian: refreshed stale protected-tail snapshot at run time (was: ${validation.detail ?? "stale"}) — eligible head ${refreshed.offset}-${refreshed.eligibleEndOrdinal - 1}`);
|
|
30455
30518
|
boundarySnapshot = refreshed;
|
|
@@ -48234,6 +48297,7 @@ function maybeFireHistorian(args) {
|
|
|
48234
48297
|
providerShapeVersion: "pi-folded-v1",
|
|
48235
48298
|
cacheNamespace: `pi:${sessionId}`,
|
|
48236
48299
|
emergencyTailScale,
|
|
48300
|
+
recovery: historianStateSnapshot.needsEmergencyRecovery,
|
|
48237
48301
|
liftLivePromptFloor
|
|
48238
48302
|
}));
|
|
48239
48303
|
const resolveRunnablePiBoundarySnapshot = (stale) => {
|
|
@@ -51212,6 +51276,8 @@ function renderUserStatusSummary(summary, style) {
|
|
|
51212
51276
|
values.push(["Dreamer skipped", skipped]);
|
|
51213
51277
|
for (const quota of summary.dreamerQuotas ?? [])
|
|
51214
51278
|
values.push(["Dreamer quota", quota]);
|
|
51279
|
+
for (const quota of summary.hiddenModelSkips ?? [])
|
|
51280
|
+
values.push(["Hidden model quota", quota]);
|
|
51215
51281
|
if (summary.historianRefusal) {
|
|
51216
51282
|
values.push([
|
|
51217
51283
|
"Historian refusal",
|
|
@@ -51400,6 +51466,7 @@ function checkStatusViewSource(candidate) {
|
|
|
51400
51466
|
lastDreamerRunAt: optional.read("lastDreamerRunAt", isNullableNumber),
|
|
51401
51467
|
dreamerUnsupportedTasks: optional.readArray("dreamerUnsupportedTasks", isString),
|
|
51402
51468
|
dreamerSkipped: optional.readArray("dreamerSkipped", isString),
|
|
51469
|
+
hiddenModelSkips: optional.readArray("hiddenModelSkips", isString),
|
|
51403
51470
|
dreamerFailures: optional.readArray("dreamerFailures", (value) => isRecord6(value) && isString(value.task) && isString(value.error)),
|
|
51404
51471
|
dreamerTickFailure: optional.read("dreamerTickFailure", (value) => value === null || isTickFailure(value)),
|
|
51405
51472
|
sessionNoteCount: optional.read("sessionNoteCount", isNumber),
|
|
@@ -51738,6 +51805,11 @@ function dreamerTickFailureRows(source, now) {
|
|
|
51738
51805
|
return quota ? [quota] : [];
|
|
51739
51806
|
}))
|
|
51740
51807
|
].map((value) => ({ label: "Dreamer quota", value, tone: "warning" }));
|
|
51808
|
+
quotas.push(...(source.hiddenModelSkips ?? []).map((value) => ({
|
|
51809
|
+
label: "Hidden model quota",
|
|
51810
|
+
value,
|
|
51811
|
+
tone: "warning"
|
|
51812
|
+
})));
|
|
51741
51813
|
const failure = source.dreamerTickFailure;
|
|
51742
51814
|
if (!failure)
|
|
51743
51815
|
return quotas;
|
|
@@ -53766,9 +53838,9 @@ var PI_STARTUP_MAINTENANCE_SCHEDULED = Symbol.for("magic-context.pi.startup-main
|
|
|
53766
53838
|
function getPiChildInitContext() {
|
|
53767
53839
|
const globals = globalThis;
|
|
53768
53840
|
const existing = globals[PI_CHILD_INIT_CONTEXT];
|
|
53769
|
-
if (existing instanceof
|
|
53841
|
+
if (existing instanceof AsyncLocalStorage2)
|
|
53770
53842
|
return existing;
|
|
53771
|
-
const context = new
|
|
53843
|
+
const context = new AsyncLocalStorage2;
|
|
53772
53844
|
globals[PI_CHILD_INIT_CONTEXT] = context;
|
|
53773
53845
|
return context;
|
|
53774
53846
|
}
|