@cortexkit/opencode-magic-context 0.49.52 → 0.49.53
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 +3 -3
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-bkkd7br4.js → context-p6r0bk7a.js} +90 -51
- package/dist/{embedding-backfill-3wdjzrvs.js → embedding-backfill-qes2kf1c.js} +2 -2
- package/dist/features/magic-context/compartment-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/message-fts-session-filter.d.ts +1 -1
- package/dist/features/magic-context/message-fts-session-filter.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +8 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts +10 -3
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +19 -0
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -1
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -1
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts +6 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +2 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-served-rows.d.ts +12 -2
- package/dist/hooks/magic-context/host-served-rows.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +10 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts +43 -0
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +102 -26
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +18 -2
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-marker-rearm.d.ts +20 -0
- package/dist/hooks/magic-context/pending-marker-rearm.d.ts.map +1 -0
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts +7 -0
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts.map +1 -1
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts +11 -1
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/served-check.d.ts +127 -0
- package/dist/hooks/magic-context/served-check.d.ts.map +1 -0
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts +32 -4
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +33 -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-x7jcqpy6.js → index-2ctn7q09.js} +531 -17
- package/dist/{index-bamnjp2t.js → index-2m54t4g1.js} +9 -5
- package/dist/{index-qbda6a8k.js → index-3b5k5vma.js} +27 -16
- package/dist/{index-0jc25yjf.js → index-3h0wyv22.js} +3 -3
- package/dist/{index-x4h461yf.js → index-3hhq18q0.js} +1 -1
- package/dist/{index-kaqs6h31.js → index-52x68mj4.js} +1 -1
- package/dist/{index-4xpff2m1.js → index-5684dzbv.js} +647 -69
- package/dist/{index-g3j49m95.js → index-7wasafnb.js} +1 -1
- package/dist/{index-8d7gkgjs.js → index-85chg6fw.js} +1 -1
- package/dist/{index-a4zmmhxs.js → index-a6bxwv4a.js} +1 -1
- package/dist/{index-42n4fhxy.js → index-chjsdqg6.js} +17 -10
- package/dist/{index-fxgaaptn.js → index-esm4farg.js} +8 -7
- package/dist/{index-qtpkkzan.js → index-fbs0f5ch.js} +4 -4
- package/dist/{index-xqhejxmd.js → index-kwpweqzs.js} +1 -1
- package/dist/{index-9gs34125.js → index-n3rxwtwt.js} +47 -14
- package/dist/{index-kanfby7e.js → index-p7ssfv6p.js} +381 -369
- package/dist/{index-k2efzh9r.js → index-pgbmbtdq.js} +4 -4
- package/dist/{index-q9m97m5g.js → index-wpab17w4.js} +1 -1
- package/dist/index.js +53 -32
- package/dist/{message-index-bounded-71b75npz.js → message-index-bounded-7p3064st.js} +2 -2
- package/dist/migration-worker.js +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts +6 -0
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/{project-embedding-registry-5dwh5zfn.js → project-embedding-registry-m8t547fb.js} +3 -1
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{read-session-chunk-bfv831yx.js → read-session-chunk-cyks9yx4.js} +1 -1
- package/dist/{recomp-orchestrator-8gj1b7pz.js → recomp-orchestrator-d4nks9da.js} +9 -9
- package/dist/{render-b3zcz9x4.js → render-gc1fn4nz.js} +5 -5
- package/dist/{search-y3w590tn.js → search-1bjy7yhc.js} +8 -8
- package/dist/{search-archive-dp9afcv1.js → search-archive-hdrfjgv8.js} +4 -4
- package/dist/shared/test-open-files.d.ts +17 -0
- package/dist/shared/test-open-files.d.ts.map +1 -0
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-8awze16a.js → transform-postprocess-phase-9e53b1dr.js} +10 -10
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-99v7x7fm.js → context-1p22880w.js} +961 -344
- package/dist/v2/{embedding-backfill-x1zpc04f.js → embedding-backfill-bwcmw1te.js} +2 -2
- package/dist/v2/fold/instruction-supersession.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-2pev910h.js → message-index-bounded-mjpxz7wp.js} +2 -2
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-v2fxrs8b.js → project-embedding-registry-7qcs8c61.js} +3 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
- package/dist/v2/{read-session-chunk-a454a4d2.js → read-session-chunk-cxk2kssy.js} +1 -1
- package/dist/v2/{recomp-orchestrator-03fskpsa.js → recomp-orchestrator-e560ryjm.js} +8 -8
- package/dist/v2/{render-cryx4xsj.js → render-rk17pvy0.js} +5 -5
- package/dist/v2/{search-archive-xw2rsq81.js → search-archive-a51g9sp7.js} +4 -4
- package/dist/v2/{search-2qj4w7rw.js → search-kvzyj2mf.js} +7 -7
- package/dist/v2/{server-kreheyw5.js → server-28g1b00j.js} +1 -1
- package/dist/v2/{server-kaqs6h31.js → server-52x68mj4.js} +1 -1
- package/dist/v2/{server-cpstyzvy.js → server-71bg2psk.js} +3 -3
- package/dist/v2/{server-qsvm6w79.js → server-77rvx3wn.js} +33 -14
- package/dist/v2/{server-txdsx71h.js → server-ah1j996f.js} +1 -1
- package/dist/v2/{server-dkfs58nq.js → server-bjsmb6zs.js} +1 -1
- package/dist/v2/{server-kfw4m268.js → server-bzh1fkvd.js} +1 -1
- package/dist/v2/{server-vjadwb3j.js → server-d5zgah57.js} +1 -1
- package/dist/v2/{server-y5cma2j1.js → server-e37d2zt4.js} +8 -7
- package/dist/v2/{server-wq9y9a03.js → server-fh6dhx8c.js} +17 -10
- package/dist/v2/{server-xjzx27w2.js → server-jmrd7vwc.js} +26 -15
- package/dist/v2/{server-4h4acntc.js → server-k3vtc89v.js} +9 -5
- package/dist/v2/{server-b3h8vqa6.js → server-zq704789.js} +531 -17
- package/dist/v2/server.js +2 -2
- package/dist/v2/{v2-archive-reader-3575hw8s.js → v2-archive-reader-hsvddme0.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-shzv6t4v.js → wrapup-orchestrator-ckpj1yvj.js} +8 -8
- package/dist/{v2-archive-reader-75fdm0te.js → v2-archive-reader-qgqrxgrq.js} +1 -1
- package/dist/{wrapup-orchestrator-e0z7nvnx.js → wrapup-orchestrator-6189f37j.js} +10 -10
- package/package.json +1 -1
- package/src/shared/escalation-bands.test.ts +16 -1
- package/src/shared/sqlite-placeholders.test.ts +103 -0
- package/src/shared/storage-file-mutex-review.test.ts +5 -7
- package/src/shared/test-open-files.test.ts +194 -0
- package/src/shared/test-open-files.ts +71 -0
|
@@ -60,8 +60,9 @@ import {
|
|
|
60
60
|
parseProcessedImageMarkers,
|
|
61
61
|
serializeProcessedImageMarkers,
|
|
62
62
|
getPendingPiCompactionMarkerState,
|
|
63
|
-
logPiCompactionMarkerClear
|
|
64
|
-
|
|
63
|
+
logPiCompactionMarkerClear,
|
|
64
|
+
isPrefixBoundThinkingModel
|
|
65
|
+
} from "./index-n3rxwtwt.js";
|
|
65
66
|
import {
|
|
66
67
|
stripTagPrefix,
|
|
67
68
|
isRecord,
|
|
@@ -520,7 +521,7 @@ function getUncoveredCompartmentEndsThrough(db, sessionId, endOrdinal = Number.M
|
|
|
520
521
|
const rows = db.prepare(`SELECT k.end_message_id, k.end_message,
|
|
521
522
|
n.start_message_id AS successor_id, n.start_message AS successor_start FROM compartments k
|
|
522
523
|
LEFT JOIN compartments n ON n.session_id = k.session_id AND n.sequence = k.sequence + 1
|
|
523
|
-
WHERE k.session_id = ?
|
|
524
|
+
WHERE k.session_id = ? AND k.end_message <= ? AND k.end_message > ? AND k.end_block_index IS NOT NULL
|
|
524
525
|
AND NOT COALESCE(n.sequence IS NOT NULL AND (
|
|
525
526
|
(n.start_message_id = k.end_message_id AND n.start_block_index > k.end_block_index)
|
|
526
527
|
OR n.start_message = k.end_message + 1), 0)
|
|
@@ -661,7 +662,7 @@ function readProjectDocsCanonical(projectDirectory) {
|
|
|
661
662
|
return { renderedBlock, canonicalHash };
|
|
662
663
|
}
|
|
663
664
|
// src/hooks/magic-context/lkg-slot.ts
|
|
664
|
-
import { createHash as
|
|
665
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
665
666
|
|
|
666
667
|
// src/hooks/magic-context/lkg-measured-request.ts
|
|
667
668
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -2835,6 +2836,7 @@ function coldStartUncapturedReplay(args) {
|
|
|
2835
2836
|
|
|
2836
2837
|
// src/hooks/magic-context/lkg-recovery-prefix.ts
|
|
2837
2838
|
var sessions = new BoundedSessionMap(1000);
|
|
2839
|
+
var restartHeadChecked = new BoundedSessionMap(1000);
|
|
2838
2840
|
function noteUncertifiedNormalLkg(sessionId, revision) {
|
|
2839
2841
|
sessions.set(sessionId, {
|
|
2840
2842
|
...sessions.get(sessionId),
|
|
@@ -2853,6 +2855,7 @@ function rememberLkgDirtyRevision(sessionId, revision) {
|
|
|
2853
2855
|
}
|
|
2854
2856
|
function clearLkgRecoverySession(sessionId) {
|
|
2855
2857
|
sessions.delete(sessionId);
|
|
2858
|
+
restartHeadChecked.delete(sessionId);
|
|
2856
2859
|
clearLkgFenceProcessState(sessionId);
|
|
2857
2860
|
}
|
|
2858
2861
|
function noteLkgCapturedPrefix(sessionId) {
|
|
@@ -2868,13 +2871,14 @@ function readPersistedLkgUntaggedInputIds(db, sessionId) {
|
|
|
2868
2871
|
return [];
|
|
2869
2872
|
}
|
|
2870
2873
|
}
|
|
2871
|
-
function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
2872
|
-
const next = [...new Set(ids)].sort();
|
|
2874
|
+
function persistLkgUntaggedInputIds(db, sessionId, ids, alsoRecord) {
|
|
2875
|
+
const next = ids === undefined ? undefined : [...new Set(ids)].sort();
|
|
2873
2876
|
try {
|
|
2874
2877
|
return updateReplayDocument(db, sessionId, (doc) => {
|
|
2878
|
+
const recorded = alsoRecord?.(doc) ?? false;
|
|
2875
2879
|
const saved = Array.isArray(doc.lkgUntaggedInputIds) ? doc.lkgUntaggedInputIds : [];
|
|
2876
|
-
if (JSON.stringify(saved) === JSON.stringify(next))
|
|
2877
|
-
return
|
|
2880
|
+
if (next === undefined || JSON.stringify(saved) === JSON.stringify(next))
|
|
2881
|
+
return recorded;
|
|
2878
2882
|
doc.version = 2;
|
|
2879
2883
|
if (next.length > 0)
|
|
2880
2884
|
doc.lkgUntaggedInputIds = next;
|
|
@@ -2888,10 +2892,7 @@ function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
|
2888
2892
|
}
|
|
2889
2893
|
}
|
|
2890
2894
|
function noteLkgRecoveryPrefix(args) {
|
|
2891
|
-
const digests = [
|
|
2892
|
-
...args.entry.entryContentDigests,
|
|
2893
|
-
...args.entry.pristineTail.map(lkgContentDigest)
|
|
2894
|
-
];
|
|
2895
|
+
const digests = [...args.entry.entryContentDigests, ...args.hostTailDigests];
|
|
2895
2896
|
if (digests.length !== args.entry.entryInputIds.length || digests.some((value) => !value))
|
|
2896
2897
|
return false;
|
|
2897
2898
|
const ids = args.entry.entryInputIds;
|
|
@@ -2928,8 +2929,15 @@ function readRecoveryIdentityPrefix(sessionId, inputs, messages, db) {
|
|
|
2928
2929
|
const prefix = state?.prefix;
|
|
2929
2930
|
if (!prefix && state?.uncertifiedNormal && ownsLkgDirtyFence(sessionId, state.fenceRevision))
|
|
2930
2931
|
return {};
|
|
2931
|
-
if (!prefix)
|
|
2932
|
-
|
|
2932
|
+
if (!prefix) {
|
|
2933
|
+
let restartedSlotJson;
|
|
2934
|
+
if (!state && slot && !restartHeadChecked.has(sessionId)) {
|
|
2935
|
+
restartHeadChecked.set(sessionId, true);
|
|
2936
|
+
restartedSlotJson = slot.jsonPrefix;
|
|
2937
|
+
}
|
|
2938
|
+
const restarted = restartedSlotJson === undefined ? {} : { restartedSlotJson };
|
|
2939
|
+
return !state && lkgRecoveryFenceUnclean(sessionId) || slot && lkgFenceRequiresRebuild(sessionId, slot, !!state) ? { rebuildReason: "lkg_restart_rebuild", ...restarted } : restarted;
|
|
2940
|
+
}
|
|
2933
2941
|
const keys = resolveLkgModelKeys(messages);
|
|
2934
2942
|
if (state?.fenceRevision !== undefined && (!slot || !ownsLkgDirtyFence(sessionId, state.fenceRevision)) || prefix.modelKey !== keys.modelKey || prefix.providerKey !== keys.providerKey || inputs.length < prefix.inputs.length || prefix.inputs.some((input, index) => input.id !== inputs[index]?.id || input.digest !== inputs[index]?.contentDigest?.()))
|
|
2935
2943
|
return { rebuildReason: "lkg_recovery_input_rebuild" };
|
|
@@ -2964,6 +2972,512 @@ function lkgRecoveryEntryUnproven(sessionId, entry, messages) {
|
|
|
2964
2972
|
return !!readRecoveryIdentityPrefix(sessionId, inputs, messages).rebuildReason;
|
|
2965
2973
|
}
|
|
2966
2974
|
|
|
2975
|
+
// src/hooks/magic-context/served-check.ts
|
|
2976
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
2977
|
+
var RECORD_SESSIONS = 256;
|
|
2978
|
+
var records = new BoundedSessionMap(RECORD_SESSIONS);
|
|
2979
|
+
var pending4 = new BoundedSessionMap(1000);
|
|
2980
|
+
var counters = new BoundedSessionMap(1000);
|
|
2981
|
+
var SERVED_FULL_CHECK_INTERVAL = 100;
|
|
2982
|
+
var COUNT_LOG_INTERVAL = 100;
|
|
2983
|
+
var HEAD_MIN = 2;
|
|
2984
|
+
var HEAD_MAX = 4;
|
|
2985
|
+
var lastWork = { fingerprinted: 0, digested: 0, full: false, ms: 0, shapeMs: 0 };
|
|
2986
|
+
function emptyCounters() {
|
|
2987
|
+
return {
|
|
2988
|
+
commits: 0,
|
|
2989
|
+
compared: 0,
|
|
2990
|
+
unknown: 0,
|
|
2991
|
+
refused: 0,
|
|
2992
|
+
appendOnly: 0,
|
|
2993
|
+
changed: 0,
|
|
2994
|
+
shorter: 0,
|
|
2995
|
+
modelChanged: 0,
|
|
2996
|
+
unpermittedChange: 0,
|
|
2997
|
+
mixedReplay: 0,
|
|
2998
|
+
thinkingPrefixChange: 0,
|
|
2999
|
+
sameShapeChange: 0,
|
|
3000
|
+
fullChecks: 0
|
|
3001
|
+
};
|
|
3002
|
+
}
|
|
3003
|
+
function countersFor(sessionId) {
|
|
3004
|
+
let value = counters.get(sessionId);
|
|
3005
|
+
if (!value) {
|
|
3006
|
+
value = emptyCounters();
|
|
3007
|
+
counters.set(sessionId, value);
|
|
3008
|
+
}
|
|
3009
|
+
return value;
|
|
3010
|
+
}
|
|
3011
|
+
function pendingFor(sessionId) {
|
|
3012
|
+
let value = pending4.get(sessionId);
|
|
3013
|
+
if (!value) {
|
|
3014
|
+
value = {};
|
|
3015
|
+
pending4.set(sessionId, value);
|
|
3016
|
+
}
|
|
3017
|
+
return value;
|
|
3018
|
+
}
|
|
3019
|
+
function beginServedRequest(sessionId) {
|
|
3020
|
+
pending4.delete(sessionId);
|
|
3021
|
+
}
|
|
3022
|
+
function noteServedPassPermission(sessionId, permission) {
|
|
3023
|
+
pendingFor(sessionId).permission = permission;
|
|
3024
|
+
}
|
|
3025
|
+
function noteServedModel(sessionId, model) {
|
|
3026
|
+
if (model)
|
|
3027
|
+
pendingFor(sessionId).model = model;
|
|
3028
|
+
}
|
|
3029
|
+
function noteServedReplay(sessionId) {
|
|
3030
|
+
pendingFor(sessionId).replay = true;
|
|
3031
|
+
}
|
|
3032
|
+
function noteServedHostInput(sessionId) {
|
|
3033
|
+
pendingFor(sessionId).input = true;
|
|
3034
|
+
}
|
|
3035
|
+
function noteServedRefusal(sessionId) {
|
|
3036
|
+
pendingFor(sessionId).refused = true;
|
|
3037
|
+
}
|
|
3038
|
+
function countServedRefusal(sessionId) {
|
|
3039
|
+
try {
|
|
3040
|
+
pending4.delete(sessionId);
|
|
3041
|
+
countersFor(sessionId).refused += 1;
|
|
3042
|
+
} catch {}
|
|
3043
|
+
}
|
|
3044
|
+
function dropServedRecord(sessionId, reason) {
|
|
3045
|
+
try {
|
|
3046
|
+
const value = counters.peek(sessionId);
|
|
3047
|
+
if (value && value.commits + value.refused > 0)
|
|
3048
|
+
logCounts(sessionId, value, reason);
|
|
3049
|
+
if (records.has(sessionId))
|
|
3050
|
+
sessionLog2(sessionId, `served check: record dropped reason=${reason}; the next request is not compared`);
|
|
3051
|
+
} catch {}
|
|
3052
|
+
records.delete(sessionId);
|
|
3053
|
+
pending4.delete(sessionId);
|
|
3054
|
+
counters.delete(sessionId);
|
|
3055
|
+
}
|
|
3056
|
+
function forgetServedRecord(sessionId) {
|
|
3057
|
+
records.delete(sessionId);
|
|
3058
|
+
pending4.delete(sessionId);
|
|
3059
|
+
}
|
|
3060
|
+
function logCounts(sessionId, value, reason) {
|
|
3061
|
+
sessionLog2(sessionId, `served check counts: compared=${value.compared} unknown=${value.unknown} refused=${value.refused} append_only=${value.appendOnly} changed=${value.changed} shorter=${value.shorter} model_changed=${value.modelChanged} unpermitted_change=${value.unpermittedChange} mixed_replay=${value.mixedReplay} thinking_prefix_change=${value.thinkingPrefixChange} same_shape_change=${value.sameShapeChange} full_checks=${value.fullChecks} reason=${reason}`);
|
|
3062
|
+
}
|
|
3063
|
+
function mix(hash, value) {
|
|
3064
|
+
return Math.imul(hash ^ (value | 0), 16777619);
|
|
3065
|
+
}
|
|
3066
|
+
function mixName(hash, value) {
|
|
3067
|
+
if (typeof value !== "string")
|
|
3068
|
+
return mix(hash, value === undefined ? -1 : -2);
|
|
3069
|
+
const length = value.length;
|
|
3070
|
+
const h = mix(hash, length);
|
|
3071
|
+
return length === 0 ? h : mix(h, value.charCodeAt(length - 1) << 16 | value.charCodeAt(length >> 1));
|
|
3072
|
+
}
|
|
3073
|
+
function mixId(hash, value) {
|
|
3074
|
+
if (typeof value !== "string")
|
|
3075
|
+
return mix(hash, value === undefined ? -1 : -2);
|
|
3076
|
+
const length = value.length;
|
|
3077
|
+
let h = mix(hash, length);
|
|
3078
|
+
const stop = length > 8 ? length - 8 : 0;
|
|
3079
|
+
let index = length - 1;
|
|
3080
|
+
for (;index > stop; index -= 2)
|
|
3081
|
+
h = mix(h, value.charCodeAt(index) << 16 | value.charCodeAt(index - 1));
|
|
3082
|
+
if (index === stop && length > 0)
|
|
3083
|
+
h = mix(h, value.charCodeAt(index));
|
|
3084
|
+
return h;
|
|
3085
|
+
}
|
|
3086
|
+
function mixNumber(hash, value) {
|
|
3087
|
+
const whole = Math.trunc(value);
|
|
3088
|
+
return mix(mix(mix(hash, whole), whole / 4294967296), Math.round((value - whole) * 1e6));
|
|
3089
|
+
}
|
|
3090
|
+
function mixLength(hash, value) {
|
|
3091
|
+
return typeof value === "string" ? mix(hash, value.length) : mix(hash, value === undefined ? -1 : -2);
|
|
3092
|
+
}
|
|
3093
|
+
function mixShallow(hash, value) {
|
|
3094
|
+
switch (typeof value) {
|
|
3095
|
+
case "string":
|
|
3096
|
+
return mix(mix(hash, 1), value.length);
|
|
3097
|
+
case "number":
|
|
3098
|
+
return mixNumber(mix(hash, 2), value);
|
|
3099
|
+
case "boolean":
|
|
3100
|
+
return mix(hash, value ? 5 : 4);
|
|
3101
|
+
case "undefined":
|
|
3102
|
+
return mix(hash, -1);
|
|
3103
|
+
case "object":
|
|
3104
|
+
if (value === null)
|
|
3105
|
+
return mix(hash, 3);
|
|
3106
|
+
if (Array.isArray(value))
|
|
3107
|
+
return mix(mix(hash, 9), value.length);
|
|
3108
|
+
{
|
|
3109
|
+
const size = value.byteLength;
|
|
3110
|
+
return typeof size === "number" ? mix(mix(hash, 7), size) : mix(hash, 10);
|
|
3111
|
+
}
|
|
3112
|
+
default:
|
|
3113
|
+
return mix(hash, 6);
|
|
3114
|
+
}
|
|
3115
|
+
}
|
|
3116
|
+
function mixToolState(hash, state) {
|
|
3117
|
+
let h = mixName(hash, state.status);
|
|
3118
|
+
h = mixShallow(h, state.input);
|
|
3119
|
+
h = mixShallow(h, state.output);
|
|
3120
|
+
if (state.error !== undefined)
|
|
3121
|
+
h = mixShallow(h, state.error);
|
|
3122
|
+
if (state.attachments !== undefined)
|
|
3123
|
+
h = mixShallow(h, state.attachments);
|
|
3124
|
+
if (state.content !== undefined)
|
|
3125
|
+
h = mixShallow(h, state.content);
|
|
3126
|
+
const time = state.time;
|
|
3127
|
+
h = mix(h, time && typeof time === "object" && time.compacted !== undefined ? 1 : 0);
|
|
3128
|
+
if (state.status === "error") {
|
|
3129
|
+
const metadata = state.metadata;
|
|
3130
|
+
if (metadata && typeof metadata === "object" && metadata.interrupted === true)
|
|
3131
|
+
h = mixShallow(h, metadata.output);
|
|
3132
|
+
}
|
|
3133
|
+
return h;
|
|
3134
|
+
}
|
|
3135
|
+
function isThinkingType(type) {
|
|
3136
|
+
return type === "reasoning" || type === "thinking" || type === "redacted_thinking";
|
|
3137
|
+
}
|
|
3138
|
+
function isKeptThinkingPart(part) {
|
|
3139
|
+
if (!isThinkingType(part.type) || part.ignored === true)
|
|
3140
|
+
return false;
|
|
3141
|
+
if (part.type === "redacted_thinking" || part.redacted === true)
|
|
3142
|
+
return true;
|
|
3143
|
+
if (typeof part.text === "string" && part.text !== "")
|
|
3144
|
+
return true;
|
|
3145
|
+
if (typeof part.thinking === "string" && part.thinking !== "")
|
|
3146
|
+
return true;
|
|
3147
|
+
const metadata = part.metadata;
|
|
3148
|
+
if (metadata && typeof metadata === "object") {
|
|
3149
|
+
for (const record of Object.values(metadata))
|
|
3150
|
+
if (record && typeof record === "object" && "redactedData" in record)
|
|
3151
|
+
return true;
|
|
3152
|
+
}
|
|
3153
|
+
return false;
|
|
3154
|
+
}
|
|
3155
|
+
var PART_FIELDS = [
|
|
3156
|
+
"text",
|
|
3157
|
+
"thinking",
|
|
3158
|
+
"thinkingSignature",
|
|
3159
|
+
"signature",
|
|
3160
|
+
"redacted",
|
|
3161
|
+
"data",
|
|
3162
|
+
"url",
|
|
3163
|
+
"mime",
|
|
3164
|
+
"mimeType",
|
|
3165
|
+
"mediaType",
|
|
3166
|
+
"filename",
|
|
3167
|
+
"name",
|
|
3168
|
+
"tool",
|
|
3169
|
+
"callID",
|
|
3170
|
+
"toolCallId",
|
|
3171
|
+
"input",
|
|
3172
|
+
"arguments",
|
|
3173
|
+
"output",
|
|
3174
|
+
"error",
|
|
3175
|
+
"isError",
|
|
3176
|
+
"providerExecuted",
|
|
3177
|
+
"synthetic",
|
|
3178
|
+
"ignored"
|
|
3179
|
+
];
|
|
3180
|
+
var walkOut = { partThinking: false, messageThinking: false, messageHead: false };
|
|
3181
|
+
function mixPart(hash, rawPart) {
|
|
3182
|
+
walkOut.partThinking = false;
|
|
3183
|
+
if (!rawPart || typeof rawPart !== "object")
|
|
3184
|
+
return mix(hash, 11);
|
|
3185
|
+
const part = rawPart;
|
|
3186
|
+
const type = part.type;
|
|
3187
|
+
let h = mixId(mixName(hash, type), part.id);
|
|
3188
|
+
if (type === "text") {
|
|
3189
|
+
h = mixLength(h, part.text);
|
|
3190
|
+
return mix(h, (part.synthetic === true ? 1 : 0) | (part.ignored === true ? 2 : 0));
|
|
3191
|
+
}
|
|
3192
|
+
if (type === "tool" && part.state && typeof part.state === "object")
|
|
3193
|
+
return mixToolState(mixId(mixName(h, part.tool), part.callID), part.state);
|
|
3194
|
+
for (let index = 0;index < PART_FIELDS.length; index += 1) {
|
|
3195
|
+
const value = part[PART_FIELDS[index]];
|
|
3196
|
+
if (value !== undefined)
|
|
3197
|
+
h = mixShallow(mix(h, index), value);
|
|
3198
|
+
}
|
|
3199
|
+
const result = part.result;
|
|
3200
|
+
if (result && typeof result === "object") {
|
|
3201
|
+
h = mixName(h, result.type);
|
|
3202
|
+
h = mixShallow(h, result.value);
|
|
3203
|
+
}
|
|
3204
|
+
if (isThinkingType(type)) {
|
|
3205
|
+
walkOut.partThinking = isKeptThinkingPart(part);
|
|
3206
|
+
const metadata = part.metadata;
|
|
3207
|
+
const anthropic = metadata && typeof metadata === "object" ? metadata.anthropic : undefined;
|
|
3208
|
+
if (anthropic && typeof anthropic === "object") {
|
|
3209
|
+
h = mixShallow(h, anthropic.signature);
|
|
3210
|
+
h = mixShallow(h, anthropic.redactedData);
|
|
3211
|
+
} else
|
|
3212
|
+
h = mix(h, metadata && typeof metadata === "object" ? 17 : 18);
|
|
3213
|
+
}
|
|
3214
|
+
return h;
|
|
3215
|
+
}
|
|
3216
|
+
function messageShape(message) {
|
|
3217
|
+
const record = message && typeof message === "object" ? message : {};
|
|
3218
|
+
const info = record.info && typeof record.info === "object" ? record.info : record;
|
|
3219
|
+
const parts = Array.isArray(record.parts) ? record.parts : record.content;
|
|
3220
|
+
const role = info.role;
|
|
3221
|
+
let hash = mixId(2166136261, info.id);
|
|
3222
|
+
hash = mixName(hash, role);
|
|
3223
|
+
if (typeof record.timestamp === "number")
|
|
3224
|
+
hash = mixNumber(hash, record.timestamp);
|
|
3225
|
+
if (typeof record.toolCallId === "string")
|
|
3226
|
+
hash = mixId(hash, record.toolCallId);
|
|
3227
|
+
if (record.isError === true)
|
|
3228
|
+
hash = mix(hash, 12);
|
|
3229
|
+
if (info.summary === true)
|
|
3230
|
+
hash = mix(hash, 13);
|
|
3231
|
+
let thinking = false;
|
|
3232
|
+
let synthetic = info.synthetic === true || info.summary === true;
|
|
3233
|
+
if (typeof parts === "string") {
|
|
3234
|
+
hash = mix(mix(hash, 14), parts.length);
|
|
3235
|
+
} else if (Array.isArray(parts)) {
|
|
3236
|
+
hash = mix(mix(hash, 15), parts.length);
|
|
3237
|
+
let allSynthetic = parts.length > 0;
|
|
3238
|
+
for (const part of parts) {
|
|
3239
|
+
hash = mixPart(hash, part);
|
|
3240
|
+
if (walkOut.partThinking)
|
|
3241
|
+
thinking = true;
|
|
3242
|
+
if (allSynthetic && part?.synthetic !== true)
|
|
3243
|
+
allSynthetic = false;
|
|
3244
|
+
}
|
|
3245
|
+
if (allSynthetic)
|
|
3246
|
+
synthetic = true;
|
|
3247
|
+
} else {
|
|
3248
|
+
hash = mix(hash, 16);
|
|
3249
|
+
}
|
|
3250
|
+
walkOut.messageThinking = thinking && role === "assistant";
|
|
3251
|
+
walkOut.messageHead = synthetic || role === "system" || role === "compactionSummary" || role === "branchSummary";
|
|
3252
|
+
return hash >>> 0;
|
|
3253
|
+
}
|
|
3254
|
+
function digestInto(message, out, index) {
|
|
3255
|
+
let json;
|
|
3256
|
+
try {
|
|
3257
|
+
json = JSON.stringify(contentSnapshotValue(message));
|
|
3258
|
+
} catch {
|
|
3259
|
+
json = undefined;
|
|
3260
|
+
}
|
|
3261
|
+
if (json === undefined) {
|
|
3262
|
+
out[2 * index] = 0;
|
|
3263
|
+
out[2 * index + 1] = 0;
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
const digest = createHash6("sha256").update(json).digest();
|
|
3267
|
+
out[2 * index] = digest.readUInt32LE(0);
|
|
3268
|
+
out[2 * index + 1] = digest.readUInt32LE(4);
|
|
3269
|
+
}
|
|
3270
|
+
function digestsDiffer(a, ai, b, bi) {
|
|
3271
|
+
const a0 = a[2 * ai];
|
|
3272
|
+
const a1 = a[2 * ai + 1];
|
|
3273
|
+
const b0 = b[2 * bi];
|
|
3274
|
+
const b1 = b[2 * bi + 1];
|
|
3275
|
+
if (a0 === 0 && a1 === 0 || b0 === 0 && b1 === 0)
|
|
3276
|
+
return false;
|
|
3277
|
+
return a0 !== b0 || a1 !== b1;
|
|
3278
|
+
}
|
|
3279
|
+
function permittedLabel(permitted) {
|
|
3280
|
+
return permitted === null ? "unknown" : String(permitted);
|
|
3281
|
+
}
|
|
3282
|
+
function commitServedRequest(args) {
|
|
3283
|
+
try {
|
|
3284
|
+
return commit(args);
|
|
3285
|
+
} catch (error) {
|
|
3286
|
+
try {
|
|
3287
|
+
records.delete(args.sessionId);
|
|
3288
|
+
sessionLog2(args.sessionId, "served check failed; the record is unknown again:", error);
|
|
3289
|
+
} catch {}
|
|
3290
|
+
return null;
|
|
3291
|
+
}
|
|
3292
|
+
}
|
|
3293
|
+
function commit(args) {
|
|
3294
|
+
const { sessionId, messages, host } = args;
|
|
3295
|
+
const startedAt = performance.now();
|
|
3296
|
+
const note = pending4.peek(sessionId) ?? {};
|
|
3297
|
+
pending4.delete(sessionId);
|
|
3298
|
+
const count = countersFor(sessionId);
|
|
3299
|
+
const kind = note.replay ? "replay" : note.input ? "input" : "pass";
|
|
3300
|
+
const permission = note.permission;
|
|
3301
|
+
const permitted = permission?.permitted ?? (args.compactionOff ? false : kind === "input" ? false : null);
|
|
3302
|
+
const prior = records.get(sessionId);
|
|
3303
|
+
if (note.refused) {
|
|
3304
|
+
count.refused += 1;
|
|
3305
|
+
return {
|
|
3306
|
+
class: "refused",
|
|
3307
|
+
kind,
|
|
3308
|
+
firstIndex: null,
|
|
3309
|
+
recorded: prior?.count ?? 0,
|
|
3310
|
+
served: messages.length,
|
|
3311
|
+
seenBy: null,
|
|
3312
|
+
keptThinkingIndex: -1,
|
|
3313
|
+
recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
|
|
3314
|
+
permitted,
|
|
3315
|
+
events: []
|
|
3316
|
+
};
|
|
3317
|
+
}
|
|
3318
|
+
count.commits += 1;
|
|
3319
|
+
const m = messages.length;
|
|
3320
|
+
const providerID = note.model?.providerID ?? args.providerID;
|
|
3321
|
+
const modelID = note.model?.modelID ?? args.modelID;
|
|
3322
|
+
const prefixBound = isPrefixBoundThinkingModel(providerID, modelID);
|
|
3323
|
+
const modelKey = modelID ? `${providerID ?? ""}/${modelID}` : null;
|
|
3324
|
+
const shapes = new Uint32Array(m);
|
|
3325
|
+
let keptThinkingIndex = -1;
|
|
3326
|
+
let headCount = Math.min(HEAD_MIN, m);
|
|
3327
|
+
let leading = true;
|
|
3328
|
+
for (let index = 0;index < m; index += 1) {
|
|
3329
|
+
shapes[index] = messageShape(messages[index]);
|
|
3330
|
+
if (prefixBound && keptThinkingIndex < 0 && walkOut.messageThinking)
|
|
3331
|
+
keptThinkingIndex = index;
|
|
3332
|
+
if (leading && index >= HEAD_MIN) {
|
|
3333
|
+
if (walkOut.messageHead && index < HEAD_MAX)
|
|
3334
|
+
headCount = index + 1;
|
|
3335
|
+
else
|
|
3336
|
+
leading = false;
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
const shapeMs = performance.now() - startedAt;
|
|
3340
|
+
const digests = new Uint32Array(2 * m);
|
|
3341
|
+
const computed = new Uint8Array(m);
|
|
3342
|
+
let digested = 0;
|
|
3343
|
+
const digest = (index) => {
|
|
3344
|
+
if (index < 0 || index >= m || computed[index])
|
|
3345
|
+
return;
|
|
3346
|
+
computed[index] = 1;
|
|
3347
|
+
digested += 1;
|
|
3348
|
+
digestInto(messages[index], digests, index);
|
|
3349
|
+
};
|
|
3350
|
+
const finish = (comparison, full, passesSinceFull) => {
|
|
3351
|
+
records.set(sessionId, {
|
|
3352
|
+
count: m,
|
|
3353
|
+
shapes,
|
|
3354
|
+
digests,
|
|
3355
|
+
modelKey: modelKey ?? prior?.modelKey ?? null,
|
|
3356
|
+
kind,
|
|
3357
|
+
keptThinkingIndex,
|
|
3358
|
+
passesSinceFull
|
|
3359
|
+
});
|
|
3360
|
+
lastWork = { fingerprinted: m, digested, full, ms: 0, shapeMs };
|
|
3361
|
+
if (count.commits % COUNT_LOG_INTERVAL === 0)
|
|
3362
|
+
logCounts(sessionId, count, "periodic");
|
|
3363
|
+
lastWork.ms = performance.now() - startedAt;
|
|
3364
|
+
return { ...comparison, kind, permitted, served: m };
|
|
3365
|
+
};
|
|
3366
|
+
const modelChanged = prior !== undefined && prior.modelKey !== null && modelKey !== null && prior.modelKey !== modelKey;
|
|
3367
|
+
if (!prior || modelChanged) {
|
|
3368
|
+
for (let index = 0;index < m; index += 1)
|
|
3369
|
+
digest(index);
|
|
3370
|
+
if (prior)
|
|
3371
|
+
count.modelChanged += 1;
|
|
3372
|
+
else
|
|
3373
|
+
count.unknown += 1;
|
|
3374
|
+
return finish({
|
|
3375
|
+
class: prior ? "model_change" : "unknown",
|
|
3376
|
+
firstIndex: null,
|
|
3377
|
+
recorded: prior?.count ?? 0,
|
|
3378
|
+
seenBy: null,
|
|
3379
|
+
keptThinkingIndex,
|
|
3380
|
+
recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
|
|
3381
|
+
events: []
|
|
3382
|
+
}, true, 0);
|
|
3383
|
+
}
|
|
3384
|
+
count.compared += 1;
|
|
3385
|
+
const n = prior.count;
|
|
3386
|
+
const overlap = Math.min(n, m);
|
|
3387
|
+
let shapeDiff = -1;
|
|
3388
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3389
|
+
if (shapes[index] !== prior.shapes[index]) {
|
|
3390
|
+
shapeDiff = index;
|
|
3391
|
+
break;
|
|
3392
|
+
}
|
|
3393
|
+
for (let index = 0;index < headCount; index += 1)
|
|
3394
|
+
digest(index);
|
|
3395
|
+
digest(n - 1);
|
|
3396
|
+
digest(prior.keptThinkingIndex);
|
|
3397
|
+
digest(keptThinkingIndex);
|
|
3398
|
+
for (let index = n;index < m; index += 1)
|
|
3399
|
+
digest(index);
|
|
3400
|
+
let handfulDiff = -1;
|
|
3401
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3402
|
+
if (computed[index] && digestsDiffer(digests, index, prior.digests, index)) {
|
|
3403
|
+
handfulDiff = index;
|
|
3404
|
+
break;
|
|
3405
|
+
}
|
|
3406
|
+
const full = kind === "replay" || prior.kind === "replay" || shapeDiff >= 0 || handfulDiff >= 0 || m < n || prior.passesSinceFull + 1 >= SERVED_FULL_CHECK_INTERVAL;
|
|
3407
|
+
let contentDiff = handfulDiff;
|
|
3408
|
+
if (full) {
|
|
3409
|
+
count.fullChecks += 1;
|
|
3410
|
+
for (let index = 0;index < m; index += 1)
|
|
3411
|
+
digest(index);
|
|
3412
|
+
contentDiff = -1;
|
|
3413
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3414
|
+
if (digestsDiffer(digests, index, prior.digests, index)) {
|
|
3415
|
+
contentDiff = index;
|
|
3416
|
+
break;
|
|
3417
|
+
}
|
|
3418
|
+
} else {
|
|
3419
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3420
|
+
if (!computed[index]) {
|
|
3421
|
+
digests[2 * index] = prior.digests[2 * index];
|
|
3422
|
+
digests[2 * index + 1] = prior.digests[2 * index + 1];
|
|
3423
|
+
}
|
|
3424
|
+
}
|
|
3425
|
+
const candidates = [shapeDiff, contentDiff].filter((value) => value >= 0);
|
|
3426
|
+
const firstIndex = candidates.length > 0 ? Math.min(...candidates) : -1;
|
|
3427
|
+
let comparisonClass;
|
|
3428
|
+
let seenBy = null;
|
|
3429
|
+
if (firstIndex >= 0) {
|
|
3430
|
+
comparisonClass = "changed";
|
|
3431
|
+
count.changed += 1;
|
|
3432
|
+
seenBy = shapeDiff >= 0 && shapeDiff === firstIndex ? "shape" : handfulDiff === firstIndex ? "digest" : "full";
|
|
3433
|
+
} else if (m < n) {
|
|
3434
|
+
comparisonClass = "shorter";
|
|
3435
|
+
count.shorter += 1;
|
|
3436
|
+
seenBy = "length";
|
|
3437
|
+
} else {
|
|
3438
|
+
comparisonClass = "append_only";
|
|
3439
|
+
count.appendOnly += 1;
|
|
3440
|
+
}
|
|
3441
|
+
const reportedIndex = firstIndex >= 0 ? firstIndex : comparisonClass === "shorter" ? m : null;
|
|
3442
|
+
const events = [];
|
|
3443
|
+
const permissionInputs = permission ? `decision=${permission.schedulerDecision} ${permission.rides} thinking_hold=${permission.signedThinkingHold} first_render=${permission.firstRender} host_checkpoint_head=${permission.hostCheckpointHead} emergency=${permission.emergency}` : "decision=unknown ride=unknown";
|
|
3444
|
+
if (reportedIndex !== null) {
|
|
3445
|
+
const after = n - reportedIndex;
|
|
3446
|
+
if (kind === "replay") {
|
|
3447
|
+
events.push("mixed_replay");
|
|
3448
|
+
count.mixedReplay += 1;
|
|
3449
|
+
sessionLog2(sessionId, `served check: a replay differed from the request served before it first_index=${reportedIndex} recorded=${n} after_first=${after} served=${m} class=${comparisonClass} seen_by=${seenBy} refused_pass_permitted=${permittedLabel(permitted)} host=${host}`);
|
|
3450
|
+
} else if (permitted !== true) {
|
|
3451
|
+
events.push("unpermitted_change");
|
|
3452
|
+
count.unpermittedChange += 1;
|
|
3453
|
+
sessionLog2(sessionId, `served check: a pass without rebuild permission changed served messages first_index=${reportedIndex} recorded=${n} after_first=${after} served=${m} class=${comparisonClass} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} ${permissionInputs} previous_kind=${prior.kind} host=${host}`);
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
if (firstIndex >= 0 && shapeDiff !== firstIndex) {
|
|
3457
|
+
events.push("same_shape_change");
|
|
3458
|
+
count.sameShapeChange += 1;
|
|
3459
|
+
sessionLog2(sessionId, `served check: content changed with the same shape first_index=${firstIndex} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} host=${host}`);
|
|
3460
|
+
}
|
|
3461
|
+
if (prefixBound && firstIndex >= 0) {
|
|
3462
|
+
const unstripped = keptThinkingIndex >= 0 && firstIndex <= keptThinkingIndex;
|
|
3463
|
+
const stripped = !unstripped && prior.keptThinkingIndex >= 0 && firstIndex <= prior.keptThinkingIndex;
|
|
3464
|
+
if (unstripped || stripped && permitted !== true) {
|
|
3465
|
+
events.push("thinking_prefix_change");
|
|
3466
|
+
count.thinkingPrefixChange += 1;
|
|
3467
|
+
sessionLog2(sessionId, `served check: a change in front of kept signed thinking on a prefix-bound model first_index=${firstIndex} kept_thinking_index=${keptThinkingIndex} recorded_thinking_index=${prior.keptThinkingIndex} thinking_stripped=${stripped} kind=${kind} permitted=${permittedLabel(permitted)} seen_by=${seenBy} host=${host}`);
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
return finish({
|
|
3471
|
+
class: comparisonClass,
|
|
3472
|
+
firstIndex: reportedIndex,
|
|
3473
|
+
recorded: n,
|
|
3474
|
+
seenBy,
|
|
3475
|
+
keptThinkingIndex,
|
|
3476
|
+
recordedThinkingIndex: prior.keptThinkingIndex,
|
|
3477
|
+
events
|
|
3478
|
+
}, full, full ? 0 : prior.passesSinceFull + 1);
|
|
3479
|
+
}
|
|
3480
|
+
|
|
2967
3481
|
// src/hooks/magic-context/lkg-slot.ts
|
|
2968
3482
|
var POSITIONAL_SYSTEM_KEY = "\x00mc-system:";
|
|
2969
3483
|
function lkgInputIdentity(id, role, index) {
|
|
@@ -3178,7 +3692,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
|
|
|
3178
3692
|
var digestChunk;
|
|
3179
3693
|
function lkgContentDigestFromFields(fields) {
|
|
3180
3694
|
lkgDigestsComputed += 1;
|
|
3181
|
-
const hash =
|
|
3695
|
+
const hash = createHash7("sha256");
|
|
3182
3696
|
digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
|
|
3183
3697
|
const chunk = digestChunk;
|
|
3184
3698
|
let offset = 0;
|
|
@@ -3241,7 +3755,7 @@ function legacyLkgDigestFromFields(fields) {
|
|
|
3241
3755
|
const value = typeof field === "symbol" ? field.description ?? "" : String(field);
|
|
3242
3756
|
key += `${typeof field}:${value.length}:${value}\x00`;
|
|
3243
3757
|
}
|
|
3244
|
-
return
|
|
3758
|
+
return createHash7("sha256").update(key).digest("base64url");
|
|
3245
3759
|
}
|
|
3246
3760
|
function legacyLkgContentDigest(message) {
|
|
3247
3761
|
const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
|
|
@@ -4644,4 +5158,4 @@ var ERROR_CLASSES = new Set([
|
|
|
4644
5158
|
"permission_denied",
|
|
4645
5159
|
"unknown"
|
|
4646
5160
|
]);
|
|
4647
|
-
export { advanceSessionActivity, observeSessionActivity, backfillSessionActivity, COMPARTMENT_LEASE_RENEWAL_MS, getCompartmentLeaseBlocker, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getCompartmentsByEndMessageId, appendCompartments, buildCompartmentBlock, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndsThrough, isPartialCompartmentEnd, readProjectDocsCanonical, readServerFallbackUsage, providerResponseFailed, isSuccessfulProviderCompletion, LkgRecoveryFenceError, lkgServedArrayDigest, hasCleanLkgRecoveryFence, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, clearPendingMaterializationOrigin, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, lkgInputIdentity, registerLkgPersistence, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, externalHistorianFailureReason, recordHistorianRun, summarizeImportance, tallyFactsByCategory, MEMORY_VISIBILITY_MUTATION_CATEGORY, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId };
|
|
5161
|
+
export { advanceSessionActivity, observeSessionActivity, backfillSessionActivity, COMPARTMENT_LEASE_RENEWAL_MS, getCompartmentLeaseBlocker, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, releaseCompartmentLeaseBestEffort, isCompartmentLeaseHeld, isNoContentCompartment, queueM0Mutation, getMaxM0MutationId, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, getCompartmentsByEndMessageId, appendCompartments, buildCompartmentBlock, saveRecompStagingPass, getRecompStaging, clearRecompStaging, getRecompPartialRange, setRecompPartialRange, escapeXmlAttr, escapeXmlContent, getUncoveredCompartmentEndsThrough, isPartialCompartmentEnd, readProjectDocsCanonical, readServerFallbackUsage, providerResponseFailed, isSuccessfulProviderCompletion, LkgRecoveryFenceError, lkgServedArrayDigest, hasCleanLkgRecoveryFence, dirtyLkgRecoveryRevision, ownsLkgDirtyFence, invalidateCleanLkgRecoveryFence, prepareLkgCaptureFence, certifyCommittedLkgCapture, markLkgRecoveryDirty, rememberUnpublishedAutoSearchNoHint, getUnpublishedAutoSearchNoHint, forgetUnpublishedAutoSearchNoHint, registerAutoSearchWork, cancelAutoSearchWork, readSessionMeta, getOrCreateSessionMeta, updateSessionMeta, advanceToolReclaimWatermark, markSessionCleanupPending, retryPendingSessionCleanups, retryPendingRustSessionCleanupsForProject, clearSession, requestPendingMaterialization, pendingMaterializationOrigin, hasPendingMaterializationOrigin, clearPendingMaterialization, clearPendingMaterializationOrigin, recordSystemPromptForRequest, recordHeldHeadForRequest, bindSystemPromptResponse, isHeldHeadForRequest, deferDeliveredSystemRefresh, retirePendingSystemPromptDelivery, lkgProviderInputTotal, beginV2LkgRequest, claimLkgRequestIdentity, currentLkgRequestIdentity, noteCapturedLkgRequest, noteLkgProviderResponse, measuredLkgPrefix, clearLkgMeasuredRequest, saveLkgSlotToDb, clearPersistedLkgSlotStrict, loadPersistedLkgSlot, drainStaleLkgSlots, createDbLkgPersistence, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, beginServedRequest, noteServedPassPermission, noteServedModel, noteServedReplay, noteServedHostInput, noteServedRefusal, countServedRefusal, dropServedRecord, forgetServedRecord, commitServedRequest, lkgInputIdentity, registerLkgPersistence, beginLkgPass, visitMessageContentFields, contentSnapshotValue, messageContentFields, signatureForFields, exactReusablePrefix, incrementalLkgContentDigests, lkgContentDigest, lkgSlotRejection, captureSlot, getInMemorySlot, getSlot, forgetInMemorySlot, dropSlot, noteEntry, getLkgSlotHeapStats, TOOL_SWEEP_SCOPED_MARKER, useScopedToolSweep, createPreAdoptionToolSweepResolver, copySessionStateForClone, externalHistorianFailureReason, recordHistorianRun, summarizeImportance, tallyFactsByCategory, MEMORY_VISIBILITY_MUTATION_CATEGORY, queueMemoryMutation, getMemoryMutationsForRender, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationId, getMaxMemoryMutationIdForProjects, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, recordSubagentInvocation, getLatestHistorianInvocationId };
|
|
@@ -2573,17 +2573,21 @@ async function embedItemsForProject2(projectIdentity, items, signal, db, session
|
|
|
2573
2573
|
}
|
|
2574
2574
|
return { vectors, modelId, generation };
|
|
2575
2575
|
}
|
|
2576
|
-
async function
|
|
2576
|
+
async function embedItemsWindowBounded2(projectIdentity, items, signal, db, sessionId = projectIdentity, options = {}) {
|
|
2577
2577
|
if (items.length <= MAX_WINDOWS_PER_EMBED_CALL) {
|
|
2578
|
-
return embedItemsForProject2(projectIdentity, items, signal, db,
|
|
2578
|
+
return embedItemsForProject2(projectIdentity, items, signal, db, sessionId);
|
|
2579
2579
|
}
|
|
2580
2580
|
const vectors = new Map;
|
|
2581
2581
|
let modelId = null;
|
|
2582
2582
|
let generation = null;
|
|
2583
2583
|
for (let start = 0;start < items.length; start += MAX_WINDOWS_PER_EMBED_CALL) {
|
|
2584
|
-
const
|
|
2584
|
+
const slice = items.slice(start, start + MAX_WINDOWS_PER_EMBED_CALL);
|
|
2585
|
+
const result = await embedItemsForProject2(projectIdentity, slice, signal, db, sessionId);
|
|
2585
2586
|
if (!result)
|
|
2586
2587
|
return null;
|
|
2588
|
+
if (options.stopOnIncompleteSlice && slice.some((item) => !result.vectors.has(item.id))) {
|
|
2589
|
+
return null;
|
|
2590
|
+
}
|
|
2587
2591
|
if (modelId === null) {
|
|
2588
2592
|
modelId = result.modelId;
|
|
2589
2593
|
generation = result.generation;
|
|
@@ -2796,7 +2800,7 @@ async function embedCandidateChunkBatch(db, projectIdentity, modelId, candidates
|
|
|
2796
2800
|
let result = null;
|
|
2797
2801
|
const attemptStart = Date.now();
|
|
2798
2802
|
try {
|
|
2799
|
-
result = await
|
|
2803
|
+
result = await embedItemsWindowBounded2(projectIdentity, items, signal, db);
|
|
2800
2804
|
} catch (error) {
|
|
2801
2805
|
log2("[magic-context] failed to proactively embed compartment chunks:", error);
|
|
2802
2806
|
}
|
|
@@ -3160,4 +3164,4 @@ function _resetProjectEmbeddingRegistryForTests2() {
|
|
|
3160
3164
|
setBootQuietPeriodForTests(null);
|
|
3161
3165
|
}
|
|
3162
3166
|
|
|
3163
|
-
export { withQueryEmbeddingDeadline, OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, describeShadowBackfillWriteRefusal2, listShadowBackfillStalls2, retainProjectEmbedding2, getShadowBackfillStopReason2, markProjectLoadUntrusted2, contentSha2562, drainProjectEmbeddingIdentityMaintenance2, drainStaleEmbeddingIdentitiesForProject2, registerProjectEmbedding2, registerProjectShadowEmbedding2, getShadowEmbeddingMeasurementCohort2, getPrimaryEmbeddingMeasurementCohort2, embedShadowTextForProject2, enqueueShadowEmbeddingItems2, getShadowBackfillRemaining2, flushShadowEmbeddingBacklog2, registerProjectInObservationMode2, unregisterProjectShadowEmbedding2, unregisterProjectEmbedding2, getProjectEmbeddingSnapshot2, installProjectEmbeddingSearchBridge2, getProjectChunkEmbeddingModelId2, getProjectEmbeddingMaxInputTokens2, embedTextForProject2, embedBatchForProject2, embedItemsForProject2, embedUnembeddedMemoriesForProject2, embedUnembeddedMemoriesForProjectOutcome2, drainCommitBacklogForProject2, embedUnembeddedCompartmentChunksForProject2, embedSessionCompartmentChunks2, getEmbeddingCoverageStatus2, getAutoEmbeddingSessionCoverage2, sweepAllRegisteredProjects2, _setTestProviderFactoryForProject2, _resetProjectEmbeddingRegistryForTests2 };
|
|
3167
|
+
export { withQueryEmbeddingDeadline, OpenAICompatibleEmbeddingProvider, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitSha, enforceProjectCap, describeShadowBackfillWriteRefusal2, listShadowBackfillStalls2, retainProjectEmbedding2, getShadowBackfillStopReason2, markProjectLoadUntrusted2, contentSha2562, drainProjectEmbeddingIdentityMaintenance2, drainStaleEmbeddingIdentitiesForProject2, registerProjectEmbedding2, registerProjectShadowEmbedding2, getShadowEmbeddingMeasurementCohort2, getPrimaryEmbeddingMeasurementCohort2, embedShadowTextForProject2, enqueueShadowEmbeddingItems2, getShadowBackfillRemaining2, flushShadowEmbeddingBacklog2, registerProjectInObservationMode2, unregisterProjectShadowEmbedding2, unregisterProjectEmbedding2, getProjectEmbeddingSnapshot2, installProjectEmbeddingSearchBridge2, getProjectChunkEmbeddingModelId2, getProjectEmbeddingMaxInputTokens2, embedTextForProject2, embedBatchForProject2, embedItemsForProject2, embedItemsWindowBounded2, embedUnembeddedMemoriesForProject2, embedUnembeddedMemoriesForProjectOutcome2, drainCommitBacklogForProject2, embedUnembeddedCompartmentChunksForProject2, embedSessionCompartmentChunks2, getEmbeddingCoverageStatus2, getAutoEmbeddingSessionCoverage2, sweepAllRegisteredProjects2, _setTestProviderFactoryForProject2, _resetProjectEmbeddingRegistryForTests2 };
|