@cortexkit/opencode-magic-context 0.49.84 → 0.49.85

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.
Files changed (101) hide show
  1. package/dist/{announcement-p41dde4h.js → announcement-fnyxaahs.js} +3 -1
  2. package/dist/auto-search-worker.js +3 -3
  3. package/dist/chunk-embedding-write-worker.js +5 -4
  4. package/dist/{context-3sajdysh.js → context-bjfwzbts.js} +27 -26
  5. package/dist/{derive-budgets-0kcek5ex.js → derive-budgets-90869322.js} +3 -1
  6. package/dist/{embedding-backfill-k994xdas.js → embedding-backfill-v6sw58m8.js} +7 -5
  7. package/dist/embedding-worker.js +15 -27
  8. package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts +24 -0
  9. package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts.map +1 -0
  10. package/dist/features/magic-context/memory/embedding-worker-client.d.ts +35 -1
  11. package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
  12. package/dist/features/magic-context/memory/embedding-worker-loop.d.ts +57 -0
  13. package/dist/features/magic-context/memory/embedding-worker-loop.d.ts.map +1 -0
  14. package/dist/features/magic-context/project-embedding-registry.d.ts +6 -1
  15. package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
  16. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  17. package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
  18. package/dist/{index-tvbkemec.js → index-08jfpny9.js} +1 -1
  19. package/dist/{index-k0jnsjcp.js → index-0rge5rkh.js} +6 -6
  20. package/dist/{index-0wehkw71.js → index-1pf5qrx4.js} +4 -4
  21. package/dist/{index-98qy103c.js → index-2kf73btc.js} +1 -1
  22. package/dist/{index-vpw46557.js → index-3dtzyred.js} +1 -1
  23. package/dist/{index-bd34njzg.js → index-4ntnt8ee.js} +1 -1
  24. package/dist/{index-w2wpx7t5.js → index-4w5rx7de.js} +1 -1
  25. package/dist/{index-xd0ww0ns.js → index-798s7c8s.js} +1 -1
  26. package/dist/{index-fpqdbb67.js → index-7svecf3m.js} +3 -3
  27. package/dist/{index-tqnvn9pa.js → index-9fsxmjs6.js} +3 -3
  28. package/dist/{v2/server-fvnzcnww.js → index-c5tmzym6.js} +192 -11
  29. package/dist/{index-w8dcjt7f.js → index-k0tb2z28.js} +1 -1
  30. package/dist/{index-zb4h9nrk.js → index-k50xhjw1.js} +202 -14
  31. package/dist/{index-qybp04ff.js → index-kqnef2tg.js} +3 -3
  32. package/dist/{index-szwrpyac.js → index-nny4gm06.js} +1 -1
  33. package/dist/{index-fgy6hnr3.js → index-pw279hmt.js} +2 -2
  34. package/dist/{index-xjfan0za.js → index-qvn3q9f1.js} +37 -37
  35. package/dist/{index-shpyv8gq.js → index-s8ks5nz4.js} +16 -9
  36. package/dist/{index-cfy5k1pa.js → index-sbr58jaf.js} +5 -5
  37. package/dist/{index-d028gmgp.js → index-tzbcb8yt.js} +14 -14
  38. package/dist/{index-skwwbcnv.js → index-w6v4dw5f.js} +24 -24
  39. package/dist/{index-5wjv4c41.js → index-xccywqdj.js} +15 -15
  40. package/dist/{index-kthfyf45.js → index-zmqx48vt.js} +3 -3
  41. package/dist/index.js +33 -33
  42. package/dist/migration-worker.js +4 -3
  43. package/dist/{project-embedding-registry-y3z36mjy.js → project-embedding-registry-q80scexh.js} +6 -4
  44. package/dist/raw-ordinal-warmup-worker.js +2 -2
  45. package/dist/{recomp-orchestrator-m2s3jpvj.js → recomp-orchestrator-xzs0a455.js} +16 -15
  46. package/dist/{render-p2j7rn9a.js → render-yqp7q79f.js} +8 -7
  47. package/dist/{search-archive-hz9xh7nh.js → search-archive-r4h96j2z.js} +2 -2
  48. package/dist/{search-ksx0f1qd.js → search-ztgy3ya6.js} +12 -10
  49. package/dist/shared/storage-file-mutex.d.ts.map +1 -1
  50. package/dist/shared/storage-permissions.d.ts +5 -3
  51. package/dist/shared/storage-permissions.d.ts.map +1 -1
  52. package/dist/{store-x0swqb5c.js → store-n4yz3n66.js} +2 -2
  53. package/dist/{store-reader-tsv1w4vt.js → store-reader-nf8z86n9.js} +1 -1
  54. package/dist/{transform-postprocess-phase-1wb2rrr1.js → transform-postprocess-phase-39a5hm2a.js} +17 -16
  55. package/dist/v2/auto-search-worker.js +3 -3
  56. package/dist/v2/chunk-embedding-write-worker.js +5 -4
  57. package/dist/v2/{context-at9nje0j.js → context-k2rrqzf4.js} +39 -39
  58. package/dist/v2/{derive-budgets-xbwcap8k.js → derive-budgets-ecjy1aqh.js} +4 -2
  59. package/dist/v2/{embedding-backfill-hjvjxp7d.js → embedding-backfill-k8kqnwfq.js} +7 -5
  60. package/dist/v2/embedding-worker.js +15 -27
  61. package/dist/v2/migration-worker.js +4 -3
  62. package/dist/v2/{project-embedding-registry-mzsvyads.js → project-embedding-registry-2jp1antr.js} +6 -4
  63. package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
  64. package/dist/v2/{recomp-orchestrator-nhef90gc.js → recomp-orchestrator-jnbxbsc8.js} +17 -16
  65. package/dist/v2/{render-c9r2g2jv.js → render-fezgh7pa.js} +8 -7
  66. package/dist/v2/{search-archive-80ckv9kq.js → search-archive-zz1kza50.js} +2 -2
  67. package/dist/v2/{search-t06js5dc.js → search-h5w7510x.js} +11 -9
  68. package/dist/v2/{server-4z964n1c.js → server-3p6b0qya.js} +1 -1
  69. package/dist/v2/{server-3cndh146.js → server-4wwwm2ya.js} +24 -24
  70. package/dist/v2/{server-mr9rqn0y.js → server-97w51d8n.js} +4 -4
  71. package/dist/v2/{server-gx1s06dx.js → server-98hsp35q.js} +2 -2
  72. package/dist/v2/{server-d706s5xn.js → server-b93f0bqh.js} +205 -17
  73. package/dist/v2/{server-dfesqfv1.js → server-brgandk4.js} +1 -1
  74. package/dist/v2/{server-w1jfaxas.js → server-cwtehwbb.js} +1 -1
  75. package/dist/v2/{server-y4favn4d.js → server-e2k9mt86.js} +1 -1
  76. package/dist/v2/{server-68q80y27.js → server-hn8b7sfe.js} +16 -9
  77. package/dist/v2/{server-pejjj0nv.js → server-mbkwcwgw.js} +1 -1
  78. package/dist/v2/{server-ry6rpspz.js → server-n5zr7190.js} +15 -15
  79. package/dist/v2/{server-210rc0z9.js → server-ps6rz88g.js} +1 -1
  80. package/dist/{index-fvnzcnww.js → v2/server-r2es6zt7.js} +192 -11
  81. package/dist/v2/{server-bt546axy.js → server-rz4snd3x.js} +3 -3
  82. package/dist/v2/{server-3hhakg5a.js → server-s76ty4ws.js} +13 -13
  83. package/dist/v2/{server-hhw6rzsn.js → server-w7mpvkpj.js} +1 -1
  84. package/dist/v2/{server-863bwkga.js → server-x77hd658.js} +6 -6
  85. package/dist/v2/{server-sy98vksf.js → server-xa8fefhw.js} +3 -3
  86. package/dist/v2/{server-cce6m31c.js → server-ytqps2xa.js} +1 -1
  87. package/dist/v2/server.js +6 -4
  88. package/dist/v2/{store-reader-paamf0ac.js → store-reader-2vhx33n6.js} +1 -1
  89. package/dist/v2/{store-h3s95ywe.js → store-y56y034s.js} +2 -2
  90. package/dist/v2/{v2-archive-reader-1zzteaa5.js → v2-archive-reader-e2w39c3p.js} +1 -1
  91. package/dist/v2/{wrapup-orchestrator-9y98qcqz.js → wrapup-orchestrator-mmje3etf.js} +16 -15
  92. package/dist/{v2-archive-reader-3yjxaj5z.js → v2-archive-reader-8dsngf2j.js} +1 -1
  93. package/dist/{wrapup-orchestrator-sa3a075a.js → wrapup-orchestrator-sm6pwf3p.js} +17 -16
  94. package/package.json +1 -1
  95. package/src/shared/storage-file-mutex-review.test.ts +125 -2
  96. package/src/shared/storage-file-mutex.ts +17 -8
  97. package/src/shared/storage-permissions-creators.test.ts +194 -0
  98. package/src/shared/storage-permissions-startup.test.ts +476 -0
  99. package/src/shared/storage-permissions.ts +227 -12
  100. /package/dist/{index-rdh63md0.js → index-1y4y98r1.js} +0 -0
  101. /package/dist/v2/{server-9nk5h6w6.js → server-qyazxy92.js} +0 -0
@@ -7,8 +7,16 @@ import {
7
7
  import {
8
8
  getMagicContextStorageDir,
9
9
  importPluginModule,
10
- log2
10
+ log2,
11
+ flushLogger2
11
12
  } from "./server-j8376q08.js";
13
+ import {
14
+ shouldEnforcePrivateStoragePermissions,
15
+ ensureStorageDirectorySync,
16
+ writeStorageFileAsync,
17
+ writeStorageFileHandleAsync,
18
+ createStorageFileHandleAsync
19
+ } from "./server-r2es6zt7.js";
12
20
  import {
13
21
  getSynapseLaneIdentity
14
22
  } from "./server-x6fn9x8q.js";
@@ -18,13 +26,6 @@ import {
18
26
  import {
19
27
  computeNormalizedHash
20
28
  } from "./server-2bvekkfy.js";
21
- import {
22
- shouldEnforcePrivateStoragePermissions,
23
- ensureStorageDirectorySync,
24
- writeStorageFileAsync,
25
- writeStorageFileHandleAsync,
26
- createStorageFileHandleAsync
27
- } from "./server-fvnzcnww.js";
28
29
 
29
30
  // src/features/magic-context/memory/embedding-local.ts
30
31
  import { readdirSync, statSync as statSync2 } from "node:fs";
@@ -675,6 +676,80 @@ function getEmbeddingProviderIdentity(config) {
675
676
  import { fork } from "node:child_process";
676
677
  import { Worker } from "node:worker_threads";
677
678
 
679
+ // src/features/magic-context/memory/embedding-worker-loop.ts
680
+ var EMBEDDING_WORKER_STOPPING_ERROR = "embedding worker stopping";
681
+ function isEmbeddingWorkerStopNotice(message) {
682
+ return typeof message === "object" && message !== null && "control" in message && (message.control === "stopping" || message.control === "stopped");
683
+ }
684
+ function serveEmbeddingWorker(port, model, options) {
685
+ const now = options.now ?? (() => performance.now());
686
+ let queue = Promise.resolve();
687
+ let stopping = false;
688
+ let busySince = null;
689
+ const refuse = (id) => port.postMessage({ id, loaded: false, error: EMBEDDING_WORKER_STOPPING_ERROR });
690
+ const handle = async (request) => {
691
+ if (stopping)
692
+ return refuse(request.id);
693
+ busySince = now();
694
+ try {
695
+ const loaded = await model.initialize();
696
+ let vectors;
697
+ if (loaded && request.texts) {
698
+ vectors = [];
699
+ for (let offset = 0;offset < request.texts.length; offset += options.batchSize) {
700
+ if (offset > 0)
701
+ await new Promise((resolve) => setImmediate(resolve));
702
+ if (stopping)
703
+ throw new Error(EMBEDDING_WORKER_STOPPING_ERROR);
704
+ vectors.push(...await model.embedBatch(request.texts.slice(offset, offset + options.batchSize)));
705
+ }
706
+ }
707
+ port.postMessage({
708
+ id: request.id,
709
+ loaded,
710
+ vectors,
711
+ failure: model.getLastFailureReason(),
712
+ stats: options.stats?.()
713
+ }, vectors?.flatMap((vector) => vector ? [vector.buffer] : []) ?? []);
714
+ } catch (error) {
715
+ port.postMessage({ id: request.id, loaded: false, error: String(error) });
716
+ } finally {
717
+ busySince = null;
718
+ }
719
+ };
720
+ const stop = async () => {
721
+ stopping = true;
722
+ const requestedAt = now();
723
+ const busy = busySince !== null;
724
+ port.postMessage({
725
+ control: "stopping",
726
+ busy,
727
+ busyMs: busySince === null ? 0 : requestedAt - busySince
728
+ });
729
+ await queue;
730
+ try {
731
+ await model.dispose();
732
+ } catch {}
733
+ port.postMessage({
734
+ control: "stopped",
735
+ busy,
736
+ waitedMs: now() - requestedAt
737
+ });
738
+ options.exit();
739
+ };
740
+ port.on("message", (message) => {
741
+ if (message?.stop === true) {
742
+ if (!stopping)
743
+ stop();
744
+ return;
745
+ }
746
+ const request = message;
747
+ if (stopping)
748
+ return refuse(request.id);
749
+ queue = queue.then(() => handle(request));
750
+ });
751
+ }
752
+
678
753
  // src/features/magic-context/memory/onnx-telemetry.ts
679
754
  import { isMainThread } from "node:worker_threads";
680
755
  var FFI_SPECIFIER = "bun:ffi";
@@ -721,6 +796,41 @@ async function prepareNativeOnnxTelemetry() {
721
796
 
722
797
  // src/features/magic-context/memory/embedding-worker-client.ts
723
798
  var warnedWindowsTelemetry = false;
799
+ var EMBEDDING_WORKER_STOP_GRACE_MS = 5000;
800
+ var EMBEDDING_WORKER_FORCED_EXIT_WAIT_MS = 2000;
801
+ var EMBEDDING_WORKER_SIGKILL_WAIT_MS = 200;
802
+ var EMBEDDING_WORKER_STOP_MAX_MS = EMBEDDING_WORKER_STOP_GRACE_MS + EMBEDDING_WORKER_FORCED_EXIT_WAIT_MS + EMBEDDING_WORKER_SIGKILL_WAIT_MS;
803
+ function busySince(state) {
804
+ let oldest = null;
805
+ for (const sentAt of state.dispatched.values()) {
806
+ if (oldest === null || sentAt < oldest)
807
+ oldest = sentAt;
808
+ }
809
+ return oldest;
810
+ }
811
+ async function exitsWithin(exit, ms) {
812
+ let timer;
813
+ try {
814
+ return await Promise.race([
815
+ exit.then(() => true),
816
+ new Promise((resolve) => {
817
+ timer = setTimeout(() => resolve(false), ms);
818
+ })
819
+ ]);
820
+ } finally {
821
+ clearTimeout(timer);
822
+ }
823
+ }
824
+ function describeRunning(since, at) {
825
+ return since === null ? "no" : `yes (for ${Math.max(0, Math.round(at - since))}ms)`;
826
+ }
827
+ function describeStuckWorker(state, stopSince) {
828
+ const notice = state.stopNotice;
829
+ const at = performance.now();
830
+ if (notice)
831
+ return describeRunning(notice.busy ? notice.receivedAt - notice.busyMs : null, at);
832
+ return `${describeRunning(stopSince, at)}, no answer to the stop request`;
833
+ }
724
834
 
725
835
  class EmbeddingWorkerClient {
726
836
  data;
@@ -728,19 +838,23 @@ class EmbeddingWorkerClient {
728
838
  timeoutMs;
729
839
  prepareTelemetry;
730
840
  idleMs;
841
+ options;
731
842
  worker = null;
732
843
  startPromise = null;
844
+ states = new WeakMap;
845
+ stopping = new Set;
733
846
  nextId = 1;
734
847
  pending = new Map;
735
848
  disposed = false;
736
849
  activeRequests = 0;
737
850
  idleTimer = null;
738
- constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry, idleMs = 10 * 60000) {
851
+ constructor(data, entry = new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./embedding-worker.ts" : "./embedding-worker.js", import.meta.url), timeoutMs = 5 * 60000, prepareTelemetry = prepareNativeOnnxTelemetry, idleMs = 10 * 60000, options = {}) {
739
852
  this.data = data;
740
853
  this.entry = entry;
741
854
  this.timeoutMs = timeoutMs;
742
855
  this.prepareTelemetry = prepareTelemetry;
743
856
  this.idleMs = idleMs;
857
+ this.options = options;
744
858
  }
745
859
  start() {
746
860
  if (this.startPromise)
@@ -778,14 +892,38 @@ class EmbeddingWorkerClient {
778
892
  }
779
893
  }
780
894
  this.worker = worker;
895
+ let markExited;
896
+ const state = {
897
+ dispatched: new Map,
898
+ stopNotice: null,
899
+ exited: false,
900
+ exit: new Promise((resolve) => {
901
+ markExited = resolve;
902
+ })
903
+ };
904
+ this.states.set(worker, state);
905
+ worker.once("exit", () => {
906
+ state.exited = true;
907
+ markExited();
908
+ });
781
909
  worker.unref();
782
910
  if (!(worker instanceof Worker))
783
911
  worker.channel?.unref?.();
784
912
  worker.on("message", (wire) => {
913
+ if (isEmbeddingWorkerStopNotice(wire)) {
914
+ if (wire.control === "stopping")
915
+ state.stopNotice = {
916
+ busy: wire.busy,
917
+ busyMs: wire.busyMs,
918
+ receivedAt: performance.now()
919
+ };
920
+ return;
921
+ }
785
922
  const reply = worker instanceof Worker ? wire : {
786
923
  ...wire,
787
924
  vectors: wire.vectors?.map((vector) => vector === null ? null : new Float32Array(Uint8Array.from(Buffer.from(vector, "base64")).buffer))
788
925
  };
926
+ state.dispatched.delete(reply.id);
789
927
  if (this.worker !== worker)
790
928
  return;
791
929
  const request = this.pending.get(reply.id);
@@ -893,6 +1031,7 @@ class EmbeddingWorkerClient {
893
1031
  worker.ref();
894
1032
  if (!(worker instanceof Worker))
895
1033
  worker.channel?.ref?.();
1034
+ this.states.get(worker)?.dispatched.set(id, performance.now());
896
1035
  try {
897
1036
  if (worker instanceof Worker)
898
1037
  worker.postMessage({ id, texts });
@@ -915,21 +1054,70 @@ class EmbeddingWorkerClient {
915
1054
  request.reject(error);
916
1055
  }
917
1056
  this.pending.clear();
918
- if (worker instanceof Worker) {
919
- await worker.terminate();
920
- } else if (worker && worker.exitCode === null && worker.signalCode === null) {
921
- worker.ref();
1057
+ if (!worker)
1058
+ return;
1059
+ const stopped = this.stopWorker(worker, error.message);
1060
+ this.stopping.add(stopped);
1061
+ try {
1062
+ await stopped;
1063
+ } finally {
1064
+ this.stopping.delete(stopped);
1065
+ }
1066
+ }
1067
+ async stopWorker(worker, reason) {
1068
+ const state = this.states.get(worker);
1069
+ if (!state || state.exited)
1070
+ return;
1071
+ const writeLog = this.options.log ?? log2;
1072
+ const graceMs = this.options.stopGraceMs ?? EMBEDDING_WORKER_STOP_GRACE_MS;
1073
+ const forcedExitWaitMs = this.options.forcedExitWaitMs ?? EMBEDDING_WORKER_FORCED_EXIT_WAIT_MS;
1074
+ const owner = worker instanceof Worker ? `pid ${process.pid}` : `pid ${process.pid}, worker pid ${worker.pid ?? "unknown"}`;
1075
+ const startedAt = performance.now();
1076
+ const stopSince = busySince(state);
1077
+ worker.ref();
1078
+ if (!(worker instanceof Worker))
922
1079
  worker.channel?.ref?.();
923
- await new Promise((resolve) => {
924
- worker.once("exit", () => resolve());
1080
+ const request = { stop: true };
1081
+ try {
1082
+ if (worker instanceof Worker)
1083
+ worker.postMessage(request);
1084
+ else if (worker.connected)
1085
+ worker.send(request, () => {});
1086
+ } catch {}
1087
+ if (await exitsWithin(state.exit, graceMs)) {
1088
+ writeLog(`[magic-context] embedding worker stopped (${reason}; ${owner}; inference running: ${describeRunning(stopSince, startedAt)}; stop took ${Math.round(performance.now() - startedAt)}ms)`);
1089
+ flushLogger2();
1090
+ return;
1091
+ }
1092
+ writeLog(`[magic-context] embedding worker did not stop within ${graceMs}ms; terminating it (${reason}; ${owner}; inference running: ${describeStuckWorker(state, stopSince)})`);
1093
+ flushLogger2();
1094
+ try {
1095
+ if (worker instanceof Worker)
1096
+ worker.terminate().catch(() => {});
1097
+ else
925
1098
  worker.kill();
926
- });
1099
+ } catch {}
1100
+ if (await exitsWithin(state.exit, forcedExitWaitMs))
1101
+ return;
1102
+ let killed = false;
1103
+ if (!(worker instanceof Worker) && process.platform !== "win32") {
1104
+ try {
1105
+ killed = worker.kill("SIGKILL");
1106
+ } catch {}
1107
+ if (await exitsWithin(state.exit, EMBEDDING_WORKER_SIGKILL_WAIT_MS))
1108
+ return;
927
1109
  }
1110
+ writeLog(`[magic-context] embedding worker has not exited ${forcedExitWaitMs}ms after it was terminated${killed ? " and sent SIGKILL" : ""}; no longer waiting for it (${reason}; ${owner})`);
1111
+ flushLogger2();
1112
+ worker.unref();
1113
+ if (!(worker instanceof Worker))
1114
+ worker.channel?.unref?.();
928
1115
  }
929
1116
  async dispose() {
930
1117
  this.disposed = true;
931
1118
  await this.startPromise?.catch(() => {});
932
1119
  await this.stop(new Error("embedding worker disposed"));
1120
+ await Promise.all([...this.stopping]);
933
1121
  }
934
1122
  }
935
1123
 
@@ -1651,4 +1839,4 @@ class LocalEmbeddingProvider {
1651
1839
  }
1652
1840
  }
1653
1841
 
1654
- export { dominantEmbeddingFailure, embeddingModelsMatch, resolveEmbeddingTextPrefixes, getCachedLocalEmbeddingPooling, logLocalEmbeddingPoolingDecisionOnce, preflightLocalEmbeddingPooling, logLocalEmbeddingPoolingUnavailableOnce, getEmbeddingProviderIdentity, resolveLocalEmbeddingWorkerRuntime, getLocalEmbeddingNativeMemoryStats, LocalEmbeddingProvider };
1842
+ export { dominantEmbeddingFailure, embeddingModelsMatch, resolveEmbeddingTextPrefixes, getCachedLocalEmbeddingPooling, logLocalEmbeddingPoolingDecisionOnce, preflightLocalEmbeddingPooling, logLocalEmbeddingPoolingUnavailableOnce, getEmbeddingProviderIdentity, serveEmbeddingWorker, resolveLocalEmbeddingWorkerRuntime, getLocalEmbeddingNativeMemoryStats, LocalEmbeddingProvider };
@@ -22,7 +22,7 @@ import {
22
22
  } from "./server-2k8tkbhz.js";
23
23
  import {
24
24
  readV2ArchiveOffThread2
25
- } from "./server-mr9rqn0y.js";
25
+ } from "./server-97w51d8n.js";
26
26
 
27
27
  // src/tools/ctx-expand/search-archive.ts
28
28
  var archiveReadsOnThisThread = 0;
@@ -5,7 +5,7 @@ import {
5
5
  getSdkWindowGeometry,
6
6
  getSdkContextLimit,
7
7
  getSdkInputLimit
8
- } from "./server-sy98vksf.js";
8
+ } from "./server-xa8fefhw.js";
9
9
  import {
10
10
  localBudget,
11
11
  calibrationForModelKey
@@ -3,7 +3,7 @@ import {
3
3
  } from "./server-j8376q08.js";
4
4
  import {
5
5
  setOutputReserveConfig
6
- } from "./server-sy98vksf.js";
6
+ } from "./server-xa8fefhw.js";
7
7
  import {
8
8
  DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE,
9
9
  PROTECTED_TOKENS_MIN,
@@ -15,7 +15,7 @@ import {
15
15
  } from "./server-gzy5w8ya.js";
16
16
  import {
17
17
  setBootQuietPeriodForTests
18
- } from "./server-bt546axy.js";
18
+ } from "./server-rz4snd3x.js";
19
19
  import {
20
20
  isEmbeddingHostBusy2
21
21
  } from "./server-qt1qqasc.js";
@@ -68,7 +68,7 @@ import {
68
68
  findMisScopedCompartmentChunkEmbeddingIdsForProject,
69
69
  recordSessionProjectIdentity,
70
70
  repairMisScopedCompartmentChunkEmbeddingsForProject
71
- } from "./server-4z964n1c.js";
71
+ } from "./server-3p6b0qya.js";
72
72
  import {
73
73
  saveEmbeddingIfHashMatches,
74
74
  getMemoryEmbedCoverage,
@@ -83,7 +83,7 @@ import {
83
83
  logLocalEmbeddingPoolingUnavailableOnce,
84
84
  getEmbeddingProviderIdentity,
85
85
  LocalEmbeddingProvider
86
- } from "./server-d706s5xn.js";
86
+ } from "./server-b93f0bqh.js";
87
87
  import {
88
88
  isKnownAutocommit
89
89
  } from "./server-8ajstryz.js";
@@ -1407,12 +1407,17 @@ function snapshotFor(registration) {
1407
1407
  ...synapseDescriptor ? { synapseDescriptor } : {}
1408
1408
  };
1409
1409
  }
1410
+ var pendingProviderDisposals = new Set;
1410
1411
  function disposeProvider(provider) {
1411
1412
  if (!provider)
1412
- return;
1413
- provider.dispose().catch((error) => {
1413
+ return Promise.resolve();
1414
+ const disposal = provider.dispose().catch((error) => {
1414
1415
  log2("[magic-context] embedding provider dispose failed:", error);
1416
+ }).finally(() => {
1417
+ pendingProviderDisposals.delete(disposal);
1415
1418
  });
1419
+ pendingProviderDisposals.add(disposal);
1420
+ return disposal;
1416
1421
  }
1417
1422
  function getUpsertActiveIdentityStatement(db) {
1418
1423
  let stmt = upsertActiveIdentityStatements.get(db);
@@ -1775,7 +1780,7 @@ function registerProjectShadowEmbedding2(db, projectIdentity, config, sourceDire
1775
1780
  return null;
1776
1781
  const prior = shadowRegistrations.get(projectIdentity);
1777
1782
  if (prior && prior.providerIdentity === providerIdentity) {
1778
- provider.dispose();
1783
+ disposeProvider(provider);
1779
1784
  dbForShadowQueue.set(projectIdentity, db);
1780
1785
  persistShadowDescriptor(db, prior);
1781
1786
  const backfillAlreadyArmed = hasPendingShadowBackfill(projectIdentity) || shadowQueue.some((item) => item.projectIdentity === projectIdentity);
@@ -2428,13 +2433,15 @@ function unregisterProjectEmbedding2(projectIdentity) {
2428
2433
  const prior = projectRegistrations.get(projectIdentity);
2429
2434
  const shadow = shadowRegistrations.get(projectIdentity);
2430
2435
  if (!prior && !shadow)
2431
- return;
2436
+ return Promise.resolve();
2432
2437
  projectRegistrations.delete(projectIdentity);
2433
2438
  shadowRegistrations.delete(projectIdentity);
2434
2439
  dbForShadowQueue.delete(projectIdentity);
2435
2440
  globalRegistrationGeneration += 1;
2436
- disposeProvider(prior?.provider ?? null);
2437
- disposeProvider(shadow?.provider ?? null);
2441
+ return Promise.all([
2442
+ disposeProvider(prior?.provider ?? null),
2443
+ disposeProvider(shadow?.provider ?? null)
2444
+ ]).then(() => {});
2438
2445
  }
2439
2446
  function getProjectEmbeddingSnapshot2(projectIdentity) {
2440
2447
  const registration = projectRegistrations.get(projectIdentity);
@@ -10,7 +10,7 @@ import {
10
10
  readSearchBackfillCursor2,
11
11
  writeSearchBackfillCursor2,
12
12
  embedItemsWindowBounded2
13
- } from "./server-68q80y27.js";
13
+ } from "./server-hn8b7sfe.js";
14
14
  import {
15
15
  saveEmbeddingIfHashMatches
16
16
  } from "./server-4dhv7mqz.js";
@@ -13,7 +13,7 @@ import {
13
13
  } from "./server-gzy5w8ya.js";
14
14
  import {
15
15
  scheduleAfterBootQuiet
16
- } from "./server-bt546axy.js";
16
+ } from "./server-rz4snd3x.js";
17
17
  import {
18
18
  getHarness2,
19
19
  harnessOwnsOpenCodeStore2
@@ -39,6 +39,14 @@ import {
39
39
  import {
40
40
  configureContextDatabasePragmas2
41
41
  } from "./server-fb3zxn06.js";
42
+ import {
43
+ shouldEnforcePrivateStoragePermissions,
44
+ ensureStorageDirectorySync,
45
+ writeStorageFileSync,
46
+ copyStorageFileSync,
47
+ copyStorageTreeSync,
48
+ tightenStorageTreeSync
49
+ } from "./server-r2es6zt7.js";
42
50
  import {
43
51
  attachFailClosedBlockingProcessEvidence
44
52
  } from "./server-39bcszk4.js";
@@ -57,7 +65,7 @@ import {
57
65
  hasPendingMigrations,
58
66
  getMainThreadMigrationBodyCount,
59
67
  runMigrations
60
- } from "./server-210rc0z9.js";
68
+ } from "./server-ps6rz88g.js";
61
69
  import {
62
70
  ensureColumn,
63
71
  setDatabase,
@@ -78,14 +86,6 @@ import {
78
86
  import {
79
87
  logSlowWriteTransaction
80
88
  } from "./server-5sbsnpkn.js";
81
- import {
82
- shouldEnforcePrivateStoragePermissions,
83
- ensureStorageDirectorySync,
84
- writeStorageFileSync,
85
- copyStorageFileSync,
86
- copyStorageTreeSync,
87
- tightenStorageTreeSync
88
- } from "./server-fvnzcnww.js";
89
89
 
90
90
  // src/features/magic-context/storage-db.ts
91
91
  import {
@@ -586,8 +586,8 @@ var BOOT_SQLITE_BUSY_TIMEOUT_MS = 5000;
586
586
  function ensureSecureStorageDir(dir) {
587
587
  ensureStorageDirectorySync(dir);
588
588
  }
589
- function tightenStorageTree(dir) {
590
- const { failures } = tightenStorageTreeSync(dir);
589
+ function tightenStorageTree(dbPath) {
590
+ const { failures } = tightenStorageTreeSync(dirname(dbPath), dbPath);
591
591
  log2(`[magic-context] storage permission tightening failures=${failures}`);
592
592
  }
593
593
  function resolveBootBusyTimeoutMs(value) {
@@ -1047,7 +1047,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1047
1047
  }
1048
1048
  setDatabase(db);
1049
1049
  loadToolDefinitionMeasurements(db);
1050
- tightenStorageTree(dirname(dbPath));
1050
+ tightenStorageTree(dbPath);
1051
1051
  databases.set(dbPath, db);
1052
1052
  pathByDatabase.set(db, dbPath);
1053
1053
  persistenceByDatabase.set(db, true);
@@ -2347,7 +2347,7 @@ function openDatabase(dbPathOrOptions) {
2347
2347
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
2348
2348
  }
2349
2349
  ensureSecureStorageDir(dbDir);
2350
- tightenStorageTree(dbDir);
2350
+ tightenStorageTree(dbPath);
2351
2351
  if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
2352
2352
  try {
2353
2353
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
@@ -2444,7 +2444,7 @@ async function openDatabaseAsync(dbPathOrOptions) {
2444
2444
  if (!explicitDbPath)
2445
2445
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
2446
2446
  ensureSecureStorageDir(dbDir);
2447
- tightenStorageTree(dbDir);
2447
+ tightenStorageTree(dbPath);
2448
2448
  if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
2449
2449
  try {
2450
2450
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
@@ -20,7 +20,7 @@ import {
20
20
  import {
21
21
  normalizeStoredProjectPath,
22
22
  storedPathBelongsToIdentity
23
- } from "./server-bt546axy.js";
23
+ } from "./server-rz4snd3x.js";
24
24
  import {
25
25
  logSlowWriteTransaction
26
26
  } from "./server-5sbsnpkn.js";