@yeaft/webchat-agent 0.1.771 → 0.1.773

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.1.771",
3
+ "version": "0.1.773",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -32,10 +32,19 @@
32
32
  * 'reserved'/'invalid_vp_id'/... — bubbled from ids.js validators
33
33
  */
34
34
 
35
- import { existsSync, renameSync, rmSync, readdirSync, statSync } from 'fs';
35
+ import {
36
+ existsSync,
37
+ renameSync,
38
+ rmSync,
39
+ readdirSync,
40
+ statSync,
41
+ mkdirSync,
42
+ readFileSync,
43
+ writeFileSync,
44
+ } from 'fs';
36
45
  import { randomBytes } from 'crypto';
37
46
  import { homedir } from 'os';
38
- import { join } from 'path';
47
+ import { isAbsolute, join, resolve } from 'path';
39
48
  import {
40
49
  openGroup, createGroup, listGroups, loadGroupMeta,
41
50
  } from './group-store.js';
@@ -87,10 +96,77 @@ export class GroupCrudError extends Error {
87
96
  }
88
97
  }
89
98
 
90
- function groupsRoot(yeaftDir) {
99
+ const GROUP_WORKDIR_REGISTRY = 'group-workdirs.json';
100
+
101
+ export function groupsRoot(yeaftDir) {
91
102
  return join(yeaftDir, 'groups');
92
103
  }
93
104
 
105
+ export function normalizeWorkDir(workDir) {
106
+ const raw = String(workDir || '').trim();
107
+ if (!raw) return '';
108
+ return isAbsolute(raw) ? raw : resolve(raw);
109
+ }
110
+
111
+ export function yeaftDirForWorkDir(workDir) {
112
+ const normalized = normalizeWorkDir(workDir);
113
+ return normalized ? join(normalized, '.yeaft') : '';
114
+ }
115
+
116
+ function registryPath(yeaftDir) {
117
+ return join(yeaftDir, GROUP_WORKDIR_REGISTRY);
118
+ }
119
+
120
+ export function readWorkDirRegistry(yeaftDir) {
121
+ if (!yeaftDir) return {};
122
+ const file = registryPath(yeaftDir);
123
+ if (!existsSync(file)) return {};
124
+ try {
125
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
126
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
127
+ } catch {
128
+ return {};
129
+ }
130
+ }
131
+
132
+ function writeWorkDirRegistry(yeaftDir, registry) {
133
+ if (!yeaftDir) return;
134
+ mkdirSync(yeaftDir, { recursive: true });
135
+ writeFileSync(registryPath(yeaftDir), `${JSON.stringify(registry, null, 2)}\n`);
136
+ }
137
+
138
+ export function registerGroupWorkDir(defaultYeaftDir, groupId, workDir) {
139
+ const normalized = normalizeWorkDir(workDir);
140
+ if (!defaultYeaftDir || !groupId || !normalized) return;
141
+ const registry = readWorkDirRegistry(defaultYeaftDir);
142
+ registry[groupId] = normalized;
143
+ writeWorkDirRegistry(defaultYeaftDir, registry);
144
+ }
145
+
146
+ export function unregisterGroupWorkDir(defaultYeaftDir, groupId) {
147
+ if (!defaultYeaftDir || !groupId) return;
148
+ const registry = readWorkDirRegistry(defaultYeaftDir);
149
+ if (!Object.prototype.hasOwnProperty.call(registry, groupId)) return;
150
+ delete registry[groupId];
151
+ writeWorkDirRegistry(defaultYeaftDir, registry);
152
+ }
153
+
154
+ export function resolveGroupYeaftDir(defaultYeaftDir, groupId) {
155
+ if (!defaultYeaftDir || !groupId) return defaultYeaftDir;
156
+ const defaultGroupDir = join(groupsRoot(defaultYeaftDir), groupId);
157
+ if (existsSync(defaultGroupDir) && loadGroupMeta(defaultGroupDir)) return defaultYeaftDir;
158
+
159
+ const registry = readWorkDirRegistry(defaultYeaftDir);
160
+ const workDir = normalizeWorkDir(registry[groupId]);
161
+ if (workDir) {
162
+ const candidate = yeaftDirForWorkDir(workDir);
163
+ const candidateDir = join(groupsRoot(candidate), groupId);
164
+ if (existsSync(candidateDir) && loadGroupMeta(candidateDir)) return candidate;
165
+ }
166
+
167
+ return defaultYeaftDir;
168
+ }
169
+
94
170
  /** Build a safe group id from a display name (slug + ulid-lite suffix). */
95
171
  export function makeGroupId(name) {
96
172
  const slug = String(name || 'group')
@@ -146,11 +222,13 @@ export function ensureDefaultGroupIfEmpty(yeaftDir, options = {}) {
146
222
  * we do NOT auto-expand to the full VP library here. That's D1's job only.
147
223
  *
148
224
  * @param {string} yeaftDir
149
- * @param {{name:string, roster?:string[], defaultVpId?:string|null}} spec
150
- * @returns {{id:string, name:string, roster:string[], defaultVpId:string|null}}
225
+ * @param {{name:string, roster?:string[], defaultVpId?:string|null, workDir?:string}} spec
226
+ * @returns {{id:string, name:string, roster:string[], defaultVpId:string|null, workDir?:string}}
151
227
  */
152
228
  export function createGroupFromSpec(yeaftDir, spec, options = {}) {
153
- const memoryRoot = options.memoryRoot || DEFAULT_MEMORY_ROOT;
229
+ const normalizedWorkDir = normalizeWorkDir(spec && spec.workDir);
230
+ const groupYeaftDir = normalizedWorkDir ? yeaftDirForWorkDir(normalizedWorkDir) : yeaftDir;
231
+ const memoryRoot = options.memoryRoot || (groupYeaftDir ? join(groupYeaftDir, 'memory') : DEFAULT_MEMORY_ROOT);
154
232
  const name = String(spec && spec.name || '').trim();
155
233
  if (!name) throw new GroupCrudError('invalid_name', null, 'group name required');
156
234
 
@@ -174,15 +252,16 @@ export function createGroupFromSpec(yeaftDir, spec, options = {}) {
174
252
  if (!defaultVpId) defaultVpId = roster[0] || null;
175
253
 
176
254
  const id = makeGroupId(name);
177
- const root = groupsRoot(yeaftDir);
255
+ const root = groupsRoot(groupYeaftDir);
178
256
  if (existsSync(join(root, id))) {
179
257
  // Extremely unlikely (ulid suffix), but surface deterministically.
180
258
  throw new GroupCrudError('duplicate', id);
181
259
  }
182
260
 
183
- const handle = createGroup(root, { id, name, roster, defaultVpId });
261
+ const handle = createGroup(root, { id, name, roster, defaultVpId, workDir: normalizedWorkDir });
184
262
  const meta = handle.getMeta();
185
263
  handle.close();
264
+ if (normalizedWorkDir) registerGroupWorkDir(yeaftDir, id, normalizedWorkDir);
186
265
 
187
266
  // Seed Layer-A resident summary so the first session has memory content
188
267
  // even before Dream-v2 has run. No-op if a summary.md already exists.
@@ -243,7 +322,8 @@ export function updateGroupAnnouncement(yeaftDir, groupId, text) {
243
322
  * own second-confirm modal (acceptance #4 in task-334-slice-specs.md 334m).
244
323
  */
245
324
  export function archiveGroup(yeaftDir, groupId) {
246
- const root = groupsRoot(yeaftDir);
325
+ const groupYeaftDir = resolveGroupYeaftDir(yeaftDir, groupId);
326
+ const root = groupsRoot(groupYeaftDir);
247
327
  const srcDir = join(root, groupId);
248
328
  if (!existsSync(srcDir) || !loadGroupMeta(srcDir)) {
249
329
  throw new GroupCrudError('not_found', groupId);
@@ -253,6 +333,7 @@ export function archiveGroup(yeaftDir, groupId) {
253
333
  const suffix = randomBytes(2).toString('hex');
254
334
  const dstDir = join(root, `.archived-${ts}-${suffix}-${groupId}`);
255
335
  renameSync(srcDir, dstDir);
336
+ unregisterGroupWorkDir(yeaftDir, groupId);
256
337
  return { groupId, archivedAs: dstDir };
257
338
  }
258
339
 
@@ -269,8 +350,9 @@ export function archiveGroup(yeaftDir, groupId) {
269
350
  * delete cleans up legacy state too.
270
351
  */
271
352
  export function deleteGroup(yeaftDir, groupId, options = {}) {
272
- const memoryRoot = options.memoryRoot || DEFAULT_MEMORY_ROOT;
273
- const root = groupsRoot(yeaftDir);
353
+ const groupYeaftDir = resolveGroupYeaftDir(yeaftDir, groupId);
354
+ const memoryRoot = options.memoryRoot || (groupYeaftDir ? join(groupYeaftDir, 'memory') : DEFAULT_MEMORY_ROOT);
355
+ const root = groupsRoot(groupYeaftDir);
274
356
  const srcDir = join(root, groupId);
275
357
  const liveExists = existsSync(srcDir) && !!loadGroupMeta(srcDir);
276
358
 
@@ -307,6 +389,7 @@ export function deleteGroup(yeaftDir, groupId, options = {}) {
307
389
  console.warn(`[group-crud] failed to remove memory dir for ${groupId}:`, err?.message || err);
308
390
  }
309
391
 
392
+ unregisterGroupWorkDir(yeaftDir, groupId);
310
393
  return { groupId, deleted: true, legacyCleanedUp: legacyDirs.length };
311
394
  }
312
395
 
@@ -382,8 +465,9 @@ export function setGroupDefaultVp(yeaftDir, groupId, vpId) {
382
465
  }
383
466
  }
384
467
 
385
- function requireGroup(yeaftDir, groupId) {
386
- const root = groupsRoot(yeaftDir);
468
+ export function requireGroup(yeaftDir, groupId) {
469
+ const groupYeaftDir = resolveGroupYeaftDir(yeaftDir, groupId);
470
+ const root = groupsRoot(groupYeaftDir);
387
471
  const dir = join(root, groupId);
388
472
  if (!existsSync(dir) || !loadGroupMeta(dir)) {
389
473
  throw new GroupCrudError('not_found', groupId);
@@ -393,7 +477,18 @@ function requireGroup(yeaftDir, groupId) {
393
477
 
394
478
  /** Convenience: snapshot all non-archived groups for WS broadcast. */
395
479
  export function snapshotGroups(yeaftDir) {
396
- return listGroups(groupsRoot(yeaftDir));
480
+ const byId = new Map();
481
+ for (const group of listGroups(groupsRoot(yeaftDir))) {
482
+ byId.set(group.id, group);
483
+ }
484
+ const registry = readWorkDirRegistry(yeaftDir);
485
+ for (const [groupId, workDir] of Object.entries(registry)) {
486
+ const groupYeaftDir = yeaftDirForWorkDir(workDir);
487
+ const dir = join(groupsRoot(groupYeaftDir), groupId);
488
+ const meta = existsSync(dir) ? loadGroupMeta(dir) : null;
489
+ if (meta) byId.set(meta.id, meta);
490
+ }
491
+ return Array.from(byId.values()).sort((a, b) => String(a.createdAt || '').localeCompare(String(b.createdAt || '')));
397
492
  }
398
493
 
399
494
  export { DEFAULT_GROUP_ID };
@@ -139,6 +139,7 @@ export function createGroup(groupsRoot, spec) {
139
139
  roster,
140
140
  defaultVpId: spec.defaultVpId || null,
141
141
  announcement: typeof spec.announcement === 'string' ? spec.announcement : '',
142
+ workDir: typeof spec.workDir === 'string' ? spec.workDir.trim() : '',
142
143
  createdAt: spec.createdAt || new Date().toISOString(),
143
144
  };
144
145
  h.saveMeta(meta);
@@ -153,9 +154,10 @@ export function loadGroupMeta(dir) {
153
154
  const raw = readFileSync(path, 'utf8');
154
155
  const parsed = JSON.parse(raw);
155
156
  validateMeta(parsed);
156
- // Legacy groups created before the announcement field was added are
157
- // forward-compat: missing field reads back as empty string.
157
+ // Legacy groups created before optional fields were added are
158
+ // forward-compat: missing fields read back as safe empty strings.
158
159
  if (typeof parsed.announcement !== 'string') parsed.announcement = '';
160
+ if (typeof parsed.workDir !== 'string') parsed.workDir = '';
159
161
  return parsed;
160
162
  } catch {
161
163
  return null;
@@ -192,6 +194,9 @@ function validateMeta(meta) {
192
194
  if (meta.announcement != null && typeof meta.announcement !== 'string') {
193
195
  throw new Error('group.announcement must be string');
194
196
  }
197
+ if (meta.workDir != null && typeof meta.workDir !== 'string') {
198
+ throw new Error('group.workDir must be string');
199
+ }
195
200
  }
196
201
 
197
202
  /**
@@ -41,6 +41,8 @@ import {
41
41
  removeMember,
42
42
  setGroupDefaultVp,
43
43
  snapshotGroups,
44
+ resolveGroupYeaftDir,
45
+ groupsRoot,
44
46
  } from './groups/group-crud.js';
45
47
  import { openGroup, loadGroupMeta } from './groups/group-store.js';
46
48
  import { createCoordinator } from './groups/coordinator.js';
@@ -55,6 +57,23 @@ import { createVpStatusBroker } from './vp-status-broker.js';
55
57
  /** @type {import('./session.js').Session | null} */
56
58
  let session = null;
57
59
 
60
+ /**
61
+ * Tracks scoped-dream triggers that are currently inflight, keyed by
62
+ * groupId. Used by `handleUnifyDreamTrigger` to reject any overlapping
63
+ * scoped trigger rather than racing the sink-wrapping logic against
64
+ * itself.
65
+ *
66
+ * Cross-group overlap is rejected (not just same-group): under the
67
+ * existing dream scheduler a second concurrent trigger silently shares
68
+ * the first's inflight promise and dropped its own scope filter. So
69
+ * "B during A's run" doesn't actually produce a separate scoped pass
70
+ * for B — letting B install a second sink wrapper would only mis-stamp
71
+ * A's events with B's groupId. Rejecting B with an explicit error is
72
+ * the honest answer; the user can re-click after A settles.
73
+ * @type {Set<string>}
74
+ */
75
+ const inflightScopedDreamGroups = new Set();
76
+
58
77
  /**
59
78
  * Single in-flight AbortController. A new user message cancels the prior
60
79
  * round (if any). H2.f.2: replaces the per-thread Map.
@@ -980,6 +999,7 @@ function sendGroupRosterChanged(group) {
980
999
  name: group.name,
981
1000
  roster: group.roster,
982
1001
  defaultVpId: group.defaultVpId,
1002
+ workDir: group.workDir || '',
983
1003
  });
984
1004
  }
985
1005
 
@@ -1007,8 +1027,7 @@ export function handleUnifyCreateGroup(msg) {
1007
1027
  const payload = (msg && msg.payload) || {};
1008
1028
  try {
1009
1029
  const yeaftDir = ctx.CONFIG?.yeaftDir;
1010
- const memoryRoot = yeaftDir ? join(yeaftDir, 'memory') : undefined;
1011
- const group = createGroupFromSpec(yeaftDir, payload, memoryRoot ? { memoryRoot } : {});
1030
+ const group = createGroupFromSpec(yeaftDir, payload);
1012
1031
  sendGroupCrudResult({ op: 'create', requestId, ok: true, group });
1013
1032
  sendGroupSnapshotBroadcast();
1014
1033
  } catch (err) {
@@ -1090,8 +1109,7 @@ export function handleUnifyDeleteGroup(msg) {
1090
1109
  const groupId = msg && msg.groupId;
1091
1110
  try {
1092
1111
  const yeaftDir = ctx.CONFIG?.yeaftDir;
1093
- const memoryRoot = yeaftDir ? join(yeaftDir, 'memory') : undefined;
1094
- const result = deleteGroup(yeaftDir, groupId, memoryRoot ? { memoryRoot } : {});
1112
+ const result = deleteGroup(yeaftDir, groupId);
1095
1113
  // Cascade: remove every persisted message stamped with this group id.
1096
1114
  // Hard delete (per user spec): no soft-archive, the bytes are gone.
1097
1115
  // Skipped silently if the session/store isn't initialized — the next
@@ -1185,9 +1203,23 @@ export function installUnifyRuntimeBridge(s) {
1185
1203
  if (!s) return;
1186
1204
 
1187
1205
  // Forward dream pipeline progress events to the web debug panel.
1206
+ //
1207
+ // Group-id stamping is NO LONGER done here. It used to be: this sink
1208
+ // read a module-level `activeScopedDreamGroupId` that
1209
+ // `handleUnifyDreamTrigger({groupId})` parked before awaiting the
1210
+ // scope-filtered pass. That created a race when two scoped triggers
1211
+ // overlapped (auto-tick during a manual click; or two manual clicks
1212
+ // for different groups): the second handler's `finally` could clear
1213
+ // the module slot while the first run was still emitting events,
1214
+ // dropping the stamp from the tail of the first pass. The new design:
1215
+ // `handleUnifyDreamTrigger` wraps THIS sink for the lifetime of the
1216
+ // trigger to inject `groupId` per-call (see that function below). The
1217
+ // base sink is intentionally a pure passthrough.
1188
1218
  s._dreamProgressSink = (evt) => {
1189
1219
  try {
1190
- sendUnifyEvent({ type: 'dream_progress', ...evt });
1220
+ const out = { type: 'dream_progress', ...evt };
1221
+ const tag = evt && evt.groupId ? { groupId: evt.groupId } : {};
1222
+ sendUnifyEvent(out, tag);
1191
1223
  } catch { /* never let event delivery throw */ }
1192
1224
  };
1193
1225
 
@@ -1601,15 +1633,17 @@ export async function handleUnifyGroupChat(msg) {
1601
1633
  // seedFailed separately so a seed crash surfaces a different message
1602
1634
  // than a genuinely-missing group.
1603
1635
  let groupHandle = null;
1636
+ let groupRoot = null;
1604
1637
  let seedFailed = false;
1605
1638
  try {
1606
- const root = join(yeaftDir, 'groups');
1607
- const dir = join(root, groupId);
1639
+ const groupYeaftDir = resolveGroupYeaftDir(yeaftDir, groupId);
1640
+ groupRoot = groupsRoot(groupYeaftDir);
1641
+ const dir = join(groupRoot, groupId);
1608
1642
  if (existsSync(dir) && loadGroupMeta(dir)) {
1609
- groupHandle = openGroup(root, groupId);
1643
+ groupHandle = openGroup(groupRoot, groupId);
1610
1644
  } else if (groupId === 'grp_default') {
1611
1645
  try {
1612
- const seeded = seedDefaultGroup(yeaftDir, { memoryRoot: join(yeaftDir, 'memory') });
1646
+ const seeded = seedDefaultGroup(groupYeaftDir, { memoryRoot: join(groupYeaftDir, 'memory') });
1613
1647
  groupHandle = seeded.group;
1614
1648
  } catch (seedErr) {
1615
1649
  seedFailed = true;
@@ -1624,7 +1658,7 @@ export async function handleUnifyGroupChat(msg) {
1624
1658
 
1625
1659
  if (!groupHandle) {
1626
1660
  const errText = seedFailed
1627
- ? `⚠️ Failed to seed default group ${groupId} — check ~/.yeaft/ permissions.`
1661
+ ? `⚠️ Failed to seed default group ${groupId} — check group .yeaft permissions.`
1628
1662
  : `⚠️ Group ${groupId} not found.`;
1629
1663
  sendUnifyOutput({
1630
1664
  type: 'assistant',
@@ -1652,7 +1686,7 @@ export async function handleUnifyGroupChat(msg) {
1652
1686
  }
1653
1687
  if (rosterMutated) {
1654
1688
  try { groupHandle.close && groupHandle.close(); } catch { /* best-effort */ }
1655
- groupHandle = openGroup(join(yeaftDir, 'groups'), groupId);
1689
+ groupHandle = openGroup(groupRoot, groupId);
1656
1690
  sendGroupRosterChanged(groupHandle.getMeta());
1657
1691
  }
1658
1692
  }
@@ -1661,7 +1695,7 @@ export async function handleUnifyGroupChat(msg) {
1661
1695
  try {
1662
1696
  setGroupDefaultVp(yeaftDir, groupId, meta2.roster[0]);
1663
1697
  try { groupHandle.close && groupHandle.close(); } catch { /* best-effort */ }
1664
- groupHandle = openGroup(join(yeaftDir, 'groups'), groupId);
1698
+ groupHandle = openGroup(groupRoot, groupId);
1665
1699
  sendGroupRosterChanged(groupHandle.getMeta());
1666
1700
  rosterMutated = true;
1667
1701
  } catch { /* best-effort */ }
@@ -2660,6 +2694,46 @@ export async function handleUnifyDreamTrigger(msg = {}) {
2660
2694
  return;
2661
2695
  }
2662
2696
 
2697
+ // Concurrent-trigger guard for scoped runs. Two scoped clicks (same
2698
+ // group or different) overlapping the same inflight pass used to set
2699
+ // the module-level groupId slot, race the sink wrapping, and let the
2700
+ // second `finally` restore the original sink while the first run was
2701
+ // still emitting events. We now refuse any second scoped trigger
2702
+ // while ANY scoped pass is inflight — the scheduler already
2703
+ // short-circuits the underlying run for same-group, and a different
2704
+ // group's filter would have been silently dropped anyway (see
2705
+ // dream-v2/schedule.js inflight reuse), so the user-facing semantics
2706
+ // are unchanged ("you already asked").
2707
+ if (groupId && inflightScopedDreamGroups.size > 0) {
2708
+ sendToServer({
2709
+ type: 'unify_dream_result',
2710
+ ...tag,
2711
+ success: false,
2712
+ error: 'A dream pass is already running.',
2713
+ });
2714
+ return;
2715
+ }
2716
+
2717
+ // Per-call sink wrapper. For scoped runs we install a closure that
2718
+ // injects this trigger's groupId onto top-level events the runner
2719
+ // emits without one (start/merge/done), then delegates to the
2720
+ // original passthrough sink. The wrapper lives only for the lifetime
2721
+ // of this trigger and is restored in `finally`; concurrent calls for
2722
+ // OTHER groupIds chain (last-installed wins) but each restoration
2723
+ // unwinds back to its predecessor.
2724
+ const originalSink = session?._dreamProgressSink;
2725
+ if (groupId && typeof originalSink === 'function') {
2726
+ inflightScopedDreamGroups.add(groupId);
2727
+ session._dreamProgressSink = (evt) => {
2728
+ try {
2729
+ const stamped = evt && evt.groupId
2730
+ ? evt
2731
+ : { ...evt, groupId };
2732
+ originalSink(stamped);
2733
+ } catch { /* never let event delivery throw */ }
2734
+ };
2735
+ }
2736
+
2663
2737
  try {
2664
2738
  sendToServer({
2665
2739
  type: 'unify_dream_status',
@@ -2678,6 +2752,7 @@ export async function handleUnifyDreamTrigger(msg = {}) {
2678
2752
  const targets = Array.isArray(result?.targets) ? result.targets : [];
2679
2753
  const entriesCreated = targets.filter(t => t && t.status === 'done').length;
2680
2754
  const lastDreamAt = result?.startedAt || new Date().toISOString();
2755
+ const success = !result.error && !result.skipped;
2681
2756
 
2682
2757
  // Spread `result` FIRST so derived fields (success, entriesCreated,
2683
2758
  // lastDreamAt) authoritatively shadow anything the runner might grow
@@ -2685,11 +2760,19 @@ export async function handleUnifyDreamTrigger(msg = {}) {
2685
2760
  // { groups, targets, startedAt, error?, skipped? }) but the failure
2686
2761
  // mode of the alternative ordering is silent — review feedback from
2687
2762
  // PR #743.
2763
+ //
2764
+ // This `unify_dream_result` envelope is the SOLE terminal signal for
2765
+ // a dream pass. The chat-store projects it into BOTH `unifyDreamLatest`
2766
+ // (final tally row) AND `unifyDreamEvents` (ring-buffer terminal
2767
+ // marker), so we no longer mirror a synthetic `phase:'result'`
2768
+ // dream_progress event — that mirror used to race the
2769
+ // `unifyDreamLatest` writer and flip the success row back to
2770
+ // 'running' (Critical reviewer finding pre-merge).
2688
2771
  sendToServer({
2689
2772
  type: 'unify_dream_result',
2690
2773
  ...tag,
2691
2774
  ...result,
2692
- success: !result.error && !result.skipped,
2775
+ success,
2693
2776
  entriesCreated,
2694
2777
  lastDreamAt,
2695
2778
  });
@@ -2700,6 +2783,12 @@ export async function handleUnifyDreamTrigger(msg = {}) {
2700
2783
  success: false,
2701
2784
  error: err?.message || String(err),
2702
2785
  });
2786
+ } finally {
2787
+ // Restore the original sink and release the per-group inflight lock.
2788
+ if (groupId && typeof originalSink === 'function') {
2789
+ session._dreamProgressSink = originalSink;
2790
+ inflightScopedDreamGroups.delete(groupId);
2791
+ }
2703
2792
  }
2704
2793
  }
2705
2794