oasis_test 0.1.120 → 0.1.121

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 (2) hide show
  1. package/dist/index.js +52 -6
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -174165,6 +174165,13 @@ var init_daemon_hub = __esm({
174165
174165
  sessionMeta = /* @__PURE__ */ new Map();
174166
174166
  sessionConnectListeners = [];
174167
174167
  sessionDisconnectListeners = [];
174168
+ /**
174169
+ * 「这次派发归谁管、现在什么状态」的认领口。**必须由 hub 汇总,不能各 adapter 自己判**——
174170
+ * serve 里同时有两个 DaemonHubAdapter(chat 一个、dispatch 一个),一次派发只属于其中一个。
174171
+ * 让 adapter 自己判「我不认识就 evict」,另一个 adapter 会把别人的活会话一枪打死
174172
+ * (2026-08-25 真机实测:chat 会话刚连上就收到 evict(unknown),用户看到「对话已中断」)。
174173
+ */
174174
+ sessionClaimCheckers = [];
174168
174175
  resolveDataplane;
174169
174176
  /** 每个 daemon 最近一次收到任何帧的时间戳(含它自发的心跳 pong)——liveness 判定的依据。 */
174170
174177
  lastSeen = /* @__PURE__ */ new Map();
@@ -174374,6 +174381,7 @@ var init_daemon_hub = __esm({
174374
174381
  this.sessionSockets.set(dispatchId, ws);
174375
174382
  this.sessionMeta.set(dispatchId, { nodeId, sessionId: msg.sessionId, connectedAt: Date.now() });
174376
174383
  for (const l of this.sessionConnectListeners) l({ dispatchId, sessionId: msg.sessionId, nodeId });
174384
+ this.judgeSession(dispatchId);
174377
174385
  }
174378
174386
  return;
174379
174387
  }
@@ -174395,6 +174403,28 @@ var init_daemon_hub = __esm({
174395
174403
  });
174396
174404
  ws.on("error", (err) => console.error(`[hub] session ${dispatchId} error:`, err.message));
174397
174405
  }
174406
+ /**
174407
+ * 注册一个认领判断。返回:
174408
+ * live —— 这次派发在我这儿还活着(别动它)
174409
+ * settled —— 我这儿已经收尾/收割了(该 evict,让旧进程自尽)
174410
+ * unknown —— 我不认识(可能归别人管,**不构成 evict 理由**)
174411
+ */
174412
+ registerSessionClaimCheck(fn) {
174413
+ this.sessionClaimCheckers.push(fn);
174414
+ }
174415
+ /** 会话连上来时问一圈:没人说 live、且有人说 settled,才 evict。全 unknown = 没人认领,也 evict。 */
174416
+ judgeSession(dispatchId) {
174417
+ if (this.sessionClaimCheckers.length === 0) return;
174418
+ const verdicts = this.sessionClaimCheckers.map((f2) => {
174419
+ try {
174420
+ return f2(dispatchId);
174421
+ } catch {
174422
+ return "unknown";
174423
+ }
174424
+ });
174425
+ if (verdicts.includes("live")) return;
174426
+ this.evictSession(dispatchId, verdicts.includes("settled") ? "reaped" : "unknown");
174427
+ }
174398
174428
  /** 会话连接建立(`session_hello` 通过校验)时触发——2b 的收割判据挂在这上面。 */
174399
174429
  addSessionConnectListener(l) {
174400
174430
  this.sessionConnectListeners.push(l);
@@ -189472,6 +189502,11 @@ var init_daemon_adapter = __esm({
189472
189502
  hub.addDisconnectListener((daemonId) => this.onNodeDown(daemonId));
189473
189503
  hub.addConnectListener((daemon) => this.onNodeUp(daemon));
189474
189504
  hub.addSessionConnectListener?.((i) => this.onSessionUp(i.dispatchId));
189505
+ hub.registerSessionClaimCheck?.((dispatchId) => {
189506
+ const e = this.pending.get(dispatchId);
189507
+ if (e) return e.exited ? "settled" : "live";
189508
+ return this.settledDispatchIds.has(dispatchId) ? "settled" : "unknown";
189509
+ });
189475
189510
  hub.addSessionDisconnectListener?.((i) => this.onSessionDown(i.dispatchId));
189476
189511
  }
189477
189512
  pending = /* @__PURE__ */ new Map();
@@ -189489,6 +189524,9 @@ var init_daemon_adapter = __esm({
189489
189524
  /** 会话粒度的失联倒计时(键=dispatchId)。与上面按 nodeId 的那张表并存,判据不同、互不替代。 */
189490
189525
  sessionReapTimers = /* @__PURE__ */ new Map();
189491
189526
  sessionReapGraceMs;
189527
+ /** 近期已收尾的 dispatchId(有界)。用于回答「这次派发我收过了」——否则收尾后 pending 里就没了,
189528
+ * 旧会话重连时会被判成 unknown,分不清「我收割过它」和「压根不归我管」。 */
189529
+ settledDispatchIds = /* @__PURE__ */ new Set();
189492
189530
  sessionAuth;
189493
189531
  /** 取走(并清除)某会话的暂存帧;无暂存返回空数组对。 */
189494
189532
  drainStash(dispatchId) {
@@ -189536,6 +189574,15 @@ var init_daemon_adapter = __esm({
189536
189574
  else this.health?.recordReachable(entry.nodeId);
189537
189575
  for (const cb of entry.exitCbs.splice(0)) cb(info);
189538
189576
  this.pending.delete(dispatchId);
189577
+ this.settledDispatchIds.add(dispatchId);
189578
+ if (this.settledDispatchIds.size > 2e3) {
189579
+ const it = this.settledDispatchIds.values();
189580
+ for (let i = 0; i < 500; i++) {
189581
+ const v2 = it.next();
189582
+ if (v2.done) break;
189583
+ this.settledDispatchIds.delete(v2.value);
189584
+ }
189585
+ }
189539
189586
  }
189540
189587
  /** 当前在途(未退出)会话数;传 runtimeKind 时收窄到单个 runtime 实例。 */
189541
189588
  activeRunCount(nodeId, runtimeKind) {
@@ -189628,11 +189675,6 @@ var init_daemon_adapter = __esm({
189628
189675
  clearTimeout(timer);
189629
189676
  this.sessionReapTimers.delete(dispatchId);
189630
189677
  }
189631
- const entry = this.pending.get(dispatchId);
189632
- if (!entry || entry.exited) {
189633
- this.log(`[dispatch-delivery] ${dispatchId}\uFF1A\u4F1A\u8BDD\u8FDE\u4E0A\u6765\u4E86\uFF0C\u4F46\u670D\u52A1\u7AEF\u5DF2\u4E0D\u8BA4\u5B83\uFF08\u5DF2\u6536\u5272/\u5DF2\u91CD\u6D3E\uFF09\u2192 evict`);
189634
- this.hub.evictSession?.(dispatchId, entry ? "reaped" : "unknown");
189635
- }
189636
189678
  }
189637
189679
  /**
189638
189680
  * 会话连接断开(D2′.4):**断联即该会话失联**,不再经由节点代为证明。
@@ -202187,6 +202229,10 @@ var SessionProcessState = class {
202187
202229
  },
202188
202230
  onHandle: (h) => {
202189
202231
  this.handle = h;
202232
+ if (this.stopping) {
202233
+ void h.kill().catch(() => {
202234
+ });
202235
+ }
202190
202236
  },
202191
202237
  onExited: () => {
202192
202238
  this.exited = true;
@@ -208332,7 +208378,7 @@ function shimScript() {
208332
208378
  }
208333
208379
 
208334
208380
  // src/index.ts
208335
- var PKG_VERSION = true ? "0.1.120" : "dev";
208381
+ var PKG_VERSION = true ? "0.1.121" : "dev";
208336
208382
  var LOCAL_BIN = localBin();
208337
208383
  var NPM_PREFIX = npmPrefix();
208338
208384
  var INSTANCE = DEFAULT_INSTANCE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oasis_test",
3
- "version": "0.1.120",
3
+ "version": "0.1.121",
4
4
  "description": "Oasis node daemon + CLI — background daemon, auto-start, full server CLI",
5
5
  "bin": {
6
6
  "oasis": "./dist/index.js"
@@ -26,6 +26,6 @@
26
26
  "node": ">=20"
27
27
  },
28
28
  "oasisRelease": {
29
- "sourceHead": "4a3cbe607e3ce0b988df380d3ed7b48e5201836e"
29
+ "sourceHead": "de07ed05bed446afd5e304b496de39d5ac28bad5"
30
30
  }
31
31
  }