@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
|
@@ -27,6 +27,9 @@ import {
|
|
|
27
27
|
readProcessStartTime
|
|
28
28
|
} from "./server-tmf0ayqp.js";
|
|
29
29
|
import {
|
|
30
|
+
stripTagPrefix,
|
|
31
|
+
isRecord,
|
|
32
|
+
providerVisibleMessage,
|
|
30
33
|
MERGED_REASONING_PARTS_PREFIX,
|
|
31
34
|
decodeMergedReasoningParts,
|
|
32
35
|
SESSION_META_SELECT_COLUMNS,
|
|
@@ -52,32 +55,26 @@ import {
|
|
|
52
55
|
parseProcessedImageMarkers,
|
|
53
56
|
serializeProcessedImageMarkers,
|
|
54
57
|
getPendingPiCompactionMarkerState,
|
|
55
|
-
logPiCompactionMarkerClear
|
|
56
|
-
|
|
58
|
+
logPiCompactionMarkerClear,
|
|
59
|
+
isPrefixBoundThinkingModel
|
|
60
|
+
} from "./server-beydmd68.js";
|
|
57
61
|
import {
|
|
62
|
+
BoundedSessionMap,
|
|
63
|
+
getMeasuredToolDefinitionTokens,
|
|
58
64
|
getTableColumnNames,
|
|
59
65
|
tagTombstoneOwnerRange,
|
|
60
66
|
tagTombstoneOwnerKey,
|
|
61
67
|
tagRevisionKey,
|
|
62
68
|
tagIdentityRevisionKey,
|
|
63
69
|
deleteTagIdentityRevisions
|
|
64
|
-
} from "./server-
|
|
65
|
-
import {
|
|
66
|
-
stripTagPrefix,
|
|
67
|
-
isRecord,
|
|
68
|
-
providerVisibleMessage
|
|
69
|
-
} from "./server-rcchadw0.js";
|
|
70
|
+
} from "./server-b0357as4.js";
|
|
70
71
|
import {
|
|
71
72
|
withReadOnlySessionDb
|
|
72
73
|
} from "./server-7vrtk78d.js";
|
|
73
|
-
import {
|
|
74
|
-
BoundedSessionMap,
|
|
75
|
-
getMeasuredToolDefinitionTokens
|
|
76
|
-
} from "./server-kgq2e2hh.js";
|
|
77
74
|
import {
|
|
78
75
|
layoutLkgPrefix,
|
|
79
76
|
assembleLkgPrefix
|
|
80
|
-
} from "./server-
|
|
77
|
+
} from "./server-6k0rnwbd.js";
|
|
81
78
|
import {
|
|
82
79
|
gaDatabasePath2,
|
|
83
80
|
V2StoreReader2
|
|
@@ -442,7 +439,7 @@ function getUncoveredCompartmentEndsThrough(db, sessionId, endOrdinal = Number.M
|
|
|
442
439
|
const rows = db.prepare(`SELECT k.end_message_id, k.end_message,
|
|
443
440
|
n.start_message_id AS successor_id, n.start_message AS successor_start FROM compartments k
|
|
444
441
|
LEFT JOIN compartments n ON n.session_id = k.session_id AND n.sequence = k.sequence + 1
|
|
445
|
-
WHERE k.session_id = ?
|
|
442
|
+
WHERE k.session_id = ? AND k.end_message <= ? AND k.end_message > ? AND k.end_block_index IS NOT NULL
|
|
446
443
|
AND NOT COALESCE(n.sequence IS NOT NULL AND (
|
|
447
444
|
(n.start_message_id = k.end_message_id AND n.start_block_index > k.end_block_index)
|
|
448
445
|
OR n.start_message = k.end_message + 1), 0)
|
|
@@ -583,7 +580,7 @@ function readProjectDocsCanonical(projectDirectory) {
|
|
|
583
580
|
return { renderedBlock, canonicalHash };
|
|
584
581
|
}
|
|
585
582
|
// src/hooks/magic-context/lkg-slot.ts
|
|
586
|
-
import { createHash as
|
|
583
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
587
584
|
|
|
588
585
|
// src/hooks/magic-context/lkg-measured-request.ts
|
|
589
586
|
import { createHash as createHash4 } from "node:crypto";
|
|
@@ -2798,6 +2795,7 @@ function coldStartUncapturedReplay(args) {
|
|
|
2798
2795
|
|
|
2799
2796
|
// src/hooks/magic-context/lkg-recovery-prefix.ts
|
|
2800
2797
|
var sessions = new BoundedSessionMap(1000);
|
|
2798
|
+
var restartHeadChecked = new BoundedSessionMap(1000);
|
|
2801
2799
|
function noteUncertifiedNormalLkg(sessionId, revision) {
|
|
2802
2800
|
sessions.set(sessionId, {
|
|
2803
2801
|
...sessions.get(sessionId),
|
|
@@ -2816,6 +2814,7 @@ function rememberLkgDirtyRevision(sessionId, revision) {
|
|
|
2816
2814
|
}
|
|
2817
2815
|
function clearLkgRecoverySession(sessionId) {
|
|
2818
2816
|
sessions.delete(sessionId);
|
|
2817
|
+
restartHeadChecked.delete(sessionId);
|
|
2819
2818
|
clearLkgFenceProcessState(sessionId);
|
|
2820
2819
|
}
|
|
2821
2820
|
function noteLkgCapturedPrefix(sessionId) {
|
|
@@ -2831,13 +2830,14 @@ function readPersistedLkgUntaggedInputIds(db, sessionId) {
|
|
|
2831
2830
|
return [];
|
|
2832
2831
|
}
|
|
2833
2832
|
}
|
|
2834
|
-
function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
2835
|
-
const next = [...new Set(ids)].sort();
|
|
2833
|
+
function persistLkgUntaggedInputIds(db, sessionId, ids, alsoRecord) {
|
|
2834
|
+
const next = ids === undefined ? undefined : [...new Set(ids)].sort();
|
|
2836
2835
|
try {
|
|
2837
2836
|
return updateReplayDocument(db, sessionId, (doc) => {
|
|
2837
|
+
const recorded = alsoRecord?.(doc) ?? false;
|
|
2838
2838
|
const saved = Array.isArray(doc.lkgUntaggedInputIds) ? doc.lkgUntaggedInputIds : [];
|
|
2839
|
-
if (JSON.stringify(saved) === JSON.stringify(next))
|
|
2840
|
-
return
|
|
2839
|
+
if (next === undefined || JSON.stringify(saved) === JSON.stringify(next))
|
|
2840
|
+
return recorded;
|
|
2841
2841
|
doc.version = 2;
|
|
2842
2842
|
if (next.length > 0)
|
|
2843
2843
|
doc.lkgUntaggedInputIds = next;
|
|
@@ -2851,10 +2851,7 @@ function persistLkgUntaggedInputIds(db, sessionId, ids) {
|
|
|
2851
2851
|
}
|
|
2852
2852
|
}
|
|
2853
2853
|
function noteLkgRecoveryPrefix(args) {
|
|
2854
|
-
const digests = [
|
|
2855
|
-
...args.entry.entryContentDigests,
|
|
2856
|
-
...args.entry.pristineTail.map(lkgContentDigest)
|
|
2857
|
-
];
|
|
2854
|
+
const digests = [...args.entry.entryContentDigests, ...args.hostTailDigests];
|
|
2858
2855
|
if (digests.length !== args.entry.entryInputIds.length || digests.some((value) => !value))
|
|
2859
2856
|
return false;
|
|
2860
2857
|
const ids = args.entry.entryInputIds;
|
|
@@ -2891,8 +2888,15 @@ function readRecoveryIdentityPrefix(sessionId, inputs, messages, db) {
|
|
|
2891
2888
|
const prefix = state?.prefix;
|
|
2892
2889
|
if (!prefix && state?.uncertifiedNormal && ownsLkgDirtyFence(sessionId, state.fenceRevision))
|
|
2893
2890
|
return {};
|
|
2894
|
-
if (!prefix)
|
|
2895
|
-
|
|
2891
|
+
if (!prefix) {
|
|
2892
|
+
let restartedSlotJson;
|
|
2893
|
+
if (!state && slot && !restartHeadChecked.has(sessionId)) {
|
|
2894
|
+
restartHeadChecked.set(sessionId, true);
|
|
2895
|
+
restartedSlotJson = slot.jsonPrefix;
|
|
2896
|
+
}
|
|
2897
|
+
const restarted = restartedSlotJson === undefined ? {} : { restartedSlotJson };
|
|
2898
|
+
return !state && lkgRecoveryFenceUnclean(sessionId) || slot && lkgFenceRequiresRebuild(sessionId, slot, !!state) ? { rebuildReason: "lkg_restart_rebuild", ...restarted } : restarted;
|
|
2899
|
+
}
|
|
2896
2900
|
const keys = resolveLkgModelKeys(messages);
|
|
2897
2901
|
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?.()))
|
|
2898
2902
|
return { rebuildReason: "lkg_recovery_input_rebuild" };
|
|
@@ -2927,6 +2931,512 @@ function lkgRecoveryEntryUnproven(sessionId, entry, messages) {
|
|
|
2927
2931
|
return !!readRecoveryIdentityPrefix(sessionId, inputs, messages).rebuildReason;
|
|
2928
2932
|
}
|
|
2929
2933
|
|
|
2934
|
+
// src/hooks/magic-context/served-check.ts
|
|
2935
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
2936
|
+
var RECORD_SESSIONS = 256;
|
|
2937
|
+
var records = new BoundedSessionMap(RECORD_SESSIONS);
|
|
2938
|
+
var pending4 = new BoundedSessionMap(1000);
|
|
2939
|
+
var counters = new BoundedSessionMap(1000);
|
|
2940
|
+
var SERVED_FULL_CHECK_INTERVAL = 100;
|
|
2941
|
+
var COUNT_LOG_INTERVAL = 100;
|
|
2942
|
+
var HEAD_MIN = 2;
|
|
2943
|
+
var HEAD_MAX = 4;
|
|
2944
|
+
var lastWork = { fingerprinted: 0, digested: 0, full: false, ms: 0, shapeMs: 0 };
|
|
2945
|
+
function emptyCounters() {
|
|
2946
|
+
return {
|
|
2947
|
+
commits: 0,
|
|
2948
|
+
compared: 0,
|
|
2949
|
+
unknown: 0,
|
|
2950
|
+
refused: 0,
|
|
2951
|
+
appendOnly: 0,
|
|
2952
|
+
changed: 0,
|
|
2953
|
+
shorter: 0,
|
|
2954
|
+
modelChanged: 0,
|
|
2955
|
+
unpermittedChange: 0,
|
|
2956
|
+
mixedReplay: 0,
|
|
2957
|
+
thinkingPrefixChange: 0,
|
|
2958
|
+
sameShapeChange: 0,
|
|
2959
|
+
fullChecks: 0
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
function countersFor(sessionId) {
|
|
2963
|
+
let value = counters.get(sessionId);
|
|
2964
|
+
if (!value) {
|
|
2965
|
+
value = emptyCounters();
|
|
2966
|
+
counters.set(sessionId, value);
|
|
2967
|
+
}
|
|
2968
|
+
return value;
|
|
2969
|
+
}
|
|
2970
|
+
function pendingFor(sessionId) {
|
|
2971
|
+
let value = pending4.get(sessionId);
|
|
2972
|
+
if (!value) {
|
|
2973
|
+
value = {};
|
|
2974
|
+
pending4.set(sessionId, value);
|
|
2975
|
+
}
|
|
2976
|
+
return value;
|
|
2977
|
+
}
|
|
2978
|
+
function beginServedRequest(sessionId) {
|
|
2979
|
+
pending4.delete(sessionId);
|
|
2980
|
+
}
|
|
2981
|
+
function noteServedPassPermission(sessionId, permission) {
|
|
2982
|
+
pendingFor(sessionId).permission = permission;
|
|
2983
|
+
}
|
|
2984
|
+
function noteServedModel(sessionId, model) {
|
|
2985
|
+
if (model)
|
|
2986
|
+
pendingFor(sessionId).model = model;
|
|
2987
|
+
}
|
|
2988
|
+
function noteServedReplay(sessionId) {
|
|
2989
|
+
pendingFor(sessionId).replay = true;
|
|
2990
|
+
}
|
|
2991
|
+
function noteServedHostInput(sessionId) {
|
|
2992
|
+
pendingFor(sessionId).input = true;
|
|
2993
|
+
}
|
|
2994
|
+
function noteServedRefusal(sessionId) {
|
|
2995
|
+
pendingFor(sessionId).refused = true;
|
|
2996
|
+
}
|
|
2997
|
+
function countServedRefusal(sessionId) {
|
|
2998
|
+
try {
|
|
2999
|
+
pending4.delete(sessionId);
|
|
3000
|
+
countersFor(sessionId).refused += 1;
|
|
3001
|
+
} catch {}
|
|
3002
|
+
}
|
|
3003
|
+
function dropServedRecord(sessionId, reason) {
|
|
3004
|
+
try {
|
|
3005
|
+
const value = counters.peek(sessionId);
|
|
3006
|
+
if (value && value.commits + value.refused > 0)
|
|
3007
|
+
logCounts(sessionId, value, reason);
|
|
3008
|
+
if (records.has(sessionId))
|
|
3009
|
+
sessionLog2(sessionId, `served check: record dropped reason=${reason}; the next request is not compared`);
|
|
3010
|
+
} catch {}
|
|
3011
|
+
records.delete(sessionId);
|
|
3012
|
+
pending4.delete(sessionId);
|
|
3013
|
+
counters.delete(sessionId);
|
|
3014
|
+
}
|
|
3015
|
+
function forgetServedRecord(sessionId) {
|
|
3016
|
+
records.delete(sessionId);
|
|
3017
|
+
pending4.delete(sessionId);
|
|
3018
|
+
}
|
|
3019
|
+
function logCounts(sessionId, value, reason) {
|
|
3020
|
+
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}`);
|
|
3021
|
+
}
|
|
3022
|
+
function mix(hash, value) {
|
|
3023
|
+
return Math.imul(hash ^ (value | 0), 16777619);
|
|
3024
|
+
}
|
|
3025
|
+
function mixName(hash, value) {
|
|
3026
|
+
if (typeof value !== "string")
|
|
3027
|
+
return mix(hash, value === undefined ? -1 : -2);
|
|
3028
|
+
const length = value.length;
|
|
3029
|
+
const h = mix(hash, length);
|
|
3030
|
+
return length === 0 ? h : mix(h, value.charCodeAt(length - 1) << 16 | value.charCodeAt(length >> 1));
|
|
3031
|
+
}
|
|
3032
|
+
function mixId(hash, value) {
|
|
3033
|
+
if (typeof value !== "string")
|
|
3034
|
+
return mix(hash, value === undefined ? -1 : -2);
|
|
3035
|
+
const length = value.length;
|
|
3036
|
+
let h = mix(hash, length);
|
|
3037
|
+
const stop = length > 8 ? length - 8 : 0;
|
|
3038
|
+
let index = length - 1;
|
|
3039
|
+
for (;index > stop; index -= 2)
|
|
3040
|
+
h = mix(h, value.charCodeAt(index) << 16 | value.charCodeAt(index - 1));
|
|
3041
|
+
if (index === stop && length > 0)
|
|
3042
|
+
h = mix(h, value.charCodeAt(index));
|
|
3043
|
+
return h;
|
|
3044
|
+
}
|
|
3045
|
+
function mixNumber(hash, value) {
|
|
3046
|
+
const whole = Math.trunc(value);
|
|
3047
|
+
return mix(mix(mix(hash, whole), whole / 4294967296), Math.round((value - whole) * 1e6));
|
|
3048
|
+
}
|
|
3049
|
+
function mixLength(hash, value) {
|
|
3050
|
+
return typeof value === "string" ? mix(hash, value.length) : mix(hash, value === undefined ? -1 : -2);
|
|
3051
|
+
}
|
|
3052
|
+
function mixShallow(hash, value) {
|
|
3053
|
+
switch (typeof value) {
|
|
3054
|
+
case "string":
|
|
3055
|
+
return mix(mix(hash, 1), value.length);
|
|
3056
|
+
case "number":
|
|
3057
|
+
return mixNumber(mix(hash, 2), value);
|
|
3058
|
+
case "boolean":
|
|
3059
|
+
return mix(hash, value ? 5 : 4);
|
|
3060
|
+
case "undefined":
|
|
3061
|
+
return mix(hash, -1);
|
|
3062
|
+
case "object":
|
|
3063
|
+
if (value === null)
|
|
3064
|
+
return mix(hash, 3);
|
|
3065
|
+
if (Array.isArray(value))
|
|
3066
|
+
return mix(mix(hash, 9), value.length);
|
|
3067
|
+
{
|
|
3068
|
+
const size = value.byteLength;
|
|
3069
|
+
return typeof size === "number" ? mix(mix(hash, 7), size) : mix(hash, 10);
|
|
3070
|
+
}
|
|
3071
|
+
default:
|
|
3072
|
+
return mix(hash, 6);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
function mixToolState(hash, state) {
|
|
3076
|
+
let h = mixName(hash, state.status);
|
|
3077
|
+
h = mixShallow(h, state.input);
|
|
3078
|
+
h = mixShallow(h, state.output);
|
|
3079
|
+
if (state.error !== undefined)
|
|
3080
|
+
h = mixShallow(h, state.error);
|
|
3081
|
+
if (state.attachments !== undefined)
|
|
3082
|
+
h = mixShallow(h, state.attachments);
|
|
3083
|
+
if (state.content !== undefined)
|
|
3084
|
+
h = mixShallow(h, state.content);
|
|
3085
|
+
const time = state.time;
|
|
3086
|
+
h = mix(h, time && typeof time === "object" && time.compacted !== undefined ? 1 : 0);
|
|
3087
|
+
if (state.status === "error") {
|
|
3088
|
+
const metadata = state.metadata;
|
|
3089
|
+
if (metadata && typeof metadata === "object" && metadata.interrupted === true)
|
|
3090
|
+
h = mixShallow(h, metadata.output);
|
|
3091
|
+
}
|
|
3092
|
+
return h;
|
|
3093
|
+
}
|
|
3094
|
+
function isThinkingType(type) {
|
|
3095
|
+
return type === "reasoning" || type === "thinking" || type === "redacted_thinking";
|
|
3096
|
+
}
|
|
3097
|
+
function isKeptThinkingPart(part) {
|
|
3098
|
+
if (!isThinkingType(part.type) || part.ignored === true)
|
|
3099
|
+
return false;
|
|
3100
|
+
if (part.type === "redacted_thinking" || part.redacted === true)
|
|
3101
|
+
return true;
|
|
3102
|
+
if (typeof part.text === "string" && part.text !== "")
|
|
3103
|
+
return true;
|
|
3104
|
+
if (typeof part.thinking === "string" && part.thinking !== "")
|
|
3105
|
+
return true;
|
|
3106
|
+
const metadata = part.metadata;
|
|
3107
|
+
if (metadata && typeof metadata === "object") {
|
|
3108
|
+
for (const record of Object.values(metadata))
|
|
3109
|
+
if (record && typeof record === "object" && "redactedData" in record)
|
|
3110
|
+
return true;
|
|
3111
|
+
}
|
|
3112
|
+
return false;
|
|
3113
|
+
}
|
|
3114
|
+
var PART_FIELDS = [
|
|
3115
|
+
"text",
|
|
3116
|
+
"thinking",
|
|
3117
|
+
"thinkingSignature",
|
|
3118
|
+
"signature",
|
|
3119
|
+
"redacted",
|
|
3120
|
+
"data",
|
|
3121
|
+
"url",
|
|
3122
|
+
"mime",
|
|
3123
|
+
"mimeType",
|
|
3124
|
+
"mediaType",
|
|
3125
|
+
"filename",
|
|
3126
|
+
"name",
|
|
3127
|
+
"tool",
|
|
3128
|
+
"callID",
|
|
3129
|
+
"toolCallId",
|
|
3130
|
+
"input",
|
|
3131
|
+
"arguments",
|
|
3132
|
+
"output",
|
|
3133
|
+
"error",
|
|
3134
|
+
"isError",
|
|
3135
|
+
"providerExecuted",
|
|
3136
|
+
"synthetic",
|
|
3137
|
+
"ignored"
|
|
3138
|
+
];
|
|
3139
|
+
var walkOut = { partThinking: false, messageThinking: false, messageHead: false };
|
|
3140
|
+
function mixPart(hash, rawPart) {
|
|
3141
|
+
walkOut.partThinking = false;
|
|
3142
|
+
if (!rawPart || typeof rawPart !== "object")
|
|
3143
|
+
return mix(hash, 11);
|
|
3144
|
+
const part = rawPart;
|
|
3145
|
+
const type = part.type;
|
|
3146
|
+
let h = mixId(mixName(hash, type), part.id);
|
|
3147
|
+
if (type === "text") {
|
|
3148
|
+
h = mixLength(h, part.text);
|
|
3149
|
+
return mix(h, (part.synthetic === true ? 1 : 0) | (part.ignored === true ? 2 : 0));
|
|
3150
|
+
}
|
|
3151
|
+
if (type === "tool" && part.state && typeof part.state === "object")
|
|
3152
|
+
return mixToolState(mixId(mixName(h, part.tool), part.callID), part.state);
|
|
3153
|
+
for (let index = 0;index < PART_FIELDS.length; index += 1) {
|
|
3154
|
+
const value = part[PART_FIELDS[index]];
|
|
3155
|
+
if (value !== undefined)
|
|
3156
|
+
h = mixShallow(mix(h, index), value);
|
|
3157
|
+
}
|
|
3158
|
+
const result = part.result;
|
|
3159
|
+
if (result && typeof result === "object") {
|
|
3160
|
+
h = mixName(h, result.type);
|
|
3161
|
+
h = mixShallow(h, result.value);
|
|
3162
|
+
}
|
|
3163
|
+
if (isThinkingType(type)) {
|
|
3164
|
+
walkOut.partThinking = isKeptThinkingPart(part);
|
|
3165
|
+
const metadata = part.metadata;
|
|
3166
|
+
const anthropic = metadata && typeof metadata === "object" ? metadata.anthropic : undefined;
|
|
3167
|
+
if (anthropic && typeof anthropic === "object") {
|
|
3168
|
+
h = mixShallow(h, anthropic.signature);
|
|
3169
|
+
h = mixShallow(h, anthropic.redactedData);
|
|
3170
|
+
} else
|
|
3171
|
+
h = mix(h, metadata && typeof metadata === "object" ? 17 : 18);
|
|
3172
|
+
}
|
|
3173
|
+
return h;
|
|
3174
|
+
}
|
|
3175
|
+
function messageShape(message) {
|
|
3176
|
+
const record = message && typeof message === "object" ? message : {};
|
|
3177
|
+
const info = record.info && typeof record.info === "object" ? record.info : record;
|
|
3178
|
+
const parts = Array.isArray(record.parts) ? record.parts : record.content;
|
|
3179
|
+
const role = info.role;
|
|
3180
|
+
let hash = mixId(2166136261, info.id);
|
|
3181
|
+
hash = mixName(hash, role);
|
|
3182
|
+
if (typeof record.timestamp === "number")
|
|
3183
|
+
hash = mixNumber(hash, record.timestamp);
|
|
3184
|
+
if (typeof record.toolCallId === "string")
|
|
3185
|
+
hash = mixId(hash, record.toolCallId);
|
|
3186
|
+
if (record.isError === true)
|
|
3187
|
+
hash = mix(hash, 12);
|
|
3188
|
+
if (info.summary === true)
|
|
3189
|
+
hash = mix(hash, 13);
|
|
3190
|
+
let thinking = false;
|
|
3191
|
+
let synthetic = info.synthetic === true || info.summary === true;
|
|
3192
|
+
if (typeof parts === "string") {
|
|
3193
|
+
hash = mix(mix(hash, 14), parts.length);
|
|
3194
|
+
} else if (Array.isArray(parts)) {
|
|
3195
|
+
hash = mix(mix(hash, 15), parts.length);
|
|
3196
|
+
let allSynthetic = parts.length > 0;
|
|
3197
|
+
for (const part of parts) {
|
|
3198
|
+
hash = mixPart(hash, part);
|
|
3199
|
+
if (walkOut.partThinking)
|
|
3200
|
+
thinking = true;
|
|
3201
|
+
if (allSynthetic && part?.synthetic !== true)
|
|
3202
|
+
allSynthetic = false;
|
|
3203
|
+
}
|
|
3204
|
+
if (allSynthetic)
|
|
3205
|
+
synthetic = true;
|
|
3206
|
+
} else {
|
|
3207
|
+
hash = mix(hash, 16);
|
|
3208
|
+
}
|
|
3209
|
+
walkOut.messageThinking = thinking && role === "assistant";
|
|
3210
|
+
walkOut.messageHead = synthetic || role === "system" || role === "compactionSummary" || role === "branchSummary";
|
|
3211
|
+
return hash >>> 0;
|
|
3212
|
+
}
|
|
3213
|
+
function digestInto(message, out, index) {
|
|
3214
|
+
let json;
|
|
3215
|
+
try {
|
|
3216
|
+
json = JSON.stringify(contentSnapshotValue(message));
|
|
3217
|
+
} catch {
|
|
3218
|
+
json = undefined;
|
|
3219
|
+
}
|
|
3220
|
+
if (json === undefined) {
|
|
3221
|
+
out[2 * index] = 0;
|
|
3222
|
+
out[2 * index + 1] = 0;
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
const digest = createHash6("sha256").update(json).digest();
|
|
3226
|
+
out[2 * index] = digest.readUInt32LE(0);
|
|
3227
|
+
out[2 * index + 1] = digest.readUInt32LE(4);
|
|
3228
|
+
}
|
|
3229
|
+
function digestsDiffer(a, ai, b, bi) {
|
|
3230
|
+
const a0 = a[2 * ai];
|
|
3231
|
+
const a1 = a[2 * ai + 1];
|
|
3232
|
+
const b0 = b[2 * bi];
|
|
3233
|
+
const b1 = b[2 * bi + 1];
|
|
3234
|
+
if (a0 === 0 && a1 === 0 || b0 === 0 && b1 === 0)
|
|
3235
|
+
return false;
|
|
3236
|
+
return a0 !== b0 || a1 !== b1;
|
|
3237
|
+
}
|
|
3238
|
+
function permittedLabel(permitted) {
|
|
3239
|
+
return permitted === null ? "unknown" : String(permitted);
|
|
3240
|
+
}
|
|
3241
|
+
function commitServedRequest(args) {
|
|
3242
|
+
try {
|
|
3243
|
+
return commit(args);
|
|
3244
|
+
} catch (error) {
|
|
3245
|
+
try {
|
|
3246
|
+
records.delete(args.sessionId);
|
|
3247
|
+
sessionLog2(args.sessionId, "served check failed; the record is unknown again:", error);
|
|
3248
|
+
} catch {}
|
|
3249
|
+
return null;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
function commit(args) {
|
|
3253
|
+
const { sessionId, messages, host } = args;
|
|
3254
|
+
const startedAt = performance.now();
|
|
3255
|
+
const note = pending4.peek(sessionId) ?? {};
|
|
3256
|
+
pending4.delete(sessionId);
|
|
3257
|
+
const count = countersFor(sessionId);
|
|
3258
|
+
const kind = note.replay ? "replay" : note.input ? "input" : "pass";
|
|
3259
|
+
const permission = note.permission;
|
|
3260
|
+
const permitted = permission?.permitted ?? (args.compactionOff ? false : kind === "input" ? false : null);
|
|
3261
|
+
const prior = records.get(sessionId);
|
|
3262
|
+
if (note.refused) {
|
|
3263
|
+
count.refused += 1;
|
|
3264
|
+
return {
|
|
3265
|
+
class: "refused",
|
|
3266
|
+
kind,
|
|
3267
|
+
firstIndex: null,
|
|
3268
|
+
recorded: prior?.count ?? 0,
|
|
3269
|
+
served: messages.length,
|
|
3270
|
+
seenBy: null,
|
|
3271
|
+
keptThinkingIndex: -1,
|
|
3272
|
+
recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
|
|
3273
|
+
permitted,
|
|
3274
|
+
events: []
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
count.commits += 1;
|
|
3278
|
+
const m = messages.length;
|
|
3279
|
+
const providerID = note.model?.providerID ?? args.providerID;
|
|
3280
|
+
const modelID = note.model?.modelID ?? args.modelID;
|
|
3281
|
+
const prefixBound = isPrefixBoundThinkingModel(providerID, modelID);
|
|
3282
|
+
const modelKey = modelID ? `${providerID ?? ""}/${modelID}` : null;
|
|
3283
|
+
const shapes = new Uint32Array(m);
|
|
3284
|
+
let keptThinkingIndex = -1;
|
|
3285
|
+
let headCount = Math.min(HEAD_MIN, m);
|
|
3286
|
+
let leading = true;
|
|
3287
|
+
for (let index = 0;index < m; index += 1) {
|
|
3288
|
+
shapes[index] = messageShape(messages[index]);
|
|
3289
|
+
if (prefixBound && keptThinkingIndex < 0 && walkOut.messageThinking)
|
|
3290
|
+
keptThinkingIndex = index;
|
|
3291
|
+
if (leading && index >= HEAD_MIN) {
|
|
3292
|
+
if (walkOut.messageHead && index < HEAD_MAX)
|
|
3293
|
+
headCount = index + 1;
|
|
3294
|
+
else
|
|
3295
|
+
leading = false;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
const shapeMs = performance.now() - startedAt;
|
|
3299
|
+
const digests = new Uint32Array(2 * m);
|
|
3300
|
+
const computed = new Uint8Array(m);
|
|
3301
|
+
let digested = 0;
|
|
3302
|
+
const digest = (index) => {
|
|
3303
|
+
if (index < 0 || index >= m || computed[index])
|
|
3304
|
+
return;
|
|
3305
|
+
computed[index] = 1;
|
|
3306
|
+
digested += 1;
|
|
3307
|
+
digestInto(messages[index], digests, index);
|
|
3308
|
+
};
|
|
3309
|
+
const finish = (comparison, full, passesSinceFull) => {
|
|
3310
|
+
records.set(sessionId, {
|
|
3311
|
+
count: m,
|
|
3312
|
+
shapes,
|
|
3313
|
+
digests,
|
|
3314
|
+
modelKey: modelKey ?? prior?.modelKey ?? null,
|
|
3315
|
+
kind,
|
|
3316
|
+
keptThinkingIndex,
|
|
3317
|
+
passesSinceFull
|
|
3318
|
+
});
|
|
3319
|
+
lastWork = { fingerprinted: m, digested, full, ms: 0, shapeMs };
|
|
3320
|
+
if (count.commits % COUNT_LOG_INTERVAL === 0)
|
|
3321
|
+
logCounts(sessionId, count, "periodic");
|
|
3322
|
+
lastWork.ms = performance.now() - startedAt;
|
|
3323
|
+
return { ...comparison, kind, permitted, served: m };
|
|
3324
|
+
};
|
|
3325
|
+
const modelChanged = prior !== undefined && prior.modelKey !== null && modelKey !== null && prior.modelKey !== modelKey;
|
|
3326
|
+
if (!prior || modelChanged) {
|
|
3327
|
+
for (let index = 0;index < m; index += 1)
|
|
3328
|
+
digest(index);
|
|
3329
|
+
if (prior)
|
|
3330
|
+
count.modelChanged += 1;
|
|
3331
|
+
else
|
|
3332
|
+
count.unknown += 1;
|
|
3333
|
+
return finish({
|
|
3334
|
+
class: prior ? "model_change" : "unknown",
|
|
3335
|
+
firstIndex: null,
|
|
3336
|
+
recorded: prior?.count ?? 0,
|
|
3337
|
+
seenBy: null,
|
|
3338
|
+
keptThinkingIndex,
|
|
3339
|
+
recordedThinkingIndex: prior?.keptThinkingIndex ?? -1,
|
|
3340
|
+
events: []
|
|
3341
|
+
}, true, 0);
|
|
3342
|
+
}
|
|
3343
|
+
count.compared += 1;
|
|
3344
|
+
const n = prior.count;
|
|
3345
|
+
const overlap = Math.min(n, m);
|
|
3346
|
+
let shapeDiff = -1;
|
|
3347
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3348
|
+
if (shapes[index] !== prior.shapes[index]) {
|
|
3349
|
+
shapeDiff = index;
|
|
3350
|
+
break;
|
|
3351
|
+
}
|
|
3352
|
+
for (let index = 0;index < headCount; index += 1)
|
|
3353
|
+
digest(index);
|
|
3354
|
+
digest(n - 1);
|
|
3355
|
+
digest(prior.keptThinkingIndex);
|
|
3356
|
+
digest(keptThinkingIndex);
|
|
3357
|
+
for (let index = n;index < m; index += 1)
|
|
3358
|
+
digest(index);
|
|
3359
|
+
let handfulDiff = -1;
|
|
3360
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3361
|
+
if (computed[index] && digestsDiffer(digests, index, prior.digests, index)) {
|
|
3362
|
+
handfulDiff = index;
|
|
3363
|
+
break;
|
|
3364
|
+
}
|
|
3365
|
+
const full = kind === "replay" || prior.kind === "replay" || shapeDiff >= 0 || handfulDiff >= 0 || m < n || prior.passesSinceFull + 1 >= SERVED_FULL_CHECK_INTERVAL;
|
|
3366
|
+
let contentDiff = handfulDiff;
|
|
3367
|
+
if (full) {
|
|
3368
|
+
count.fullChecks += 1;
|
|
3369
|
+
for (let index = 0;index < m; index += 1)
|
|
3370
|
+
digest(index);
|
|
3371
|
+
contentDiff = -1;
|
|
3372
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3373
|
+
if (digestsDiffer(digests, index, prior.digests, index)) {
|
|
3374
|
+
contentDiff = index;
|
|
3375
|
+
break;
|
|
3376
|
+
}
|
|
3377
|
+
} else {
|
|
3378
|
+
for (let index = 0;index < overlap; index += 1)
|
|
3379
|
+
if (!computed[index]) {
|
|
3380
|
+
digests[2 * index] = prior.digests[2 * index];
|
|
3381
|
+
digests[2 * index + 1] = prior.digests[2 * index + 1];
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
const candidates = [shapeDiff, contentDiff].filter((value) => value >= 0);
|
|
3385
|
+
const firstIndex = candidates.length > 0 ? Math.min(...candidates) : -1;
|
|
3386
|
+
let comparisonClass;
|
|
3387
|
+
let seenBy = null;
|
|
3388
|
+
if (firstIndex >= 0) {
|
|
3389
|
+
comparisonClass = "changed";
|
|
3390
|
+
count.changed += 1;
|
|
3391
|
+
seenBy = shapeDiff >= 0 && shapeDiff === firstIndex ? "shape" : handfulDiff === firstIndex ? "digest" : "full";
|
|
3392
|
+
} else if (m < n) {
|
|
3393
|
+
comparisonClass = "shorter";
|
|
3394
|
+
count.shorter += 1;
|
|
3395
|
+
seenBy = "length";
|
|
3396
|
+
} else {
|
|
3397
|
+
comparisonClass = "append_only";
|
|
3398
|
+
count.appendOnly += 1;
|
|
3399
|
+
}
|
|
3400
|
+
const reportedIndex = firstIndex >= 0 ? firstIndex : comparisonClass === "shorter" ? m : null;
|
|
3401
|
+
const events = [];
|
|
3402
|
+
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";
|
|
3403
|
+
if (reportedIndex !== null) {
|
|
3404
|
+
const after = n - reportedIndex;
|
|
3405
|
+
if (kind === "replay") {
|
|
3406
|
+
events.push("mixed_replay");
|
|
3407
|
+
count.mixedReplay += 1;
|
|
3408
|
+
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}`);
|
|
3409
|
+
} else if (permitted !== true) {
|
|
3410
|
+
events.push("unpermitted_change");
|
|
3411
|
+
count.unpermittedChange += 1;
|
|
3412
|
+
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}`);
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
if (firstIndex >= 0 && shapeDiff !== firstIndex) {
|
|
3416
|
+
events.push("same_shape_change");
|
|
3417
|
+
count.sameShapeChange += 1;
|
|
3418
|
+
sessionLog2(sessionId, `served check: content changed with the same shape first_index=${firstIndex} seen_by=${seenBy} kind=${kind} permitted=${permittedLabel(permitted)} host=${host}`);
|
|
3419
|
+
}
|
|
3420
|
+
if (prefixBound && firstIndex >= 0) {
|
|
3421
|
+
const unstripped = keptThinkingIndex >= 0 && firstIndex <= keptThinkingIndex;
|
|
3422
|
+
const stripped = !unstripped && prior.keptThinkingIndex >= 0 && firstIndex <= prior.keptThinkingIndex;
|
|
3423
|
+
if (unstripped || stripped && permitted !== true) {
|
|
3424
|
+
events.push("thinking_prefix_change");
|
|
3425
|
+
count.thinkingPrefixChange += 1;
|
|
3426
|
+
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}`);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
return finish({
|
|
3430
|
+
class: comparisonClass,
|
|
3431
|
+
firstIndex: reportedIndex,
|
|
3432
|
+
recorded: n,
|
|
3433
|
+
seenBy,
|
|
3434
|
+
keptThinkingIndex,
|
|
3435
|
+
recordedThinkingIndex: prior.keptThinkingIndex,
|
|
3436
|
+
events
|
|
3437
|
+
}, full, full ? 0 : prior.passesSinceFull + 1);
|
|
3438
|
+
}
|
|
3439
|
+
|
|
2930
3440
|
// src/hooks/magic-context/lkg-slot.ts
|
|
2931
3441
|
var POSITIONAL_SYSTEM_KEY = "\x00mc-system:";
|
|
2932
3442
|
function lkgInputIdentity(id, role, index) {
|
|
@@ -3136,7 +3646,7 @@ var DIGEST_CHUNK_BYTES = 64 * 1024;
|
|
|
3136
3646
|
var digestChunk;
|
|
3137
3647
|
function lkgContentDigestFromFields(fields) {
|
|
3138
3648
|
lkgDigestsComputed += 1;
|
|
3139
|
-
const hash =
|
|
3649
|
+
const hash = createHash7("sha256");
|
|
3140
3650
|
digestChunk ??= Buffer.allocUnsafe(DIGEST_CHUNK_BYTES);
|
|
3141
3651
|
const chunk = digestChunk;
|
|
3142
3652
|
let offset = 0;
|
|
@@ -3199,7 +3709,7 @@ function legacyLkgDigestFromFields(fields) {
|
|
|
3199
3709
|
const value = typeof field === "symbol" ? field.description ?? "" : String(field);
|
|
3200
3710
|
key += `${typeof field}:${value.length}:${value}\x00`;
|
|
3201
3711
|
}
|
|
3202
|
-
return
|
|
3712
|
+
return createHash7("sha256").update(key).digest("base64url");
|
|
3203
3713
|
}
|
|
3204
3714
|
function legacyLkgContentDigest(message) {
|
|
3205
3715
|
const fields = flattenContentFields(withoutEmptyUserDiffSummary(message));
|
|
@@ -4602,4 +5112,4 @@ var ERROR_CLASSES = new Set([
|
|
|
4602
5112
|
"permission_denied",
|
|
4603
5113
|
"unknown"
|
|
4604
5114
|
]);
|
|
4605
|
-
export { 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, advanceSessionActivity, backfillSessionActivity, 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, resolveLkgModelKeys, createLkgEntryProjector, captureLkgSlot, validateAnthropicReasoningRuns, validateLkgSeam, replayLkg, coldStartRawServedIndex, coldStartUncapturedReplay, noteUncertifiedNormalLkg, hasProcessLocalLkgProof, lkgDirtyRevision, rememberLkgDirtyRevision, readPersistedLkgUntaggedInputIds, persistLkgUntaggedInputIds, noteLkgRecoveryPrefix, readLkgRecoveryPrefix, noteLkgHealthyPrefix, lkgRecoveryReplayUnproven, lkgRecoveryEntryUnproven, lkgInputIdentity, 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 };
|
|
5115
|
+
export { 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, advanceSessionActivity, backfillSessionActivity, 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, 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, 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 };
|