dsh-session-conductor 1.3.1 → 1.3.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.
Files changed (2) hide show
  1. package/lib/core/domain.js +36 -16
  2. package/package.json +1 -1
@@ -115,30 +115,50 @@ export function pluginDomain(ctx) {
115
115
  if (!storage) return Promise.reject(new Error("storageDomain 不可用"));
116
116
  domainPromise = storage.open(pluginDomainSpec).then((domain) => {
117
117
  domainLive = true;
118
- // 只在 apply 的活跃 fiber 上挂 close;HTTP handler / 事件回调 fiber 是 inactive,
119
- // ctx.effect 会抛 cannot create effect on inactive context,且 rejected Promise 被缓存后 list 一直 500。
120
- try {
121
- ctx.effect(() => () => {
122
- // 关闭的同时把缓存与存活标记一起清掉——下一次 apply 才会重新 open。
123
- // 【原代码】只 return domain.close()(缓存不清),靠 apply 开头无条件 domainPromise = null 兜,
124
- // 遇到「域还活着就重载」时会在旧的活域上再 open 一次 → storage 报 already open → list 500。
125
- domainLive = false;
126
- domainPromise = null;
127
- return domain.close();
128
- }, "session-conductor: domain close");
129
- } catch {
130
- /* 请求路径打开时不挂 effect;apply() 已预热并挂过 */
131
- }
118
+ attachDomainClose(ctx, domain);
132
119
  return domain;
133
- }).catch((err) => {
120
+ }).catch((error) => {
121
+ // 模块热重载场景:本实例的缓存是空的,但上一份实例打开的域仍被 storageDomain
122
+ // 按名字占用(facility 用 reserved 集合挡重复 open),于是再 open 必报 already-open。
123
+ // 宿主提供了按名字查已开域的口子,这里直接复用那份 handle——
124
+ // 否则重载后列表/模板/开关会一路 500,直到整个实例重启为止。
125
+ const reused = isAlreadyOpenError(error) && typeof storage.get === "function"
126
+ ? storage.get(pluginDomainSpec.name)
127
+ : undefined;
128
+ if (reused) {
129
+ domainLive = true;
130
+ attachDomainClose(ctx, reused);
131
+ return reused;
132
+ }
134
133
  domainPromise = null;
135
134
  domainLive = false;
136
- throw err;
135
+ throw error;
137
136
  });
138
137
  }
139
138
  return domainPromise;
140
139
  }
141
140
 
141
+ /** 判定「这个名字已经被占用」的重复打开错误(宿主 DomainError 带 code,保底看文案)。 */
142
+ function isAlreadyOpenError(error) {
143
+ return error?.code === "already-open" || /is already open/.test(String(error?.message ?? ""));
144
+ }
145
+
146
+ /** 挂关闭效果:只在 apply 的活跃 fiber 上成功,请求路径(inactive fiber)会抛并被吞掉。 */
147
+ function attachDomainClose(ctx, domain) {
148
+ try {
149
+ ctx.effect(() => () => {
150
+ // 关闭的同时把缓存与存活标记一起清掉——下一次 apply 才会重新 open。
151
+ // 【原代码】只 return domain.close()(缓存不清),靠 apply 开头无条件 domainPromise = null 兜,
152
+ // 遇到「域还活着就重载」时会在旧的活域上再 open 一次 → storage 报 already open → list 500。
153
+ domainLive = false;
154
+ domainPromise = null;
155
+ return domain.close();
156
+ }, "session-conductor: domain close");
157
+ } catch {
158
+ /* 请求路径打开时不挂 effect;apply() 已预热并挂过 */
159
+ }
160
+ }
161
+
142
162
  /** 读域里的全局状态对象。 */
143
163
  export async function pluginState(ctx) {
144
164
  const domain = await pluginDomain(ctx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-conductor",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "DSH session management enhancement: archive/restore sessions, batch & conditional delete, AI auto-rename, interrupted-session auto-resume, release idle sessions, workspace grouping, undo last message, repair damaged session logs, value analysis, full-text search, per-member model switching (list_models / set_member_model), and plan/closing template injection (system-prompt + context).",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",