@koed-labs/server 0.10.3 → 0.11.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.
Files changed (54) hide show
  1. package/README.md +3 -3
  2. package/package.json +1 -1
  3. package/vendor/{chunk-A6WMU2GG.js → chunk-2XKSVKQA.js} +5 -4
  4. package/vendor/{chunk-VPC5NLZG.js → chunk-4OO6VAU3.js} +1 -1
  5. package/vendor/{chunk-HK2H3MVE.js → chunk-53ZFCDHP.js} +4 -0
  6. package/vendor/chunk-6KS67EQE.js +75 -0
  7. package/vendor/chunk-7EGSY3E4.js +8 -0
  8. package/vendor/{chunk-JKOG52PE.js → chunk-7FSHVVTZ.js} +1 -1
  9. package/vendor/chunk-ALJUSOF7.js +175 -0
  10. package/vendor/{chunk-KUIWH33N.js → chunk-AVQCUFYQ.js} +1 -1
  11. package/vendor/chunk-BGENSONI.js +18 -0
  12. package/vendor/{chunk-ZXX4ZNJY.js → chunk-BUIM2M4R.js} +3 -2
  13. package/vendor/{chunk-YK4F4VY2.js → chunk-C4V72GXC.js} +51 -30
  14. package/vendor/{chunk-JJNLH5GA.js → chunk-C5SNDPAP.js} +21 -19
  15. package/vendor/{chunk-J2L726BC.js → chunk-CHMH4LH5.js} +3 -3
  16. package/vendor/{chunk-2S3OGPUC.js → chunk-EA4QDDQA.js} +2 -2
  17. package/vendor/{chunk-HZJK5RWC.js → chunk-EDPNYIX5.js} +575 -215
  18. package/vendor/{chunk-NM5NXCVM.js → chunk-FN3HUUO2.js} +558 -988
  19. package/vendor/{chunk-473OA62O.js → chunk-FSNLU46W.js} +218 -12497
  20. package/vendor/{chunk-GELDEJJ2.js → chunk-FYYRFX4U.js} +133 -47
  21. package/vendor/{chunk-YOFI4PCH.js → chunk-GFASBPV2.js} +7 -1
  22. package/vendor/chunk-HC76426R.js +48 -0
  23. package/vendor/{chunk-QIIKMG3M.js → chunk-IY2HRXOZ.js} +1 -5
  24. package/vendor/{chunk-ZUGNCQZE.js → chunk-JYK6UL6D.js} +22 -8
  25. package/vendor/{chunk-2BWTLF7A.js → chunk-LRP66XEY.js} +45 -21
  26. package/vendor/{chunk-DXTAWHY3.js → chunk-NOU7RHYZ.js} +8 -7
  27. package/vendor/{chunk-C3N4N5HR.js → chunk-NVTMIAAF.js} +26 -21
  28. package/vendor/chunk-O7DW2VAV.js +14 -0
  29. package/vendor/{chunk-YJ6XUZT6.js → chunk-OCILJ737.js} +23 -16
  30. package/vendor/{chunk-TSRPHKAC.js → chunk-PL3LWC5C.js} +16 -42
  31. package/vendor/chunk-QRKHHWJJ.js +104 -0
  32. package/vendor/{chunk-YJWREXN6.js → chunk-RCR4XPE3.js} +1 -1
  33. package/vendor/{chunk-AFLKCQHF.js → chunk-SHLRINKO.js} +2 -2
  34. package/vendor/{chunk-NEWIOOM6.js → chunk-SNKWETM5.js} +3 -2
  35. package/vendor/{chunk-XNFVSVBS.js → chunk-SRKIBFOE.js} +1 -1
  36. package/vendor/{chunk-G4IIVVJO.js → chunk-T6UB5PNX.js} +70 -2
  37. package/vendor/{chunk-RVYJKKWA.js → chunk-TG26CZGQ.js} +5 -4
  38. package/vendor/{chunk-HFM6ROJL.js → chunk-TISYUUEJ.js} +1 -1
  39. package/vendor/{chunk-K2EIFEQF.js → chunk-TSAYTRX3.js} +1 -1
  40. package/vendor/chunk-TVYEB2GN.js +343 -0
  41. package/vendor/{chunk-PT3AUPGE.js → chunk-UB6JCVQ3.js} +3 -1
  42. package/vendor/chunk-VGIYSDNU.js +522 -0
  43. package/vendor/{chunk-X6M525ZJ.js → chunk-W2OJZZ6X.js} +5 -5
  44. package/vendor/{chunk-YCDEMYY6.js → chunk-WDFERJG3.js} +231 -99
  45. package/vendor/{chunk-SKVYP7NY.js → chunk-WPIEF4LY.js} +8 -8
  46. package/vendor/{chunk-UI5RLBKQ.js → chunk-YZLQZU5E.js} +17 -1
  47. package/vendor/{chunk-PY5LYLV7.js → chunk-Z5WCAUA6.js} +26 -21
  48. package/vendor/chunk-ZIOKV2X6.js +1589 -0
  49. package/vendor/chunk-ZOHNXUDY.js +12501 -0
  50. package/vendor/chunk-ZUDSZGVO.js +11 -0
  51. package/vendor/component-manifest-catalog.js +2 -1
  52. package/vendor/control-plane.js +11 -6
  53. package/vendor/chunk-2DA7EFZV.js +0 -924
  54. /package/vendor/{chunk-A4NKL2PK.js → chunk-V67IQB7H.js} +0 -0
@@ -1,11 +1,29 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ calculateRuntimeRequirements,
4
+ resolveEffectiveRuntimeConfig
5
+ } from "./chunk-SHLRINKO.js";
6
+ import {
7
+ redeemPairingLink
8
+ } from "./chunk-CHMH4LH5.js";
9
+ import {
10
+ bundledPdsSecretProviderEnvironment
11
+ } from "./chunk-EA4QDDQA.js";
12
+ import {
13
+ resolveLocalModelManifest
14
+ } from "./chunk-JYK6UL6D.js";
15
+ import {
16
+ invalidateUpstreamEnrollmentReferences
17
+ } from "./chunk-WPIEF4LY.js";
2
18
  import {
3
19
  collectKoedServerDoctor,
4
20
  collectKoedServerStartupStatus,
5
21
  collectKoedServerStatus,
6
22
  ensurePackagedLocalServiceSecrets,
23
+ hasCompletePostgresOverride,
7
24
  koedServerStartupBlockingComponentIds,
8
25
  migrateKoedOwnedCodexRegistrationBestEffort,
26
+ nativeLlamaServerOverride,
9
27
  pinAndResolvePackagedRuntime,
10
28
  provisionDesktopApiToken,
11
29
  provisionLocalApiToken,
@@ -21,77 +39,72 @@ import {
21
39
  startLocalPostgresRuntime,
22
40
  startLocalPrivacyRuntime,
23
41
  stopLocalPostgresRuntime
24
- } from "./chunk-HZJK5RWC.js";
42
+ } from "./chunk-EDPNYIX5.js";
25
43
  import {
26
44
  resolveActiveIntegrationApiToken,
27
45
  resolveLocalApiToken,
28
46
  writeLocalAppCredential
29
47
  } from "./chunk-QT24SAW6.js";
30
- import {
31
- invalidateUpstreamEnrollmentReferences
32
- } from "./chunk-SKVYP7NY.js";
33
48
  import {
34
49
  allocateAndPersistLocalPorts
35
- } from "./chunk-HFM6ROJL.js";
36
- import {
37
- calculateRuntimeRequirements,
38
- resolveEffectiveRuntimeConfig
39
- } from "./chunk-AFLKCQHF.js";
40
- import {
41
- acquireKoedServerSupervisorLock,
42
- readCurrentRuntimeOwner,
43
- readSupervisorLock,
44
- releaseKoedServerSupervisorLock,
45
- resolveDesktopRuntimeOwner,
46
- resolveKoedServerConfig,
47
- resolveProcessIdentity,
48
- validateDesktopRuntimeCapability
49
- } from "./chunk-NM5NXCVM.js";
50
- import {
51
- isProcessRunning,
52
- isRuntimeGenerationState
53
- } from "./chunk-G4IIVVJO.js";
54
- import {
55
- maintainSupervisorLog,
56
- startKoedServerDaemon
57
- } from "./chunk-JKOG52PE.js";
58
- import {
59
- assertKoedAppRuntimeAvailable,
60
- resolveKoedAppRuntime,
61
- resolveKoedAppRuntimeExecution,
62
- resolveKoedRuntimeOwner
63
- } from "./chunk-A4NKL2PK.js";
64
- import {
65
- listUpstreamBackends,
66
- refreshUpstreamBackendCapabilities
67
- } from "./chunk-YJWREXN6.js";
50
+ } from "./chunk-TISYUUEJ.js";
68
51
  import {
69
- redeemPairingLink
70
- } from "./chunk-J2L726BC.js";
71
- import {
72
- bundledPdsSecretProviderEnvironment
73
- } from "./chunk-2S3OGPUC.js";
52
+ resolveKoedServerConfig
53
+ } from "./chunk-ALJUSOF7.js";
74
54
  import {
75
55
  ensureDeviceIdentity,
76
56
  inspectDeviceIdentityStatus,
77
57
  rotateDeviceIdentity
78
- } from "./chunk-XNFVSVBS.js";
58
+ } from "./chunk-SRKIBFOE.js";
59
+ import {
60
+ maintainSupervisorLog,
61
+ startKoedServerDaemon
62
+ } from "./chunk-7FSHVVTZ.js";
79
63
  import {
80
64
  ensureKoedHome,
81
65
  resolveKoedServerPaths
82
- } from "./chunk-K2EIFEQF.js";
66
+ } from "./chunk-TSAYTRX3.js";
67
+ import {
68
+ hasReleaseRuntime
69
+ } from "./chunk-YZLQZU5E.js";
83
70
  import {
84
71
  environmentWithRepoEnv,
85
72
  loadRepoEnv,
86
73
  resolveApiUrl
87
74
  } from "./chunk-W2HNI6AA.js";
75
+ import {
76
+ assertKoedAppRuntimeAvailable,
77
+ resolveKoedAppRuntime,
78
+ resolveKoedAppRuntimeExecution,
79
+ resolveKoedRuntimeOwner
80
+ } from "./chunk-V67IQB7H.js";
81
+ import {
82
+ acquireKoedServerSupervisorLock,
83
+ observeStoppedRuntime,
84
+ readCurrentRuntimeOwner,
85
+ readSupervisorLock,
86
+ releaseKoedServerSupervisorLock,
87
+ removeStaleRuntimeRecords,
88
+ resolveDesktopRuntimeOwner,
89
+ resolveProcessIdentity,
90
+ validateDesktopRuntimeCapability,
91
+ withLifecycleLock,
92
+ withSourceNativeStartLock
93
+ } from "./chunk-FN3HUUO2.js";
94
+ import {
95
+ isProcessRunning,
96
+ isRuntimeGenerationState,
97
+ removeOwnedRuntimeState,
98
+ writeRuntimeState
99
+ } from "./chunk-T6UB5PNX.js";
100
+ import {
101
+ listUpstreamBackends,
102
+ refreshUpstreamBackendCapabilities
103
+ } from "./chunk-RCR4XPE3.js";
88
104
  import {
89
105
  createPdsApplicationSecretStore,
90
106
  isPrivateNetworkIpv4Address
91
- } from "./chunk-473OA62O.js";
92
- import {
93
- resolveLocalModelManifest
94
- } from "./chunk-ZUGNCQZE.js";
107
+ } from "./chunk-ZOHNXUDY.js";
95
108
 
96
109
  // packages/koed-server/dist/personal-device-request.js
97
110
  import { createHash as createHash2, randomBytes as randomBytes2, randomUUID as randomUUID2 } from "node:crypto";
@@ -599,6 +612,25 @@ var defaultCheckPid = (pid) => {
599
612
  return false;
600
613
  }
601
614
  };
615
+ var defaultIsProcessGroupLeader = (pid) => {
616
+ try {
617
+ const stat = readFileSync2(`/proc/${pid}/stat`, "utf8");
618
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
619
+ return Number(fields[2]) === pid;
620
+ } catch {
621
+ return false;
622
+ }
623
+ };
624
+ var removeStaleRecordsLocked = (paths, observation) => {
625
+ if (observation.state !== "stopped" || !observation.staleRecords?.length)
626
+ return void 0;
627
+ try {
628
+ withLifecycleLock(paths, () => removeStaleRuntimeRecords(observation));
629
+ return void 0;
630
+ } catch (error) {
631
+ return `Stale runtime records were left in place: ${errorMessage(error)}`;
632
+ }
633
+ };
602
634
  var errorCode = (error) => typeof error === "object" && error !== null && "code" in error ? String(error.code) : "";
603
635
  var errorMessage = (error) => error instanceof Error ? error.message : String(error);
604
636
  var defaultSleepSync = (ms) => {
@@ -634,15 +666,16 @@ var stopPid = (label, pid, deps) => {
634
666
  return { stoppedPids: [], missingPids: [pid], errors: [] };
635
667
  if (!identityMatches())
636
668
  return identityError();
669
+ const target = deps.processGroup ? -pid : pid;
637
670
  try {
638
- deps.kill(pid, "SIGTERM");
639
- if (waitForPidExit(pid, deps)) {
671
+ deps.kill(target, "SIGTERM");
672
+ if (waitForPidExit(target, deps)) {
640
673
  return { stoppedPids: [pid], missingPids: [], errors: [] };
641
674
  }
642
675
  if (!identityMatches())
643
676
  return identityError();
644
- deps.kill(pid, "SIGKILL");
645
- if (waitForPidExit(pid, deps)) {
677
+ deps.kill(target, "SIGKILL");
678
+ if (waitForPidExit(target, deps)) {
646
679
  return { stoppedPids: [pid], missingPids: [], errors: [] };
647
680
  }
648
681
  return {
@@ -669,19 +702,24 @@ var stopPid = (label, pid, deps) => {
669
702
  var shouldStopNativePostgres = (runtime) => runtime.dependencyMode === "bundled-local" && runtime.services.includes("postgres-native");
670
703
  var stopKoedServer = ({ environment = process.env, existsSync: pathExists = nodeExistsSync, readFileSync: readFile = readFileSync2, rmSync: remove = rmSync2, spawnSync = nodeSpawnSync, kill = (pid, signal) => {
671
704
  process.kill(pid, signal);
672
- }, checkPid = defaultCheckPid, waitForExitMs = 5e3, pollIntervalMs = 100, sleepSync = defaultSleepSync, readSupervisorLock: readLock = readSupervisorLock, resolveProcessIdentity: resolveProcessIdentity2 = resolveProcessIdentity, desktopRuntimeCapability } = {}) => {
705
+ }, checkPid = defaultCheckPid, waitForExitMs: requestedWait, pollIntervalMs = 100, sleepSync = defaultSleepSync, readSupervisorLock: readLock = readSupervisorLock, resolveProcessIdentity: resolveProcessIdentity2 = resolveProcessIdentity, isProcessGroupLeader = defaultIsProcessGroupLeader, desktopRuntimeCapability } = {}) => {
673
706
  const paths = resolveKoedServerPaths(environment);
707
+ const waitForExitMs = requestedWait ?? 5e3;
708
+ const releaseManaged = hasReleaseRuntime(paths);
674
709
  const runtimeEnvironment = environmentWithRepoEnv(paths.repoRoot, environment);
675
710
  const runtime = readRuntimeState(paths.runtimeStatePath, {
676
711
  existsSync: pathExists,
677
712
  readFileSync: readFile
678
713
  });
679
714
  if (!runtime) {
715
+ const observation = releaseManaged ? observeStoppedRuntime(paths) : void 0;
716
+ const cleanupError = observation ? removeStaleRecordsLocked(paths, observation) : void 0;
717
+ const uncertain = observation && observation.state !== "stopped" || !!cleanupError;
680
718
  return {
681
- ok: true,
682
- state: "not_configured",
719
+ ok: !uncertain,
720
+ state: uncertain ? "needs_attention" : "not_configured",
683
721
  koedHome: paths.koedHome,
684
- message: "No koed runtime state was found.",
722
+ message: cleanupError ?? (uncertain ? observation.message : "No koed runtime state was found."),
685
723
  stoppedPids: [],
686
724
  missingPids: [],
687
725
  stoppedServices: [],
@@ -712,11 +750,31 @@ var stopKoedServer = ({ environment = process.env, existsSync: pathExists = node
712
750
  error: "Supervisor identity changed during stop; refusing fallback signals"
713
751
  });
714
752
  };
753
+ let supervisorExitChecked = false;
754
+ const noteExitedSupervisor = () => {
755
+ if (supervisorExitChecked)
756
+ return;
757
+ supervisorExitChecked = true;
758
+ for (const [name, pid] of Object.entries(runtime.processes ?? {})) {
759
+ if (typeof pid !== "number" || pid <= 0)
760
+ continue;
761
+ if (checkPid(pid))
762
+ errors.push({
763
+ target: `${name} (${pid})`,
764
+ error: "Supervisor exited; refusing to signal a recorded child without supervisor identity"
765
+ });
766
+ else
767
+ missingPids.push(pid);
768
+ }
769
+ };
715
770
  const canSignalFallbackProcesses = () => {
716
771
  if (!supervisorLockMatches)
717
772
  return false;
718
773
  if (expectedSupervisorIdentity && !isExpectedSupervisorRunning(expectedSupervisorIdentity)) {
719
- markSupervisorIdentityUnverified();
774
+ if (runtime.pid > 0 && !checkPid(runtime.pid))
775
+ noteExitedSupervisor();
776
+ else
777
+ markSupervisorIdentityUnverified();
720
778
  return false;
721
779
  }
722
780
  return true;
@@ -768,7 +826,9 @@ var stopKoedServer = ({ environment = process.env, existsSync: pathExists = node
768
826
  });
769
827
  supervisorStoppedGracefully = waitForPidExit(runtime.pid, {
770
828
  checkPid,
771
- waitForExitMs,
829
+ // Let the supervisor finish its bounded per-child shutdown before falling
830
+ // back to direct PID signals, which cannot reach llama-server descendants.
831
+ waitForExitMs: requestedWait ?? (releaseManaged ? 6e4 : 5e3),
772
832
  pollIntervalMs,
773
833
  sleepSync
774
834
  });
@@ -809,16 +869,27 @@ var stopKoedServer = ({ environment = process.env, existsSync: pathExists = node
809
869
  }
810
870
  if (runtime.dependencyMode === "bundled-local") {
811
871
  const embeddingPid = runtime.processes?.embeddingService;
872
+ const embeddingIdentity = runtime.processIdentities?.embeddingService;
812
873
  if (canSignalFallbackProcesses() && runtime.services.includes("embedding-service-native")) {
813
874
  if (!embeddingPid || embeddingPid <= 0) {
814
875
  missingServices.push("embedding-service-native");
876
+ } else if (releaseManaged && !embeddingIdentity) {
877
+ errors.push({
878
+ target: `embedding-service-native (${embeddingPid})`,
879
+ error: "Embedding Service process identity is missing; refusing to signal it"
880
+ });
815
881
  } else {
816
882
  const stopped = stopPid("embedding-service-native", embeddingPid, {
817
883
  kill,
818
884
  checkPid,
819
885
  waitForExitMs,
820
886
  pollIntervalMs,
821
- sleepSync
887
+ sleepSync,
888
+ ...embeddingIdentity ? {
889
+ expectedProcessIdentity: embeddingIdentity,
890
+ resolveProcessIdentity: resolveProcessIdentity2
891
+ } : {},
892
+ processGroup: releaseManaged && embeddingIdentity !== void 0 && checkPid(embeddingPid) && resolveProcessIdentity2(embeddingPid) === embeddingIdentity && isProcessGroupLeader(embeddingPid)
822
893
  });
823
894
  stoppedPids.push(...stopped.stoppedPids);
824
895
  missingPids.push(...stopped.missingPids);
@@ -866,18 +937,26 @@ var stopKoedServer = ({ environment = process.env, existsSync: pathExists = node
866
937
  }
867
938
  }
868
939
  if (errors.length === 0) {
869
- const currentRuntime = readRuntimeState(paths.runtimeStatePath, {
870
- existsSync: pathExists,
871
- readFileSync: readFile
872
- });
873
- if (currentRuntime && (currentRuntime.pid !== runtime.pid || currentRuntime.startedAt !== runtime.startedAt)) {
940
+ try {
941
+ if (!removeOwnedRuntimeState(paths.runtimeStatePath, runtime, readFile, remove))
942
+ errors.push({
943
+ target: "runtime-state",
944
+ error: "Runtime state changed while stop was in progress"
945
+ });
946
+ } catch (error) {
947
+ errors.push({ target: "runtime-state", error: errorMessage(error) });
948
+ }
949
+ }
950
+ if (releaseManaged && errors.length === 0) {
951
+ const observation = observeStoppedRuntime(paths);
952
+ const cleanupError = removeStaleRecordsLocked(paths, observation);
953
+ if (cleanupError)
954
+ errors.push({ target: "runtime records", error: cleanupError });
955
+ if (observation.state !== "stopped")
874
956
  errors.push({
875
- target: "runtime-state",
876
- error: "Runtime state changed while stop was in progress"
957
+ target: observation.pid ? `native process (${observation.pid})` : "native runtime",
958
+ error: observation.message
877
959
  });
878
- } else {
879
- remove(paths.runtimeStatePath, { force: true });
880
- }
881
960
  }
882
961
  return {
883
962
  ok: errors.length === 0,
@@ -1026,7 +1105,7 @@ var maintainUpstreamCapabilities = (paths, options = {}) => {
1026
1105
  import { spawn as nodeSpawn2, spawnSync as nodeSpawnSync2 } from "node:child_process";
1027
1106
  import { randomBytes as randomBytes3 } from "node:crypto";
1028
1107
  import { setTimeout as delay } from "node:timers/promises";
1029
- import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, rmSync as rmSync3, writeFileSync as writeFileSync2 } from "node:fs";
1108
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3 } from "node:fs";
1030
1109
  import { dirname, resolve as resolve4 } from "node:path";
1031
1110
 
1032
1111
  // packages/koed-server/dist/runtime-lifecycle.js
@@ -1320,15 +1399,62 @@ var waitForChildExit = (child, timeoutMs) => new Promise((resolveExit) => {
1320
1399
  const timeout = setTimeout(() => finish(false), timeoutMs);
1321
1400
  child.once("exit", onExit);
1322
1401
  });
1323
- var stopChildProcess = async (child, timeoutMs = 5e3, label = "managed child") => {
1324
- if (!child?.pid || child.exitCode != null || child.signalCode != null)
1402
+ var processGroupAlive = (pid) => {
1403
+ try {
1404
+ process.kill(-pid, 0);
1405
+ return true;
1406
+ } catch (error) {
1407
+ const code = error.code;
1408
+ if (code === "ESRCH")
1409
+ return false;
1410
+ if (code === "EPERM")
1411
+ return true;
1412
+ throw error;
1413
+ }
1414
+ };
1415
+ var signalProcessGroup = (pid, value) => {
1416
+ if (!processGroupAlive(pid))
1417
+ return;
1418
+ try {
1419
+ process.kill(-pid, value);
1420
+ } catch (error) {
1421
+ if (error.code !== "ESRCH")
1422
+ throw error;
1423
+ }
1424
+ };
1425
+ var waitForProcessGroupExit = async (pid, timeoutMs) => {
1426
+ const deadline = Date.now() + timeoutMs;
1427
+ while (processGroupAlive(pid)) {
1428
+ if (Date.now() >= deadline)
1429
+ return false;
1430
+ await delay(Math.min(50, Math.max(1, deadline - Date.now())));
1431
+ }
1432
+ return true;
1433
+ };
1434
+ var stopChildProcess = async (child, timeoutMs = 5e3, label = "managed child", privateGroup = false) => {
1435
+ if (!child?.pid)
1325
1436
  return;
1326
- child.kill("SIGTERM");
1327
- if (await waitForChildExit(child, timeoutMs))
1437
+ const pid = child.pid;
1438
+ const exited = () => child.exitCode != null || child.signalCode != null;
1439
+ if (!privateGroup) {
1440
+ if (exited())
1441
+ return;
1442
+ child.kill("SIGTERM");
1443
+ if (await waitForChildExit(child, timeoutMs))
1444
+ return;
1445
+ child.kill("SIGKILL");
1446
+ if (!await waitForChildExit(child, timeoutMs))
1447
+ throw new Error(`Timed out stopping ${label} process ${child.pid}.`);
1448
+ return;
1449
+ }
1450
+ const deadline = Date.now() + timeoutMs;
1451
+ signalProcessGroup(pid, "SIGTERM");
1452
+ await waitForChildExit(child, timeoutMs);
1453
+ if (exited() && await waitForProcessGroupExit(pid, Math.max(0, deadline - Date.now())))
1328
1454
  return;
1329
- child.kill("SIGKILL");
1330
- if (!await waitForChildExit(child, timeoutMs)) {
1331
- throw new Error(`Timed out stopping ${label} process ${child.pid}.`);
1455
+ signalProcessGroup(pid, "SIGKILL");
1456
+ if (!await waitForChildExit(child, timeoutMs) || !await waitForProcessGroupExit(pid, timeoutMs)) {
1457
+ throw new Error(`Timed out stopping ${label} process group ${pid}.`);
1332
1458
  }
1333
1459
  };
1334
1460
  var createManagedProcessMonitor = (options = {}) => {
@@ -1422,7 +1548,9 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1422
1548
  };
1423
1549
  assertObservedOwner(observeRuntimeLifecycle(paths));
1424
1550
  ensureKoedHome(paths);
1425
- const supervisorLock = acquireKoedServerSupervisorLock(paths);
1551
+ const supervisorLock = acquireKoedServerSupervisorLock(paths, {
1552
+ exclusive: (action) => withLifecycleLock(paths, action)
1553
+ });
1426
1554
  if (!supervisorLock.acquired) {
1427
1555
  assertObservedOwner(observeRuntimeLifecycle(paths));
1428
1556
  console.log(JSON.stringify({
@@ -1570,14 +1698,6 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1570
1698
  let runtimeStateWritten = false;
1571
1699
  let stopSupervisorExitMonitor = () => void 0;
1572
1700
  let stopCapabilityMaintenance = () => void 0;
1573
- const runtimeStateOwnedByCurrentProcess = () => {
1574
- try {
1575
- const runtime = JSON.parse(readFileSync4(paths.runtimeStatePath, "utf8"));
1576
- return runtime.pid === process.pid && runtime.startedAt === supervisorStartedAt;
1577
- } catch {
1578
- return false;
1579
- }
1580
- };
1581
1701
  let deviceRequestService;
1582
1702
  let cleanupPromise;
1583
1703
  let cleanupCompleted = false;
@@ -1601,14 +1721,14 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1601
1721
  ];
1602
1722
  for (const name of shutdownOrder) {
1603
1723
  try {
1604
- await stopChildProcess(managedChildren[name], 5e3, name);
1724
+ await stopChildProcess(managedChildren[name], 5e3, name, name === "embeddingService" && Boolean(paths.nativeSelectionRoot));
1605
1725
  } catch (error) {
1606
1726
  cleanupErrors.push(error instanceof Error ? error.message : String(error));
1607
1727
  }
1608
1728
  }
1609
1729
  if (nativeEmbeddingProcess && !Object.values(managedChildren).includes(nativeEmbeddingProcess)) {
1610
1730
  try {
1611
- await stopChildProcess(nativeEmbeddingProcess, 5e3, "embeddingService");
1731
+ await stopChildProcess(nativeEmbeddingProcess, 5e3, "embeddingService", Boolean(paths.nativeSelectionRoot));
1612
1732
  } catch (error) {
1613
1733
  cleanupErrors.push(error instanceof Error ? error.message : String(error));
1614
1734
  }
@@ -1689,6 +1809,13 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1689
1809
  appRuntime = resolveKoedAppRuntime(paths, environment, existsSync3, void 0, requiredRuntime);
1690
1810
  assertKoedAppRuntimeAvailable(appRuntime, paths);
1691
1811
  }
1812
+ if (useBundledLocalDependencies && hasReleaseRuntime(paths) && !(hasCompletePostgresOverride(refreshedEnv) && nativeLlamaServerOverride(refreshedEnv))) {
1813
+ const { resolveSelectedCoreForStart } = await import("./chunk-VGIYSDNU.js");
1814
+ const admitSelection = () => resolveSelectedCoreForStart(paths, refreshedEnv, !nativeLlamaServerOverride(refreshedEnv));
1815
+ const selected = generationPin ? admitSelection() : withSourceNativeStartLock(paths, admitSelection);
1816
+ if (selected)
1817
+ paths.nativeSelectionRoot = selected;
1818
+ }
1692
1819
  if (appRuntime.kind === "source") {
1693
1820
  runCommand(paths, "Check source runtime artifacts", process.execPath, [
1694
1821
  resolve4(paths.repoRoot, "scripts/source-runtime-build.mjs"),
@@ -1766,6 +1893,7 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1766
1893
  const api = appRuntime.kind === "packaged" ? spawnManagedProcess(paths, "API", process.execPath, [appRuntime.apiEntry], appProcessEnvironment(refreshedEnv), spawn, resolve4(appRuntime.root, "api")) : spawnManagedProcess(paths, "API", process.execPath, [resolve4(paths.repoRoot, "apps/api/dist/index.js")], appProcessEnvironment(refreshedEnv), spawn, resolve4(paths.repoRoot, "apps/api"));
1767
1894
  manageChild("api", api);
1768
1895
  emitStartupMilestone("api_process_spawned");
1896
+ const embeddingIdentity = paths.nativeSelectionRoot && nativeEmbeddingProcess?.pid ? resolveProcessIdentity(nativeEmbeddingProcess.pid) : null;
1769
1897
  const runtime = {
1770
1898
  pid: process.pid,
1771
1899
  startedAt: supervisorStartedAt,
@@ -1778,6 +1906,9 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1778
1906
  claudeTranscriptWatcherEnabled: config.claudeTranscriptWatcherEnabled,
1779
1907
  piTranscriptWatcherEnabled: config.piTranscriptWatcherEnabled,
1780
1908
  services: [...runtimeServices, "api"],
1909
+ // The release-managed Embedding Service leads a private process group.
1910
+ // koed stop signals that group only while its leader keeps this identity.
1911
+ ...embeddingIdentity ? { processIdentities: { embeddingService: embeddingIdentity } } : {},
1781
1912
  processes: {
1782
1913
  ...nativeEmbeddingProcess ? { embeddingService: nativeEmbeddingProcess.pid ?? 0 } : {},
1783
1914
  ...nativePrivacyProcess ? { privacyService: nativePrivacyProcess.pid ?? 0 } : {},
@@ -1785,10 +1916,7 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1785
1916
  }
1786
1917
  };
1787
1918
  const persistRuntime = () => {
1788
- writeFileSync2(paths.runtimeStatePath, `${JSON.stringify(runtime, null, 2)}
1789
- `, {
1790
- mode: 384
1791
- });
1919
+ writeRuntimeState(paths.runtimeStatePath, runtime);
1792
1920
  runtimeStateWritten = true;
1793
1921
  };
1794
1922
  persistRuntime();
@@ -1898,9 +2026,6 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1898
2026
  emitStartupMilestone("startup_failed");
1899
2027
  try {
1900
2028
  await cleanupStartedResources();
1901
- if (runtimeStateOwnedByCurrentProcess()) {
1902
- rmSync3(paths.runtimeStatePath, { force: true });
1903
- }
1904
2029
  } catch (cleanupError) {
1905
2030
  throw new Error(`${error instanceof Error ? error.message : String(error)} Cleanup failed: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`, { cause: cleanupError });
1906
2031
  }
@@ -1913,8 +2038,15 @@ var startKoedServer = async ({ environment = process.env, pollIntervalMs = 500,
1913
2038
  process.off("SIGTERM", shutdown);
1914
2039
  signal?.removeEventListener("abort", shutdown);
1915
2040
  managedProcessMonitor.dispose();
1916
- if (runtimeStateWritten && runtimeStateOwnedByCurrentProcess()) {
1917
- rmSync3(paths.runtimeStatePath, { force: true });
2041
+ if (runtimeStateWritten) {
2042
+ try {
2043
+ removeOwnedRuntimeState(paths.runtimeStatePath, {
2044
+ pid: process.pid,
2045
+ startedAt: supervisorStartedAt
2046
+ });
2047
+ } catch (error) {
2048
+ console.warn(`Could not clear runtime state: ${error instanceof Error ? error.message : String(error)}`);
2049
+ }
1918
2050
  }
1919
2051
  if (sourceRuntimeLeaseAcquired) {
1920
2052
  try {
@@ -2018,7 +2150,7 @@ var createCliServiceContext = ({ collectStatus = collectKoedServerStatus, collec
2018
2150
  };
2019
2151
 
2020
2152
  // packages/koed-server/dist/cli-service-output.js
2021
- import { existsSync as existsSync4, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
2153
+ import { existsSync as existsSync4, mkdirSync as mkdirSync4, writeFileSync as writeFileSync2 } from "node:fs";
2022
2154
  import { resolve as resolve5 } from "node:path";
2023
2155
  var safeLifecycle = (paths) => {
2024
2156
  try {
@@ -2040,7 +2172,7 @@ var persistDoctorVerification = (paths, doctor) => {
2040
2172
  recursive: true,
2041
2173
  mode: 448
2042
2174
  });
2043
- writeFileSync3(paths.lastVerificationPath, `${JSON.stringify({
2175
+ writeFileSync2(paths.lastVerificationPath, `${JSON.stringify({
2044
2176
  ok: doctor.ok,
2045
2177
  checkedAt: doctor.generatedAt,
2046
2178
  message: doctor.summary
@@ -1,4 +1,10 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
+ import {
3
+ ensureDeviceIdentity
4
+ } from "./chunk-SRKIBFOE.js";
5
+ import {
6
+ require_proper_lockfile
7
+ } from "./chunk-7NXKPDF3.js";
2
8
  import {
3
9
  beginUpstreamDisconnectCleanup,
4
10
  clearUpstreamBackendCapabilities,
@@ -13,13 +19,7 @@ import {
13
19
  upstreamBackendAdvertisesCapability,
14
20
  upstreamBackendSupportsTeamMemoryAnswerTasks,
15
21
  upstreamDisconnectCleanupPending
16
- } from "./chunk-YJWREXN6.js";
17
- import {
18
- ensureDeviceIdentity
19
- } from "./chunk-XNFVSVBS.js";
20
- import {
21
- require_proper_lockfile
22
- } from "./chunk-7NXKPDF3.js";
22
+ } from "./chunk-RCR4XPE3.js";
23
23
  import {
24
24
  assertSecureHttpTransport,
25
25
  deleteLocalEdgeClientCredential,
@@ -30,7 +30,7 @@ import {
30
30
  storeLocalEdgeClientCredential,
31
31
  storeUpstreamCredentialSecret,
32
32
  upstreamCredentialReferenceFor
33
- } from "./chunk-473OA62O.js";
33
+ } from "./chunk-ZOHNXUDY.js";
34
34
  import {
35
35
  __toESM
36
36
  } from "./chunk-BTS4ZTF3.js";
@@ -1,6 +1,7 @@
1
1
  import { createRequire as createKoedRequire } from "node:module"; const require = createKoedRequire(import.meta.url);
2
2
 
3
3
  // packages/koed-server/dist/runtime-artifact-source.js
4
+ import { lstatSync, readlinkSync } from "node:fs";
4
5
  import { resolve } from "node:path";
5
6
  var runtimeProcess = process;
6
7
  var trimRuntimeValue = (value) => {
@@ -21,10 +22,25 @@ var resolvePackagedKoedRuntimeRoot = (environment = process.env) => {
21
22
  const resourcesPath = resolvePackagedResourcesPath(environment);
22
23
  return resourcesPath ? resolve(resourcesPath, "koed-runtime") : void 0;
23
24
  };
25
+ function hasReleaseRuntime(paths) {
26
+ const runtime = resolve(paths.koedHome, "runtime");
27
+ if (lstatSync(resolve(runtime, "native"), { throwIfNoEntry: false }))
28
+ return true;
29
+ return ["postgres", "llama.cpp"].some((name) => {
30
+ const path = resolve(runtime, name);
31
+ return lstatSync(path, { throwIfNoEntry: false })?.isSymbolicLink() && readlinkSync(path) === `native/current/${name}`;
32
+ });
33
+ }
34
+ function assertNoReleaseRuntime(paths) {
35
+ if (hasReleaseRuntime(paths))
36
+ throw new Error("The release provider owns this runtime. Use koed runtime install --provider release --dependency-mode bundled-local or a fresh KOED_HOME.");
37
+ }
24
38
 
25
39
  export {
26
40
  isPackagedRuntimeMode,
27
41
  canUseSourceCheckoutFallback,
28
42
  resolvePackagedResourcesPath,
29
- resolvePackagedKoedRuntimeRoot
43
+ resolvePackagedKoedRuntimeRoot,
44
+ hasReleaseRuntime,
45
+ assertNoReleaseRuntime
30
46
  };
@@ -6,29 +6,34 @@ import {
6
6
  persistDoctorVerification,
7
7
  printJson,
8
8
  safeLifecycle
9
- } from "./chunk-YCDEMYY6.js";
10
- import "./chunk-HZJK5RWC.js";
9
+ } from "./chunk-WDFERJG3.js";
10
+ import "./chunk-SHLRINKO.js";
11
+ import "./chunk-CHMH4LH5.js";
12
+ import "./chunk-EA4QDDQA.js";
13
+ import "./chunk-JYK6UL6D.js";
14
+ import "./chunk-WPIEF4LY.js";
15
+ import "./chunk-EDPNYIX5.js";
11
16
  import "./chunk-QT24SAW6.js";
12
- import "./chunk-SKVYP7NY.js";
13
- import "./chunk-HFM6ROJL.js";
14
- import "./chunk-AFLKCQHF.js";
15
- import "./chunk-NM5NXCVM.js";
16
- import "./chunk-G4IIVVJO.js";
17
- import "./chunk-JKOG52PE.js";
18
- import "./chunk-A4NKL2PK.js";
19
- import "./chunk-QIIKMG3M.js";
20
- import "./chunk-2DA7EFZV.js";
21
- import "./chunk-VPC5NLZG.js";
22
- import "./chunk-YJWREXN6.js";
23
- import "./chunk-J2L726BC.js";
24
- import "./chunk-2S3OGPUC.js";
25
- import "./chunk-XNFVSVBS.js";
26
- import "./chunk-7NXKPDF3.js";
27
- import "./chunk-K2EIFEQF.js";
28
- import "./chunk-UI5RLBKQ.js";
17
+ import "./chunk-TISYUUEJ.js";
18
+ import "./chunk-ALJUSOF7.js";
19
+ import "./chunk-SRKIBFOE.js";
20
+ import "./chunk-7FSHVVTZ.js";
21
+ import "./chunk-TSAYTRX3.js";
22
+ import "./chunk-YZLQZU5E.js";
29
23
  import "./chunk-W2HNI6AA.js";
30
- import "./chunk-473OA62O.js";
31
- import "./chunk-ZUGNCQZE.js";
24
+ import "./chunk-V67IQB7H.js";
25
+ import "./chunk-FN3HUUO2.js";
26
+ import "./chunk-T6UB5PNX.js";
27
+ import "./chunk-7NXKPDF3.js";
28
+ import "./chunk-ZUDSZGVO.js";
29
+ import "./chunk-ZIOKV2X6.js";
30
+ import "./chunk-QRKHHWJJ.js";
31
+ import "./chunk-7EGSY3E4.js";
32
+ import "./chunk-IY2HRXOZ.js";
33
+ import "./chunk-4OO6VAU3.js";
34
+ import "./chunk-RCR4XPE3.js";
35
+ import "./chunk-ZOHNXUDY.js";
36
+ import "./chunk-FSNLU46W.js";
32
37
  import "./chunk-BTS4ZTF3.js";
33
38
 
34
39
  // packages/koed-server/dist/cli-lifecycle-operations.js