@cortexkit/opencode-magic-context 0.49.24 → 0.49.26
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 +4 -4
- package/dist/chunk-embedding-write-worker.js +5 -5
- package/dist/{compartment-chunk-embedding-eypvn607.js → compartment-chunk-embedding-96ec8a7h.js} +3 -3
- package/dist/{conflict-warning-hook-a27bhggg.js → conflict-warning-hook-dv8fdc2w.js} +4 -4
- package/dist/{context-tvrjhnmj.js → context-pjqa24nd.js} +30 -24
- package/dist/{embedding-backfill-vddgmem3.js → embedding-backfill-a91rvdf9.js} +5 -5
- package/dist/features/magic-context/tool-definition-tokens.d.ts +113 -57
- package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -1
- package/dist/hooks/magic-context/caveman-cleanup.d.ts +14 -0
- package/dist/hooks/magic-context/caveman-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts +11 -0
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts +12 -4
- package/dist/hooks/magic-context/final-wire-token-estimate.d.ts.map +1 -1
- package/dist/hooks/magic-context/foreign-text-parts.d.ts +47 -0
- package/dist/hooks/magic-context/foreign-text-parts.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-measured-request.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-replay-fit.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +21 -0
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +20 -0
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/signed-thinking-fit-snapshot.d.ts +42 -0
- package/dist/hooks/magic-context/signed-thinking-fit-snapshot.d.ts.map +1 -0
- package/dist/hooks/magic-context/tag-messages.d.ts +15 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +7 -0
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-2haxh8h3.js → index-064v90e8.js} +1 -1
- package/dist/{index-p6evxfcc.js → index-40ma8m0c.js} +7 -49
- package/dist/{index-6g7tyb6e.js → index-56tfs78r.js} +96 -41
- package/dist/{index-jrjr58ez.js → index-6g1zq1sk.js} +3 -3
- package/dist/{index-3d5wnkq7.js → index-6tmf87w0.js} +1 -1
- package/dist/index-cfaet9cg.js +405 -0
- package/dist/{index-t1zk694n.js → index-dn2ke3b9.js} +30 -14
- package/dist/{index-t6j3qxnd.js → index-e5b61ty6.js} +1 -1
- package/dist/{index-dds7cxhz.js → index-hjnrp6vy.js} +67 -21
- package/dist/{index-c9zrgcnt.js → index-j43m40zd.js} +1 -1
- package/dist/{index-7tdtpqrg.js → index-m8va3mma.js} +39 -6
- package/dist/{index-z928hmnp.js → index-mphkpyap.js} +1 -1
- package/dist/{index-21bkd3m6.js → index-r3bteyev.js} +5 -5
- package/dist/{index-8e9qsnrw.js → index-rp78nqvr.js} +169 -11
- package/dist/{index-z05n7702.js → index-sgchhbvy.js} +1 -1
- package/dist/{index-jd0y50w3.js → index-va2g2q57.js} +3 -3
- package/dist/{index-jcr6pe7z.js → index-w55zp7kf.js} +1 -1
- package/dist/{index-szf8r0ba.js → index-xbbgcwd2.js} +1 -1
- package/dist/{index-7516anfj.js → index-xyx2ge2y.js} +4 -4
- package/dist/{index-57jf5ztp.js → index-zn2n24yr.js} +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -35
- package/dist/{message-fts-rowid-map-9e1getgs.js → message-fts-rowid-map-4ksatb6f.js} +2 -2
- package/dist/{message-index-bounded-k8pgrxad.js → message-index-bounded-whh5wv4a.js} +7 -7
- package/dist/{message-index-1sgzev6c.js → message-index-ywx53y30.js} +7 -7
- package/dist/migration-worker.js +4 -4
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/{project-embedding-registry-rstzmb60.js → project-embedding-registry-t9fx6jwh.js} +4 -4
- package/dist/raw-ordinal-warmup-worker.js +6 -6
- package/dist/{read-session-chunk-q9z6s48t.js → read-session-chunk-mqmkgdx0.js} +6 -4
- package/dist/{read-session-raw-s4amywnh.js → read-session-raw-dy2xxafq.js} +3 -1
- package/dist/{recomp-orchestrator-hr8ddk8z.js → recomp-orchestrator-qwcz86r1.js} +14 -14
- package/dist/{search-archive-c00etw7k.js → search-archive-8md3twv2.js} +5 -5
- package/dist/{search-3zjjmc60.js → search-y2t97tbb.js} +11 -11
- package/dist/{send-session-notification-ygj4mja0.js → send-session-notification-kzazs7fy.js} +3 -3
- package/dist/tools/ctx-reduce/tools.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-rredw6bz.js → transform-postprocess-phase-ppm1tfa7.js} +14 -14
- package/dist/v2/auto-search-worker.js +4 -4
- package/dist/v2/chunk-embedding-write-worker.js +5 -5
- package/dist/v2/{compartment-chunk-embedding-tk6g4q80.js → compartment-chunk-embedding-5rmrn09z.js} +3 -3
- package/dist/v2/{context-zbydzq4g.js → context-10pj3bwd.js} +245 -45
- package/dist/v2/{embedding-backfill-w5qp7t28.js → embedding-backfill-r9mzt2eg.js} +5 -5
- package/dist/v2/hooks/context.d.ts +4 -0
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/{message-fts-rowid-map-pqk3a55v.js → message-fts-rowid-map-2s3ta05x.js} +2 -2
- package/dist/v2/{message-index-bounded-a9xa8wsq.js → message-index-bounded-f4269d3a.js} +6 -6
- package/dist/v2/{message-index-5gnnn64b.js → message-index-v6g8mgn7.js} +6 -6
- package/dist/v2/migration-worker.js +4 -4
- package/dist/v2/{project-embedding-registry-e7zftfvj.js → project-embedding-registry-tgtmart7.js} +4 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +6 -6
- package/dist/v2/{read-session-chunk-qqvda7zv.js → read-session-chunk-ym5zvexn.js} +5 -3
- package/dist/v2/{read-session-raw-ppjxnqk4.js → read-session-raw-484g8kf2.js} +3 -1
- package/dist/v2/{recomp-orchestrator-nmt9y25j.js → recomp-orchestrator-b44s2snm.js} +11 -11
- package/dist/v2/{search-6dawx2gt.js → search-75tf953m.js} +10 -10
- package/dist/v2/{search-archive-dhqj1w31.js → search-archive-pmf2c1kb.js} +4 -4
- package/dist/v2/{send-session-notification-f8scq6ae.js → send-session-notification-gd21f5rq.js} +1 -1
- package/dist/v2/{server-y9ncq4ck.js → server-317f3x9y.js} +3 -3
- package/dist/v2/{server-wxrdher8.js → server-4frtg2z1.js} +1 -1
- package/dist/v2/server-7d6m1p2b.js +361 -0
- package/dist/v2/{server-pw21ypwb.js → server-7dpnt0ys.js} +1 -1
- package/dist/v2/{server-r209n2fk.js → server-9zh78t8y.js} +65 -19
- package/dist/v2/{server-swvhxhxz.js → server-erk2bvdf.js} +39 -6
- package/dist/v2/{server-q5z0gag0.js → server-hnmm8yzq.js} +1 -1
- package/dist/v2/{server-gwmshgx9.js → server-jcsw05aa.js} +29 -13
- package/dist/v2/{server-mefps930.js → server-k46ec388.js} +7 -49
- package/dist/v2/{server-9xbbaekh.js → server-nmwhe524.js} +1 -1
- package/dist/v2/{server-9e55n4wx.js → server-vjer2jdn.js} +5 -5
- package/dist/v2/{server-16dpnz56.js → server-w7x9wgm0.js} +2 -2
- package/dist/v2/{server-8j2e7t31.js → server-wj8h2q21.js} +1 -1
- package/dist/v2/server.js +2 -2
- package/dist/v2/{wrapup-orchestrator-9z81xj66.js → wrapup-orchestrator-gwww44st.js} +11 -11
- package/dist/{wrapup-orchestrator-dbnb530w.js → wrapup-orchestrator-a9r8r4sk.js} +15 -15
- package/package.json +1 -1
- package/dist/index-j76ah6d7.js +0 -120
- package/dist/v2/server-d1dzgvwd.js +0 -120
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import {
|
|
2
|
+
estimateTokens
|
|
3
|
+
} from "./server-3mz2qh5a.js";
|
|
4
|
+
import {
|
|
5
|
+
stableStringify
|
|
6
|
+
} from "./server-rqebawx1.js";
|
|
7
|
+
|
|
8
|
+
// src/features/magic-context/tool-definition-tokens.ts
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
|
|
11
|
+
// src/shared/bounded-session-map.ts
|
|
12
|
+
class BoundedSessionMap {
|
|
13
|
+
maxEntries;
|
|
14
|
+
store = new Map;
|
|
15
|
+
constructor(maxEntries) {
|
|
16
|
+
if (!Number.isFinite(maxEntries) || maxEntries < 1) {
|
|
17
|
+
throw new Error(`BoundedSessionMap: maxEntries must be >= 1, got ${maxEntries}`);
|
|
18
|
+
}
|
|
19
|
+
this.maxEntries = maxEntries;
|
|
20
|
+
}
|
|
21
|
+
get(sessionId) {
|
|
22
|
+
const value = this.store.get(sessionId);
|
|
23
|
+
if (value === undefined)
|
|
24
|
+
return;
|
|
25
|
+
this.store.delete(sessionId);
|
|
26
|
+
this.store.set(sessionId, value);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
peek(sessionId) {
|
|
30
|
+
return this.store.get(sessionId);
|
|
31
|
+
}
|
|
32
|
+
has(sessionId) {
|
|
33
|
+
return this.store.has(sessionId);
|
|
34
|
+
}
|
|
35
|
+
set(sessionId, value) {
|
|
36
|
+
if (this.store.has(sessionId)) {
|
|
37
|
+
this.store.delete(sessionId);
|
|
38
|
+
} else if (this.store.size >= this.maxEntries) {
|
|
39
|
+
const oldest = this.store.keys().next().value;
|
|
40
|
+
if (oldest !== undefined)
|
|
41
|
+
this.store.delete(oldest);
|
|
42
|
+
}
|
|
43
|
+
this.store.set(sessionId, value);
|
|
44
|
+
}
|
|
45
|
+
delete(sessionId) {
|
|
46
|
+
return this.store.delete(sessionId);
|
|
47
|
+
}
|
|
48
|
+
clear() {
|
|
49
|
+
this.store.clear();
|
|
50
|
+
}
|
|
51
|
+
get size() {
|
|
52
|
+
return this.store.size;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/features/magic-context/tool-definition-tokens.ts
|
|
57
|
+
var ACTIVITY_WINDOW_MS = 10 * 60000;
|
|
58
|
+
var MAX_ACTIVITY_GAP_MS = 60000;
|
|
59
|
+
var RETIRED_CACHE_LIMIT = 64;
|
|
60
|
+
var WRITE_RETRY_MS = 5000;
|
|
61
|
+
var WINDOWED_SINCE_KEY = "tool_definition_measurements:windowed_since";
|
|
62
|
+
var routes = new Map;
|
|
63
|
+
var sessionFlights = new BoundedSessionMap(1000);
|
|
64
|
+
var persistenceDb = null;
|
|
65
|
+
var windowedSince;
|
|
66
|
+
var boundAt = 0;
|
|
67
|
+
var cachedInsertStmt = null;
|
|
68
|
+
var cachedDeleteStmt = null;
|
|
69
|
+
function agentKey(agentName) {
|
|
70
|
+
return agentName && agentName.length > 0 ? agentName : "default";
|
|
71
|
+
}
|
|
72
|
+
function keyFor(providerID, modelID, agentName) {
|
|
73
|
+
return `${providerID}/${modelID}/${agentKey(agentName)}`;
|
|
74
|
+
}
|
|
75
|
+
function fingerprintFor(description, parameters) {
|
|
76
|
+
return createHash("sha256").update(description).update("\x00").update(stableStringify(parameters)).digest("hex");
|
|
77
|
+
}
|
|
78
|
+
function measure(description, parameters) {
|
|
79
|
+
let paramsText = "";
|
|
80
|
+
try {
|
|
81
|
+
paramsText = parameters === undefined ? "" : JSON.stringify(parameters);
|
|
82
|
+
} catch {
|
|
83
|
+
paramsText = "";
|
|
84
|
+
}
|
|
85
|
+
return estimateTokens(description) + estimateTokens(paramsText);
|
|
86
|
+
}
|
|
87
|
+
function routeFor(providerID, modelID, agentName) {
|
|
88
|
+
const key = keyFor(providerID, modelID, agentName);
|
|
89
|
+
let route = routes.get(key);
|
|
90
|
+
if (!route) {
|
|
91
|
+
route = {
|
|
92
|
+
providerID,
|
|
93
|
+
modelID,
|
|
94
|
+
agentName: agentKey(agentName),
|
|
95
|
+
tools: new Map,
|
|
96
|
+
live: false,
|
|
97
|
+
clock: 0,
|
|
98
|
+
lastWallAt: Date.now(),
|
|
99
|
+
oldestFireAt: Number.POSITIVE_INFINITY,
|
|
100
|
+
retired: new Map,
|
|
101
|
+
legacyRows: new Set
|
|
102
|
+
};
|
|
103
|
+
routes.set(key, route);
|
|
104
|
+
}
|
|
105
|
+
return { key, route };
|
|
106
|
+
}
|
|
107
|
+
function advanceClock(route) {
|
|
108
|
+
const now = Date.now();
|
|
109
|
+
const gap = Math.min(Math.max(now - route.lastWallAt, 0), MAX_ACTIVITY_GAP_MS);
|
|
110
|
+
route.clock += gap;
|
|
111
|
+
route.lastWallAt = Math.max(route.lastWallAt, now);
|
|
112
|
+
return route.clock;
|
|
113
|
+
}
|
|
114
|
+
function counts(route, slot) {
|
|
115
|
+
if (!route.live)
|
|
116
|
+
return true;
|
|
117
|
+
if (slot.legacy)
|
|
118
|
+
return false;
|
|
119
|
+
return slot.lastFireAt >= route.clock - ACTIVITY_WINDOW_MS;
|
|
120
|
+
}
|
|
121
|
+
function currentTools(route) {
|
|
122
|
+
return [...route.tools.entries()].filter(([, slot]) => counts(route, slot));
|
|
123
|
+
}
|
|
124
|
+
function summarize(entries, live) {
|
|
125
|
+
let total = 0;
|
|
126
|
+
for (const [, slot] of entries)
|
|
127
|
+
total += slot.tokens;
|
|
128
|
+
const ids = entries.map(([id]) => id).sort();
|
|
129
|
+
const fingerprints = new Map(entries.map(([id, slot]) => [
|
|
130
|
+
id,
|
|
131
|
+
slot.fingerprint ?? (live ? `stored:${slot.tokens}` : undefined)
|
|
132
|
+
]));
|
|
133
|
+
const complete = ids.every((id) => fingerprints.get(id) !== undefined);
|
|
134
|
+
return {
|
|
135
|
+
total,
|
|
136
|
+
signature: complete ? createHash("sha256").update(JSON.stringify(ids.map((id) => [id, fingerprints.get(id)]))).digest("hex") : undefined,
|
|
137
|
+
hash: ids.length === 0 ? "" : createHash("sha256").update(ids.join("\x00")).digest("hex")
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function resolve(providerID, modelID, agentName, sessionId) {
|
|
141
|
+
if (!providerID || !modelID)
|
|
142
|
+
return;
|
|
143
|
+
const key = keyFor(providerID, modelID, agentName);
|
|
144
|
+
if (sessionId) {
|
|
145
|
+
const flight = sessionFlights.peek(sessionId);
|
|
146
|
+
if (flight?.key === key && flight.exact)
|
|
147
|
+
return flight.exact;
|
|
148
|
+
}
|
|
149
|
+
const route = routes.get(key);
|
|
150
|
+
if (!route)
|
|
151
|
+
return;
|
|
152
|
+
const entries = currentTools(route);
|
|
153
|
+
if (!route.live && entries.length === 0)
|
|
154
|
+
return;
|
|
155
|
+
return summarize(entries, route.live);
|
|
156
|
+
}
|
|
157
|
+
function readWindowedSince(db) {
|
|
158
|
+
try {
|
|
159
|
+
const row = db.prepare("SELECT value FROM schema_migrations_meta WHERE key = ?").get(WINDOWED_SINCE_KEY);
|
|
160
|
+
if (!row)
|
|
161
|
+
return;
|
|
162
|
+
const value = Number(row.value);
|
|
163
|
+
return Number.isFinite(value) ? value : undefined;
|
|
164
|
+
} catch {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function markWindowed() {
|
|
169
|
+
if (windowedSince !== undefined || !persistenceDb)
|
|
170
|
+
return;
|
|
171
|
+
try {
|
|
172
|
+
persistenceDb.prepare("INSERT OR IGNORE INTO schema_migrations_meta (key, value) VALUES (?, ?)").run(WINDOWED_SINCE_KEY, String(boundAt));
|
|
173
|
+
windowedSince = readWindowedSince(persistenceDb);
|
|
174
|
+
} catch {}
|
|
175
|
+
}
|
|
176
|
+
function persistInsert(route, toolID, tokens) {
|
|
177
|
+
if (!persistenceDb)
|
|
178
|
+
return false;
|
|
179
|
+
try {
|
|
180
|
+
cachedInsertStmt ??= persistenceDb.prepare(`INSERT OR REPLACE INTO tool_definition_measurements
|
|
181
|
+
(provider_id, model_id, agent_name, tool_id, token_count, recorded_at)
|
|
182
|
+
VALUES (?, ?, ?, ?, ?, ?)`);
|
|
183
|
+
cachedInsertStmt.run(route.providerID, route.modelID, route.agentName, toolID, tokens, Date.now());
|
|
184
|
+
} catch {
|
|
185
|
+
cachedInsertStmt = null;
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
if (route.legacyRows.delete(toolID) && route.legacyRows.size === 0)
|
|
189
|
+
markWindowed();
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
function persistDelete(route, toolIDs) {
|
|
193
|
+
if (!persistenceDb)
|
|
194
|
+
return false;
|
|
195
|
+
try {
|
|
196
|
+
cachedDeleteStmt ??= persistenceDb.prepare(`DELETE FROM tool_definition_measurements
|
|
197
|
+
WHERE provider_id = ? AND model_id = ? AND agent_name = ?
|
|
198
|
+
AND tool_id IN (SELECT value FROM json_each(?))`);
|
|
199
|
+
cachedDeleteStmt.run(route.providerID, route.modelID, route.agentName, JSON.stringify(toolIDs));
|
|
200
|
+
} catch {
|
|
201
|
+
cachedDeleteStmt = null;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
for (const id of toolIDs)
|
|
205
|
+
route.legacyRows.delete(id);
|
|
206
|
+
markWindowed();
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
function writeSlot(route, toolID, slot) {
|
|
210
|
+
if (slot.persisted || !persistenceDb)
|
|
211
|
+
return;
|
|
212
|
+
const now = Date.now();
|
|
213
|
+
if (slot.writeFailedAt !== undefined && now - slot.writeFailedAt < WRITE_RETRY_MS)
|
|
214
|
+
return;
|
|
215
|
+
if (persistInsert(route, toolID, slot.tokens)) {
|
|
216
|
+
slot.persisted = true;
|
|
217
|
+
slot.writeFailedAt = undefined;
|
|
218
|
+
} else {
|
|
219
|
+
slot.writeFailedAt = now;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function retire(route, toolID, slot, rowDeleted) {
|
|
223
|
+
if (slot.fingerprint === undefined)
|
|
224
|
+
return;
|
|
225
|
+
route.retired.delete(toolID);
|
|
226
|
+
route.retired.set(toolID, {
|
|
227
|
+
fingerprint: slot.fingerprint,
|
|
228
|
+
tokens: slot.tokens,
|
|
229
|
+
rowKept: slot.persisted && !rowDeleted
|
|
230
|
+
});
|
|
231
|
+
if (route.retired.size > RETIRED_CACHE_LIMIT) {
|
|
232
|
+
const oldest = route.retired.keys().next().value;
|
|
233
|
+
if (oldest !== undefined)
|
|
234
|
+
route.retired.delete(oldest);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function freshSlot(route, toolID, description, parameters, fingerprint, now) {
|
|
238
|
+
const retired = route.retired.get(toolID);
|
|
239
|
+
if (retired)
|
|
240
|
+
route.retired.delete(toolID);
|
|
241
|
+
const reuse = retired?.fingerprint === fingerprint ? retired : undefined;
|
|
242
|
+
return {
|
|
243
|
+
tokens: reuse ? reuse.tokens : measure(description, parameters),
|
|
244
|
+
fingerprint,
|
|
245
|
+
lastFireAt: now,
|
|
246
|
+
legacy: false,
|
|
247
|
+
persisted: reuse?.rowKept === true
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function setDatabase(db) {
|
|
251
|
+
const rebound = persistenceDb !== null && persistenceDb !== db;
|
|
252
|
+
persistenceDb = db;
|
|
253
|
+
boundAt = Date.now();
|
|
254
|
+
cachedInsertStmt = null;
|
|
255
|
+
cachedDeleteStmt = null;
|
|
256
|
+
if (rebound) {
|
|
257
|
+
for (const route of routes.values()) {
|
|
258
|
+
for (const slot of route.tools.values()) {
|
|
259
|
+
slot.persisted = false;
|
|
260
|
+
slot.writeFailedAt = undefined;
|
|
261
|
+
}
|
|
262
|
+
for (const retired of route.retired.values())
|
|
263
|
+
retired.rowKept = false;
|
|
264
|
+
route.legacyRows.clear();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
windowedSince = readWindowedSince(db);
|
|
268
|
+
if (windowedSince !== undefined)
|
|
269
|
+
return;
|
|
270
|
+
try {
|
|
271
|
+
if (!db.prepare("SELECT 1 FROM tool_definition_measurements LIMIT 1").get())
|
|
272
|
+
markWindowed();
|
|
273
|
+
} catch {}
|
|
274
|
+
}
|
|
275
|
+
function loadToolDefinitionMeasurements(db) {
|
|
276
|
+
let rows = [];
|
|
277
|
+
try {
|
|
278
|
+
rows = db.prepare("SELECT provider_id, model_id, agent_name, tool_id, token_count, recorded_at FROM tool_definition_measurements").all();
|
|
279
|
+
} catch {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const since = readWindowedSince(db);
|
|
283
|
+
const loadedAt = new Map;
|
|
284
|
+
for (const row of rows) {
|
|
285
|
+
const { route } = routeFor(row.provider_id, row.model_id, row.agent_name);
|
|
286
|
+
if (route.live)
|
|
287
|
+
continue;
|
|
288
|
+
let now = loadedAt.get(route);
|
|
289
|
+
if (now === undefined) {
|
|
290
|
+
now = advanceClock(route);
|
|
291
|
+
loadedAt.set(route, now);
|
|
292
|
+
}
|
|
293
|
+
const legacy = since === undefined || !(Number(row.recorded_at) >= since);
|
|
294
|
+
route.tools.set(row.tool_id, {
|
|
295
|
+
tokens: row.token_count,
|
|
296
|
+
fingerprint: undefined,
|
|
297
|
+
lastFireAt: now,
|
|
298
|
+
legacy,
|
|
299
|
+
persisted: !legacy
|
|
300
|
+
});
|
|
301
|
+
route.oldestFireAt = Math.min(route.oldestFireAt, now);
|
|
302
|
+
if (legacy)
|
|
303
|
+
route.legacyRows.add(row.tool_id);
|
|
304
|
+
else
|
|
305
|
+
route.legacyRows.delete(row.tool_id);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function recordToolDefinitionSet(providerID, modelID, agentName, tools, sessionId) {
|
|
309
|
+
if (!providerID || !modelID)
|
|
310
|
+
return;
|
|
311
|
+
const { key, route } = routeFor(providerID, modelID, agentName);
|
|
312
|
+
const now = advanceClock(route);
|
|
313
|
+
route.live = true;
|
|
314
|
+
const next = new Map;
|
|
315
|
+
for (const tool of tools) {
|
|
316
|
+
if (!tool.id)
|
|
317
|
+
continue;
|
|
318
|
+
const fingerprint = fingerprintFor(tool.description ?? "", tool.parameters);
|
|
319
|
+
const previous = route.tools.get(tool.id);
|
|
320
|
+
if (previous && previous.fingerprint === fingerprint) {
|
|
321
|
+
previous.lastFireAt = now;
|
|
322
|
+
next.set(tool.id, previous);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
next.set(tool.id, freshSlot(route, tool.id, tool.description ?? "", tool.parameters, fingerprint, now));
|
|
326
|
+
}
|
|
327
|
+
const removed = [...route.tools].filter(([id]) => !next.has(id));
|
|
328
|
+
route.tools = next;
|
|
329
|
+
route.oldestFireAt = now;
|
|
330
|
+
if (removed.length > 0) {
|
|
331
|
+
const deleted = persistDelete(route, removed.map(([id]) => id));
|
|
332
|
+
for (const [id, slot] of removed)
|
|
333
|
+
retire(route, id, slot, deleted);
|
|
334
|
+
}
|
|
335
|
+
for (const [toolID, slot] of next)
|
|
336
|
+
writeSlot(route, toolID, slot);
|
|
337
|
+
if (sessionId)
|
|
338
|
+
sessionFlights.set(sessionId, { key, exact: summarize([...next.entries()], true) });
|
|
339
|
+
}
|
|
340
|
+
function getCurrentToolSetHash(providerID, modelID, agentName, sessionId) {
|
|
341
|
+
return resolve(providerID, modelID, agentName, sessionId)?.hash ?? "";
|
|
342
|
+
}
|
|
343
|
+
function getToolDefinitionMeasurementSignature(providerID, modelID, agentName, sessionId) {
|
|
344
|
+
return resolve(providerID, modelID, agentName, sessionId)?.signature;
|
|
345
|
+
}
|
|
346
|
+
function getMeasuredToolDefinitionTokens(providerID, modelID, agentName, sessionId) {
|
|
347
|
+
return resolve(providerID, modelID, agentName, sessionId)?.total;
|
|
348
|
+
}
|
|
349
|
+
function getSessionToolDefinitionTokens(sessionId) {
|
|
350
|
+
if (!sessionId)
|
|
351
|
+
return;
|
|
352
|
+
const flight = sessionFlights.peek(sessionId);
|
|
353
|
+
if (!flight)
|
|
354
|
+
return;
|
|
355
|
+
if (flight.exact)
|
|
356
|
+
return flight.exact.total;
|
|
357
|
+
const route = routes.get(flight.key);
|
|
358
|
+
return route ? summarize(currentTools(route), route.live).total : undefined;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export { BoundedSessionMap, setDatabase, loadToolDefinitionMeasurements, recordToolDefinitionSet, getCurrentToolSetHash, getToolDefinitionMeasurementSignature, getMeasuredToolDefinitionTokens, getSessionToolDefinitionTokens };
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./server-ab1g0wn9.js";
|
|
14
14
|
import {
|
|
15
15
|
messageFtsOrdinalRangeIsMapped2
|
|
16
|
-
} from "./server-
|
|
16
|
+
} from "./server-4frtg2z1.js";
|
|
17
17
|
|
|
18
18
|
// src/features/magic-context/compartment-chunk-embedding.ts
|
|
19
19
|
import { createHash } from "node:crypto";
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
getProjectChunkEmbeddingModelId2,
|
|
41
41
|
getProjectEmbeddingMaxInputTokens2,
|
|
42
42
|
embedItemsForProject2
|
|
43
|
-
} from "./server-
|
|
43
|
+
} from "./server-hnmm8yzq.js";
|
|
44
44
|
import {
|
|
45
45
|
hasMeaningfulUserText2,
|
|
46
46
|
estimateTokens,
|
|
@@ -59,8 +59,9 @@ import {
|
|
|
59
59
|
isStrictGapHealingMessage2,
|
|
60
60
|
noteRawSessionSummaryRowWritten2,
|
|
61
61
|
RawOrdinalsNotReady2,
|
|
62
|
+
dropRawSessionOrdinalCheckpoints2,
|
|
62
63
|
runSessionWarmupWorker
|
|
63
|
-
} from "./server-
|
|
64
|
+
} from "./server-erk2bvdf.js";
|
|
64
65
|
import {
|
|
65
66
|
buildCanonicalChunkTextFromFts2,
|
|
66
67
|
buildCompartmentSummaryFallbackText2,
|
|
@@ -70,12 +71,11 @@ import {
|
|
|
70
71
|
replaceCompartmentChunkEmbeddings2,
|
|
71
72
|
deleteChunkEmbedBackoffForSession2,
|
|
72
73
|
chunkWindowSourceKey2
|
|
73
|
-
} from "./server-
|
|
74
|
+
} from "./server-7dpnt0ys.js";
|
|
74
75
|
import {
|
|
75
76
|
isPidAlive
|
|
76
77
|
} from "./server-k3t06fxr.js";
|
|
77
78
|
import {
|
|
78
|
-
BoundedSessionMap,
|
|
79
79
|
clearLkgFenceProcessState,
|
|
80
80
|
lkgFenceRequiresRebuild,
|
|
81
81
|
lkgRecoveryFenceUnclean,
|
|
@@ -90,7 +90,7 @@ import {
|
|
|
90
90
|
toMessageIndexSource2,
|
|
91
91
|
clearIndexedMessagesInTransaction2,
|
|
92
92
|
indexSourcesAfterOrdinal2
|
|
93
|
-
} from "./server-
|
|
93
|
+
} from "./server-k46ec388.js";
|
|
94
94
|
import {
|
|
95
95
|
retreatPastHostUnservedRows,
|
|
96
96
|
snapTerminalCompartmentToServedRow,
|
|
@@ -183,12 +183,13 @@ import {
|
|
|
183
183
|
readRawSessionMessageIdOrdinalsForRange2,
|
|
184
184
|
hasRawSessionMessageById2,
|
|
185
185
|
readRawSessionMessageOrdinalById2,
|
|
186
|
+
resolveHistorianChunkStart2,
|
|
186
187
|
compareRawSessionMessageOrder2,
|
|
187
188
|
getRawSessionMessageCount2,
|
|
188
189
|
getRawSessionTagKeysThrough2,
|
|
189
190
|
getLegacyProtectedTailStartOrdinal2,
|
|
190
191
|
readSessionChunk2
|
|
191
|
-
} from "./server-
|
|
192
|
+
} from "./server-jcsw05aa.js";
|
|
192
193
|
import {
|
|
193
194
|
getTableColumnNames
|
|
194
195
|
} from "./server-rqebawx1.js";
|
|
@@ -198,7 +199,7 @@ import {
|
|
|
198
199
|
LATEST_SUPPORTED_VERSION,
|
|
199
200
|
getPersistedSchemaVersion,
|
|
200
201
|
openDatabase
|
|
201
|
-
} from "./server-
|
|
202
|
+
} from "./server-317f3x9y.js";
|
|
202
203
|
import {
|
|
203
204
|
providerMass,
|
|
204
205
|
calibrationForModelKey,
|
|
@@ -229,8 +230,9 @@ import {
|
|
|
229
230
|
getMessageTimesFromOpenCodeDb
|
|
230
231
|
} from "./server-3vhxy2k5.js";
|
|
231
232
|
import {
|
|
233
|
+
BoundedSessionMap,
|
|
232
234
|
getMeasuredToolDefinitionTokens
|
|
233
|
-
} from "./server-
|
|
235
|
+
} from "./server-7d6m1p2b.js";
|
|
234
236
|
import {
|
|
235
237
|
V2_MEMORY_CATEGORIES,
|
|
236
238
|
CATEGORY_PRIORITY,
|
|
@@ -259,7 +261,7 @@ import {
|
|
|
259
261
|
userFacingFailureCode,
|
|
260
262
|
promoteSessionFactsDurable,
|
|
261
263
|
embedPromotedFacts
|
|
262
|
-
} from "./server-
|
|
264
|
+
} from "./server-nmwhe524.js";
|
|
263
265
|
import {
|
|
264
266
|
isMarkerCandidateBasisCurrent2,
|
|
265
267
|
invalidateMarkerCandidateBasis2,
|
|
@@ -1489,13 +1491,13 @@ function identity(slot) {
|
|
|
1489
1491
|
slot.inputContentDigests
|
|
1490
1492
|
])).update(slot.jsonPrefix).digest("hex");
|
|
1491
1493
|
}
|
|
1492
|
-
function envelope(modelKey, systemPromptTokens, agentName) {
|
|
1494
|
+
function envelope(modelKey, systemPromptTokens, agentName, sessionId) {
|
|
1493
1495
|
const slash = modelKey.indexOf("/");
|
|
1494
1496
|
return JSON.stringify([
|
|
1495
1497
|
modelKey,
|
|
1496
1498
|
systemPromptTokens,
|
|
1497
1499
|
agentName,
|
|
1498
|
-
getMeasuredToolDefinitionTokens(modelKey.slice(0, slash), modelKey.slice(slash + 1), agentName)
|
|
1500
|
+
getMeasuredToolDefinitionTokens(modelKey.slice(0, slash), modelKey.slice(slash + 1), agentName, sessionId)
|
|
1499
1501
|
]);
|
|
1500
1502
|
}
|
|
1501
1503
|
function beginV2LkgRequest(sessionId, modelKey, previousResponseId, responseAfterSequence) {
|
|
@@ -1527,7 +1529,7 @@ function noteCapturedLkgRequest(args) {
|
|
|
1527
1529
|
request,
|
|
1528
1530
|
slot: identity(args.slot),
|
|
1529
1531
|
prefixCount: JSON.parse(args.slot.jsonPrefix).length,
|
|
1530
|
-
envelope: envelope(request.modelKey, args.systemPromptTokens, args.agentName)
|
|
1532
|
+
envelope: envelope(request.modelKey, args.systemPromptTokens, args.agentName, args.sessionId)
|
|
1531
1533
|
});
|
|
1532
1534
|
}
|
|
1533
1535
|
function noteLkgProviderResponse(args) {
|
|
@@ -1558,7 +1560,7 @@ function noteLkgProviderResponse(args) {
|
|
|
1558
1560
|
}
|
|
1559
1561
|
function measuredLkgPrefix(args) {
|
|
1560
1562
|
const capture = captures.get(args.sessionId);
|
|
1561
|
-
if (!capture?.usage || !args.slot || capture.slot !== identity(args.slot) || capture.request.modelKey !== args.modelKey || capture.envelope !== envelope(args.modelKey, args.systemPromptTokens, args.agentName))
|
|
1563
|
+
if (!capture?.usage || !args.slot || capture.slot !== identity(args.slot) || capture.request.modelKey !== args.modelKey || capture.envelope !== envelope(args.modelKey, args.systemPromptTokens, args.agentName, args.sessionId))
|
|
1562
1564
|
return;
|
|
1563
1565
|
const appendedMessages = args.messages.slice(capture.prefixCount);
|
|
1564
1566
|
if (appendedMessages[0]?.info.id !== capture.usage.responseId || appendedMessages[0]?.info.role !== "assistant" || JSON.stringify(args.messages.slice(0, capture.prefixCount)) !== args.slot.jsonPrefix)
|
|
@@ -17258,6 +17260,24 @@ function shouldSuppressHistorianAlert(sessionId) {
|
|
|
17258
17260
|
lastHistorianAlertBySession.set(sessionId, Date.now());
|
|
17259
17261
|
return false;
|
|
17260
17262
|
}
|
|
17263
|
+
function isServingOrdinalDriftSignal(detail) {
|
|
17264
|
+
if (!detail)
|
|
17265
|
+
return false;
|
|
17266
|
+
if (detail === "raw message count shrank")
|
|
17267
|
+
return true;
|
|
17268
|
+
return /(?:offset|protectedTailStart|eligibleEnd) ordinal \d+ id changed$/.test(detail);
|
|
17269
|
+
}
|
|
17270
|
+
function shouldRefuseStaleSnapshotForDrift(sessionId, detail) {
|
|
17271
|
+
if (hasRawMessageProvider2(sessionId) || !openCodeDbExists())
|
|
17272
|
+
return false;
|
|
17273
|
+
return isServingOrdinalDriftSignal(detail);
|
|
17274
|
+
}
|
|
17275
|
+
function dropDriftedServingOrdinalRanks(sessionId, detail) {
|
|
17276
|
+
if (hasRawMessageProvider2(sessionId) || !openCodeDbExists())
|
|
17277
|
+
return;
|
|
17278
|
+
withReadOnlySessionDb((reader) => dropRawSessionOrdinalCheckpoints2(reader, sessionId));
|
|
17279
|
+
sessionLog2(sessionId, `historian: dropped drifted ordinal checkpoints after exact-read disagreement (${detail}); the next run rebuilds them from a full scan`);
|
|
17280
|
+
}
|
|
17261
17281
|
function findDanglingPublicationBoundary(sessionId, compartments, messageExists = hasRawSessionMessageById2) {
|
|
17262
17282
|
for (const compartment of compartments) {
|
|
17263
17283
|
if (!messageExists(sessionId, compartment.startMessageId)) {
|
|
@@ -17425,7 +17445,16 @@ async function runCompartmentAgent(deps) {
|
|
|
17425
17445
|
}
|
|
17426
17446
|
return;
|
|
17427
17447
|
}
|
|
17428
|
-
|
|
17448
|
+
let offset;
|
|
17449
|
+
try {
|
|
17450
|
+
offset = resolveHistorianChunkStart2(sessionId, priorCompartments[priorCompartments.length - 1] ?? null);
|
|
17451
|
+
} catch (error) {
|
|
17452
|
+
if (error instanceof RawOrdinalsNotReady2) {
|
|
17453
|
+
deferUntilOrdinalsReady("chunk start unreadable");
|
|
17454
|
+
return;
|
|
17455
|
+
}
|
|
17456
|
+
throw error;
|
|
17457
|
+
}
|
|
17429
17458
|
let boundarySnapshot = deps.boundarySnapshot ?? null;
|
|
17430
17459
|
if (!boundarySnapshot) {
|
|
17431
17460
|
telemetry.failureReason = "missing protected-tail boundary snapshot";
|
|
@@ -17435,17 +17464,34 @@ async function runCompartmentAgent(deps) {
|
|
|
17435
17464
|
}
|
|
17436
17465
|
let validation = { ok: true };
|
|
17437
17466
|
if (boundarySnapshot.rawRangeFingerprint.length > 0) {
|
|
17438
|
-
|
|
17439
|
-
|
|
17440
|
-
|
|
17441
|
-
|
|
17442
|
-
|
|
17467
|
+
let checked;
|
|
17468
|
+
try {
|
|
17469
|
+
checked = await validateBoundarySnapshotOffThread({
|
|
17470
|
+
db,
|
|
17471
|
+
snapshot: boundarySnapshot,
|
|
17472
|
+
currentContextLimit: deps.currentContextLimit ?? boundarySnapshot.contextLimit
|
|
17473
|
+
});
|
|
17474
|
+
} catch (error) {
|
|
17475
|
+
if (error instanceof RawOrdinalsNotReady2) {
|
|
17476
|
+
deferUntilOrdinalsReady("boundary validation unreadable");
|
|
17477
|
+
return;
|
|
17478
|
+
}
|
|
17479
|
+
throw error;
|
|
17480
|
+
}
|
|
17443
17481
|
if (checked.kind === "not-ready") {
|
|
17444
17482
|
deferUntilOrdinalsReady(`boundary validation ${checked.reason}`);
|
|
17445
17483
|
return;
|
|
17446
17484
|
}
|
|
17447
17485
|
validation = checked.result;
|
|
17448
17486
|
}
|
|
17487
|
+
if (!validation.ok && validation.reason === "stale_snapshot" && shouldRefuseStaleSnapshotForDrift(sessionId, validation.detail)) {
|
|
17488
|
+
dropDriftedServingOrdinalRanks(sessionId, validation.detail ?? validation.reason ?? "stale_snapshot");
|
|
17489
|
+
sessionLog2(sessionId, `historian: refusing to publish over a stale protected-tail snapshot (was: ${validation.detail ?? "stale"}); ending the run without publishing`);
|
|
17490
|
+
telemetry.status = "noop";
|
|
17491
|
+
telemetry.failureReason = "stale_snapshot";
|
|
17492
|
+
rollbackDrainReservation();
|
|
17493
|
+
return;
|
|
17494
|
+
}
|
|
17449
17495
|
if (!validation.ok && validation.reason === "stale_snapshot") {
|
|
17450
17496
|
const refreshed = deps.refreshBoundarySnapshot ? deps.refreshBoundarySnapshot(boundarySnapshot, validation) : resolveOpenCodeProtectedTailBoundary({
|
|
17451
17497
|
db,
|
|
@@ -566,6 +566,20 @@ function survivingAnchor(db, set) {
|
|
|
566
566
|
}
|
|
567
567
|
var ordinalCheckpoints = new WeakMap;
|
|
568
568
|
var ordinalSummarySeeds = new WeakMap;
|
|
569
|
+
function hasLateCommitBehindCheckpoint(db, sessionId, scan) {
|
|
570
|
+
const tail = scan.checkpoints?.at(-1);
|
|
571
|
+
if (!tail || scan.maxRowid === undefined)
|
|
572
|
+
return false;
|
|
573
|
+
const row = db.prepare(`SELECT COUNT(*) AS count FROM message
|
|
574
|
+
WHERE rowid > ? AND +session_id = ?
|
|
575
|
+
AND (time_created, id) <= (?, ?)
|
|
576
|
+
AND NOT (${EXCLUDED_ROW_SQL})`).get(scan.maxRowid, sessionId, tail.timeCreated, tail.id);
|
|
577
|
+
return typeof row?.count === "number" && row.count > 0;
|
|
578
|
+
}
|
|
579
|
+
function discardRetainedOrdinalRanks(db, sessionId) {
|
|
580
|
+
ordinalCheckpoints.get(db)?.delete(sessionId);
|
|
581
|
+
ordinalSummarySeeds.get(db)?.delete(sessionId);
|
|
582
|
+
}
|
|
569
583
|
var ORDINAL_LOOKUP_LIMIT = 512;
|
|
570
584
|
function currentOrdinalCheckpoints(db, sessionId) {
|
|
571
585
|
const cached = ordinalCheckpoints.get(db)?.get(sessionId);
|
|
@@ -596,10 +610,16 @@ function extendOrdinalCheckpoints(db, sessionId, scan, limit) {
|
|
|
596
610
|
scan.sessionRows = points.at(-1)?.storedCount ?? 0;
|
|
597
611
|
}
|
|
598
612
|
const tail = points.at(-1);
|
|
599
|
-
const rows = db.prepare(`SELECT id, time_created AS timeCreated, ${EXCLUDED_ROW_SQL} AS excluded FROM message
|
|
613
|
+
const rows = db.prepare(`SELECT id, time_created AS timeCreated, rowid AS rowid, ${EXCLUDED_ROW_SQL} AS excluded FROM message
|
|
600
614
|
WHERE session_id=?${tail ? " AND (time_created,id) > (?,?)" : ""}
|
|
601
615
|
ORDER BY time_created,id${limit === undefined ? "" : ` LIMIT ${limit + 1}`}`).all(sessionId, ...tail ? [tail.timeCreated, tail.id] : []);
|
|
602
616
|
ordinalJsonRowsRead += rows.length;
|
|
617
|
+
if (hasLateCommitBehindCheckpoint(db, sessionId, scan)) {
|
|
618
|
+
discardRetainedOrdinalRanks(db, sessionId);
|
|
619
|
+
if (isMainThread)
|
|
620
|
+
forgetRawSessionSummaryRows2(sessionId);
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
603
623
|
if (limit !== undefined && rows.length > limit)
|
|
604
624
|
return false;
|
|
605
625
|
let total = scan.total ?? 0;
|
|
@@ -616,6 +636,13 @@ function extendOrdinalCheckpoints(db, sessionId, scan, limit) {
|
|
|
616
636
|
scan.checkpoints = points;
|
|
617
637
|
scan.sessionRows += rows.length;
|
|
618
638
|
scan.total = total;
|
|
639
|
+
if (rows.length > 0) {
|
|
640
|
+
let maxRowid = scan.maxRowid ?? -1;
|
|
641
|
+
for (const row of rows)
|
|
642
|
+
if (row.rowid > maxRowid)
|
|
643
|
+
maxRowid = row.rowid;
|
|
644
|
+
scan.maxRowid = maxRowid;
|
|
645
|
+
}
|
|
619
646
|
return true;
|
|
620
647
|
}
|
|
621
648
|
|
|
@@ -636,6 +663,10 @@ function rawOrdinalSummarySeed2(db, sessionId) {
|
|
|
636
663
|
ids: [...new Set([...seed.scan.ids, ...writtenSummaryIds.get(sessionId) ?? []])]
|
|
637
664
|
};
|
|
638
665
|
}
|
|
666
|
+
function dropRawSessionOrdinalCheckpoints2(db, sessionId) {
|
|
667
|
+
discardRetainedOrdinalRanks(db, sessionId);
|
|
668
|
+
forgetRawSessionSummaryRows2(sessionId);
|
|
669
|
+
}
|
|
639
670
|
function boundedOrdinalPrefix(db, sessionId, through) {
|
|
640
671
|
const cached = currentOrdinalCheckpoints(db, sessionId);
|
|
641
672
|
if (cached && through === null)
|
|
@@ -674,8 +705,7 @@ function boundedOrdinalPrefix(db, sessionId, through) {
|
|
|
674
705
|
}
|
|
675
706
|
function scanRawSessionSummaryRows2(db, sessionId, previous) {
|
|
676
707
|
return withReadSnapshot(db, () => {
|
|
677
|
-
if (previous?.checkpoints) {
|
|
678
|
-
extendOrdinalCheckpoints(db, sessionId, previous);
|
|
708
|
+
if (previous?.checkpoints && extendOrdinalCheckpoints(db, sessionId, previous)) {
|
|
679
709
|
return previous;
|
|
680
710
|
}
|
|
681
711
|
if (previous) {
|
|
@@ -707,12 +737,15 @@ function scanRawSessionSummaryRows2(db, sessionId, previous) {
|
|
|
707
737
|
}
|
|
708
738
|
anchors.sort((left, right) => right.rowid - left.rowid);
|
|
709
739
|
anchors.length = Math.min(anchors.length, SUMMARY_ANCHOR_LIMIT);
|
|
710
|
-
const keys = db.prepare(`SELECT id, time_created AS timeCreated, ${EXCLUDED_ROW_SQL} AS excluded FROM message WHERE session_id = ?
|
|
740
|
+
const keys = db.prepare(`SELECT id, time_created AS timeCreated, rowid AS rowid, ${EXCLUDED_ROW_SQL} AS excluded FROM message WHERE session_id = ?
|
|
711
741
|
ORDER BY time_created, id`).all(sessionId);
|
|
712
742
|
const checkpoints = [];
|
|
713
743
|
let total = 0;
|
|
744
|
+
let maxRowid;
|
|
714
745
|
for (let index = 0;index < keys.length; index++) {
|
|
715
746
|
const key = keys[index];
|
|
747
|
+
if (typeof key.rowid === "number")
|
|
748
|
+
maxRowid = maxRowid === undefined ? key.rowid : Math.max(maxRowid, key.rowid);
|
|
716
749
|
if (key.excluded !== 1)
|
|
717
750
|
total++;
|
|
718
751
|
if (index % 256 === 255 || index === keys.length - 1)
|
|
@@ -723,7 +756,7 @@ function scanRawSessionSummaryRows2(db, sessionId, previous) {
|
|
|
723
756
|
storedCount: index + 1
|
|
724
757
|
});
|
|
725
758
|
}
|
|
726
|
-
return { anchors, ids, sessionRows, checkpoints, total };
|
|
759
|
+
return { anchors, ids, sessionRows, checkpoints, total, maxRowid };
|
|
727
760
|
});
|
|
728
761
|
}
|
|
729
762
|
function getRawSessionSummaryEpoch2(sessionId) {
|
|
@@ -1297,4 +1330,4 @@ function recordFailure(key, sessionId, failure, detail) {
|
|
|
1297
1330
|
log2(`[magic-context] WARN canonical ordinal warm-up failed for ${sessionId} (${failure}: ${detail}); counts remain bounded and callers must defer or retry`);
|
|
1298
1331
|
}
|
|
1299
1332
|
|
|
1300
|
-
export { areRustHistorianSyntheticParts2, isStrictGapHealingMessage2, isRawCompactionSummaryInfo2, readRawSessionMessagesFromDb2, readRawSessionMessagePageFromDb2, readRawSessionMessageSummaryPageFromDb2, countRawSessionMessageOrdinalsFromDb2, readRawSessionMessageIdOrdinalsForRangeFromDb2, readRawSessionMessageIdsAtOrdinalsFromDb2, readRawSessionMessageOrdinalPageFromDb2, countStoredRawSessionMessagesFromDb2, readRawSessionTailFromDb2, extractInMemoryMessageViews2, buildInMemoryTailRawMessages2, readRawSessionMessagePartsByIdFromDb2, forgetRawSessionOrdinalWatermark2, forgetRawSessionSummaryRows2, noteRawSessionSummaryRowWritten2, RawOrdinalsNotReady2, rawOrdinalSummarySeed2, scanRawSessionSummaryRows2, getRawSessionSummaryEpoch2, installRawSessionSummaryScan2, isRawSessionSummaryWarm2, readRawSessionMessageOrdinalByIdFromDb2, readRawSessionMessageByIdFromDb2, hasRawSessionMessageByIdFromDb2, readRawSeedTailFromDb2, readRawSessionBoundaryEndpointsFromDb2, runSessionWarmupWorker, prewarmRawSessionOrdinalsForDb };
|
|
1333
|
+
export { areRustHistorianSyntheticParts2, isStrictGapHealingMessage2, isRawCompactionSummaryInfo2, readRawSessionMessagesFromDb2, readRawSessionMessagePageFromDb2, readRawSessionMessageSummaryPageFromDb2, countRawSessionMessageOrdinalsFromDb2, readRawSessionMessageIdOrdinalsForRangeFromDb2, readRawSessionMessageIdsAtOrdinalsFromDb2, readRawSessionMessageOrdinalPageFromDb2, countStoredRawSessionMessagesFromDb2, readRawSessionTailFromDb2, extractInMemoryMessageViews2, buildInMemoryTailRawMessages2, readRawSessionMessagePartsByIdFromDb2, forgetRawSessionOrdinalWatermark2, forgetRawSessionSummaryRows2, noteRawSessionSummaryRowWritten2, RawOrdinalsNotReady2, rawOrdinalSummarySeed2, dropRawSessionOrdinalCheckpoints2, scanRawSessionSummaryRows2, getRawSessionSummaryEpoch2, installRawSessionSummaryScan2, isRawSessionSummaryWarm2, readRawSessionMessageOrdinalByIdFromDb2, readRawSessionMessageByIdFromDb2, hasRawSessionMessageByIdFromDb2, readRawSeedTailFromDb2, readRawSessionBoundaryEndpointsFromDb2, runSessionWarmupWorker, prewarmRawSessionOrdinalsForDb };
|
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
countSessionCompartmentEmbedCoverage2,
|
|
51
51
|
countSessionCompartmentEmbedCoveragePolite2,
|
|
52
52
|
countUnembeddedSessionCompartmentsPolite2
|
|
53
|
-
} from "./server-
|
|
53
|
+
} from "./server-7dpnt0ys.js";
|
|
54
54
|
import {
|
|
55
55
|
acquireGitSweepLease,
|
|
56
56
|
renewGitSweepLease,
|