or3-provider-sqlite 0.0.29 → 0.0.30
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/README.md +10 -0
- package/dist/module.json +1 -1
- package/dist/runtime/server/db/migrate.js +3 -1
- package/dist/runtime/server/db/migrations/033_tool_result_operation_ids.d.ts +4 -0
- package/dist/runtime/server/db/migrations/033_tool_result_operation_ids.js +29 -0
- package/dist/runtime/server/sync/sqlite-sync-gateway-adapter.js +3 -6
- package/dist/runtime/server/utils/digest-uuid.d.ts +2 -0
- package/dist/runtime/server/utils/digest-uuid.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -435,6 +435,16 @@ Migration 030 adds generation records, current-hash heads, and canonical write b
|
|
|
435
435
|
|
|
436
436
|
Migrations 030–032 resume safely after interrupted startup and reject incompatible preexisting schema objects. Released migration 029 remains unchanged.
|
|
437
437
|
|
|
438
|
+
Tool-result retention writes deterministic UUID operation IDs so both incremental
|
|
439
|
+
pull and snapshot bootstrap remain valid. Migration 033 repairs legacy
|
|
440
|
+
`background-tool:<sha256>` IDs in the change log, canonical KV, tombstones and
|
|
441
|
+
captured snapshot pages, including embedded payload IDs. It preserves content,
|
|
442
|
+
clocks, server versions and cursors; replay allocates no duplicate versions.
|
|
443
|
+
With the updated host, every nonempty tool result uses immutable KV chunks and
|
|
444
|
+
bounded transcript references instead of consuming the assistant response budget.
|
|
445
|
+
Full results remain available after sync/reload and for model replay. The existing
|
|
446
|
+
256 KiB per-result limit remains in force. D1 background retention remains unsupported.
|
|
447
|
+
|
|
438
448
|
Migration 031 adds the upload ledger and restore tickets. Normal generation transfer routes remain unregistered. See [upload, restore, and recovery invariants](docs/storage-generation-uploads.md).
|
|
439
449
|
|
|
440
450
|
Background history admission and finalization failures expose structured codes for validation, authorization, conflicts, and supersession. Transient SQLite failures retain their original errors for retry.
|
package/dist/module.json
CHANGED
|
@@ -68,6 +68,7 @@ import * as m029 from "./migrations/029_delegation_wait.js";
|
|
|
68
68
|
import * as m030 from "./migrations/030_storage_generations.js";
|
|
69
69
|
import * as m031 from "./migrations/031_storage_generation_uploads.js";
|
|
70
70
|
import * as m032 from "./migrations/032_sync_observations.js";
|
|
71
|
+
import * as m033 from "./migrations/033_tool_result_operation_ids.js";
|
|
71
72
|
const migrations = {
|
|
72
73
|
"001_init": m001,
|
|
73
74
|
"002_sync_tables": m002,
|
|
@@ -100,7 +101,8 @@ const migrations = {
|
|
|
100
101
|
"029_delegation_wait": m029,
|
|
101
102
|
"030_storage_generations": m030,
|
|
102
103
|
"031_storage_generation_uploads": m031,
|
|
103
|
-
"032_sync_observations": m032
|
|
104
|
+
"032_sync_observations": m032,
|
|
105
|
+
"033_tool_result_operation_ids": m033
|
|
104
106
|
};
|
|
105
107
|
class StaticMigrationProvider {
|
|
106
108
|
async getMigrations() {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { sql } from "kysely";
|
|
2
|
+
import { digestUuid } from "../../utils/digest-uuid.js";
|
|
3
|
+
export async function up(db) {
|
|
4
|
+
const tables = [
|
|
5
|
+
["change_log", "payload_json"],
|
|
6
|
+
["s_kv", "data_json"],
|
|
7
|
+
["sync_snapshot_items", "payload_json"],
|
|
8
|
+
["tombstones", null]
|
|
9
|
+
];
|
|
10
|
+
for (const [table, payload] of tables) {
|
|
11
|
+
let after = "";
|
|
12
|
+
for (; ; ) {
|
|
13
|
+
const { rows } = await sql`SELECT DISTINCT op_id FROM ${sql.table(table)}
|
|
14
|
+
WHERE op_id LIKE 'background-tool:%' AND op_id > ${after} ORDER BY op_id LIMIT 500`.execute(db);
|
|
15
|
+
if (!rows.length) break;
|
|
16
|
+
for (const { op_id: oldId } of rows) {
|
|
17
|
+
const match = /^background-tool:([a-f0-9]{64})$/.exec(oldId);
|
|
18
|
+
if (!match) continue;
|
|
19
|
+
const opId = digestUuid(match[1]);
|
|
20
|
+
const assignment = payload ? sql`, ${sql.ref(payload)} = CASE WHEN json_extract(${sql.ref(payload)}, '$.op_id') = ${oldId}
|
|
21
|
+
THEN json_set(${sql.ref(payload)}, '$.op_id', ${opId}) ELSE ${sql.ref(payload)} END` : sql``;
|
|
22
|
+
await sql`UPDATE ${sql.table(table)} SET op_id = ${opId}${assignment} WHERE op_id = ${oldId}`.execute(db);
|
|
23
|
+
}
|
|
24
|
+
after = rows.at(-1).op_id;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function down(_db) {
|
|
29
|
+
}
|
|
@@ -2,6 +2,7 @@ import { SqliteExternalStorageGenerationUploadCoordinator } from "../storage/sql
|
|
|
2
2
|
import { backgroundFinalizationFingerprint, stableJson } from "./background-history-fingerprint.js";
|
|
3
3
|
import { hasWorkspaceItemSemantics, WORKSPACE_ITEM_CAPABILITY } from "./workspace-item-capability.js";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
|
+
import { digestUuid } from "../utils/digest-uuid.js";
|
|
5
6
|
import { sql } from "kysely";
|
|
6
7
|
import { canRunSyncHistoryGc } from "./history-gc-policy.js";
|
|
7
8
|
import { createError } from "h3";
|
|
@@ -166,11 +167,7 @@ export async function pruneExpiredSyncSnapshots() {
|
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
function backgroundHistoryOpId(admission, stage) {
|
|
169
|
-
|
|
170
|
-
hex[12] = "4";
|
|
171
|
-
hex[16] = (Number.parseInt(hex[16], 16) & 3 | 8).toString(16);
|
|
172
|
-
const value = hex.join("");
|
|
173
|
-
return `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
|
|
170
|
+
return digestUuid(createHash("sha256").update(`${admission.workspaceId}\0${admission.generationId}\0${stage}`).digest("hex"));
|
|
174
171
|
}
|
|
175
172
|
function fingerprintPayload(tableName, operation, payload) {
|
|
176
173
|
if (tableName !== "notifications" || operation !== "delete") return payload;
|
|
@@ -1076,7 +1073,7 @@ export class SqliteSyncGatewayAdapter {
|
|
|
1076
1073
|
ON CONFLICT(workspace_id) DO UPDATE SET value = excluded.value`).run(admission.workspaceId, baseVersion + newRows.length);
|
|
1077
1074
|
const now = nowEpoch();
|
|
1078
1075
|
newRows.forEach((row, index) => {
|
|
1079
|
-
const opId =
|
|
1076
|
+
const opId = digestUuid(createHash("sha256").update(JSON.stringify([admission.workspaceId, admission.generationId, row.id])).digest("hex"));
|
|
1080
1077
|
const hlc = `${Date.now().toString(36).padStart(9, "0")}:000:background`;
|
|
1081
1078
|
const sanitized = sanitizePayloadForSync("kv", row, "put");
|
|
1082
1079
|
if (!sanitized) throw Object.assign(new Error("Invalid tool result payload"), { code: "VALIDATION_ERROR" });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function digestUuid(digest) {
|
|
2
|
+
const hex = digest.slice(0, 32).split("");
|
|
3
|
+
hex[12] = "4";
|
|
4
|
+
hex[16] = (Number.parseInt(hex[16], 16) & 3 | 8).toString(16);
|
|
5
|
+
const value = hex.join("");
|
|
6
|
+
return `${value.slice(0, 8)}-${value.slice(8, 12)}-${value.slice(12, 16)}-${value.slice(16, 20)}-${value.slice(20)}`;
|
|
7
|
+
}
|