@ai-ecoverse/slicc-kernel 1.124.0 → 1.124.2

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/node.js CHANGED
@@ -5779,18 +5779,19 @@ var UnlinkedKeeper = class {
5779
5779
  const keeper = this;
5780
5780
  const { replacing } = this;
5781
5781
  const replace = async (target, op) => {
5782
- const before = replacing.get(target);
5783
5782
  const { promise, resolve: resolve2 } = Promise.withResolvers();
5784
- const mine = {
5785
- done: Promise.all([before?.done, promise]).then(() => void 0)
5783
+ let mine;
5784
+ const gated = () => {
5785
+ const before = replacing.get(target);
5786
+ mine = { done: Promise.all([before?.done, promise]).then(() => void 0) };
5787
+ replacing.set(target, mine);
5786
5788
  };
5787
- replacing.set(target, mine);
5788
5789
  try {
5789
- await op();
5790
+ await op(gated);
5790
5791
  } finally {
5791
5792
  keeper.replaced += 1;
5792
5793
  resolve2();
5793
- if (replacing.get(target) === mine) replacing.delete(target);
5794
+ if (mine && replacing.get(target) === mine) replacing.delete(target);
5794
5795
  }
5795
5796
  };
5796
5797
  const unreplaced = async (path, op) => {
@@ -5835,8 +5836,8 @@ var UnlinkedKeeper = class {
5835
5836
  async rename(from, to) {
5836
5837
  const target = fs.resolvePath("/", to);
5837
5838
  if (target === fs.resolvePath("/", from)) return fs.rename(from, to);
5838
- await replace(target, async () => {
5839
- const pinned = await keeper.pin(target);
5839
+ await replace(target, async (gated) => {
5840
+ const pinned = await keeper.pin(target, gated);
5840
5841
  await keeper.settle(pinned, () => fs.rename(from, to));
5841
5842
  });
5842
5843
  },
@@ -5853,7 +5854,7 @@ var UnlinkedKeeper = class {
5853
5854
  }
5854
5855
  pinned.commit();
5855
5856
  }
5856
- async pin(target) {
5857
+ heldWithin(target) {
5857
5858
  const held = /* @__PURE__ */ new Map();
5858
5859
  for (const holder of this.holders) {
5859
5860
  if (holder.owns(target)) continue;
@@ -5862,11 +5863,19 @@ var UnlinkedKeeper = class {
5862
5863
  held.set(path, [...held.get(path) ?? [], holder]);
5863
5864
  }
5864
5865
  }
5865
- const paths = [...held.keys()].sort();
5866
+ return held;
5867
+ }
5868
+ async pin(target, gated = () => void 0) {
5869
+ const paths = [...this.heldWithin(target).keys()].sort();
5866
5870
  const releases = [];
5867
5871
  for (const path of paths) releases.push(await this.gate.acquire(path));
5872
+ gated();
5873
+ const now = this.heldWithin(target);
5874
+ const held = new Map(
5875
+ paths.flatMap((path) => now.has(path) ? [[path, now.get(path)]] : [])
5876
+ );
5868
5877
  const hidden = /* @__PURE__ */ new Map();
5869
- for (const path of paths) {
5878
+ for (const path of held.keys()) {
5870
5879
  const at = await this.hide(path);
5871
5880
  if (at !== void 0) hidden.set(path, at);
5872
5881
  }
@@ -6935,7 +6944,7 @@ function satisfies(version, range2) {
6935
6944
  }
6936
6945
 
6937
6946
  // src/version.ts
6938
- var KERNEL_VERSION = true ? "1.124.0" : "0.0.0-dev";
6947
+ var KERNEL_VERSION = true ? "1.124.2" : "0.0.0-dev";
6939
6948
  var OS_RELEASE = "6.0.0-slicc";
6940
6949
  function procVersion() {
6941
6950
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -12807,7 +12816,9 @@ var SYS_TREE = {
12807
12816
  osrelease: `${OS_RELEASE}
12808
12817
  `,
12809
12818
  ostype: "Linux\n",
12810
- slicc_wasm_memories: (listing) => `${listing.wasm?.live ?? 0} ${listing.wasm?.ceiling ?? 0}
12819
+ slicc_wasm_memories: (listing) => `${listing.wasm?.live ?? 0} ${listing.wasm?.ceiling ?? 0} ${listing.wasm?.source ?? "none"}
12820
+ `,
12821
+ slicc_shared_root: (listing) => `${listing.peers ?? 0}
12811
12822
  `
12812
12823
  }
12813
12824
  };
@@ -21854,37 +21865,65 @@ var SettlingChildren = class {
21854
21865
 
21855
21866
  // src/kernel/wasm-memories.ts
21856
21867
  var DEFAULT_CEILING = 112;
21868
+ var CEILING_FLOOR = 16;
21857
21869
  var IDLE_MS = 1e4;
21858
21870
  var MARGIN = 16;
21871
+ var DECAY_MS = 6e4;
21872
+ var DECAY_STEP = 8;
21859
21873
  var WasmMemories = class {
21860
21874
  live = 0;
21861
- ceiling;
21875
+ learned;
21862
21876
  waiters = /* @__PURE__ */ new Set();
21877
+ base;
21863
21878
  idleMs;
21864
- constructor(ceiling, idleMs = IDLE_MS) {
21865
- this.ceiling = ceiling;
21879
+ now;
21880
+ constructor(ceiling, idleMs = IDLE_MS, now = Date.now) {
21881
+ this.base = ceiling;
21866
21882
  this.idleMs = idleMs;
21883
+ this.now = now;
21884
+ }
21885
+ ceiling() {
21886
+ const learned = this.learned;
21887
+ if (!learned) return this.base;
21888
+ const steps = Math.floor((this.now() - learned.at) / DECAY_MS);
21889
+ const raised = learned.ceiling + steps * DECAY_STEP;
21890
+ if (raised < (this.base ?? DEFAULT_CEILING)) return raised;
21891
+ this.learned = void 0;
21892
+ return this.base;
21867
21893
  }
21868
21894
  count() {
21869
- return { live: this.live, ceiling: this.ceiling ?? 0 };
21895
+ const ceiling = this.ceiling();
21896
+ const source = this.learned ? "learned" : ceiling === void 0 ? "none" : "default";
21897
+ return { live: this.live, ceiling: ceiling ?? 0, source };
21870
21898
  }
21871
21899
  ended() {
21872
21900
  this.live = Math.max(0, this.live - 1);
21873
21901
  this.progress();
21874
21902
  }
21875
21903
  learn() {
21876
- this.ceiling = Math.max(1, this.live - 1);
21904
+ const top = this.base ?? DEFAULT_CEILING;
21905
+ this.learned = {
21906
+ ceiling: Math.min(top, Math.max(CEILING_FLOOR, this.live - 1)),
21907
+ at: this.now()
21908
+ };
21877
21909
  }
21878
21910
  near() {
21879
- return this.ceiling !== void 0 && this.live + MARGIN >= this.ceiling;
21911
+ const ceiling = this.ceiling();
21912
+ return ceiling !== void 0 && this.live + MARGIN >= ceiling;
21880
21913
  }
21881
21914
  async admit() {
21882
- while (this.ceiling !== void 0 && this.live >= this.ceiling) {
21915
+ for (let ceiling = this.ceiling(); ceiling !== void 0 && this.live >= ceiling; ) {
21883
21916
  if (!await this.changed()) throw new SpawnError("EAGAIN");
21917
+ ceiling = this.ceiling();
21884
21918
  }
21885
21919
  this.live += 1;
21886
21920
  this.progress();
21887
21921
  }
21922
+ async refused() {
21923
+ const ceiling = this.ceiling();
21924
+ if (ceiling === void 0 || this.live >= ceiling) return;
21925
+ if (!await this.changed()) throw new SpawnError("EAGAIN");
21926
+ }
21888
21927
  progress() {
21889
21928
  const waiters = [...this.waiters];
21890
21929
  this.waiters.clear();
@@ -25213,6 +25252,10 @@ var Launcher = class {
25213
25252
  return handle;
25214
25253
  }
25215
25254
  await handle.exited;
25255
+ await this.memories.refused().catch(async (err) => {
25256
+ await fds.closeAll();
25257
+ throw err;
25258
+ });
25216
25259
  }
25217
25260
  }
25218
25261
  start(req) {
@@ -25278,7 +25321,8 @@ var Launcher = class {
25278
25321
  processes: this.list(this.credOf(pid)),
25279
25322
  load: this.loadAverage(),
25280
25323
  cpu: this.cpuTotal(),
25281
- wasm: this.memories.count()
25324
+ wasm: this.memories.count(),
25325
+ peers: Number(this.locks.shared?.() === true)
25282
25326
  }),
25283
25327
  sudo: (call, signal) => this.sudo(pid, call, signal),
25284
25328
  crontab: (call) => this.crontab(pid, call),