niceeval 0.16.3-canary.99 → 0.17.1
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/cli/bootstrap.cjs +7 -1
- package/dist/cli/bootstrap.cjs.map +1 -1
- package/dist/cli/project-configuration.cjs +8 -11
- package/dist/cli/project-configuration.cjs.map +1 -1
- package/dist/expect/index.cjs.map +1 -1
- package/dist/expect/index.d.cts +2 -1
- package/dist/expect/index.d.mts +2 -1
- package/dist/expect/index.d.ts +2 -1
- package/dist/experiment/host/cli/contribution.cjs +6 -11
- package/dist/experiment/host/cli/contribution.cjs.map +1 -1
- package/dist/experiment/host/cli/contribution.d.cts +0 -16
- package/dist/experiment/host/cli/contribution.d.mts +0 -16
- package/dist/experiment/host/cli/contribution.d.ts +0 -16
- package/dist/experiment/host/operations.cjs +3 -3
- package/dist/experiment/host/operations.cjs.map +1 -1
- package/dist/experiment/host/types.cjs.map +1 -1
- package/dist/experiment/host/types.d.cts +0 -4
- package/dist/experiment/host/types.d.mts +0 -4
- package/dist/experiment/host/types.d.ts +0 -4
- package/dist/fresh-import.cjs +2 -2
- package/dist/fresh-import.cjs.map +1 -1
- package/dist/fresh-import.d.cts +3 -3
- package/dist/fresh-import.d.mts +3 -3
- package/dist/fresh-import.d.ts +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/inspection/codec.cjs.map +1 -1
- package/dist/inspection/codec.d.cts +1 -1
- package/dist/inspection/codec.d.mts +1 -1
- package/dist/inspection/codec.d.ts +1 -1
- package/dist/inspection/facts.cjs +66 -9
- package/dist/inspection/facts.cjs.map +1 -1
- package/dist/inspection/facts.d.cts +4 -0
- package/dist/inspection/facts.d.mts +4 -0
- package/dist/inspection/facts.d.ts +4 -0
- package/dist/inspection/facts.js +4 -2
- package/dist/inspection/index.cjs +1 -3
- package/dist/inspection/index.cjs.map +1 -1
- package/dist/inspection/index.d.cts +1 -1
- package/dist/inspection/index.d.mts +1 -1
- package/dist/inspection/index.d.ts +1 -1
- package/dist/inspection/index.js +44 -48
- package/dist/inspection/limits.cjs +3 -1
- package/dist/inspection/limits.cjs.map +1 -1
- package/dist/inspection/limits.d.cts +2 -0
- package/dist/inspection/limits.d.mts +2 -0
- package/dist/inspection/limits.d.ts +2 -0
- package/dist/inspection/limits.js +6 -4
- package/dist/inspection/project-source.cjs +4 -1
- package/dist/inspection/project-source.cjs.map +1 -1
- package/dist/inspection/protocol.cjs +10 -18
- package/dist/inspection/protocol.cjs.map +1 -1
- package/dist/inspection/protocol.d.cts +111 -173
- package/dist/inspection/protocol.d.mts +111 -173
- package/dist/inspection/protocol.d.ts +111 -173
- package/dist/inspection/public.mjs +73 -109
- package/dist/inspection/results.cjs +12 -48
- package/dist/inspection/results.cjs.map +1 -1
- package/dist/inspection/results.d.cts +124 -122
- package/dist/inspection/results.d.mts +124 -122
- package/dist/inspection/results.d.ts +124 -122
- package/dist/inspection/results.js +16 -20
- package/dist/inspection/select.cjs +80 -117
- package/dist/inspection/select.cjs.map +1 -1
- package/dist/inspection/source.cjs +14 -15
- package/dist/inspection/source.cjs.map +1 -1
- package/dist/inspection/source.d.cts +6 -3
- package/dist/inspection/source.d.mts +6 -3
- package/dist/inspection/source.d.ts +6 -3
- package/dist/inspection/trace.cjs +1 -1
- package/dist/inspection/trace.cjs.map +1 -1
- package/dist/load-config.cjs +17 -11
- package/dist/load-config.cjs.map +1 -1
- package/dist/load-config.d.cts +3 -2
- package/dist/load-config.d.mts +3 -2
- package/dist/load-config.d.ts +3 -2
- package/dist/o11y/adapter-usage-projection.cjs +5 -1
- package/dist/o11y/adapter-usage-projection.cjs.map +1 -1
- package/dist/o11y/adapter-usage-projection.d.cts +109 -1
- package/dist/o11y/adapter-usage-projection.d.mts +109 -1
- package/dist/o11y/adapter-usage-projection.d.ts +109 -1
- package/dist/o11y/cache-read.cjs +113 -0
- package/dist/o11y/cache-read.cjs.map +1 -0
- package/dist/o11y/cache-read.d.cts +80 -0
- package/dist/o11y/cache-read.d.mts +80 -0
- package/dist/o11y/cache-read.d.ts +80 -0
- package/dist/o11y/cache-read.js +8 -0
- package/dist/o11y/cache-read.js.map +1 -0
- package/dist/o11y/eval-usage.cjs +22 -1
- package/dist/o11y/eval-usage.cjs.map +1 -1
- package/dist/o11y/eval-usage.d.cts +9 -1
- package/dist/o11y/eval-usage.d.mts +9 -1
- package/dist/o11y/eval-usage.d.ts +9 -1
- package/dist/record/host/sqlite-host.cjs +188 -53
- package/dist/record/host/sqlite-host.cjs.map +1 -1
- package/dist/record/host/sqlite-host.d.cts +37 -1
- package/dist/record/host/sqlite-host.d.mts +37 -1
- package/dist/record/host/sqlite-host.d.ts +37 -1
- package/dist/record/host/sqlite-host.js +16 -8
- package/dist/record/maintenance/runtime.cjs +3 -3
- package/dist/record/maintenance/runtime.cjs.map +1 -1
- package/dist/record/sqlite/admission-repository.cjs +18 -18
- package/dist/record/sqlite/admission-repository.cjs.map +1 -1
- package/dist/record/sqlite/case-repository.cjs +6 -6
- package/dist/record/sqlite/case-repository.cjs.map +1 -1
- package/dist/record/sqlite/coordination-repository.cjs +25 -25
- package/dist/record/sqlite/coordination-repository.cjs.map +1 -1
- package/dist/record/sqlite/current-schema.cjs +115 -111
- package/dist/record/sqlite/current-schema.cjs.map +1 -1
- package/dist/record/sqlite/current-schema.d.cts +3 -3
- package/dist/record/sqlite/current-schema.d.mts +3 -3
- package/dist/record/sqlite/current-schema.d.ts +3 -3
- package/dist/record/sqlite/database.cjs +56 -53
- package/dist/record/sqlite/database.cjs.map +1 -1
- package/dist/record/sqlite/index.cjs +3 -1
- package/dist/record/sqlite/index.cjs.map +1 -1
- package/dist/record/sqlite/index.d.cts +5 -2
- package/dist/record/sqlite/index.d.mts +5 -2
- package/dist/record/sqlite/index.d.ts +5 -2
- package/dist/record/sqlite/legacy-schema-018.cjs +443 -0
- package/dist/record/sqlite/legacy-schema-018.cjs.map +1 -0
- package/dist/record/sqlite/legacy-schema-018.d.cts +6 -0
- package/dist/record/sqlite/legacy-schema-018.d.mts +6 -0
- package/dist/record/sqlite/legacy-schema-018.d.ts +6 -0
- package/dist/record/sqlite/legacy-schema-018.js +6 -0
- package/dist/record/sqlite/legacy-schema-018.js.map +1 -0
- package/dist/record/sqlite/migration.cjs +105 -46
- package/dist/record/sqlite/migration.cjs.map +1 -1
- package/dist/record/sqlite/migration.d.cts +2 -1
- package/dist/record/sqlite/migration.d.mts +2 -1
- package/dist/record/sqlite/migration.d.ts +2 -1
- package/dist/record/sqlite/portable-capture.cjs +13 -13
- package/dist/record/sqlite/portable-capture.cjs.map +1 -1
- package/dist/record/sqlite/registry-repository.cjs +22 -22
- package/dist/record/sqlite/registry-repository.cjs.map +1 -1
- package/dist/record/sqlite/schema.cjs +10 -2
- package/dist/record/sqlite/schema.cjs.map +1 -1
- package/dist/record/sqlite/schema.d.cts +4 -1
- package/dist/record/sqlite/schema.d.mts +4 -1
- package/dist/record/sqlite/schema.d.ts +4 -1
- package/dist/record/sqlite/schema.js +20 -14
- package/dist/record/sqlite/storage-worker.cjs +1 -1
- package/dist/record/sqlite/storage-worker.cjs.map +1 -1
- package/dist/record/sqlite/storage.cjs +316 -232
- package/dist/record/sqlite/storage.cjs.map +1 -1
- package/dist/record/sqlite/storage.d.cts +10 -2
- package/dist/record/sqlite/storage.d.mts +10 -2
- package/dist/record/sqlite/storage.d.ts +10 -2
- package/dist/record/sqlite/storage.js +54 -50
- package/dist/record/sqlite/types.cjs +1 -1
- package/dist/record/sqlite/types.cjs.map +1 -1
- package/dist/record/sqlite/types.d.cts +13 -1
- package/dist/record/sqlite/types.d.mts +13 -1
- package/dist/record/sqlite/types.d.ts +13 -1
- package/dist/run/cli/contribution.cjs +17 -12
- package/dist/run/cli/contribution.cjs.map +1 -1
- package/dist/run/host/lifecycle-adapter.cjs +1 -1
- package/dist/run/host/lifecycle-adapter.cjs.map +1 -1
- package/dist/run/storage/owner-identity.cjs +78 -16
- package/dist/run/storage/owner-identity.cjs.map +1 -1
- package/dist/run/storage/owner-identity.d.cts +2 -1
- package/dist/run/storage/owner-identity.d.mts +2 -1
- package/dist/run/storage/owner-identity.d.ts +2 -1
- package/dist/run/storage/sqlite.cjs +55 -55
- package/dist/run/storage/sqlite.cjs.map +1 -1
- package/dist/runner/accept.cjs +12 -42
- package/dist/runner/accept.cjs.map +1 -1
- package/dist/runner/accept.d.cts +2 -3
- package/dist/runner/accept.d.mts +2 -3
- package/dist/runner/accept.d.ts +2 -3
- package/dist/runner/adapter-usage.cjs +2 -2
- package/dist/runner/adapter-usage.cjs.map +1 -1
- package/dist/runner/adoption.cjs +14 -26
- package/dist/runner/adoption.cjs.map +1 -1
- package/dist/runner/adoption.d.cts +5 -13
- package/dist/runner/adoption.d.mts +5 -13
- package/dist/runner/adoption.d.ts +5 -13
- package/dist/runner/adoption.js +2 -4
- package/dist/runner/record.cjs +24 -18
- package/dist/runner/record.cjs.map +1 -1
- package/dist/runner/rename-experiment.cjs +5 -7
- package/dist/runner/rename-experiment.cjs.map +1 -1
- package/dist/runner/reuse-plan.cjs +37 -18
- package/dist/runner/reuse-plan.cjs.map +1 -1
- package/dist/runner/reuse-plan.d.cts +4 -1
- package/dist/runner/reuse-plan.d.mts +4 -1
- package/dist/runner/reuse-plan.d.ts +4 -1
- package/dist/runner/setup-prefix-plan.cjs +17 -12
- package/dist/runner/setup-prefix-plan.cjs.map +1 -1
- package/dist/runner/setup-prefix-plan.d.cts +0 -2
- package/dist/runner/setup-prefix-plan.d.mts +0 -2
- package/dist/runner/setup-prefix-plan.d.ts +0 -2
- package/dist/runner/setup-prefix-plan.js +8 -12
- package/dist/sandbox/backend.cjs +10 -1
- package/dist/sandbox/backend.cjs.map +1 -1
- package/dist/sandbox/backend.d.cts +16 -8
- package/dist/sandbox/backend.d.mts +16 -8
- package/dist/sandbox/backend.d.ts +16 -8
- package/dist/sandbox/backend.js +28 -26
- package/dist/sandbox/docker.cjs +7 -1
- package/dist/sandbox/docker.cjs.map +1 -1
- package/dist/sandbox/e2b-cache-repository.cjs +13 -3
- package/dist/sandbox/e2b-cache-repository.cjs.map +1 -1
- package/dist/sandbox/e2b-cache-repository.d.cts +3 -0
- package/dist/sandbox/e2b-cache-repository.d.mts +3 -0
- package/dist/sandbox/e2b-cache-repository.d.ts +3 -0
- package/dist/sandbox/e2b-cache-repository.js +16 -12
- package/dist/sandbox/e2b.cjs +2 -2
- package/dist/sandbox/e2b.cjs.map +1 -1
- package/dist/sandbox/incus/materialize.cjs +1 -1
- package/dist/sandbox/incus/materialize.cjs.map +1 -1
- package/dist/show/contribution.cjs +3 -3
- package/dist/show/contribution.cjs.map +1 -1
- package/dist/show/model.cjs +14 -13
- package/dist/show/model.cjs.map +1 -1
- package/dist/show/model.d.cts +7 -7
- package/dist/show/model.d.mts +7 -7
- package/dist/show/model.d.ts +7 -7
- package/dist/show/render.cjs +14 -0
- package/dist/show/render.cjs.map +1 -1
- package/dist/user-database/storage-worker.cjs +13 -3
- package/dist/user-database/storage-worker.cjs.map +1 -1
- package/dist/view/app-dist/.vite/manifest.json +2 -2
- package/dist/view/app-dist/assets/{index-CmVoXbwG.js → index-B3ijZRph.js} +17 -17
- package/dist/view/app-dist/assets/{quality-cost-scatter-BuLISaH4.js → quality-cost-scatter-B--DfJ9s.js} +1 -1
- package/dist/view/app-dist/index.html +1 -1
- package/dist/view/application-runtime.cjs +8 -0
- package/dist/view/application-runtime.cjs.map +1 -0
- package/dist/view/application-runtime.d.cts +9 -0
- package/dist/view/application-runtime.d.mts +9 -0
- package/dist/view/application-runtime.d.ts +9 -0
- package/dist/view/application-runtime.js +6 -0
- package/dist/view/application-runtime.js.map +1 -0
- package/dist/view/cli/contribution.cjs +5 -2
- package/dist/view/cli/contribution.cjs.map +1 -1
- package/dist/view/cli/contribution.d.cts +2 -1
- package/dist/view/cli/contribution.d.mts +2 -1
- package/dist/view/cli/contribution.d.ts +2 -1
- package/dist/view/function-runtime.mjs +1019 -456
- package/dist/view/http-protocol.d.cts +1 -9
- package/dist/view/http-protocol.d.mts +1 -9
- package/dist/view/http-protocol.d.ts +1 -9
- package/dist/view/inspection-host.cjs +39 -30
- package/dist/view/inspection-host.cjs.map +1 -1
- package/dist/view/inspection-host.d.cts +7545 -2
- package/dist/view/inspection-host.d.mts +7545 -2
- package/dist/view/inspection-host.d.ts +7545 -2
- package/dist/view/server.cjs +8 -5
- package/dist/view/server.cjs.map +1 -1
- package/dist/view/server.d.cts +4 -2
- package/dist/view/server.d.mts +4 -2
- package/dist/view/server.d.ts +4 -2
- package/docs-site/zh/reference/cli.mdx +1 -2
- package/docs-site/zh/tutorials/control-run-cost.mdx +61 -0
- package/docs-site/zh/tutorials/niceeval-taste-application.mdx +21 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"case-repository.js","sourceRoot":"","sources":["case-repository.ts"],"names":[],"mappings":";;AA6CA,gDAsCC;AAjFD,+CAAqE;AACrE,2CAA0C;AAC1C,qDAA4D;AAE5D,SAAS,QAAQ,CAAC,SAAiB,EAAE,OAAe;IAChD,MAAM,IAAA,uBAAW,EAAC,yBAAyB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,IAAI,CAAC,GAAQ,EAAE,KAAa;IACjC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,IAAI,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAA,uBAAW,EAAC,yBAAyB,EAAE,aAAa,EAAE,GAAG,KAAK,cAAc,CAAC,CAAC;IACxF,OAAO,KAAK,CAAC;AACjB,CAAC;AACD,SAAS,OAAO,CAAC,GAAQ,EAAE,KAAa;IACpC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,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AAC,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;gBACpR,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;oBAC7B,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,qCAAqC,CAAC,CAAC;gBAClE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { SQLOutputValue } from \"node:sqlite\";\nimport type { CaseCoordinationCommand } from \"./worker-protocol.ts\";\nimport { recordStatement, type RecordDatabase } from \"./database.ts\";\nimport { sqliteError } from \"./errors.ts\";\nimport { withImmediateTransaction } from \"./transaction.ts\";\ntype Row = Readonly<Record<string, SQLOutputValue>>;\nfunction conflict(operation: string, message: string): never {\n throw sqliteError(\"record-command-conflict\", operation, message);\n}\nfunction text(row: Row, field: string): string {\n const value = row[field];\n if (typeof value !== \"string\")\n throw sqliteError(\"record-database-invalid\", \"case-decode\", `${field} is not text`);\n return value;\n}\nfunction integer(row: Row, field: string): number {\n const value = row[field];\n const decoded = typeof value === \"bigint\" ? Number(value) : value;\n if (typeof decoded !== \"number\" || !Number.isSafeInteger(decoded)) {\n throw sqliteError(\"record-database-invalid\", \"case-decode\", `${field} is not an integer`);\n }\n return decoded;\n}\nfunction requireOpen(connection: RecordDatabase, operation: string): void {\n const row = recordStatement(connection, \"SELECT barrier_state FROM
|
|
1
|
+
{"version":3,"file":"case-repository.js","sourceRoot":"","sources":["case-repository.ts"],"names":[],"mappings":";;AA6CA,gDAsCC;AAjFD,+CAAqE;AACrE,2CAA0C;AAC1C,qDAA4D;AAE5D,SAAS,QAAQ,CAAC,SAAiB,EAAE,OAA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AM,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;gBACtD,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;oBAC7B,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,sCAAsC,CAAC,CAAC;gBACnE,OAAO,SAAS,CAAC;YACrB,CAAC;YACD,KAAK,eAAe,CAAC,CAAC,CAAC;gBACnB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;gBACxC,MAAM,OAAO,GAAG,IAAA,6BAAe,EAAC,UAAU,EAAE;mGACuC,QAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;gBACpR,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;oBAC7B,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,qCAAqC,CAAC,CAAC;gBAClE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC,CAAC;YAC3F,CAAC;QACL,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { SQLOutputValue } from \"node:sqlite\";\nimport type { CaseCoordinationCommand } from \"./worker-protocol.ts\";\nimport { recordStatement, type RecordDatabase } from \"./database.ts\";\nimport { sqliteError } from \"./errors.ts\";\nimport { withImmediateTransaction } from \"./transaction.ts\";\ntype Row = Readonly<Record<string, SQLOutputValue>>;\nfunction conflict(operation: string, message: string): never {\n throw sqliteError(\"record-command-conflict\", operation, message);\n}\nfunction text(row: Row, field: string): string {\n const value = row[field];\n if (typeof value !== \"string\")\n throw sqliteError(\"record-database-invalid\", \"case-decode\", `${field} is not text`);\n return value;\n}\nfunction integer(row: Row, field: string): number {\n const value = row[field];\n const decoded = typeof value === \"bigint\" ? Number(value) : value;\n if (typeof decoded !== \"number\" || !Number.isSafeInteger(decoded)) {\n throw sqliteError(\"record-database-invalid\", \"case-decode\", `${field} is not an integer`);\n }\n return decoded;\n}\nfunction requireOpen(connection: RecordDatabase, operation: string): void {\n const row = recordStatement(connection, \"SELECT barrier_state FROM ne19_record_metadata WHERE singleton=1\").get() as Row | undefined;\n if (row === undefined || text(row, \"barrier_state\") !== \"open\")\n conflict(operation, \"ProjectDatabase writer barrier is not open\");\n}\nfunction ownerSql(): string {\n return \"owner_id=? AND owner_generation=? AND owner_host=? AND owner_pid=? AND owner_boot_id=? AND owner_process_start=?\";\n}\nfunction ownerArgs(owner: import(\"./coordination-repository.ts\").FencedOwner): readonly (string | number)[] {\n return [owner.ownerId, owner.generation, owner.host, owner.pid, owner.bootId, owner.processStart];\n}\nfunction read(connection: RecordDatabase, caseId: string) {\n const row = recordStatement(connection, \"SELECT * FROM ne19_case_locks WHERE case_id=?\").get(caseId) as Row | undefined;\n return row === undefined ? undefined : Object.freeze({\n owner: Object.freeze({\n ownerId: text(row, \"owner_id\"), generation: integer(row, \"owner_generation\"),\n host: text(row, \"owner_host\"), pid: integer(row, \"owner_pid\"),\n bootId: text(row, \"owner_boot_id\"), processStart: text(row, \"owner_process_start\"),\n }),\n acquiredAt: text(row, \"acquired_at\"), heartbeatAt: text(row, \"heartbeat_at\"),\n });\n}\nexport function executeCaseCommand(connection: RecordDatabase, command: CaseCoordinationCommand): object | undefined {\n if (command._tag === \"case-read\")\n return read(connection, command.caseId);\n return withImmediateTransaction(connection, command.deadlineEpochMs, command._tag, () => {\n requireOpen(connection, command._tag);\n switch (command._tag) {\n case \"case-acquire\": {\n if (read(connection, command.caseId) !== undefined)\n conflict(command._tag, `case ${command.caseId} is already owned`);\n const owner = command.owner;\n recordStatement(connection, `INSERT INTO ne19_case_locks(case_id,owner_id,owner_generation,owner_host,owner_pid,owner_boot_id,owner_process_start,acquired_at,heartbeat_at)\n VALUES (?,?,1,?,?,?,?,?,?)`).run(command.caseId, owner.ownerId, owner.host, owner.pid, owner.bootId, owner.processStart, command.at, command.at);\n return Object.freeze({ ...owner, generation: 1 });\n }\n case \"case-heartbeat\": {\n const changed = recordStatement(connection, `UPDATE ne19_case_locks SET heartbeat_at=? WHERE case_id=? AND ${ownerSql()}`)\n .run(command.at, command.caseId, ...ownerArgs(command.owner));\n if (Number(changed.changes) !== 1)\n conflict(command._tag, \"case lock owner generation is fenced\");\n return undefined;\n }\n case \"case-release\": {\n const changed = recordStatement(connection, `DELETE FROM ne19_case_locks WHERE case_id=? AND ${ownerSql()}`)\n .run(command.caseId, ...ownerArgs(command.owner));\n if (Number(changed.changes) !== 1)\n conflict(command._tag, \"case lock owner generation is fenced\");\n return undefined;\n }\n case \"case-takeover\": {\n const replacement = command.replacement;\n const changed = recordStatement(connection, `UPDATE ne19_case_locks SET owner_id=?,owner_generation=owner_generation+1,owner_host=?,owner_pid=?,\n owner_boot_id=?,owner_process_start=?,acquired_at=?,heartbeat_at=? WHERE case_id=? AND ${ownerSql()}`).run(replacement.ownerId, replacement.host, replacement.pid, replacement.bootId, replacement.processStart, command.at, command.at, command.caseId, ...ownerArgs(command.deadOwner));\n if (Number(changed.changes) !== 1)\n conflict(command._tag, \"exact dead case owner did not match\");\n return Object.freeze({ ...replacement, generation: command.deadOwner.generation + 1 });\n }\n }\n });\n}\n"]}
|
|
@@ -39,7 +39,7 @@ function integer(row, field) {
|
|
|
39
39
|
return decoded;
|
|
40
40
|
}
|
|
41
41
|
function requireOpen(connection, operation) {
|
|
42
|
-
const row = (0, database_ts_1.recordStatement)(connection, "SELECT barrier_state FROM
|
|
42
|
+
const row = (0, database_ts_1.recordStatement)(connection, "SELECT barrier_state FROM ne19_record_metadata WHERE singleton=1").get();
|
|
43
43
|
if (row === undefined || text(row, "barrier_state") !== "open")
|
|
44
44
|
conflict(operation, "ProjectDatabase writer barrier is not open");
|
|
45
45
|
}
|
|
@@ -70,40 +70,40 @@ function decodeSession(row) {
|
|
|
70
70
|
function createInvocationOnConnection(connection, input) {
|
|
71
71
|
return (0, transaction_ts_1.withImmediateTransaction)(connection, input.deadlineEpochMs, "create-invocation", () => {
|
|
72
72
|
requireOpen(connection, "create-invocation");
|
|
73
|
-
(0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
73
|
+
(0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_invocation_sessions(invocation_id,state,owner_id,owner_generation,
|
|
74
74
|
owner_host,owner_pid,owner_boot_id,owner_process_start,started_at,heartbeat_at,recovering_at,closed_at,active_projection,terminal_projection)
|
|
75
75
|
VALUES (?,'active',?,1,?,?,?,?,?, ?,NULL,NULL,NULL,NULL)`).run(input.invocationId, input.owner.ownerId, input.owner.host, input.owner.pid, input.owner.bootId, input.owner.processStart, input.startedAt, input.startedAt);
|
|
76
|
-
const insertRun = (0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
76
|
+
const insertRun = (0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_run_resources(run_id,invocation_id,experiment_id,started_at,
|
|
77
77
|
initial_writer_generation,current_writer_generation,terminal_state,completed_at,created_revision,close_revision)
|
|
78
78
|
VALUES (?,?,?,?,?,?,NULL,NULL,?,NULL)`);
|
|
79
|
-
const insertExperiment = (0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
79
|
+
const insertExperiment = (0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_invocation_session_experiments(invocation_id,experiment_id,run_id,ordinal)
|
|
80
80
|
VALUES (?,?,?,?)`);
|
|
81
|
-
const insertSlot = (0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
81
|
+
const insertSlot = (0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_run_expected_slots(run_id,slot_id,ordinal,eval_id,attempt_ordinal,execution_identity_digest)
|
|
82
82
|
VALUES (?,?,?,?,?,?)`);
|
|
83
83
|
input.runs.forEach((run, runOrdinal) => {
|
|
84
|
-
(0, database_ts_1.recordStatement)(connection, "UPDATE
|
|
85
|
-
const revision = (0, database_ts_1.recordStatement)(connection, "SELECT revision FROM
|
|
84
|
+
(0, database_ts_1.recordStatement)(connection, "UPDATE ne19_run_publication_clock SET revision=revision+1 WHERE singleton=1").run();
|
|
85
|
+
const revision = (0, database_ts_1.recordStatement)(connection, "SELECT revision FROM ne19_run_publication_clock WHERE singleton=1").get();
|
|
86
86
|
insertRun.run(run.runId, input.invocationId, run.experimentId, run.startedAt, run.writerGeneration, run.writerGeneration, integer(revision, "revision"));
|
|
87
87
|
insertExperiment.run(input.invocationId, run.experimentId, run.runId, runOrdinal);
|
|
88
88
|
run.expectedSlots.forEach((slot, ordinal) => insertSlot.run(run.runId, slot.slotId, ordinal, slot.evalId, slot.attemptOrdinal, slot.executionIdentityDigest));
|
|
89
89
|
});
|
|
90
|
-
const insertQueued = (0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
90
|
+
const insertQueued = (0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_invocation_session_queued_attempts(invocation_id,attempt_id,run_id,slot_id,ordinal)
|
|
91
91
|
VALUES (?,?,?,?,?)`);
|
|
92
92
|
(input.queuedAttempts ?? []).forEach((attempt, ordinal) => insertQueued.run(input.invocationId, attempt.attemptId, attempt.runId, attempt.slotId, ordinal));
|
|
93
93
|
return readInvocationOnConnection(connection, input.invocationId);
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
function readInvocationOnConnection(connection, invocationId) {
|
|
97
|
-
const row = (0, database_ts_1.recordStatement)(connection, "SELECT * FROM
|
|
97
|
+
const row = (0, database_ts_1.recordStatement)(connection, "SELECT * FROM ne19_invocation_sessions WHERE invocation_id=?").get(invocationId);
|
|
98
98
|
return row === undefined ? undefined : decodeSession(row);
|
|
99
99
|
}
|
|
100
100
|
function listInvocationsOnConnection(connection) {
|
|
101
|
-
return Object.freeze((0, database_ts_1.recordStatement)(connection, "SELECT * FROM
|
|
101
|
+
return Object.freeze((0, database_ts_1.recordStatement)(connection, "SELECT * FROM ne19_invocation_sessions ORDER BY started_at,invocation_id").all().map(decodeSession));
|
|
102
102
|
}
|
|
103
103
|
function heartbeatInvocationOnConnection(connection, invocationId, owner, at, deadline) {
|
|
104
104
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "heartbeat-invocation", () => {
|
|
105
105
|
requireOpen(connection, "heartbeat-invocation");
|
|
106
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
106
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=? WHERE invocation_id=? AND state='active' AND ${sameOwnerSql("owner")}`)
|
|
107
107
|
.run(at, invocationId, ...ownerArgs(owner));
|
|
108
108
|
if (Number(changed.changes) !== 1)
|
|
109
109
|
conflict("heartbeat-invocation", "invocation owner generation is fenced");
|
|
@@ -112,7 +112,7 @@ function heartbeatInvocationOnConnection(connection, invocationId, owner, at, de
|
|
|
112
112
|
function updateInvocationActiveProjectionOnConnection(connection, invocationId, owner, at, projection, deadline) {
|
|
113
113
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "update-invocation-active-projection", () => {
|
|
114
114
|
requireOpen(connection, "update-invocation-active-projection");
|
|
115
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
115
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=?,active_projection=?
|
|
116
116
|
WHERE invocation_id=? AND state='active' AND ${sameOwnerSql("owner")}`)
|
|
117
117
|
.run(at, projection, invocationId, ...ownerArgs(owner));
|
|
118
118
|
if (Number(changed.changes) !== 1)
|
|
@@ -122,22 +122,22 @@ function updateInvocationActiveProjectionOnConnection(connection, invocationId,
|
|
|
122
122
|
function queueInvocationAttemptOnConnection(connection, invocationId, owner, attempt, at, deadline) {
|
|
123
123
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "queue-invocation-attempt", () => {
|
|
124
124
|
requireOpen(connection, "queue-invocation-attempt");
|
|
125
|
-
const heartbeat = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
125
|
+
const heartbeat = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=?
|
|
126
126
|
WHERE invocation_id=? AND state='active' AND ${sameOwnerSql("owner")}`).run(at, invocationId, ...ownerArgs(owner));
|
|
127
127
|
if (Number(heartbeat.changes) !== 1)
|
|
128
128
|
conflict("queue-invocation-attempt", "invocation owner generation is fenced");
|
|
129
|
-
(0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
129
|
+
(0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_invocation_session_queued_attempts(invocation_id,attempt_id,run_id,slot_id,ordinal)
|
|
130
130
|
VALUES (?,?,?,?,?)`).run(invocationId, attempt.attemptId, attempt.runId, attempt.slotId, attempt.ordinal);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
function finishInvocationAttemptOnConnection(connection, invocationId, owner, attemptId, at, deadline) {
|
|
134
134
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "finish-invocation-attempt", () => {
|
|
135
135
|
requireOpen(connection, "finish-invocation-attempt");
|
|
136
|
-
const heartbeat = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
136
|
+
const heartbeat = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=?
|
|
137
137
|
WHERE invocation_id=? AND state='active' AND ${sameOwnerSql("owner")}`).run(at, invocationId, ...ownerArgs(owner));
|
|
138
138
|
if (Number(heartbeat.changes) !== 1)
|
|
139
139
|
conflict("finish-invocation-attempt", "invocation owner generation is fenced");
|
|
140
|
-
const removed = (0, database_ts_1.recordStatement)(connection, "DELETE FROM
|
|
140
|
+
const removed = (0, database_ts_1.recordStatement)(connection, "DELETE FROM ne19_invocation_session_queued_attempts WHERE invocation_id=? AND attempt_id=?")
|
|
141
141
|
.run(invocationId, attemptId);
|
|
142
142
|
if (Number(removed.changes) !== 1)
|
|
143
143
|
conflict("finish-invocation-attempt", "queued attempt does not exist");
|
|
@@ -146,7 +146,7 @@ function finishInvocationAttemptOnConnection(connection, invocationId, owner, at
|
|
|
146
146
|
function beginInvocationRecoveryOnConnection(connection, invocationId, deadOwner, recoveryOwner, at, deadline) {
|
|
147
147
|
return (0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "begin-invocation-recovery", () => {
|
|
148
148
|
requireOpen(connection, "begin-invocation-recovery");
|
|
149
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
149
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_invocation_sessions SET state='recovering',recovering_at=?,owner_id=?,
|
|
150
150
|
owner_generation=owner_generation+1,owner_host=?,owner_pid=?,owner_boot_id=?,owner_process_start=?,heartbeat_at=?
|
|
151
151
|
WHERE invocation_id=? AND state='active' AND ${sameOwnerSql("owner")}`).run(at, recoveryOwner.ownerId, recoveryOwner.host, recoveryOwner.pid, recoveryOwner.bootId, recoveryOwner.processStart, at, invocationId, ...ownerArgs(deadOwner));
|
|
152
152
|
if (Number(changed.changes) !== 1)
|
|
@@ -157,11 +157,11 @@ function beginInvocationRecoveryOnConnection(connection, invocationId, deadOwner
|
|
|
157
157
|
function closeInvocationOnConnection(connection, invocationId, owner, state, at, projection, deadline) {
|
|
158
158
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "close-invocation", () => {
|
|
159
159
|
requireOpen(connection, "close-invocation");
|
|
160
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
160
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_invocation_sessions SET state=?,closed_at=?,active_projection=NULL,terminal_projection=?,recovering_at=NULL
|
|
161
161
|
WHERE invocation_id=? AND state IN ('active','recovering') AND ${sameOwnerSql("owner")}`).run(state, at, projection, invocationId, ...ownerArgs(owner));
|
|
162
162
|
if (Number(changed.changes) !== 1)
|
|
163
163
|
conflict("close-invocation", "invocation owner generation is fenced or terminal");
|
|
164
|
-
(0, database_ts_1.recordStatement)(connection, "DELETE FROM
|
|
164
|
+
(0, database_ts_1.recordStatement)(connection, "DELETE FROM ne19_invocation_session_queued_attempts WHERE invocation_id=?").run(invocationId);
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
function finishInvocationRecoveryOnConnection(connection, invocationId, owner, at, projection, deadline) {
|
|
@@ -170,16 +170,16 @@ function finishInvocationRecoveryOnConnection(connection, invocationId, owner, a
|
|
|
170
170
|
function acquireCaseLockOnConnection(connection, caseId, owner, at, deadline) {
|
|
171
171
|
return (0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "acquire-case-lock", () => {
|
|
172
172
|
requireOpen(connection, "acquire-case-lock");
|
|
173
|
-
const existing = (0, database_ts_1.recordStatement)(connection, "SELECT * FROM
|
|
173
|
+
const existing = (0, database_ts_1.recordStatement)(connection, "SELECT * FROM ne19_case_locks WHERE case_id=?").get(caseId);
|
|
174
174
|
if (existing !== undefined)
|
|
175
175
|
conflict("acquire-case-lock", `case ${caseId} is already owned`);
|
|
176
|
-
(0, database_ts_1.recordStatement)(connection, `INSERT INTO
|
|
176
|
+
(0, database_ts_1.recordStatement)(connection, `INSERT INTO ne19_case_locks(case_id,owner_id,owner_generation,owner_host,owner_pid,owner_boot_id,owner_process_start,acquired_at,heartbeat_at)
|
|
177
177
|
VALUES (?,?,1,?,?,?,?,?,?)`).run(caseId, owner.ownerId, owner.host, owner.pid, owner.bootId, owner.processStart, at, at);
|
|
178
178
|
return Object.freeze({ ...owner, generation: 1 });
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
function readCaseLockProjectionOnConnection(connection, caseId) {
|
|
182
|
-
const row = (0, database_ts_1.recordStatement)(connection, "SELECT * FROM
|
|
182
|
+
const row = (0, database_ts_1.recordStatement)(connection, "SELECT * FROM ne19_case_locks WHERE case_id=?").get(caseId);
|
|
183
183
|
return row === undefined ? undefined : Object.freeze({
|
|
184
184
|
owner: Object.freeze({
|
|
185
185
|
ownerId: text(row, "owner_id"), generation: integer(row, "owner_generation"),
|
|
@@ -196,7 +196,7 @@ function readCaseLockOnConnection(connection, caseId) {
|
|
|
196
196
|
function heartbeatCaseLockOnConnection(connection, caseId, owner, at, deadline) {
|
|
197
197
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "heartbeat-case-lock", () => {
|
|
198
198
|
requireOpen(connection, "heartbeat-case-lock");
|
|
199
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
199
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_case_locks SET heartbeat_at=? WHERE case_id=? AND ${sameOwnerSql("owner")}`).run(at, caseId, ...ownerArgs(owner));
|
|
200
200
|
if (Number(changed.changes) !== 1)
|
|
201
201
|
conflict("heartbeat-case-lock", "case lock owner generation is fenced");
|
|
202
202
|
});
|
|
@@ -204,7 +204,7 @@ function heartbeatCaseLockOnConnection(connection, caseId, owner, at, deadline)
|
|
|
204
204
|
function releaseCaseLockOnConnection(connection, caseId, owner, deadline) {
|
|
205
205
|
(0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "release-case-lock", () => {
|
|
206
206
|
requireOpen(connection, "release-case-lock");
|
|
207
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `DELETE FROM
|
|
207
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `DELETE FROM ne19_case_locks WHERE case_id=? AND ${sameOwnerSql("owner")}`).run(caseId, ...ownerArgs(owner));
|
|
208
208
|
if (Number(changed.changes) !== 1)
|
|
209
209
|
conflict("release-case-lock", "case lock owner generation is fenced");
|
|
210
210
|
});
|
|
@@ -212,7 +212,7 @@ function releaseCaseLockOnConnection(connection, caseId, owner, deadline) {
|
|
|
212
212
|
function takeoverDeadCaseLockOnConnection(connection, caseId, deadOwner, replacement, at, deadline) {
|
|
213
213
|
return (0, transaction_ts_1.withImmediateTransaction)(connection, deadline, "takeover-case-lock", () => {
|
|
214
214
|
requireOpen(connection, "takeover-case-lock");
|
|
215
|
-
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE
|
|
215
|
+
const changed = (0, database_ts_1.recordStatement)(connection, `UPDATE ne19_case_locks SET owner_id=?,owner_generation=owner_generation+1,owner_host=?,owner_pid=?,
|
|
216
216
|
owner_boot_id=?,owner_process_start=?,acquired_at=?,heartbeat_at=? WHERE case_id=? AND ${sameOwnerSql("owner")}`).run(replacement.ownerId, replacement.host, replacement.pid, replacement.bootId, replacement.processStart, at, at, caseId, ...ownerArgs(deadOwner));
|
|
217
217
|
if (Number(changed.changes) !== 1)
|
|
218
218
|
conflict("takeover-case-lock", "exact dead case owner did not match");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordination-repository.js","sourceRoot":"","sources":["coordination-repository.ts"],"names":[],"mappings":";;AAwGA,oEAyBC;AACD,gEAGC;AACD,kEAEC;AACD,0EAQC;AACD,oGASC;AACD,gFAeC;AACD,kFAYC;AACD,kFAUC;AACD,kEASC;AACD,oFAEC;AACD,kEAUC;AACD,gFAWC;AACD,4DAEC;AACD,sEAOC;AACD,kEAOC;AACD,4EASC;AAnQD,+CAAqE;AACrE,6DAA4D;AAC5D,qDAA4D;AAqD5D,SAAS,QAAQ,CAAC,SAAiB,EAAE,OAAe;IAChD,MAAM,IAAA,uBAAW,EAAC,yBAAyB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,OAAO,CAAC,SAAiB,EAAE,OAAe;IAC/C,MAAM,IAAA,uBAAW,EAAC,yBAAyB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,IAAI,CAAC,GAAQ,EAAE,KAAa;IACjC,MAAM,KAAK,GAAG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AA0B,EAAE,MAAc,EAAE,SAAsB,EAAE,WAAiC,EAAE,EAAU,EAAE,QAAgB;IAChL,OAAO,IAAA,yCAAwB,EAAC,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,EAAE;QAC7E,WAAW,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;QAC9C,MAAM,OAAO,GAAG,IAAA,6BAAe,EAAC,UAAU,EAAE;+FAC2C,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;QACnQ,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;YAC7B,QAAQ,CAAC,oBAAoB,EAAE,qCAAqC,CAAC,CAAC;QAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { SQLOutputValue } from \"node:sqlite\";\nimport { recordStatement, type RecordDatabase } from \"./database.ts\";\nimport { sqliteError } from \"../../record/sqlite/errors.ts\";\nimport { withImmediateTransaction } from \"./transaction.ts\";\ntype Row = Readonly<Record<string, SQLOutputValue>>;\nexport interface ProcessOwnerIdentity {\n readonly ownerId: string;\n readonly host: string;\n readonly pid: number;\n readonly bootId: string;\n readonly processStart: string;\n}\nexport interface FencedOwner extends ProcessOwnerIdentity {\n readonly generation: number;\n}\nexport interface CaseLockProjection {\n readonly owner: FencedOwner;\n readonly acquiredAt: string;\n readonly heartbeatAt: string;\n}\nexport interface InvocationRunInput {\n readonly runId: string;\n readonly experimentId: string;\n readonly writerGeneration: string;\n readonly startedAt: string;\n readonly expectedSlots: readonly {\n readonly slotId: string;\n readonly evalId: string;\n readonly attemptOrdinal: number;\n readonly executionIdentityDigest: string;\n }[];\n}\nexport interface CreateInvocationInput {\n readonly invocationId: string;\n readonly owner: ProcessOwnerIdentity;\n readonly startedAt: string;\n readonly runs: readonly InvocationRunInput[];\n readonly queuedAttempts?: readonly {\n readonly attemptId: string;\n readonly runId: string;\n readonly slotId: string;\n }[];\n readonly deadlineEpochMs: number;\n}\nexport type InvocationSessionState = \"active\" | \"recovering\" | \"completed\" | \"interrupted\" | \"failed\";\nexport interface InvocationSessionRecord {\n readonly invocationId: string;\n readonly state: InvocationSessionState;\n readonly owner: FencedOwner;\n readonly startedAt: string;\n readonly heartbeatAt: string;\n readonly recoveringAt?: string;\n readonly closedAt?: string;\n readonly activeProjection?: Uint8Array;\n readonly terminalProjection?: Uint8Array;\n}\nfunction conflict(operation: string, message: string): never {\n throw sqliteError(\"record-command-conflict\", operation, message);\n}\nfunction invalid(operation: string, message: string): never {\n throw sqliteError(\"record-database-invalid\", operation, message);\n}\nfunction text(row: Row, field: string): string {\n const value = row[field];\n if (typeof value !== \"string\")\n invalid(\"coordination-decode\", `${field} is not text`);\n return value;\n}\nfunction integer(row: Row, field: string): number {\n const value = row[field];\n const decoded = typeof value === \"bigint\" ? Number(value) : value;\n if (typeof decoded !== \"number\" || !Number.isSafeInteger(decoded))\n invalid(\"coordination-decode\", `${field} is not an integer`);\n return decoded;\n}\nfunction requireOpen(connection: RecordDatabase, operation: string): void {\n const row = recordStatement(connection, \"SELECT barrier_state FROM ne18_record_metadata WHERE singleton=1\").get() as Row | undefined;\n if (row === undefined || text(row, \"barrier_state\") !== \"open\")\n conflict(operation, \"ProjectDatabase writer barrier is not open\");\n}\nfunction sameOwnerSql(prefix: string): string {\n return `${prefix}_id=? AND ${prefix}_generation=? AND ${prefix}_host=? AND ${prefix}_pid=? AND ${prefix}_boot_id=? AND ${prefix}_process_start=?`;\n}\nfunction ownerArgs(owner: FencedOwner): readonly (string | number)[] {\n return [owner.ownerId, owner.generation, owner.host, owner.pid, owner.bootId, owner.processStart];\n}\nfunction decodeSession(row: Row): InvocationSessionRecord {\n const active = row.active_projection;\n const terminal = row.terminal_projection;\n return Object.freeze({\n invocationId: text(row, \"invocation_id\"),\n state: text(row, \"state\") as InvocationSessionState,\n owner: Object.freeze({\n ownerId: text(row, \"owner_id\"), generation: integer(row, \"owner_generation\"),\n host: text(row, \"owner_host\"), pid: integer(row, \"owner_pid\"),\n bootId: text(row, \"owner_boot_id\"), processStart: text(row, \"owner_process_start\"),\n }),\n startedAt: text(row, \"started_at\"), heartbeatAt: text(row, \"heartbeat_at\"),\n ...(typeof row.recovering_at === \"string\" ? { recoveringAt: row.recovering_at } : {}),\n ...(typeof row.closed_at === \"string\" ? { closedAt: row.closed_at } : {}),\n ...(active instanceof Uint8Array ? { activeProjection: new Uint8Array(active) } : {}),\n ...(terminal instanceof Uint8Array ? { terminalProjection: new Uint8Array(terminal) } : {}),\n });\n}\nexport function createInvocationOnConnection(connection: RecordDatabase, input: CreateInvocationInput): InvocationSessionRecord {\n return withImmediateTransaction(connection, input.deadlineEpochMs, \"create-invocation\", () => {\n requireOpen(connection, \"create-invocation\");\n recordStatement(connection, `INSERT INTO ne18_invocation_sessions(invocation_id,state,owner_id,owner_generation,\n owner_host,owner_pid,owner_boot_id,owner_process_start,started_at,heartbeat_at,recovering_at,closed_at,active_projection,terminal_projection)\n VALUES (?,'active',?,1,?,?,?,?,?, ?,NULL,NULL,NULL,NULL)`).run(input.invocationId, input.owner.ownerId, input.owner.host, input.owner.pid, input.owner.bootId, input.owner.processStart, input.startedAt, input.startedAt);\n const insertRun = recordStatement(connection, `INSERT INTO ne18_run_resources(run_id,invocation_id,experiment_id,started_at,\n initial_writer_generation,current_writer_generation,terminal_state,completed_at,created_revision,close_revision)\n VALUES (?,?,?,?,?,?,NULL,NULL,?,NULL)`);\n const insertExperiment = recordStatement(connection, `INSERT INTO ne18_invocation_session_experiments(invocation_id,experiment_id,run_id,ordinal)\n VALUES (?,?,?,?)`);\n const insertSlot = recordStatement(connection, `INSERT INTO ne18_run_expected_slots(run_id,slot_id,ordinal,eval_id,attempt_ordinal,execution_identity_digest)\n VALUES (?,?,?,?,?,?)`);\n input.runs.forEach((run, runOrdinal) => {\n recordStatement(connection, \"UPDATE ne18_run_publication_clock SET revision=revision+1 WHERE singleton=1\").run();\n const revision = recordStatement(connection, \"SELECT revision FROM ne18_run_publication_clock WHERE singleton=1\").get() as Row;\n insertRun.run(run.runId, input.invocationId, run.experimentId, run.startedAt, run.writerGeneration, run.writerGeneration, integer(revision, \"revision\"));\n insertExperiment.run(input.invocationId, run.experimentId, run.runId, runOrdinal);\n run.expectedSlots.forEach((slot, ordinal) => insertSlot.run(run.runId, slot.slotId, ordinal, slot.evalId, slot.attemptOrdinal, slot.executionIdentityDigest));\n });\n const insertQueued = recordStatement(connection, `INSERT INTO ne18_invocation_session_queued_attempts(invocation_id,attempt_id,run_id,slot_id,ordinal)\n VALUES (?,?,?,?,?)`);\n (input.queuedAttempts ?? []).forEach((attempt, ordinal) => insertQueued.run(input.invocationId, attempt.attemptId, attempt.runId, attempt.slotId, ordinal));\n return readInvocationOnConnection(connection, input.invocationId)!;\n });\n}\nexport function readInvocationOnConnection(connection: RecordDatabase, invocationId: string): InvocationSessionRecord | undefined {\n const row = recordStatement(connection, \"SELECT * FROM ne18_invocation_sessions WHERE invocation_id=?\").get(invocationId) as Row | undefined;\n return row === undefined ? undefined : decodeSession(row);\n}\nexport function listInvocationsOnConnection(connection: RecordDatabase): readonly InvocationSessionRecord[] {\n return Object.freeze((recordStatement(connection, \"SELECT * FROM ne18_invocation_sessions ORDER BY started_at,invocation_id\").all() as unknown as readonly Row[]).map(decodeSession));\n}\nexport function heartbeatInvocationOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"heartbeat-invocation\", () => {\n requireOpen(connection, \"heartbeat-invocation\");\n const changed = recordStatement(connection, `UPDATE ne18_invocation_sessions SET heartbeat_at=? WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`)\n .run(at, invocationId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"heartbeat-invocation\", \"invocation owner generation is fenced\");\n });\n}\nexport function updateInvocationActiveProjectionOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, at: string, projection: Uint8Array, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"update-invocation-active-projection\", () => {\n requireOpen(connection, \"update-invocation-active-projection\");\n const changed = recordStatement(connection, `UPDATE ne18_invocation_sessions SET heartbeat_at=?,active_projection=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`)\n .run(at, projection, invocationId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"update-invocation-active-projection\", \"invocation owner generation is fenced\");\n });\n}\nexport function queueInvocationAttemptOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, attempt: {\n readonly attemptId: string;\n readonly runId: string;\n readonly slotId: string;\n readonly ordinal: number;\n}, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"queue-invocation-attempt\", () => {\n requireOpen(connection, \"queue-invocation-attempt\");\n const heartbeat = recordStatement(connection, `UPDATE ne18_invocation_sessions SET heartbeat_at=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`).run(at, invocationId, ...ownerArgs(owner));\n if (Number(heartbeat.changes) !== 1)\n conflict(\"queue-invocation-attempt\", \"invocation owner generation is fenced\");\n recordStatement(connection, `INSERT INTO ne18_invocation_session_queued_attempts(invocation_id,attempt_id,run_id,slot_id,ordinal)\n VALUES (?,?,?,?,?)`).run(invocationId, attempt.attemptId, attempt.runId, attempt.slotId, attempt.ordinal);\n });\n}\nexport function finishInvocationAttemptOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, attemptId: string, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"finish-invocation-attempt\", () => {\n requireOpen(connection, \"finish-invocation-attempt\");\n const heartbeat = recordStatement(connection, `UPDATE ne18_invocation_sessions SET heartbeat_at=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`).run(at, invocationId, ...ownerArgs(owner));\n if (Number(heartbeat.changes) !== 1)\n conflict(\"finish-invocation-attempt\", \"invocation owner generation is fenced\");\n const removed = recordStatement(connection, \"DELETE FROM ne18_invocation_session_queued_attempts WHERE invocation_id=? AND attempt_id=?\")\n .run(invocationId, attemptId);\n if (Number(removed.changes) !== 1)\n conflict(\"finish-invocation-attempt\", \"queued attempt does not exist\");\n });\n}\nexport function beginInvocationRecoveryOnConnection(connection: RecordDatabase, invocationId: string, deadOwner: FencedOwner, recoveryOwner: ProcessOwnerIdentity, at: string, deadline: number): FencedOwner {\n return withImmediateTransaction(connection, deadline, \"begin-invocation-recovery\", () => {\n requireOpen(connection, \"begin-invocation-recovery\");\n const changed = recordStatement(connection, `UPDATE ne18_invocation_sessions SET state='recovering',recovering_at=?,owner_id=?,\n owner_generation=owner_generation+1,owner_host=?,owner_pid=?,owner_boot_id=?,owner_process_start=?,heartbeat_at=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`).run(at, recoveryOwner.ownerId, recoveryOwner.host, recoveryOwner.pid, recoveryOwner.bootId, recoveryOwner.processStart, at, invocationId, ...ownerArgs(deadOwner));\n if (Number(changed.changes) !== 1)\n conflict(\"begin-invocation-recovery\", \"exact dead invocation owner did not match\");\n return Object.freeze({ ...recoveryOwner, generation: deadOwner.generation + 1 });\n });\n}\nexport function closeInvocationOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, state: Exclude<InvocationSessionState, \"active\" | \"recovering\">, at: string, projection: Uint8Array, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"close-invocation\", () => {\n requireOpen(connection, \"close-invocation\");\n const changed = recordStatement(connection, `UPDATE ne18_invocation_sessions SET state=?,closed_at=?,active_projection=NULL,terminal_projection=?,recovering_at=NULL\n WHERE invocation_id=? AND state IN ('active','recovering') AND ${sameOwnerSql(\"owner\")}`).run(state, at, projection, invocationId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"close-invocation\", \"invocation owner generation is fenced or terminal\");\n recordStatement(connection, \"DELETE FROM ne18_invocation_session_queued_attempts WHERE invocation_id=?\").run(invocationId);\n });\n}\nexport function finishInvocationRecoveryOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, at: string, projection: Uint8Array, deadline: number): void {\n closeInvocationOnConnection(connection, invocationId, owner, \"interrupted\", at, projection, deadline);\n}\nexport function acquireCaseLockOnConnection(connection: RecordDatabase, caseId: string, owner: ProcessOwnerIdentity, at: string, deadline: number): FencedOwner {\n return withImmediateTransaction(connection, deadline, \"acquire-case-lock\", () => {\n requireOpen(connection, \"acquire-case-lock\");\n const existing = recordStatement(connection, \"SELECT * FROM ne18_case_locks WHERE case_id=?\").get(caseId) as Row | undefined;\n if (existing !== undefined)\n conflict(\"acquire-case-lock\", `case ${caseId} is already owned`);\n recordStatement(connection, `INSERT INTO ne18_case_locks(case_id,owner_id,owner_generation,owner_host,owner_pid,owner_boot_id,owner_process_start,acquired_at,heartbeat_at)\n VALUES (?,?,1,?,?,?,?,?,?)`).run(caseId, owner.ownerId, owner.host, owner.pid, owner.bootId, owner.processStart, at, at);\n return Object.freeze({ ...owner, generation: 1 });\n });\n}\nexport function readCaseLockProjectionOnConnection(connection: RecordDatabase, caseId: string): CaseLockProjection | undefined {\n const row = recordStatement(connection, \"SELECT * FROM ne18_case_locks WHERE case_id=?\").get(caseId) as Row | undefined;\n return row === undefined ? undefined : Object.freeze({\n owner: Object.freeze({\n ownerId: text(row, \"owner_id\"), generation: integer(row, \"owner_generation\"),\n host: text(row, \"owner_host\"), pid: integer(row, \"owner_pid\"),\n bootId: text(row, \"owner_boot_id\"), processStart: text(row, \"owner_process_start\"),\n }),\n acquiredAt: text(row, \"acquired_at\"),\n heartbeatAt: text(row, \"heartbeat_at\"),\n });\n}\nexport function readCaseLockOnConnection(connection: RecordDatabase, caseId: string): FencedOwner | undefined {\n return readCaseLockProjectionOnConnection(connection, caseId)?.owner;\n}\nexport function heartbeatCaseLockOnConnection(connection: RecordDatabase, caseId: string, owner: FencedOwner, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"heartbeat-case-lock\", () => {\n requireOpen(connection, \"heartbeat-case-lock\");\n const changed = recordStatement(connection, `UPDATE ne18_case_locks SET heartbeat_at=? WHERE case_id=? AND ${sameOwnerSql(\"owner\")}`).run(at, caseId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"heartbeat-case-lock\", \"case lock owner generation is fenced\");\n });\n}\nexport function releaseCaseLockOnConnection(connection: RecordDatabase, caseId: string, owner: FencedOwner, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"release-case-lock\", () => {\n requireOpen(connection, \"release-case-lock\");\n const changed = recordStatement(connection, `DELETE FROM ne18_case_locks WHERE case_id=? AND ${sameOwnerSql(\"owner\")}`).run(caseId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"release-case-lock\", \"case lock owner generation is fenced\");\n });\n}\nexport function takeoverDeadCaseLockOnConnection(connection: RecordDatabase, caseId: string, deadOwner: FencedOwner, replacement: ProcessOwnerIdentity, at: string, deadline: number): FencedOwner {\n return withImmediateTransaction(connection, deadline, \"takeover-case-lock\", () => {\n requireOpen(connection, \"takeover-case-lock\");\n const changed = recordStatement(connection, `UPDATE ne18_case_locks SET owner_id=?,owner_generation=owner_generation+1,owner_host=?,owner_pid=?,\n owner_boot_id=?,owner_process_start=?,acquired_at=?,heartbeat_at=? WHERE case_id=? AND ${sameOwnerSql(\"owner\")}`).run(replacement.ownerId, replacement.host, replacement.pid, replacement.bootId, replacement.processStart, at, at, caseId, ...ownerArgs(deadOwner));\n if (Number(changed.changes) !== 1)\n conflict(\"takeover-case-lock\", \"exact dead case owner did not match\");\n return Object.freeze({ ...replacement, generation: deadOwner.generation + 1 });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"coordination-repository.js","sourceRoot":"","sources":["coordination-repository.ts"],"names":[],"mappings":";;AAwGA,oEAyBC;AACD,gEAGC;AACD,kEAEC;AACD,0EAQC;AACD,oGASC;AACD,gFAeC;AACD,kFAYC;AACD,kFAUC;AACD,kEASC;AACD,oFAEC;AACD,kEAUC;AACD,gFAWC;AACD,4DAEC;AACD,sEAOC;AACD,kEAOC;AACD,4EASC;AAnQD,+CAAqE;AACrE,6DAA4D;AAC5D,qDAA4D;AAqD5D,SAAS,QAAQ,CAAC,SAAiB,EAAE,OAAe;IAChD,MAAM,IAAA,uBAAW,EAAC,yBAAyB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,OAAO,CAAC,SAAiB,EAAE,OAAe;IAC/C,MAAM,IAAA,uBAAW,EAAC,yBAAyB,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,IAAI,CAAC,GAAQ,EAAE,KAAa;IACjC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,IAAI,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,CAAC,qBAAqB,EAAE,GAAG,KAAK,cAAc,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC;AACjB,CAAC;AACD,SAAS,OAAO,CAAC,GAAQ,EAAE,KAAa;IACpC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IACzB,MAAM,OAAO,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC;QAC7D,OAAO,CAAC,qBAAqB,EAAE,GA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AC,CAAC,CAAC;QACnQ,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;YAC7B,QAAQ,CAAC,oBAAoB,EAAE,qCAAqC,CAAC,CAAC;QAC1E,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,UAAU,EAAE,SAAS,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { SQLOutputValue } from \"node:sqlite\";\nimport { recordStatement, type RecordDatabase } from \"./database.ts\";\nimport { sqliteError } from \"../../record/sqlite/errors.ts\";\nimport { withImmediateTransaction } from \"./transaction.ts\";\ntype Row = Readonly<Record<string, SQLOutputValue>>;\nexport interface ProcessOwnerIdentity {\n readonly ownerId: string;\n readonly host: string;\n readonly pid: number;\n readonly bootId: string;\n readonly processStart: string;\n}\nexport interface FencedOwner extends ProcessOwnerIdentity {\n readonly generation: number;\n}\nexport interface CaseLockProjection {\n readonly owner: FencedOwner;\n readonly acquiredAt: string;\n readonly heartbeatAt: string;\n}\nexport interface InvocationRunInput {\n readonly runId: string;\n readonly experimentId: string;\n readonly writerGeneration: string;\n readonly startedAt: string;\n readonly expectedSlots: readonly {\n readonly slotId: string;\n readonly evalId: string;\n readonly attemptOrdinal: number;\n readonly executionIdentityDigest: string;\n }[];\n}\nexport interface CreateInvocationInput {\n readonly invocationId: string;\n readonly owner: ProcessOwnerIdentity;\n readonly startedAt: string;\n readonly runs: readonly InvocationRunInput[];\n readonly queuedAttempts?: readonly {\n readonly attemptId: string;\n readonly runId: string;\n readonly slotId: string;\n }[];\n readonly deadlineEpochMs: number;\n}\nexport type InvocationSessionState = \"active\" | \"recovering\" | \"completed\" | \"interrupted\" | \"failed\";\nexport interface InvocationSessionRecord {\n readonly invocationId: string;\n readonly state: InvocationSessionState;\n readonly owner: FencedOwner;\n readonly startedAt: string;\n readonly heartbeatAt: string;\n readonly recoveringAt?: string;\n readonly closedAt?: string;\n readonly activeProjection?: Uint8Array;\n readonly terminalProjection?: Uint8Array;\n}\nfunction conflict(operation: string, message: string): never {\n throw sqliteError(\"record-command-conflict\", operation, message);\n}\nfunction invalid(operation: string, message: string): never {\n throw sqliteError(\"record-database-invalid\", operation, message);\n}\nfunction text(row: Row, field: string): string {\n const value = row[field];\n if (typeof value !== \"string\")\n invalid(\"coordination-decode\", `${field} is not text`);\n return value;\n}\nfunction integer(row: Row, field: string): number {\n const value = row[field];\n const decoded = typeof value === \"bigint\" ? Number(value) : value;\n if (typeof decoded !== \"number\" || !Number.isSafeInteger(decoded))\n invalid(\"coordination-decode\", `${field} is not an integer`);\n return decoded;\n}\nfunction requireOpen(connection: RecordDatabase, operation: string): void {\n const row = recordStatement(connection, \"SELECT barrier_state FROM ne19_record_metadata WHERE singleton=1\").get() as Row | undefined;\n if (row === undefined || text(row, \"barrier_state\") !== \"open\")\n conflict(operation, \"ProjectDatabase writer barrier is not open\");\n}\nfunction sameOwnerSql(prefix: string): string {\n return `${prefix}_id=? AND ${prefix}_generation=? AND ${prefix}_host=? AND ${prefix}_pid=? AND ${prefix}_boot_id=? AND ${prefix}_process_start=?`;\n}\nfunction ownerArgs(owner: FencedOwner): readonly (string | number)[] {\n return [owner.ownerId, owner.generation, owner.host, owner.pid, owner.bootId, owner.processStart];\n}\nfunction decodeSession(row: Row): InvocationSessionRecord {\n const active = row.active_projection;\n const terminal = row.terminal_projection;\n return Object.freeze({\n invocationId: text(row, \"invocation_id\"),\n state: text(row, \"state\") as InvocationSessionState,\n owner: Object.freeze({\n ownerId: text(row, \"owner_id\"), generation: integer(row, \"owner_generation\"),\n host: text(row, \"owner_host\"), pid: integer(row, \"owner_pid\"),\n bootId: text(row, \"owner_boot_id\"), processStart: text(row, \"owner_process_start\"),\n }),\n startedAt: text(row, \"started_at\"), heartbeatAt: text(row, \"heartbeat_at\"),\n ...(typeof row.recovering_at === \"string\" ? { recoveringAt: row.recovering_at } : {}),\n ...(typeof row.closed_at === \"string\" ? { closedAt: row.closed_at } : {}),\n ...(active instanceof Uint8Array ? { activeProjection: new Uint8Array(active) } : {}),\n ...(terminal instanceof Uint8Array ? { terminalProjection: new Uint8Array(terminal) } : {}),\n });\n}\nexport function createInvocationOnConnection(connection: RecordDatabase, input: CreateInvocationInput): InvocationSessionRecord {\n return withImmediateTransaction(connection, input.deadlineEpochMs, \"create-invocation\", () => {\n requireOpen(connection, \"create-invocation\");\n recordStatement(connection, `INSERT INTO ne19_invocation_sessions(invocation_id,state,owner_id,owner_generation,\n owner_host,owner_pid,owner_boot_id,owner_process_start,started_at,heartbeat_at,recovering_at,closed_at,active_projection,terminal_projection)\n VALUES (?,'active',?,1,?,?,?,?,?, ?,NULL,NULL,NULL,NULL)`).run(input.invocationId, input.owner.ownerId, input.owner.host, input.owner.pid, input.owner.bootId, input.owner.processStart, input.startedAt, input.startedAt);\n const insertRun = recordStatement(connection, `INSERT INTO ne19_run_resources(run_id,invocation_id,experiment_id,started_at,\n initial_writer_generation,current_writer_generation,terminal_state,completed_at,created_revision,close_revision)\n VALUES (?,?,?,?,?,?,NULL,NULL,?,NULL)`);\n const insertExperiment = recordStatement(connection, `INSERT INTO ne19_invocation_session_experiments(invocation_id,experiment_id,run_id,ordinal)\n VALUES (?,?,?,?)`);\n const insertSlot = recordStatement(connection, `INSERT INTO ne19_run_expected_slots(run_id,slot_id,ordinal,eval_id,attempt_ordinal,execution_identity_digest)\n VALUES (?,?,?,?,?,?)`);\n input.runs.forEach((run, runOrdinal) => {\n recordStatement(connection, \"UPDATE ne19_run_publication_clock SET revision=revision+1 WHERE singleton=1\").run();\n const revision = recordStatement(connection, \"SELECT revision FROM ne19_run_publication_clock WHERE singleton=1\").get() as Row;\n insertRun.run(run.runId, input.invocationId, run.experimentId, run.startedAt, run.writerGeneration, run.writerGeneration, integer(revision, \"revision\"));\n insertExperiment.run(input.invocationId, run.experimentId, run.runId, runOrdinal);\n run.expectedSlots.forEach((slot, ordinal) => insertSlot.run(run.runId, slot.slotId, ordinal, slot.evalId, slot.attemptOrdinal, slot.executionIdentityDigest));\n });\n const insertQueued = recordStatement(connection, `INSERT INTO ne19_invocation_session_queued_attempts(invocation_id,attempt_id,run_id,slot_id,ordinal)\n VALUES (?,?,?,?,?)`);\n (input.queuedAttempts ?? []).forEach((attempt, ordinal) => insertQueued.run(input.invocationId, attempt.attemptId, attempt.runId, attempt.slotId, ordinal));\n return readInvocationOnConnection(connection, input.invocationId)!;\n });\n}\nexport function readInvocationOnConnection(connection: RecordDatabase, invocationId: string): InvocationSessionRecord | undefined {\n const row = recordStatement(connection, \"SELECT * FROM ne19_invocation_sessions WHERE invocation_id=?\").get(invocationId) as Row | undefined;\n return row === undefined ? undefined : decodeSession(row);\n}\nexport function listInvocationsOnConnection(connection: RecordDatabase): readonly InvocationSessionRecord[] {\n return Object.freeze((recordStatement(connection, \"SELECT * FROM ne19_invocation_sessions ORDER BY started_at,invocation_id\").all() as unknown as readonly Row[]).map(decodeSession));\n}\nexport function heartbeatInvocationOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"heartbeat-invocation\", () => {\n requireOpen(connection, \"heartbeat-invocation\");\n const changed = recordStatement(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=? WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`)\n .run(at, invocationId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"heartbeat-invocation\", \"invocation owner generation is fenced\");\n });\n}\nexport function updateInvocationActiveProjectionOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, at: string, projection: Uint8Array, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"update-invocation-active-projection\", () => {\n requireOpen(connection, \"update-invocation-active-projection\");\n const changed = recordStatement(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=?,active_projection=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`)\n .run(at, projection, invocationId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"update-invocation-active-projection\", \"invocation owner generation is fenced\");\n });\n}\nexport function queueInvocationAttemptOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, attempt: {\n readonly attemptId: string;\n readonly runId: string;\n readonly slotId: string;\n readonly ordinal: number;\n}, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"queue-invocation-attempt\", () => {\n requireOpen(connection, \"queue-invocation-attempt\");\n const heartbeat = recordStatement(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`).run(at, invocationId, ...ownerArgs(owner));\n if (Number(heartbeat.changes) !== 1)\n conflict(\"queue-invocation-attempt\", \"invocation owner generation is fenced\");\n recordStatement(connection, `INSERT INTO ne19_invocation_session_queued_attempts(invocation_id,attempt_id,run_id,slot_id,ordinal)\n VALUES (?,?,?,?,?)`).run(invocationId, attempt.attemptId, attempt.runId, attempt.slotId, attempt.ordinal);\n });\n}\nexport function finishInvocationAttemptOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, attemptId: string, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"finish-invocation-attempt\", () => {\n requireOpen(connection, \"finish-invocation-attempt\");\n const heartbeat = recordStatement(connection, `UPDATE ne19_invocation_sessions SET heartbeat_at=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`).run(at, invocationId, ...ownerArgs(owner));\n if (Number(heartbeat.changes) !== 1)\n conflict(\"finish-invocation-attempt\", \"invocation owner generation is fenced\");\n const removed = recordStatement(connection, \"DELETE FROM ne19_invocation_session_queued_attempts WHERE invocation_id=? AND attempt_id=?\")\n .run(invocationId, attemptId);\n if (Number(removed.changes) !== 1)\n conflict(\"finish-invocation-attempt\", \"queued attempt does not exist\");\n });\n}\nexport function beginInvocationRecoveryOnConnection(connection: RecordDatabase, invocationId: string, deadOwner: FencedOwner, recoveryOwner: ProcessOwnerIdentity, at: string, deadline: number): FencedOwner {\n return withImmediateTransaction(connection, deadline, \"begin-invocation-recovery\", () => {\n requireOpen(connection, \"begin-invocation-recovery\");\n const changed = recordStatement(connection, `UPDATE ne19_invocation_sessions SET state='recovering',recovering_at=?,owner_id=?,\n owner_generation=owner_generation+1,owner_host=?,owner_pid=?,owner_boot_id=?,owner_process_start=?,heartbeat_at=?\n WHERE invocation_id=? AND state='active' AND ${sameOwnerSql(\"owner\")}`).run(at, recoveryOwner.ownerId, recoveryOwner.host, recoveryOwner.pid, recoveryOwner.bootId, recoveryOwner.processStart, at, invocationId, ...ownerArgs(deadOwner));\n if (Number(changed.changes) !== 1)\n conflict(\"begin-invocation-recovery\", \"exact dead invocation owner did not match\");\n return Object.freeze({ ...recoveryOwner, generation: deadOwner.generation + 1 });\n });\n}\nexport function closeInvocationOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, state: Exclude<InvocationSessionState, \"active\" | \"recovering\">, at: string, projection: Uint8Array, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"close-invocation\", () => {\n requireOpen(connection, \"close-invocation\");\n const changed = recordStatement(connection, `UPDATE ne19_invocation_sessions SET state=?,closed_at=?,active_projection=NULL,terminal_projection=?,recovering_at=NULL\n WHERE invocation_id=? AND state IN ('active','recovering') AND ${sameOwnerSql(\"owner\")}`).run(state, at, projection, invocationId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"close-invocation\", \"invocation owner generation is fenced or terminal\");\n recordStatement(connection, \"DELETE FROM ne19_invocation_session_queued_attempts WHERE invocation_id=?\").run(invocationId);\n });\n}\nexport function finishInvocationRecoveryOnConnection(connection: RecordDatabase, invocationId: string, owner: FencedOwner, at: string, projection: Uint8Array, deadline: number): void {\n closeInvocationOnConnection(connection, invocationId, owner, \"interrupted\", at, projection, deadline);\n}\nexport function acquireCaseLockOnConnection(connection: RecordDatabase, caseId: string, owner: ProcessOwnerIdentity, at: string, deadline: number): FencedOwner {\n return withImmediateTransaction(connection, deadline, \"acquire-case-lock\", () => {\n requireOpen(connection, \"acquire-case-lock\");\n const existing = recordStatement(connection, \"SELECT * FROM ne19_case_locks WHERE case_id=?\").get(caseId) as Row | undefined;\n if (existing !== undefined)\n conflict(\"acquire-case-lock\", `case ${caseId} is already owned`);\n recordStatement(connection, `INSERT INTO ne19_case_locks(case_id,owner_id,owner_generation,owner_host,owner_pid,owner_boot_id,owner_process_start,acquired_at,heartbeat_at)\n VALUES (?,?,1,?,?,?,?,?,?)`).run(caseId, owner.ownerId, owner.host, owner.pid, owner.bootId, owner.processStart, at, at);\n return Object.freeze({ ...owner, generation: 1 });\n });\n}\nexport function readCaseLockProjectionOnConnection(connection: RecordDatabase, caseId: string): CaseLockProjection | undefined {\n const row = recordStatement(connection, \"SELECT * FROM ne19_case_locks WHERE case_id=?\").get(caseId) as Row | undefined;\n return row === undefined ? undefined : Object.freeze({\n owner: Object.freeze({\n ownerId: text(row, \"owner_id\"), generation: integer(row, \"owner_generation\"),\n host: text(row, \"owner_host\"), pid: integer(row, \"owner_pid\"),\n bootId: text(row, \"owner_boot_id\"), processStart: text(row, \"owner_process_start\"),\n }),\n acquiredAt: text(row, \"acquired_at\"),\n heartbeatAt: text(row, \"heartbeat_at\"),\n });\n}\nexport function readCaseLockOnConnection(connection: RecordDatabase, caseId: string): FencedOwner | undefined {\n return readCaseLockProjectionOnConnection(connection, caseId)?.owner;\n}\nexport function heartbeatCaseLockOnConnection(connection: RecordDatabase, caseId: string, owner: FencedOwner, at: string, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"heartbeat-case-lock\", () => {\n requireOpen(connection, \"heartbeat-case-lock\");\n const changed = recordStatement(connection, `UPDATE ne19_case_locks SET heartbeat_at=? WHERE case_id=? AND ${sameOwnerSql(\"owner\")}`).run(at, caseId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"heartbeat-case-lock\", \"case lock owner generation is fenced\");\n });\n}\nexport function releaseCaseLockOnConnection(connection: RecordDatabase, caseId: string, owner: FencedOwner, deadline: number): void {\n withImmediateTransaction(connection, deadline, \"release-case-lock\", () => {\n requireOpen(connection, \"release-case-lock\");\n const changed = recordStatement(connection, `DELETE FROM ne19_case_locks WHERE case_id=? AND ${sameOwnerSql(\"owner\")}`).run(caseId, ...ownerArgs(owner));\n if (Number(changed.changes) !== 1)\n conflict(\"release-case-lock\", \"case lock owner generation is fenced\");\n });\n}\nexport function takeoverDeadCaseLockOnConnection(connection: RecordDatabase, caseId: string, deadOwner: FencedOwner, replacement: ProcessOwnerIdentity, at: string, deadline: number): FencedOwner {\n return withImmediateTransaction(connection, deadline, \"takeover-case-lock\", () => {\n requireOpen(connection, \"takeover-case-lock\");\n const changed = recordStatement(connection, `UPDATE ne19_case_locks SET owner_id=?,owner_generation=owner_generation+1,owner_host=?,owner_pid=?,\n owner_boot_id=?,owner_process_start=?,acquired_at=?,heartbeat_at=? WHERE case_id=? AND ${sameOwnerSql(\"owner\")}`).run(replacement.ownerId, replacement.host, replacement.pid, replacement.bootId, replacement.processStart, at, at, caseId, ...ownerArgs(deadOwner));\n if (Number(changed.changes) !== 1)\n conflict(\"takeover-case-lock\", \"exact dead case owner did not match\");\n return Object.freeze({ ...replacement, generation: deadOwner.generation + 1 });\n });\n}\n"]}
|