@ai-ecoverse/slicc-kernel 1.146.3 → 1.146.5

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
@@ -3305,7 +3305,7 @@ function satisfies(version, range2) {
3305
3305
  }
3306
3306
 
3307
3307
  // src/version.ts
3308
- var KERNEL_VERSION = true ? "1.146.3" : "0.0.0-dev";
3308
+ var KERNEL_VERSION = true ? "1.146.5" : "0.0.0-dev";
3309
3309
  var OS_RELEASE = "6.0.0-slicc";
3310
3310
  function procVersion() {
3311
3311
  return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
@@ -6386,16 +6386,16 @@ var FreshModules = class {
6386
6386
  if (size < MAGIC.length && this.fresh.has(normalizePath(path))) await decide(path);
6387
6387
  };
6388
6388
  }
6389
- const bound2 = /* @__PURE__ */ new WeakMap();
6389
+ const bound3 = /* @__PURE__ */ new WeakMap();
6390
6390
  return new Proxy(fs, {
6391
6391
  get(target, key, receiver) {
6392
6392
  if (Object.hasOwn(overrides, key)) return overrides[key];
6393
6393
  const value2 = Reflect.get(target, key, receiver);
6394
6394
  if (typeof value2 !== "function") return value2;
6395
- let method = bound2.get(value2);
6395
+ let method = bound3.get(value2);
6396
6396
  if (method === void 0) {
6397
6397
  method = value2.bind(target);
6398
- bound2.set(value2, method);
6398
+ bound3.set(value2, method);
6399
6399
  }
6400
6400
  return method;
6401
6401
  }
@@ -8038,6 +8038,12 @@ var HeldSet = class extends Set {
8038
8038
  holds2.onIdle = this.idle;
8039
8039
  return super.add(holds2);
8040
8040
  }
8041
+ doubt(paths, over) {
8042
+ for (const holds2 of this) {
8043
+ for (const path of paths) holds2.doubt(path, true);
8044
+ if (over !== void 0) holds2.doubt(over);
8045
+ }
8046
+ }
8041
8047
  delete(holds2) {
8042
8048
  const removed = super.delete(holds2);
8043
8049
  for (const path of /* @__PURE__ */ new Set([...holds2.keys(), ...holds2.opens.keys()])) this.idle(path);
@@ -8059,6 +8065,9 @@ var HeldPaths = class extends Map {
8059
8065
  uses = /* @__PURE__ */ new Map();
8060
8066
  lastHandle = 0;
8061
8067
  owning;
8068
+ bound = /* @__PURE__ */ new Map();
8069
+ doubted = /* @__PURE__ */ new Map();
8070
+ doubts = 0;
8062
8071
  onIdle;
8063
8072
  keyOf(path) {
8064
8073
  return this.aliases.get(path) ?? path;
@@ -8079,6 +8088,21 @@ var HeldPaths = class extends Map {
8079
8088
  handlesAt(path) {
8080
8089
  return [...this.handles].filter(([, key]) => key === path).map(([id2]) => id2);
8081
8090
  }
8091
+ doubt(over, exact = false) {
8092
+ if (this.bound.size === 0) return;
8093
+ for (const [handle, key] of this.handles) {
8094
+ if (!this.bound.has(handle) || this.keptHandles.has(handle)) continue;
8095
+ if (exact ? key === over : within5(key, over)) this.doubted.set(handle, ++this.doubts);
8096
+ }
8097
+ }
8098
+ boundIno(handle) {
8099
+ const doubt = this.doubted.get(handle);
8100
+ const ino = this.bound.get(handle);
8101
+ return doubt === void 0 || ino === void 0 ? void 0 : { ino, doubt };
8102
+ }
8103
+ trust(handle, doubt) {
8104
+ if (this.doubted.get(handle) === doubt) this.doubted.delete(handle);
8105
+ }
8082
8106
  keptFor(handle) {
8083
8107
  return this.keptHandles.get(handle);
8084
8108
  }
@@ -8115,8 +8139,16 @@ var HeldPaths = class extends Map {
8115
8139
  for (const file of [...this.uses.keys()]) this.letGo(file, true);
8116
8140
  this.keptHandles.clear();
8117
8141
  }
8118
- hold(path, on, open = false, real, handle) {
8119
- if (open) return this.holdOpen(path, on, real, handle);
8142
+ hold(path, on, open = false, real, handle, ino) {
8143
+ if (open) {
8144
+ const made2 = this.holdOpen(path, on, real, handle);
8145
+ if (handle !== void 0) {
8146
+ this.bound.delete(handle);
8147
+ this.doubted.delete(handle);
8148
+ }
8149
+ if (made2 !== void 0 && ino !== void 0) this.bound.set(made2, ino);
8150
+ return made2;
8151
+ }
8120
8152
  this.holdWrite(path, on);
8121
8153
  return void 0;
8122
8154
  }
@@ -9795,7 +9827,7 @@ async function holdOp(entry, path, req) {
9795
9827
  await stillThere(entry, path, req);
9796
9828
  if (req.nofollow && !await ownEntry(entry, path, real ?? path)) continue;
9797
9829
  if (!r || !r.missed(path) && !r.changedSince(path, gen) && !r.inFlight?.(path))
9798
- return json2(entry.hold?.(path, on, open, real) ?? null);
9830
+ return json2(entry.hold?.(path, on, open, real, void 0, req.ino) ?? null);
9799
9831
  }
9800
9832
  }
9801
9833
  entry.hold?.(path, on, open, void 0, req.handle);
@@ -9945,10 +9977,26 @@ async function linkedElsewhere(fs, path, from) {
9945
9977
  return !(source && source.ino === st.ino && source.dev === st.dev);
9946
9978
  }
9947
9979
  async function keptOr(entry, path, handle) {
9948
- if (handle !== void 0) return entry.keptFor?.(handle)?.hidden ?? path;
9980
+ if (handle !== void 0) {
9981
+ const hidden = entry.keptFor?.(handle)?.hidden;
9982
+ if (hidden !== void 0) return hidden;
9983
+ await bound(entry, path, handle);
9984
+ return path;
9985
+ }
9949
9986
  const kept = entry.unlinked?.(path);
9950
9987
  return kept && !await entry.fs.exists(path) ? kept.hidden : path;
9951
9988
  }
9989
+ async function bound(entry, path, handle) {
9990
+ const bound3 = entry.boundIno?.(handle);
9991
+ if (bound3 === void 0) return;
9992
+ const now = await entry.fs.stat(path).catch(() => void 0);
9993
+ if (now?.ino === bound3.ino) {
9994
+ entry.trust?.(handle, bound3.doubt);
9995
+ return;
9996
+ }
9997
+ staleFds++;
9998
+ throw syncError("ESTALE", path);
9999
+ }
9952
10000
  async function keptStat(entry, req) {
9953
10001
  const hidden = entry.keptFor?.(req.handle ?? -1)?.hidden;
9954
10002
  if (hidden === void 0)
@@ -9975,6 +10023,10 @@ var served = 0;
9975
10023
  function servedFsCalls() {
9976
10024
  return served;
9977
10025
  }
10026
+ var staleFds = 0;
10027
+ function staleFdCount() {
10028
+ return staleFds;
10029
+ }
9978
10030
  async function dispatchSyncFs(req) {
9979
10031
  served++;
9980
10032
  const entry = resolveSyncFsToken(req.token);
@@ -10750,6 +10802,8 @@ var SYS_TREE = {
10750
10802
  slicc_cwd_checks: (listing) => `${listing.cwdChecks ?? 0}
10751
10803
  `,
10752
10804
  slicc_rename_ack_busy: (listing) => `${listing.renameAcks?.busy ?? 0}
10805
+ `,
10806
+ slicc_stale_fds: (listing) => `${listing.staleFds ?? 0}
10753
10807
  `,
10754
10808
  slicc_rename_acks: (listing) => {
10755
10809
  const samples = [...listing.renameAcks?.ackMs ?? []].sort((a, b) => a - b);
@@ -15262,7 +15316,7 @@ async function writeAll2(file, bytes) {
15262
15316
  const write = file.write;
15263
15317
  for (let at = 0; at < bytes.length; ) at += await write.call(file, bytes.subarray(at));
15264
15318
  }
15265
- function bound(file, key) {
15319
+ function bound2(file, key) {
15266
15320
  const method = file[key];
15267
15321
  return typeof method === "function" ? { [key]: method.bind(file) } : {};
15268
15322
  }
@@ -15354,9 +15408,9 @@ function scrubbed(inner, scrubber, idleMs = SCRUB_IDLE_MS) {
15354
15408
  later(stream2.idle());
15355
15409
  };
15356
15410
  return new OpenFile({
15357
- ...bound(file, "read"),
15358
- ...bound(file, "peek"),
15359
- ...bound(file, "stat"),
15411
+ ...bound2(file, "read"),
15412
+ ...bound2(file, "peek"),
15413
+ ...bound2(file, "stat"),
15360
15414
  poll: () => {
15361
15415
  const state = pollFile(file);
15362
15416
  return quiet3() ? state : { ...state, writable: false };
@@ -21075,7 +21129,9 @@ function holdingToken(opts, holds2, caller) {
21075
21129
  ...opts.statfs ? { statfs: opts.statfs } : {},
21076
21130
  ...opts.renames ? { renames: opts.renames } : {},
21077
21131
  ...opts.renameSeq ? { renameSeq: opts.renameSeq } : {},
21078
- hold: (path, on, open, real, handle) => holds2.hold(path, on, open, real, handle),
21132
+ hold: (path, on, open, real, handle, ino) => holds2.hold(path, on, open, real, handle, ino),
21133
+ boundIno: holds2.boundIno.bind(holds2),
21134
+ trust: holds2.trust.bind(holds2),
21079
21135
  keptFor: (handle) => holds2.keptFor(handle),
21080
21136
  unlinked: (path) => holds2.keptAt(path),
21081
21137
  gate: (path, op) => opts.unlinkGate && holds2.holding(path) ? opts.unlinkGate.run(holds2.keyOf(path), op) : op(),
@@ -23303,6 +23359,28 @@ function prefixes(path) {
23303
23359
  function within9(path, root) {
23304
23360
  return path === root || path.startsWith(`${root}/`);
23305
23361
  }
23362
+ var unstored = () => Object.assign(new Error("the file system kept fewer bytes than were written"), {
23363
+ code: "ENOSPC"
23364
+ });
23365
+ var CHECKED_BYTES = 16 * 1024 * 1024;
23366
+ var Extent = class {
23367
+ floor = 0;
23368
+ exact;
23369
+ wrote(end) {
23370
+ this.floor = Math.max(this.floor, end);
23371
+ if (this.exact !== void 0) this.exact = Math.max(this.exact, end);
23372
+ }
23373
+ cut(size) {
23374
+ this.exact = size;
23375
+ this.floor = Math.min(this.floor, size);
23376
+ }
23377
+ big() {
23378
+ return Math.max(this.floor, this.exact ?? 0) >= CHECKED_BYTES;
23379
+ }
23380
+ check(size) {
23381
+ if (size < this.floor || this.exact !== void 0 && size < this.exact) throw unstored();
23382
+ }
23383
+ };
23306
23384
  var LOCKED = /* @__PURE__ */ new Set(["NotReadableError", "NoModificationAllowedError", "InvalidStateError"]);
23307
23385
  var SYNC_BACKOFF_MS = [5, 10, 20, 40, 80];
23308
23386
  async function openSync(handle) {
@@ -23328,14 +23406,22 @@ function writeAll5(access2, at, bytes) {
23328
23406
  }
23329
23407
  }
23330
23408
  async function positioned(handle, op) {
23409
+ const extent = new Extent();
23331
23410
  const access2 = await openSync(handle);
23332
23411
  if (access2) {
23333
23412
  try {
23334
23413
  op({
23335
- write: (at, bytes) => writeAll5(access2, at, bytes),
23336
- truncate: (n) => access2.truncate(n)
23414
+ write: (at, bytes) => {
23415
+ writeAll5(access2, at, bytes);
23416
+ extent.wrote(at + bytes.length);
23417
+ },
23418
+ truncate: (n) => {
23419
+ access2.truncate(n);
23420
+ extent.cut(n);
23421
+ }
23337
23422
  });
23338
23423
  access2.flush();
23424
+ if (access2.getSize) extent.check(access2.getSize());
23339
23425
  } finally {
23340
23426
  access2.close();
23341
23427
  }
@@ -23344,14 +23430,25 @@ async function positioned(handle, op) {
23344
23430
  const writable2 = await handle.createWritable({ keepExistingData: true });
23345
23431
  try {
23346
23432
  await op({
23347
- write: (at, bytes) => writable2.write({ type: "write", position: at, data: bytes }),
23348
- truncate: (n) => writable2.truncate(n)
23433
+ write: async (at, bytes) => {
23434
+ await writable2.write({
23435
+ type: "write",
23436
+ position: at,
23437
+ data: bytes
23438
+ });
23439
+ extent.wrote(at + bytes.length);
23440
+ },
23441
+ truncate: async (n) => {
23442
+ await writable2.truncate(n);
23443
+ extent.cut(n);
23444
+ }
23349
23445
  });
23350
23446
  } catch (err) {
23351
23447
  await writable2.abort();
23352
23448
  throw err;
23353
23449
  }
23354
23450
  await writable2.close();
23451
+ if (extent.big()) extent.check((await handle.getFile()).size);
23355
23452
  }
23356
23453
  function isHandle(child) {
23357
23454
  return "kind" in child;
@@ -24326,6 +24423,11 @@ var OpfsFs = class {
24326
24423
  writable2 = await this.io(file.createWritable());
24327
24424
  await writable2.write(content);
24328
24425
  await writable2.close();
24426
+ if (typeof content !== "string" && content.length >= CHECKED_BYTES) {
24427
+ const extent = new Extent();
24428
+ extent.cut(content.length);
24429
+ extent.check((await file.getFile()).size);
24430
+ }
24329
24431
  } catch (err) {
24330
24432
  await writable2?.abort().catch(() => void 0);
24331
24433
  throw translate(err, path, "commit", false);
@@ -28145,6 +28247,7 @@ var Launcher = class {
28145
28247
  this.openFiles.add(this.nodes);
28146
28248
  options.fs.onPeer?.(() => this.flushOpen());
28147
28249
  options.fs.remoteChanges?.((change) => {
28250
+ this.held.doubt(change.paths, change.moved?.to);
28148
28251
  if (change.moved) this.moved(change.moved.from, change.moved.to);
28149
28252
  this.changes.flush();
28150
28253
  this.cwds.touched(change.paths, change.trees);
@@ -29157,7 +29260,8 @@ var Launcher = class {
29157
29260
  opfsCalls: this.rootFs.opfsCalls?.() ?? 0,
29158
29261
  opfsOps: this.rootFs.opfsOps?.() ?? 0,
29159
29262
  cwdChecks: this.cwds.checks,
29160
- renameAcks: this.rootFs.renameWaits?.()
29263
+ renameAcks: this.rootFs.renameWaits?.(),
29264
+ staleFds: staleFdCount()
29161
29265
  }),
29162
29266
  sudo: (call, signal) => this.sudo(pid, call, signal),
29163
29267
  crontab: (call) => this.crontab(pid, call),
@@ -30135,6 +30239,7 @@ var Launcher = class {
30135
30239
  this.renameLog.add(from, to);
30136
30240
  if (source) return;
30137
30241
  for (const nodes of this.openFiles) nodes.renamed(from, to);
30242
+ for (const holds2 of this.held) holds2.renamed(from, to);
30138
30243
  this.watchers.moved(from, to);
30139
30244
  }
30140
30245
  processChain(fs, nodes, unlinked) {