@cortexkit/opencode-magic-context 0.49.52 → 0.49.54
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 +3 -4
- package/dist/{context-bkkd7br4.js → context-vx5gw5h2.js} +117 -80
- package/dist/{embedding-backfill-3wdjzrvs.js → embedding-backfill-2dvf3rcn.js} +4 -4
- package/dist/embedding-worker.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/emergency-drop.d.ts +75 -2
- package/dist/hooks/magic-context/emergency-drop.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +14 -0
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts +12 -0
- package/dist/hooks/magic-context/heuristic-cleanup.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/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +35 -1
- 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-29ff546v.js +2747 -0
- package/dist/{index-8d7gkgjs.js → index-2vsd5064.js} +3 -3
- package/dist/{index-kaqs6h31.js → index-52x68mj4.js} +1 -1
- package/dist/{index-k2efzh9r.js → index-567xsm72.js} +7 -5
- package/dist/{index-q9m97m5g.js → index-5gqszjq9.js} +4 -4
- package/dist/{index-a4zmmhxs.js → index-5ptp2de1.js} +6 -8
- package/dist/{index-jjy5a5w0.js → index-6nqz8hsz.js} +16 -5
- package/dist/{index-a6aqpfp6.js → index-9mggb1nv.js} +403 -1
- package/dist/{index-kanfby7e.js → index-9n6mdfqy.js} +452 -442
- package/dist/{index-fxgaaptn.js → index-a3n2dczz.js} +8 -7
- package/dist/{index-g3j49m95.js → index-b6rdv8re.js} +1 -1
- package/dist/{index-qbda6a8k.js → index-by14cr73.js} +30 -19
- package/dist/{index-25tm250q.js → index-dhdv88e5.js} +1 -1
- package/dist/{index-4xpff2m1.js → index-eyr425dx.js} +820 -179
- package/dist/{index-x4h461yf.js → index-h62j8z2r.js} +1 -1
- package/dist/{index-xqhejxmd.js → index-pdh4tdcq.js} +1 -1
- package/dist/{index-9gs34125.js → index-sk6p6esd.js} +3777 -2544
- package/dist/{index-pb8ysnq2.js → index-sv5tn72j.js} +1 -1
- package/dist/{index-bamnjp2t.js → index-sx1sppd6.js} +11 -7
- package/dist/{index-x7jcqpy6.js → index-tx8nfw85.js} +539 -29
- package/dist/{index-42n4fhxy.js → index-xj5bap1r.js} +61 -54
- package/dist/{index-rbs27k1d.js → index-xstbytjn.js} +1 -1
- package/dist/{index-0jc25yjf.js → index-xvtjwhm6.js} +3 -3
- package/dist/{index-qtpkkzan.js → index-yamsmkmh.js} +4 -4
- package/dist/index.js +87 -68
- package/dist/{message-index-bounded-71b75npz.js → message-index-bounded-xav3h8qe.js} +5 -6
- package/dist/migration-worker.js +3 -4
- 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-f2azrq24.js} +5 -3
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-bfv831yx.js → read-session-chunk-70aam2c1.js} +4 -5
- package/dist/{recomp-orchestrator-8gj1b7pz.js → recomp-orchestrator-wbm4kpq9.js} +15 -16
- package/dist/{render-b3zcz9x4.js → render-73vrt30h.js} +10 -11
- package/dist/{search-archive-dp9afcv1.js → search-archive-ew4c3bsw.js} +7 -8
- package/dist/{search-y3w590tn.js → search-jfwb4ms3.js} +14 -15
- package/dist/shared/test-open-files.d.ts +17 -0
- package/dist/shared/test-open-files.d.ts.map +1 -0
- package/dist/{storage-tags-kdb4qsyq.js → storage-tags-arnkn5t1.js} +4 -2
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-8awze16a.js → transform-postprocess-phase-mt4dcbhd.js} +16 -17
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +3 -4
- package/dist/v2/{context-99v7x7fm.js → context-13er940g.js} +1147 -467
- package/dist/v2/{embedding-backfill-x1zpc04f.js → embedding-backfill-48qbnh7p.js} +4 -4
- package/dist/v2/embedding-worker.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-sw8hyqw1.js} +5 -6
- package/dist/v2/migration-worker.js +3 -4
- package/dist/v2/{project-embedding-registry-v2fxrs8b.js → project-embedding-registry-kwahtjgg.js} +5 -3
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-a454a4d2.js → read-session-chunk-nqkn0yb4.js} +4 -5
- package/dist/v2/{recomp-orchestrator-03fskpsa.js → recomp-orchestrator-cdkfynz4.js} +15 -16
- package/dist/v2/{render-cryx4xsj.js → render-a7j6fqbd.js} +10 -11
- package/dist/v2/{search-2qj4w7rw.js → search-8dc9ex0a.js} +13 -14
- package/dist/v2/{search-archive-xw2rsq81.js → search-archive-3a36887a.js} +7 -8
- package/dist/v2/{server-kreheyw5.js → server-0ayyh3mx.js} +5 -7
- package/dist/v2/{server-t8n27rbt.js → server-4x0xq8a1.js} +1 -1
- package/dist/v2/{server-kaqs6h31.js → server-52x68mj4.js} +1 -1
- package/dist/v2/{server-cpstyzvy.js → server-578pc4tf.js} +3 -3
- package/dist/v2/{server-sb55ddgn.js → server-5p0bjk3y.js} +1 -1
- package/dist/v2/{server-58h6rrnx.js → server-6k0rnwbd.js} +1 -1
- package/dist/v2/{server-y5cma2j1.js → server-79tbtk5w.js} +8 -7
- package/dist/v2/{server-b3h8vqa6.js → server-7rmf6a57.js} +538 -28
- package/dist/v2/{server-xjzx27w2.js → server-7waad75d.js} +29 -18
- package/dist/v2/{server-wq9y9a03.js → server-96g41nad.js} +61 -54
- package/dist/v2/{server-txdsx71h.js → server-avfc9ezb.js} +4 -4
- package/dist/v2/{server-ww7xbxxf.js → server-b0357as4.js} +357 -1
- package/dist/v2/{server-qsvm6w79.js → server-beydmd68.js} +3763 -2484
- package/dist/v2/server-gge95a03.js +2687 -0
- package/dist/v2/{server-kfw4m268.js → server-jwydbwcx.js} +1 -1
- package/dist/v2/{server-brsx45r6.js → server-kwtnrhv3.js} +1 -1
- package/dist/v2/{server-4h4acntc.js → server-rpmkz5ta.js} +11 -7
- package/dist/v2/{server-0ms13pc8.js → server-rz6g5xne.js} +16 -5
- package/dist/v2/{server-dkfs58nq.js → server-v817sf79.js} +1 -1
- package/dist/v2/{server-vjadwb3j.js → server-ycvqg2s3.js} +3 -3
- package/dist/v2/server.js +4 -4
- package/dist/v2/{storage-tags-rzv7y0n3.js → storage-tags-19da4c0m.js} +4 -2
- package/dist/v2/{v2-archive-reader-3575hw8s.js → v2-archive-reader-jm3d7ccj.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-shzv6t4v.js → wrapup-orchestrator-xnqq81c4.js} +18 -18
- package/dist/{v2-archive-reader-75fdm0te.js → v2-archive-reader-9bbfh131.js} +1 -1
- package/dist/{wrapup-orchestrator-e0z7nvnx.js → wrapup-orchestrator-svhee0fn.js} +16 -17
- 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
- package/dist/index-bkg4hdyh.js +0 -3865
- package/dist/index-d9vfe7xq.js +0 -16
- package/dist/index-hsv31e69.js +0 -405
- package/dist/v2/server-d9vfe7xq.js +0 -16
- package/dist/v2/server-kgq2e2hh.js +0 -361
- package/dist/v2/server-rcchadw0.js +0 -3865
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BoundedSessionMap,
|
|
2
3
|
tagTombstoneOwnerRange,
|
|
3
4
|
tagTombstoneOwnerKey,
|
|
4
5
|
tagRevisionKey,
|
|
5
6
|
tagIdentityRevisionKey,
|
|
6
7
|
deleteTagIdentityRevisions,
|
|
7
|
-
getTableColumnNames
|
|
8
|
-
|
|
8
|
+
getTableColumnNames,
|
|
9
|
+
getMeasuredToolDefinitionTokens
|
|
10
|
+
} from "./index-9mggb1nv.js";
|
|
9
11
|
import {
|
|
10
12
|
invalidateAutoEmbedSession,
|
|
11
13
|
drainBackgroundBatches
|
|
@@ -35,6 +37,9 @@ import {
|
|
|
35
37
|
readProcessStartTime
|
|
36
38
|
} from "./index-ga5q492k.js";
|
|
37
39
|
import {
|
|
40
|
+
stripTagPrefix,
|
|
41
|
+
isRecord,
|
|
42
|
+
providerVisibleMessage,
|
|
38
43
|
MERGED_REASONING_PARTS_PREFIX,
|
|
39
44
|
decodeMergedReasoningParts,
|
|
40
45
|
SESSION_META_SELECT_COLUMNS,
|
|
@@ -60,24 +65,16 @@ import {
|
|
|
60
65
|
parseProcessedImageMarkers,
|
|
61
66
|
serializeProcessedImageMarkers,
|
|
62
67
|
getPendingPiCompactionMarkerState,
|
|
63
|
-
logPiCompactionMarkerClear
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
stripTagPrefix,
|
|
67
|
-
isRecord,
|
|
68
|
-
providerVisibleMessage
|
|
69
|
-
} from "./index-bkg4hdyh.js";
|
|
68
|
+
logPiCompactionMarkerClear,
|
|
69
|
+
isPrefixBoundThinkingModel
|
|
70
|
+
} from "./index-sk6p6esd.js";
|
|
70
71
|
import {
|
|
71
72
|
withReadOnlySessionDb
|
|
72
73
|
} from "./index-em92bp7f.js";
|
|
73
|
-
import {
|
|
74
|
-
BoundedSessionMap,
|
|
75
|
-
getMeasuredToolDefinitionTokens
|
|
76
|
-
} from "./index-hsv31e69.js";
|
|
77
74
|
import {
|
|
78
75
|
layoutLkgPrefix,
|
|
79
76
|
assembleLkgPrefix
|
|
80
|
-
} from "./index-
|
|
77
|
+
} from "./index-sv5tn72j.js";
|
|
81
78
|
import {
|
|
82
79
|
gaDatabasePath2,
|
|
83
80
|
V2StoreReader2
|
|
@@ -520,7 +517,7 @@ function getUncoveredCompartmentEndsThrough(db, sessionId, endOrdinal = Number.M
|
|
|
520
517
|
const rows = db.prepare(`SELECT k.end_message_id, k.end_message,
|
|
521
518
|
n.start_message_id AS successor_id, n.start_message AS successor_start FROM compartments k
|
|
522
519
|
LEFT JOIN compartments n ON n.session_id = k.session_id AND n.sequence = k.sequence + 1
|
|
523
|
-
WHERE k.session_id = ?
|
|
520
|
+
WHERE k.session_id = ? AND k.end_message <= ? AND k.end_message > ? AND k.end_block_index IS NOT NULL
|
|
524
521
|
AND NOT COALESCE(n.sequence IS NOT NULL AND (
|
|
525
522
|
(n.start_message_id = k.end_message_id AND n.start_block_index > k.end_block_index)
|
|
526
523
|
OR n.start_message = k.end_message + 1), 0)
|
|
@@ -661,7 +658,7 @@ function readProjectDocsCanonical(projectDirectory) {
|
|
|
661
658
|
return { renderedBlock, canonicalHash };
|
|
662
659
|
}
|
|
663
660
|
// src/hooks/magic-context/lkg-slot.ts
|
|
664
|
-
import { createHash as
|
|
661
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
665
662
|
|
|
666
663
|
// src/hooks/magic-context/lkg-measured-request.ts
|
|
667
664
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -2835,6 +2832,7 @@ function coldStartUncapturedReplay(args) {
|
|
|
2835
2832
|
|
|
2836
2833
|
// src/hooks/magic-context/lkg-recovery-prefix.ts
|
|
2837
2834
|
var sessions = new BoundedSessionMap(1000);
|
|
2835
|
+
var restartHeadChecked = new BoundedSessionMap(1000);
|
|
2838
2836
|
function noteUncertifiedNormalLkg(sessionId, revision) {
|
|
2839
2837
|
sessions.set(sessionId, {
|
|
2840
2838
|
...sessions.get(sessionId),
|
|
@@ -2853,6 +2851,7 @@ function rememberLkgDirtyRevision(sessionId, revision) {
|
|
|
2853
2851
|
}
|
|
2854
2852
|
function clearLkgRecoverySession(sessionId) {
|
|
2855
2853
|
sessions.delete(sessionId);
|
|
2854
|
+
restartHeadChecked.delete(sessionId);
|
|
2856
2855
|
clearLkgFenceProcessState(sessionId);
|
|
2857
2856
|
}
|
|
2858
2857
|
function noteLkgCapturedPrefix(sessionId) {
|
|
@@ -2868,13 +2867,14 @@ function readPersistedLkgUntaggedInputIds(db, sessionId) {
|
|
|
2868
2867
|
return [];
|
|
2869
2868
|
}
|
|
2870
2869
|
}
|
|
2871
|
-
function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
2872
|
-
const next = [...new Set(ids)].sort();
|
|
2870
|
+
function persistLkgUntaggedInputIds(db, sessionId, ids, alsoRecord) {
|
|
2871
|
+
const next = ids === undefined ? undefined : [...new Set(ids)].sort();
|
|
2873
2872
|
try {
|
|
2874
2873
|
return updateReplayDocument(db, sessionId, (doc) => {
|
|
2874
|
+
const recorded = alsoRecord?.(doc) ?? false;
|
|
2875
2875
|
const saved = Array.isArray(doc.lkgUntaggedInputIds) ? doc.lkgUntaggedInputIds : [];
|
|
2876
|
-
if (JSON.stringify(saved) === JSON.stringify(next))
|
|
2877
|
-
return
|
|
2876
|
+
if (next === undefined || JSON.stringify(saved) === JSON.stringify(next))
|
|
2877
|
+
return recorded;
|
|
2878
2878
|
doc.version = 2;
|
|
2879
2879
|
if (next.length > 0)
|
|
2880
2880
|
doc.lkgUntaggedInputIds = next;
|
|
@@ -2888,10 +2888,7 @@ function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
|
2888
2888
|
}
|
|
2889
2889
|
}
|
|
2890
2890
|
function noteLkgRecoveryPrefix(args) {
|
|
2891
|
-
const digests = [
|
|
2892
|
-
...args.entry.entryContentDigests,
|
|
2893
|
-
...args.entry.pristineTail.map(lkgContentDigest)
|
|
2894
|
-
];
|
|
2891
|
+
const digests = [...args.entry.entryContentDigests, ...args.hostTailDigests];
|
|
2895
2892
|
if (digests.length !== args.entry.entryInputIds.length || digests.some((value) => !value))
|
|
2896
2893
|
return false;
|
|
2897
2894
|
const ids = args.entry.entryInputIds;
|
|
@@ -2928,8 +2925,15 @@ function readRecoveryIdentityPrefix(sessionId, inputs, messages, db) {
|
|
|
2928
2925
|
const prefix = state?.prefix;
|
|
2929
2926
|
if (!prefix && state?.uncertifiedNormal && ownsLkgDirtyFence(sessionId, state.fenceRevision))
|
|
2930
2927
|
return {};
|
|
2931
|
-
if (!prefix)
|
|
2932
|
-
|
|
2928
|
+
if (!prefix) {
|
|
2929
|
+
let restartedSlotJson;
|
|
2930
|
+
if (!state && slot && !restartHeadChecked.has(sessionId)) {
|
|
2931
|
+
restartHeadChecked.set(sessionId, true);
|
|
2932
|
+
restartedSlotJson = slot.jsonPrefix;
|
|
2933
|
+
}
|
|
2934
|
+
const restarted = restartedSlotJson === undefined ? {} : { restartedSlotJson };
|
|
2935
|
+
return !state && lkgRecoveryFenceUnclean(sessionId) || slot && lkgFenceRequiresRebuild(sessionId, slot, !!state) ? { rebuildReason: "lkg_restart_rebuild", ...restarted } : restarted;
|
|
2936
|
+
}
|
|
2933
2937
|
const keys = resolveLkgModelKeys(messages);
|
|
2934
2938
|
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
2939
|
return { rebuildReason: "lkg_recovery_input_rebuild" };
|
|
@@ -2964,6 +2968,512 @@ function lkgRecoveryEntryUnproven(sessionId, entry, messages) {
|
|
|
2964
2968
|
return !!readRecoveryIdentityPrefix(sessionId, inputs, messages).rebuildReason;
|
|
2965
2969
|
}
|
|
2966
2970
|
|
|
2971
|
+
// src/hooks/magic-context/served-check.ts
|
|
2972
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
2973
|
+
var RECORD_SESSIONS = 256;
|
|
2974
|
+
var records = new BoundedSessionMap(RECORD_SESSIONS);
|
|
2975
|
+
var pending4 = new BoundedSessionMap(1000);
|
|
2976
|
+
var counters = new BoundedSessionMap(1000);
|
|
2977
|
+
var SERVED_FULL_CHECK_INTERVAL = 100;
|
|
2978
|
+
var COUNT_LOG_INTERVAL = 100;
|
|
2979
|
+
var HEAD_MIN = 2;
|
|
2980
|
+
var HEAD_MAX = 4;
|
|
2981
|
+
var lastWork = { fingerprinted: 0, digested: 0, full: false, ms: 0, shapeMs: 0 };
|
|
2982
|
+
function emptyCounters() {
|
|
2983
|
+
return {
|
|
2984
|
+
commits: 0,
|
|
2985
|
+
compared: 0,
|
|
2986
|
+
unknown: 0,
|
|
2987
|
+
refused: 0,
|
|
2988
|
+
appendOnly: 0,
|
|
2989
|
+
changed: 0,
|
|
2990
|
+
shorter: 0,
|
|
2991
|
+
modelChanged: 0,
|
|
2992
|
+
unpermittedChange: 0,
|
|
2993
|
+
mixedReplay: 0,
|
|
2994
|
+
thinkingPrefixChange: 0,
|
|
2995
|
+
sameShapeChange: 0,
|
|
2996
|
+
fullChecks: 0
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
function countersFor(sessionId) {
|
|
3000
|
+
let value = counters.get(sessionId);
|
|
3001
|
+
if (!value) {
|
|
3002
|
+
value = emptyCounters();
|
|
3003
|
+
counters.set(sessionId, value);
|
|
3004
|
+
}
|
|
3005
|
+
return value;
|
|
3006
|
+
}
|
|
3007
|
+
function pendingFor(sessionId) {
|
|
3008
|
+
let value = pending4.get(sessionId);
|
|
3009
|
+
if (!value) {
|
|
3010
|
+
value = {};
|
|
3011
|
+
pending4.set(sessionId, value);
|
|
3012
|
+
}
|
|
3013
|
+
return value;
|
|
3014
|
+
}
|
|
3015
|
+
function beginServedRequest(sessionId) {
|
|
3016
|
+
pending4.delete(sessionId);
|
|
3017
|
+
}
|
|
3018
|
+
function noteServedPassPermission(sessionId, permission) {
|
|
3019
|
+
pendingFor(sessionId).permission = permission;
|
|
3020
|
+
}
|
|
3021
|
+
function noteServedModel(sessionId, model) {
|
|
3022
|
+
if (model)
|
|
3023
|
+
pendingFor(sessionId).model = model;
|
|
3024
|
+
}
|
|
3025
|
+
function noteServedReplay(sessionId) {
|
|
3026
|
+
pendingFor(sessionId).replay = true;
|
|
3027
|
+
}
|
|
3028
|
+
function noteServedHostInput(sessionId) {
|
|
3029
|
+
pendingFor(sessionId).input = true;
|
|
3030
|
+
}
|
|
3031
|
+
function noteServedRefusal(sessionId) {
|
|
3032
|
+
pendingFor(sessionId).refused = true;
|
|
3033
|
+
}
|
|
3034
|
+
function countServedRefusal(sessionId) {
|
|
3035
|
+
try {
|
|
3036
|
+
pending4.delete(sessionId);
|
|
3037
|
+
countersFor(sessionId).refused += 1;
|
|
3038
|
+
} catch {}
|
|
3039
|
+
}
|
|
3040
|
+
function dropServedRecord(sessionId, reason) {
|
|
3041
|
+
try {
|
|
3042
|
+
const value = counters.peek(sessionId);
|
|
3043
|
+
if (value && value.commits + value.refused > 0)
|
|
3044
|
+
logCounts(sessionId, value, reason);
|
|
3045
|
+
if (records.has(sessionId))
|
|
3046
|
+
sessionLog2(sessionId, `served check: record dropped reason=${reason}; the next request is not compared`);
|
|
3047
|
+
} catch {}
|
|
3048
|
+
records.delete(sessionId);
|
|
3049
|
+
pending4.delete(sessionId);
|
|
3050
|
+
counters.delete(sessionId);
|
|
3051
|
+
}
|
|
3052
|
+
function forgetServedRecord(sessionId) {
|
|
3053
|
+
records.delete(sessionId);
|
|
3054
|
+
pending4.delete(sessionId);
|
|
3055
|
+
}
|
|
3056
|
+
function logCounts(sessionId, value, reason) {
|
|
3057
|
+
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}`);
|
|
3058
|
+
}
|
|
3059
|
+
function mix(hash, value) {
|
|
3060
|
+
return Math.imul(hash ^ (value | 0), 16777619);
|
|
3061
|
+
}
|
|
3062
|
+
function mixName(hash, value) {
|
|
3063
|
+
if (typeof value !== "string")
|
|
3064
|
+
return mix(hash, value === undefined ? -1 : -2);
|
|
3065
|
+
const length = value.length;
|
|
3066
|
+
const h = mix(hash, length);
|
|
3067
|
+
return length === 0 ? h : mix(h, value.charCodeAt(length - 1) << 16 | value.charCodeAt(length >> 1));
|
|
3068
|
+
}
|
|
3069
|
+
function mixId(hash, value) {
|
|
3070
|
+
if (typeof value !== "string")
|
|
3071
|
+
return mix(hash, value === undefined ? -1 : -2);
|
|
3072
|
+
const length = value.length;
|
|
3073
|
+
let h = mix(hash, length);
|
|
3074
|
+
const stop = length > 8 ? length - 8 : 0;
|
|
3075
|
+
let index = length - 1;
|
|
3076
|
+
for (;index > stop; index -= 2)
|
|
3077
|
+
h = mix(h, value.charCodeAt(index) << 16 | value.charCodeAt(index - 1));
|
|
3078
|
+
if (index === stop && length > 0)
|
|
3079
|
+
h = mix(h, value.charCodeAt(index));
|
|
3080
|
+
return h;
|
|
3081
|
+
}
|
|
3082
|
+
function mixNumber(hash, value) {
|
|
3083
|
+
const whole = Math.trunc(value);
|
|
3084
|
+
return mix(mix(mix(hash, whole), whole / 4294967296), Math.round((value - whole) * 1e6));
|
|
3085
|
+
}
|
|
3086
|
+
function mixLength(hash, value) {
|
|
3087
|
+
return typeof value === "string" ? mix(hash, value.length) : mix(hash, value === undefined ? -1 : -2);
|
|
3088
|
+
}
|
|
3089
|
+
function mixShallow(hash, value) {
|
|
3090
|
+
switch (typeof value) {
|
|
3091
|
+
case "string":
|
|
3092
|
+
return mix(mix(hash, 1), value.length);
|
|
3093
|
+
case "number":
|
|
3094
|
+
return mixNumber(mix(hash, 2), value);
|
|
3095
|
+
case "boolean":
|
|
3096
|
+
return mix(hash, value ? 5 : 4);
|
|
3097
|
+
case "undefined":
|
|
3098
|
+
return mix(hash, -1);
|
|
3099
|
+
case "object":
|
|
3100
|
+
if (value === null)
|
|
3101
|
+
return mix(hash, 3);
|
|
3102
|
+
if (Array.isArray(value))
|
|
3103
|
+
return mix(mix(hash, 9), value.length);
|
|
3104
|
+
{
|
|
3105
|
+
const size = value.byteLength;
|
|
3106
|
+
return typeof size === "number" ? mix(mix(hash, 7), size) : mix(hash, 10);
|
|
3107
|
+
}
|
|
3108
|
+
default:
|
|
3109
|
+
return mix(hash, 6);
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
function mixToolState(hash, state) {
|
|
3113
|
+
let h = mixName(hash, state.status);
|
|
3114
|
+
h = mixShallow(h, state.input);
|
|
3115
|
+
h = mixShallow(h, state.output);
|
|
3116
|
+
if (state.error !== undefined)
|
|
3117
|
+
h = mixShallow(h, state.error);
|
|
3118
|
+
if (state.attachments !== undefined)
|
|
3119
|
+
h = mixShallow(h, state.attachments);
|
|
3120
|
+
if (state.content !== undefined)
|
|
3121
|
+
h = mixShallow(h, state.content);
|
|
3122
|
+
const time = state.time;
|
|
3123
|
+
h = mix(h, time && typeof time === "object" && time.compacted !== undefined ? 1 : 0);
|
|
3124
|
+
if (state.status === "error") {
|
|
3125
|
+
const metadata = state.metadata;
|
|
3126
|
+
if (metadata && typeof metadata === "object" && metadata.interrupted === true)
|
|
3127
|
+
h = mixShallow(h, metadata.output);
|
|
3128
|
+
}
|
|
3129
|
+
return h;
|
|
3130
|
+
}
|
|
3131
|
+
function isThinkingType(type) {
|
|
3132
|
+
return type === "reasoning" || type === "thinking" || type === "redacted_thinking";
|
|
3133
|
+
}
|
|
3134
|
+
function isKeptThinkingPart(part) {
|
|
3135
|
+
if (!isThinkingType(part.type) || part.ignored === true)
|
|
3136
|
+
return false;
|
|
3137
|
+
if (part.type === "redacted_thinking" || part.redacted === true)
|
|
3138
|
+
return true;
|
|
3139
|
+
if (typeof part.text === "string" && part.text !== "")
|
|
3140
|
+
return true;
|
|
3141
|
+
if (typeof part.thinking === "string" && part.thinking !== "")
|
|
3142
|
+
return true;
|
|
3143
|
+
const metadata = part.metadata;
|
|
3144
|
+
if (metadata && typeof metadata === "object") {
|
|
3145
|
+
for (const record of Object.values(metadata))
|
|
3146
|
+
if (record && typeof record === "object" && "redactedData" in record)
|
|
3147
|
+
return true;
|
|
3148
|
+
}
|
|
3149
|
+
return false;
|
|
3150
|
+
}
|
|
3151
|
+
var PART_FIELDS = [
|
|
3152
|
+
"text",
|
|
3153
|
+
"thinking",
|
|
3154
|
+
"thinkingSignature",
|
|
3155
|
+
"signature",
|
|
3156
|
+
"redacted",
|
|
3157
|
+
"data",
|
|
3158
|
+
"url",
|
|
3159
|
+
"mime",
|
|
3160
|
+
"mimeType",
|
|
3161
|
+
"mediaType",
|
|
3162
|
+
"filename",
|
|
3163
|
+
"name",
|
|
3164
|
+
"tool",
|
|
3165
|
+
"callID",
|
|
3166
|
+
"toolCallId",
|
|
3167
|
+
"input",
|
|
3168
|
+
"arguments",
|
|
3169
|
+
"output",
|
|
3170
|
+
"error",
|
|
3171
|
+
"isError",
|
|
3172
|
+
"providerExecuted",
|
|
3173
|
+
"synthetic",
|
|
3174
|
+
"ignored"
|
|
3175
|
+
];
|
|
3176
|
+
var walkOut = { partThinking: false, messageThinking: false, messageHead: false };
|
|
3177
|
+
function mixPart(hash, rawPart) {
|
|
3178
|
+
walkOut.partThinking = false;
|
|
3179
|
+
if (!rawPart || typeof rawPart !== "object")
|
|
3180
|
+
return mix(hash, 11);
|
|
3181
|
+
const part = rawPart;
|
|
3182
|
+
const type = part.type;
|
|
3183
|
+
let h = mixId(mixName(hash, type), part.id);
|
|
3184
|
+
if (type === "text") {
|
|
3185
|
+
h = mixLength(h, part.text);
|
|
3186
|
+
return mix(h, (part.synthetic === true ? 1 : 0) | (part.ignored === true ? 2 : 0));
|
|
3187
|
+
}
|
|
3188
|
+
if (type === "tool" && part.state && typeof part.state === "object")
|
|
3189
|
+
return mixToolState(mixId(mixName(h, part.tool), part.callID), part.state);
|
|
3190
|
+
for (let index = 0;index < PART_FIELDS.length; index += 1) {
|
|
3191
|
+
const value = part[PART_FIELDS[index]];
|
|
3192
|
+
if (value !== undefined)
|
|
3193
|
+
h = mixShallow(mix(h, index), value);
|
|
3194
|
+
}
|
|
3195
|
+
const result = part.result;
|
|
3196
|
+
if (result && typeof result === "object") {
|
|
3197
|
+
h = mixName(h, result.type);
|
|
3198
|
+
h = mixShallow(h, result.value);
|
|
3199
|
+
}
|
|
3200
|
+
if (isThinkingType(type)) {
|
|
3201
|
+
walkOut.partThinking = isKeptThinkingPart(part);
|
|
3202
|
+
const metadata = part.metadata;
|
|
3203
|
+
const anthropic = metadata && typeof metadata === "object" ? metadata.anthropic : undefined;
|
|
3204
|
+
if (anthropic && typeof anthropic === "object") {
|
|
3205
|
+
h = mixShallow(h, anthropic.signature);
|
|
3206
|
+
h = mixShallow(h, anthropic.redactedData);
|
|
3207
|
+
} else
|
|
3208
|
+
h = mix(h, metadata && typeof metadata === "object" ? 17 : 18);
|
|
3209
|
+
}
|
|
3210
|
+
return h;
|
|
3211
|
+
}
|
|
3212
|
+
function messageShape(message) {
|
|
3213
|
+
const record = message && typeof message === "object" ? message : {};
|
|
3214
|
+
const info = record.info && typeof record.info === "object" ? record.info : record;
|
|
3215
|
+
const parts = Array.isArray(record.parts) ? record.parts : record.content;
|
|
3216
|
+
const role = info.role;
|
|
3217
|
+
let hash = mixId(2166136261, info.id);
|
|
3218
|
+
hash = mixName(hash, role);
|
|
3219
|
+
if (typeof record.timestamp === "number")
|
|
3220
|
+
hash = mixNumber(hash, record.timestamp);
|
|
3221
|
+
if (typeof record.toolCallId === "string")
|
|
3222
|
+
hash = mixId(hash, record.toolCallId);
|
|
3223
|
+
if (record.isError === true)
|
|
3224
|
+
hash = mix(hash, 12);
|
|
3225
|
+
if (info.summary === true)
|
|
3226
|
+
hash = mix(hash, 13);
|
|
3227
|
+
let thinking = false;
|
|
3228
|
+
let synthetic = info.synthetic === true || info.summary === true;
|
|
3229
|
+
if (typeof parts === "string") {
|
|
3230
|
+
hash = mix(mix(hash, 14), parts.length);
|
|
3231
|
+
} else if (Array.isArray(parts)) {
|
|
3232
|
+
hash = mix(mix(hash, 15), parts.length);
|
|
3233
|
+
let allSynthetic = parts.length > 0;
|
|
3234
|
+
for (const part of parts) {
|
|
3235
|
+
hash = mixPart(hash, part);
|
|
3236
|
+
if (walkOut.partThinking)
|
|
3237
|
+
thinking = true;
|
|
3238
|
+
if (allSynthetic && part?.synthetic !== true)
|
|
3239
|
+
allSynthetic = false;
|
|
3240
|
+
}
|
|
3241
|
+
if (allSynthetic)
|
|
3242
|
+
synthetic = true;
|
|
3243
|
+
} else {
|
|
3244
|
+
hash = mix(hash, 16);
|
|
3245
|
+
}
|
|
3246
|
+
walkOut.messageThinking = thinking && role === "assistant";
|
|
3247
|
+
walkOut.messageHead = synthetic || role === "system" || role === "compactionSummary" || role === "branchSummary";
|
|
3248
|
+
return hash >>> 0;
|
|
3249
|
+
}
|
|
3250
|
+
function digestInto(message, out, index) {
|
|
3251
|
+
let json;
|
|
3252
|
+
try {
|
|
3253
|
+
json = JSON.stringify(contentSnapshotValue(message));
|
|
3254
|
+
} catch {
|
|
3255
|
+
json = undefined;
|
|
3256
|
+
}
|
|
3257
|
+
if (json === undefined) {
|
|
3258
|
+
out[2 * index] = 0;
|
|
3259
|
+
out[2 * index + 1] = 0;
|
|
3260
|
+
return;
|
|
3261
|
+
}
|
|
3262
|
+
const digest = createHash6("sha256").update(json).digest();
|
|
3263
|
+
out[2 * index] = digest.readUInt32LE(0);
|
|
3264
|
+
out[2 * index + 1] = digest.readUInt32LE(4);
|
|
3265
|
+
}
|
|
3266
|
+
function digestsDiffer(a, ai, b, bi) {
|
|
3267
|
+
const a0 = a[2 * ai];
|
|
3268
|
+
const a1 = a[2 * ai + 1];
|
|
3269
|
+
const b0 = b[2 * bi];
|
|
3270
|
+
const b1 = b[2 * bi + 1];
|
|
3271
|
+
if (a0 === 0 && a1 === 0 || b0 === 0 && b1 === 0)
|
|
3272
|
+
return false;
|
|
3273
|
+
return a0 !== b0 || a1 !== b1;
|
|
3274
|
+
}
|
|
3275
|
+
function permittedLabel(permitted) {
|
|
3276
|
+
return permitted === null ? "unknown" : String(permitted);
|
|
3277
|
+
}
|
|
3278
|
+
function commitServedRequest(args) {
|
|
3279
|
+
try {
|
|
3280
|
+
return commit(args);
|
|
3281
|
+
} catch (error) {
|
|
3282
|
+
try {
|
|
3283
|
+
records.delete(args.sessionId);
|
|
3284
|
+
sessionLog2(args.sessionId, "served check failed; the record is unknown again:", error);
|
|
3285
|
+
} catch {}
|
|
3286
|
+
return null;
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
function commit(args) {
|
|
3290
|
+
const { sessionId, messages, host } = args;
|
|
3291
|
+
const startedAt = performance.now();
|
|
3292
|
+
const note = pending4.peek(sessionId) ?? {};
|
|
3293
|
+
pending4.delete(sessionId);
|
|
3294
|
+
const count = countersFor(sessionId);
|
|
3295
|
+
const kind = note.replay ? "replay" : note.input ? "input" : "pass";
|
|
3296
|
+
const permission = note.permission;
|
|
3297
|
+
const permitted = permission?.permitted ?? (args.compactionOff ? false : kind === "input" ? false : null);
|
|
3298
|
+
const prior = records.get(sessionId);
|
|
3299
|
+
if (note.refused) {
|
|
3300
|
+
count.refused += 1;
|
|
3301
|
+
return {
|
|
3302
|
+
class: "refused",
|
|
3303
|
+
kind,
|
|
3304
|
+
firstIndex: null,
|
|
3305
|
+
recorded: prior?.count ?? 0,
|
|
3306
|
+
served: messages.length,
|
|
3307
|
+
seenBy: null,
|
|
3308
|
+
keptThinkingIndex: -1,
|
|
3309
|
+
recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
|
|
3310
|
+
permitted,
|
|
3311
|
+
events: []
|
|
3312
|
+
};
|
|
3313
|
+
}
|
|
3314
|
+
count.commits += 1;
|
|
3315
|
+
const m = messages.length;
|
|
3316
|
+
const providerID = note.model?.providerID ?? args.providerID;
|
|
3317
|
+
const modelID = note.model?.modelID ?? args.modelID;
|
|
3318
|
+
const prefixBound = isPrefixBoundThinkingModel(providerID, modelID);
|
|
3319
|
+
const modelKey = modelID ? `${providerID ?? ""}/${modelID}` : null;
|
|
3320
|
+
const shapes = new Uint32Array(m);
|
|
3321
|
+
let keptThinkingIndex = -1;
|
|
3322
|
+
let headCount = Math.min(HEAD_MIN, m);
|
|
3323
|
+
let leading = true;
|
|
3324
|
+
for (let index = 0;index < m; index += 1) {
|
|
3325
|
+
shapes[index] = messageShape(messages[index]);
|
|
3326
|
+
if (prefixBound && keptThinkingIndex < 0 && walkOut.messageThinking)
|
|
3327
|
+
keptThinkingIndex = index;
|
|
3328
|
+
if (leading && index >= HEAD_MIN) {
|
|
3329
|
+
if (walkOut.messageHead && index < HEAD_MAX)
|
|
3330
|
+
headCount = index + 1;
|
|
3331
|
+
else
|
|
3332
|
+
leading = false;
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
const shapeMs = performance.now() - startedAt;
|
|
3336
|
+
const digests = new Uint32Array(2 * m);
|
|
3337
|
+
const computed = new Uint8Array(m);
|
|
3338
|
+
let digested = 0;
|
|
3339
|
+
const digest = (index) => {
|
|
3340
|
+
if (index < 0 || index >= m || computed[index])
|
|
3341
|
+
return;
|
|
3342
|
+
computed[index] = 1;
|
|
3343
|
+
digested += 1;
|
|
3344
|
+
digestInto(messages[index], digests, index);
|
|
3345
|
+
};
|
|
3346
|
+
const finish = (comparison, full, passesSinceFull) => {
|
|
3347
|
+
records.set(sessionId, {
|
|
3348
|
+
count: m,
|
|
3349
|
+
shapes,
|
|
3350
|
+
digests,
|
|
3351
|
+
modelKey: modelKey ?? prior?.modelKey ?? null,
|
|
3352
|
+
kind,
|
|
3353
|
+
keptThinkingIndex,
|
|
3354
|
+
passesSinceFull
|
|
3355
|
+
});
|
|
3356
|
+
lastWork = { fingerprinted: m, digested, full, ms: 0, shapeMs };
|
|
3357
|
+
if (count.commits % COUNT_LOG_INTERVAL === 0)
|
|
3358
|
+
logCounts(sessionId, count, "periodic");
|
|
3359
|
+
lastWork.ms = performance.now() - startedAt;
|
|
3360
|
+
return { ...comparison, kind, permitted, served: m };
|
|
3361
|
+
};
|
|
3362
|
+
const modelChanged = prior !== undefined && prior.modelKey !== null && modelKey !== null && prior.modelKey !== modelKey;
|
|
3363
|
+
if (!prior || modelChanged) {
|
|
3364
|
+
for (let index = 0;index < m; index += 1)
|
|
3365
|
+
digest(index);
|
|
3366
|
+
if (prior)
|
|
3367
|
+
count.modelChanged += 1;
|
|
3368
|
+
else
|
|
3369
|
+
count.unknown += 1;
|
|
3370
|
+
return finish({
|
|
3371
|
+
class: prior ? "model_change" : "unknown",
|
|
3372
|
+
firstIndex: null,
|
|
3373
|
+
recorded: prior?.count ?? 0,
|
|
3374
|
+
seenBy: null,
|
|
3375
|
+
keptThinkingIndex,
|
|
3376
|
+
recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
|
|
3377
|
+
events: []
|
|
3378
|
+
}, true, 0);
|
|
3379
|
+
}
|
|
3380
|
+
count.compared += 1;
|
|
3381
|
+
const n = prior.count;
|
|
3382
|
+
const overlap = Math.min(n, m);
|
|
3383
|
+
let shapeDiff = -1;
|
|
3384
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3385
|
+
if (shapes[index] !== prior.shapes[index]) {
|
|
3386
|
+
shapeDiff = index;
|
|
3387
|
+
break;
|
|
3388
|
+
}
|
|
3389
|
+
for (let index = 0;index < headCount; index += 1)
|
|
3390
|
+
digest(index);
|
|
3391
|
+
digest(n - 1);
|
|
3392
|
+
digest(prior.keptThinkingIndex);
|
|
3393
|
+
digest(keptThinkingIndex);
|
|
3394
|
+
for (let index = n;index < m; index += 1)
|
|
3395
|
+
digest(index);
|
|
3396
|
+
let handfulDiff = -1;
|
|
3397
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3398
|
+
if (computed[index] && digestsDiffer(digests, index, prior.digests, index)) {
|
|
3399
|
+
handfulDiff = index;
|
|
3400
|
+
break;
|
|
3401
|
+
}
|
|
3402
|
+
const full = kind === "replay" || prior.kind === "replay" || shapeDiff >= 0 || handfulDiff >= 0 || m < n || prior.passesSinceFull + 1 >= SERVED_FULL_CHECK_INTERVAL;
|
|
3403
|
+
let contentDiff = handfulDiff;
|
|
3404
|
+
if (full) {
|
|
3405
|
+
count.fullChecks += 1;
|
|
3406
|
+
for (let index = 0;index < m; index += 1)
|
|
3407
|
+
digest(index);
|
|
3408
|
+
contentDiff = -1;
|
|
3409
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3410
|
+
if (digestsDiffer(digests, index, prior.digests, index)) {
|
|
3411
|
+
contentDiff = index;
|
|
3412
|
+
break;
|
|
3413
|
+
}
|
|
3414
|
+
} else {
|
|
3415
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3416
|
+
if (!computed[index]) {
|
|
3417
|
+
digests[2 * index] = prior.digests[2 * index];
|
|
3418
|
+
digests[2 * index + 1] = prior.digests[2 * index + 1];
|
|
3419
|
+
}
|
|
3420
|
+
}
|
|
3421
|
+
const candidates = [shapeDiff, contentDiff].filter((value) => value >= 0);
|
|
3422
|
+
const firstIndex = candidates.length > 0 ? Math.min(...candidates) : -1;
|
|
3423
|
+
let comparisonClass;
|
|
3424
|
+
let seenBy = null;
|
|
3425
|
+
if (firstIndex >= 0) {
|
|
3426
|
+
comparisonClass = "changed";
|
|
3427
|
+
count.changed += 1;
|
|
3428
|
+
seenBy = shapeDiff >= 0 && shapeDiff === firstIndex ? "shape" : handfulDiff === firstIndex ? "digest" : "full";
|
|
3429
|
+
} else if (m < n) {
|
|
3430
|
+
comparisonClass = "shorter";
|
|
3431
|
+
count.shorter += 1;
|
|
3432
|
+
seenBy = "length";
|
|
3433
|
+
} else {
|
|
3434
|
+
comparisonClass = "append_only";
|
|
3435
|
+
count.appendOnly += 1;
|
|
3436
|
+
}
|
|
3437
|
+
const reportedIndex = firstIndex >= 0 ? firstIndex : comparisonClass === "shorter" ? m : null;
|
|
3438
|
+
const events = [];
|
|
3439
|
+
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";
|
|
3440
|
+
if (reportedIndex !== null) {
|
|
3441
|
+
const after = n - reportedIndex;
|
|
3442
|
+
if (kind === "replay") {
|
|
3443
|
+
events.push("mixed_replay");
|
|
3444
|
+
count.mixedReplay += 1;
|
|
3445
|
+
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}`);
|
|
3446
|
+
} else if (permitted !== true) {
|
|
3447
|
+
events.push("unpermitted_change");
|
|
3448
|
+
count.unpermittedChange += 1;
|
|
3449
|
+
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}`);
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
if (firstIndex >= 0 && shapeDiff !== firstIndex) {
|
|
3453
|
+
events.push("same_shape_change");
|
|
3454
|
+
count.sameShapeChange += 1;
|
|
3455
|
+
sessionLog2(sessionId, `served check: content changed with the same shape first_index=${firstIndex} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} host=${host}`);
|
|
3456
|
+
}
|
|
3457
|
+
if (prefixBound && firstIndex >= 0) {
|
|
3458
|
+
const unstripped = keptThinkingIndex >= 0 && firstIndex <= keptThinkingIndex;
|
|
3459
|
+
const stripped = !unstripped && prior.keptThinkingIndex >= 0 && firstIndex <= prior.keptThinkingIndex;
|
|
3460
|
+
if (unstripped || stripped && permitted !== true) {
|
|
3461
|
+
events.push("thinking_prefix_change");
|
|
3462
|
+
count.thinkingPrefixChange += 1;
|
|
3463
|
+
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}`);
|
|
3464
|
+
}
|
|
3465
|
+
}
|
|
3466
|
+
return finish({
|
|
3467
|
+
class: comparisonClass,
|
|
3468
|
+
firstIndex: reportedIndex,
|
|
3469
|
+
recorded: n,
|
|
3470
|
+
seenBy,
|
|
3471
|
+
keptThinkingIndex,
|
|
3472
|
+
recordedThinkingIndex: prior.keptThinkingIndex,
|
|
3473
|
+
events
|
|
3474
|
+
}, full, full ? 0 : prior.passesSinceFull + 1);
|
|
3475
|
+
}
|
|
3476
|
+
|
|
2967
3477
|
// src/hooks/magic-context/lkg-slot.ts
|
|
2968
3478
|
var POSITIONAL_SYSTEM_KEY = "\x00mc-system:";
|
|
2969
3479
|
function lkgInputIdentity(id, role, index) {
|
|
@@ -3178,7 +3688,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
|
|
|
3178
3688
|
var digestChunk;
|
|
3179
3689
|
function lkgContentDigestFromFields(fields) {
|
|
3180
3690
|
lkgDigestsComputed += 1;
|
|
3181
|
-
const hash =
|
|
3691
|
+
const hash = createHash7("sha256");
|
|
3182
3692
|
digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
|
|
3183
3693
|
const chunk = digestChunk;
|
|
3184
3694
|
let offset = 0;
|
|
@@ -3241,7 +3751,7 @@ function legacyLkgDigestFromFields(fields) {
|
|
|
3241
3751
|
const value = typeof field === "symbol" ? field.description ?? "" : String(field);
|
|
3242
3752
|
key += `${typeof field}:${value.length}:${value}\x00`;
|
|
3243
3753
|
}
|
|
3244
|
-
return
|
|
3754
|
+
return createHash7("sha256").update(key).digest("base64url");
|
|
3245
3755
|
}
|
|
3246
3756
|
function legacyLkgContentDigest(message) {
|
|
3247
3757
|
const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
|
|
@@ -4644,4 +5154,4 @@ var ERROR_CLASSES = new Set([
|
|
|
4644
5154
|
"permission_denied",
|
|
4645
5155
|
"unknown"
|
|
4646
5156
|
]);
|
|
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 };
|
|
5157
|
+
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 };
|