@genesislcap/ai-assistant 15.15.1 → 15.15.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/ai-assistant.api.json +367 -0
- package/dist/ai-assistant.d.ts +129 -1
- package/dist/chat-driver.cjs +3 -0
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +3 -0
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +232 -3
- package/dist/dts/main/main.d.ts +129 -0
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts +0 -1
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/main/persistence-broken-sources.test.d.ts +2 -0
- package/dist/dts/main/persistence-broken-sources.test.d.ts.map +1 -0
- package/dist/dts/state/debug-event-log.d.ts +1 -1
- package/dist/dts/state/debug-event-log.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persister.d.ts +76 -0
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/esm/main/main.js +205 -0
- package/dist/esm/main/main.template.js +89 -0
- package/dist/esm/main/persistence-broken-sources.test.js +180 -0
- package/dist/esm/state/debug-event-log.js +3 -0
- package/dist/esm/state/persistence/session-persister.js +224 -43
- package/dist/esm/state/persistence/session-persister.test.js +237 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/main/main.template.ts +101 -0
- package/src/main/main.ts +230 -0
- package/src/main/persistence-broken-sources.test.ts +219 -0
- package/src/state/debug-event-log.ts +4 -0
- package/src/state/persistence/session-persister.test.ts +302 -33
- package/src/state/persistence/session-persister.ts +260 -52
package/src/main/main.ts
CHANGED
|
@@ -220,6 +220,20 @@ const SESSION_MENU_CLOSE_MS = 200;
|
|
|
220
220
|
*/
|
|
221
221
|
const LEDGER_FLUSH_DEBOUNCE_MS = 2000;
|
|
222
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Reporter id for this element's OWN session persister in `brokenSources` (GENC-1511).
|
|
225
|
+
*
|
|
226
|
+
* Named rather than inline so the report and the recovery cannot drift apart — a typo in one of
|
|
227
|
+
* the two strings would silently make the session's recovery unable to withdraw its own warning,
|
|
228
|
+
* leaving the modal up for good.
|
|
229
|
+
*/
|
|
230
|
+
const SESSION_PERSISTENCE_SOURCE = 'session';
|
|
231
|
+
/**
|
|
232
|
+
* What a host gets if it reports a failure without naming a source. Fine for a host with a single
|
|
233
|
+
* store; a host owning several should name each, so one recovering does not withdraw the others.
|
|
234
|
+
*/
|
|
235
|
+
const DEFAULT_PERSISTENCE_SOURCE = 'host';
|
|
236
|
+
|
|
223
237
|
/** Drag-to-resize bounds for the chat input (composer), in px. */
|
|
224
238
|
const COMPOSER_MIN_HEIGHT_PX = 48;
|
|
225
239
|
const COMPOSER_MAX_HEIGHT_PX = 400;
|
|
@@ -2139,6 +2153,123 @@ export class FoundationAiAssistant extends GenesisElement {
|
|
|
2139
2153
|
@observable settingsModalTab: SettingsModalTab = 'settings';
|
|
2140
2154
|
/** Bound to the design-system modal via the template ref. */
|
|
2141
2155
|
settingsModal?: Modal;
|
|
2156
|
+
|
|
2157
|
+
/**
|
|
2158
|
+
* GENC-1511 — persistence has failed repeatedly and it is no longer saving. Drives a BLOCKING
|
|
2159
|
+
* modal with a single Reload action: the whole failure class this ticket exists for is one the
|
|
2160
|
+
* user cannot see, and a passive indicator is close to invisible (Will worked for 3h17m past
|
|
2161
|
+
* the point his session stopped saving, with nothing on screen to tell him).
|
|
2162
|
+
*
|
|
2163
|
+
* Set only at a moment when reloading is SAFE — the persister gates it on the active agent
|
|
2164
|
+
* being resumable, so we never advise a reload while an agent's in-flight work would be lost.
|
|
2165
|
+
*/
|
|
2166
|
+
@observable persistenceBroken = false;
|
|
2167
|
+
/**
|
|
2168
|
+
* Which reporters currently consider persistence broken, newest last, each with the copy it
|
|
2169
|
+
* asked for. {@link FoundationAiAssistant.persistenceBroken} is DERIVED from this (`size > 0`) rather than being the
|
|
2170
|
+
* source of truth.
|
|
2171
|
+
*
|
|
2172
|
+
* A plain boolean was wrong the moment there was more than one reporter, and review caught it:
|
|
2173
|
+
* this element's own persister covers `sessions/<key>`, while a host reports its own keyspaces
|
|
2174
|
+
* (Create's `projects/<id>.json`). With one flag, a SESSION save landing after its own broken
|
|
2175
|
+
* episode called `reportPersistenceRecovered()` and closed the modal while the PROJECT store
|
|
2176
|
+
* was still refusing writes — and because Create's own re-entry guard only clears on a
|
|
2177
|
+
* successful project write, the warning could then never be raised again for the life of the
|
|
2178
|
+
* page. The user carried on against a dead store with the warning cancelled by an unrelated
|
|
2179
|
+
* subsystem: the exact failure this modal exists to prevent, on the keyspace that holds the app
|
|
2180
|
+
* rather than the transcript.
|
|
2181
|
+
*
|
|
2182
|
+
* A `Map` and not a `Set` because the copy has to survive the same collision. The winner is the
|
|
2183
|
+
* most recently reported still-broken source (insertion order, so it is deterministic), and when
|
|
2184
|
+
* one recovers the copy falls back to whoever is left instead of reverting to the session
|
|
2185
|
+
* default — which would otherwise state something untrue of the failure still in progress.
|
|
2186
|
+
*/
|
|
2187
|
+
private readonly brokenSources = new Map<string, { message?: string; detail?: string }>();
|
|
2188
|
+
/**
|
|
2189
|
+
* Showing and hiding the modal hangs off the PROPERTY, so `persistenceBroken` is the single
|
|
2190
|
+
* entry point — for this element's own persister callback and for a host reporting a failure in
|
|
2191
|
+
* a keyspace this element knows nothing about (Create's project payload, GENC-1511 §17).
|
|
2192
|
+
*
|
|
2193
|
+
* It has to be here rather than at the call site because of the `cancel` listener: `cancel`
|
|
2194
|
+
* does not bubble, so it cannot be bound from the template, and a caller that shows the modal
|
|
2195
|
+
* without attaching it gets a modal Escape closes — which defeats the whole point. Routing
|
|
2196
|
+
* every path through one place makes a dismissible variant unreachable.
|
|
2197
|
+
*/
|
|
2198
|
+
persistenceBrokenChanged(_old: boolean, broken: boolean): void {
|
|
2199
|
+
if (!broken) {
|
|
2200
|
+
this.detachPersistenceEscapeGuard();
|
|
2201
|
+
this.persistenceModal?.close();
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
DOM.queueUpdate(() => {
|
|
2205
|
+
const modal = this.persistenceModal;
|
|
2206
|
+
// Re-read `persistenceBroken`: this callback is DEFERRED, so the state it exists to act on
|
|
2207
|
+
// may have changed since it was queued. A `true → false` landing in the same batch runs the
|
|
2208
|
+
// `!broken` branch above against a modal that was never shown — both statements no-op — and
|
|
2209
|
+
// this callback would then raise a blocking, deliberately NON-DISMISSIBLE "your work isn't
|
|
2210
|
+
// being saved" modal for a problem that had already fixed itself, with no further change
|
|
2211
|
+
// event coming to close it. The only way out would be a reload nobody needed, which is a
|
|
2212
|
+
// worse outcome than the missed warning this defer exists to avoid.
|
|
2213
|
+
//
|
|
2214
|
+
// Reachable because `maybeReportBroken` fires BEFORE `provider.save` in `persistSession`, so
|
|
2215
|
+
// a report and the successful write that withdraws it can share a tick — and per-source
|
|
2216
|
+
// recovery makes `true → false` far more common than it was (PR #2472 review).
|
|
2217
|
+
if (!modal || modal.open || !this.persistenceBroken) return;
|
|
2218
|
+
this.attachPersistenceEscapeGuard(modal);
|
|
2219
|
+
modal.show();
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
/** Swallows the native dialog's Escape route. Stored, not inline, so it can be removed again. */
|
|
2224
|
+
private readonly onPersistenceModalCancel = (e: Event): void => e.preventDefault();
|
|
2225
|
+
/** The node the guard above is bound to, so removal targets the same one it was added to. */
|
|
2226
|
+
private persistenceEscapeGuardTarget?: HTMLDialogElement;
|
|
2227
|
+
|
|
2228
|
+
/**
|
|
2229
|
+
* Make the modal survive Escape. Bound imperatively because `cancel` does not bubble.
|
|
2230
|
+
*
|
|
2231
|
+
* Attach/detach rather than fire-and-forget: a broken → recovered → broken cycle is reachable
|
|
2232
|
+
* (that is what {@link FoundationAiAssistant.reportPersistenceRecovered} is for), and re-showing previously added a
|
|
2233
|
+
* fresh anonymous closure each time, accumulating duplicate listeners on the dialog.
|
|
2234
|
+
*
|
|
2235
|
+
* A missing `mainElement` is LOGGED rather than ignored. `Dialog` declares it non-optional, so
|
|
2236
|
+
* if it is ever absent the old optional-chain quietly produced an Escape-dismissible modal —
|
|
2237
|
+
* failing open on the one property this modal must never lose.
|
|
2238
|
+
*/
|
|
2239
|
+
private attachPersistenceEscapeGuard(modal: Modal): void {
|
|
2240
|
+
const dialog = modal.mainElement;
|
|
2241
|
+
if (!dialog) {
|
|
2242
|
+
logger.error(
|
|
2243
|
+
'Persistence modal has no dialog element — Escape cannot be blocked, so the blocking ' +
|
|
2244
|
+
'warning is dismissible. The user may close it and carry on against a dead store.',
|
|
2245
|
+
);
|
|
2246
|
+
return;
|
|
2247
|
+
}
|
|
2248
|
+
this.detachPersistenceEscapeGuard();
|
|
2249
|
+
dialog.addEventListener('cancel', this.onPersistenceModalCancel);
|
|
2250
|
+
this.persistenceEscapeGuardTarget = dialog;
|
|
2251
|
+
}
|
|
2252
|
+
|
|
2253
|
+
/** Remove the Escape guard, if one is bound. Safe to call when there is none. */
|
|
2254
|
+
private detachPersistenceEscapeGuard(): void {
|
|
2255
|
+
this.persistenceEscapeGuardTarget?.removeEventListener('cancel', this.onPersistenceModalCancel);
|
|
2256
|
+
this.persistenceEscapeGuardTarget = undefined;
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
/**
|
|
2260
|
+
* Body copy for the modal; `undefined` uses the session-oriented default in the template. A
|
|
2261
|
+
* host reporting a different keyspace overrides it — "this session has stopped saving" is
|
|
2262
|
+
* simply untrue of a failed project write.
|
|
2263
|
+
*/
|
|
2264
|
+
@observable persistenceBrokenMessage?: string;
|
|
2265
|
+
/**
|
|
2266
|
+
* Optional second line, already composed. A STRING rather than the message-count fields it
|
|
2267
|
+
* replaces: quantifying is caller-specific ("N messages", "your last N changes"), and keeping
|
|
2268
|
+
* the template ignorant of what is being counted is what makes it reusable.
|
|
2269
|
+
*/
|
|
2270
|
+
@observable persistenceBrokenDetail?: string;
|
|
2271
|
+
/** The modal itself, so it can be shown and made non-dismissible. */
|
|
2272
|
+
persistenceModal?: Modal;
|
|
2142
2273
|
/** Bound to the settings modal tab bar — used to resync selection after reopen. */
|
|
2143
2274
|
settingsTabsEl?: SettingsModalTabsElement;
|
|
2144
2275
|
/** Light-DOM nodes assigned to settings modal slots (via `slotted()` bindings). */
|
|
@@ -4348,9 +4479,108 @@ export class FoundationAiAssistant extends GenesisElement {
|
|
|
4348
4479
|
getDriver: () => getDriver(key),
|
|
4349
4480
|
getStore: () => (hasSessionStore(key) ? getSessionStore(key) : undefined),
|
|
4350
4481
|
getDiagnosticEntries: () => this.buildDiagnosticEntries(),
|
|
4482
|
+
onPersistenceBroken: (d) => this.onPersistenceBroken(d),
|
|
4483
|
+
onPersistenceRecovered: () => this.onPersistenceRecovered(),
|
|
4351
4484
|
};
|
|
4352
4485
|
}
|
|
4353
4486
|
|
|
4487
|
+
/**
|
|
4488
|
+
* Tell the user their work is no longer being saved, and block until they reload (GENC-1511).
|
|
4489
|
+
*
|
|
4490
|
+
* Public because the assistant is not the only thing that persists. Its own persister covers
|
|
4491
|
+
* `sessions/<key>`; a host may own other keyspaces whose failure is just as costly — Create's
|
|
4492
|
+
* `projects/<id>.json` holds the entity model, handlers and VFS, i.e. the app itself — and had
|
|
4493
|
+
* no way to reach this modal (§17 of the GENC-1511 plan).
|
|
4494
|
+
*
|
|
4495
|
+
* Both copy fields are optional and default to the session wording in the template, so the
|
|
4496
|
+
* common case stays a bare call. Idempotent per source while already broken: re-reporting the
|
|
4497
|
+
* same source refreshes its copy, and the property change only shows a modal that is not open.
|
|
4498
|
+
*
|
|
4499
|
+
* @param overrides - `message` replaces the body; `detail` adds/replaces the second line;
|
|
4500
|
+
* `source` identifies the reporter so its own recovery withdraws only its own warning. Give
|
|
4501
|
+
* each independent keyspace its own id — see `brokenSources` for what sharing one costs.
|
|
4502
|
+
*/
|
|
4503
|
+
reportPersistenceBroken(overrides?: {
|
|
4504
|
+
message?: string;
|
|
4505
|
+
detail?: string;
|
|
4506
|
+
source?: string;
|
|
4507
|
+
}): void {
|
|
4508
|
+
const source = overrides?.source ?? DEFAULT_PERSISTENCE_SOURCE;
|
|
4509
|
+
// Delete before set so a repeat report moves this source to the END of the insertion order:
|
|
4510
|
+
// the newest failure is the one whose copy shows.
|
|
4511
|
+
this.brokenSources.delete(source);
|
|
4512
|
+
this.brokenSources.set(source, { message: overrides?.message, detail: overrides?.detail });
|
|
4513
|
+
this.syncPersistenceBrokenCopy();
|
|
4514
|
+
}
|
|
4515
|
+
|
|
4516
|
+
/**
|
|
4517
|
+
* Withdraw one reporter's warning — its save landed, or the host's own store recovered.
|
|
4518
|
+
*
|
|
4519
|
+
* Only `source`'s entry is removed, so a session recovery cannot cancel a host's still-live
|
|
4520
|
+
* project failure (GENC-1511, caught in review; see `brokenSources`). The modal closes
|
|
4521
|
+
* only once nothing is broken; while anything remains, the copy falls back to the newest
|
|
4522
|
+
* survivor.
|
|
4523
|
+
*
|
|
4524
|
+
* @param source - must match the id the failure was reported under.
|
|
4525
|
+
*/
|
|
4526
|
+
reportPersistenceRecovered(source: string = DEFAULT_PERSISTENCE_SOURCE): void {
|
|
4527
|
+
if (!this.brokenSources.delete(source)) return;
|
|
4528
|
+
this.syncPersistenceBrokenCopy();
|
|
4529
|
+
}
|
|
4530
|
+
|
|
4531
|
+
/**
|
|
4532
|
+
* Recompute the derived flag and the displayed copy from `brokenSources`.
|
|
4533
|
+
*
|
|
4534
|
+
* Copy order is last-in-wins, which is both deterministic (`Map` iterates in insertion order)
|
|
4535
|
+
* and the behaviour a reader expects — the most recent failure is the one described. Setting
|
|
4536
|
+
* `persistenceBroken` last means the modal is only ever shown or closed once the copy backing
|
|
4537
|
+
* it is already correct.
|
|
4538
|
+
*/
|
|
4539
|
+
private syncPersistenceBrokenCopy(): void {
|
|
4540
|
+
const newest = [...this.brokenSources.values()].pop();
|
|
4541
|
+
this.persistenceBrokenMessage = newest?.message;
|
|
4542
|
+
this.persistenceBrokenDetail = newest?.detail;
|
|
4543
|
+
this.persistenceBroken = this.brokenSources.size > 0;
|
|
4544
|
+
}
|
|
4545
|
+
|
|
4546
|
+
/** This element's own persister said the session snapshot is not landing (GENC-1511). */
|
|
4547
|
+
private onPersistenceBroken(d: {
|
|
4548
|
+
unsavedMessages: number;
|
|
4549
|
+
lastSavedAt?: string;
|
|
4550
|
+
reason: string;
|
|
4551
|
+
}): void {
|
|
4552
|
+
logger.error('Persistence is not saving — prompting the user to reload:', d.reason);
|
|
4553
|
+
// Composed here, not in the template: the count and the timestamp are facts about the CHAT
|
|
4554
|
+
// session, and a host reporting a different keyspace has its own sentence to write.
|
|
4555
|
+
const when = d.lastSavedAt
|
|
4556
|
+
? ` — the last successful save was at ${new Date(d.lastSavedAt).toLocaleTimeString()}`
|
|
4557
|
+
: '';
|
|
4558
|
+
const detail =
|
|
4559
|
+
d.unsavedMessages > 0
|
|
4560
|
+
? `${d.unsavedMessages} message${d.unsavedMessages === 1 ? '' : 's'} ` +
|
|
4561
|
+
`have not been saved${when}.`
|
|
4562
|
+
: undefined;
|
|
4563
|
+
this.reportPersistenceBroken({ detail, source: SESSION_PERSISTENCE_SOURCE });
|
|
4564
|
+
}
|
|
4565
|
+
|
|
4566
|
+
/**
|
|
4567
|
+
* A session save landed after a broken episode — withdraw OUR warning only (GENC-1511).
|
|
4568
|
+
*
|
|
4569
|
+
* The explicit source is the whole point: a host's project store may still be failing, and
|
|
4570
|
+
* before this was per-source a session recovery closed that modal too.
|
|
4571
|
+
*/
|
|
4572
|
+
private onPersistenceRecovered(): void {
|
|
4573
|
+
this.reportPersistenceRecovered(SESSION_PERSISTENCE_SOURCE);
|
|
4574
|
+
}
|
|
4575
|
+
|
|
4576
|
+
/**
|
|
4577
|
+
* The modal's only action. A reload re-reads the stored snapshot, which is plain data parsed
|
|
4578
|
+
* from the server, so it also clears the serialisation fault that is the most likely cause.
|
|
4579
|
+
*/
|
|
4580
|
+
reloadForPersistence(): void {
|
|
4581
|
+
window.location.reload();
|
|
4582
|
+
}
|
|
4583
|
+
|
|
4354
4584
|
/**
|
|
4355
4585
|
* First-load persistence init for a freshly created store (GENC-1351). Restores
|
|
4356
4586
|
* the user's remembered persistence-toggle choice — kept independently of the
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
|
|
2
|
+
import { DOM } from '@genesislcap/web-core';
|
|
3
|
+
import { FoundationAiAssistant } from './main';
|
|
4
|
+
|
|
5
|
+
// Hold a reference so the custom-element registration isn't tree-shaken.
|
|
6
|
+
FoundationAiAssistant;
|
|
7
|
+
|
|
8
|
+
// GENC-1511 — the blocking "not saving" modal has MORE THAN ONE reporter: this element's own
|
|
9
|
+
// session persister (`sessions/<key>`), and a host reporting its own keyspaces through the public
|
|
10
|
+
// API (Create's `projects/<id>.json`, which holds the app rather than the transcript).
|
|
11
|
+
//
|
|
12
|
+
// It was first built on a single `persistenceBroken` boolean, and review caught what that costs:
|
|
13
|
+
// whichever reporter recovered FIRST closed the modal for both, and the host's own re-entry guard
|
|
14
|
+
// then kept it from ever being raised again. This suite pins the per-source behaviour so that
|
|
15
|
+
// collision cannot come back.
|
|
16
|
+
//
|
|
17
|
+
// Like `blocked-state.test.ts`, this exercises the METHODS the template bindings read rather than
|
|
18
|
+
// the rendered DOM: `document.createElement` upgrades the element (constructor) without connecting
|
|
19
|
+
// it, so `connectedCallback` never runs and nothing subscribes to `agenticActivityBus` — which
|
|
20
|
+
// would otherwise hold the test runner's event loop open.
|
|
21
|
+
const Suite = createLogicSuite('FoundationAiAssistant persistence-broken sources');
|
|
22
|
+
|
|
23
|
+
/** A fresh, unconnected element. Nothing here needs a session store. */
|
|
24
|
+
const element = (): FoundationAiAssistant =>
|
|
25
|
+
document.createElement('foundation-ai-assistant') as FoundationAiAssistant;
|
|
26
|
+
|
|
27
|
+
/** The modal's visible copy, as the template bindings read it. */
|
|
28
|
+
const copy = (el: FoundationAiAssistant) => ({
|
|
29
|
+
broken: el.persistenceBroken,
|
|
30
|
+
message: el.persistenceBrokenMessage,
|
|
31
|
+
detail: el.persistenceBrokenDetail,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const SESSION = 'session';
|
|
35
|
+
const PROJECT = 'project';
|
|
36
|
+
|
|
37
|
+
Suite('a single reporter raises and withdraws its own warning', () => {
|
|
38
|
+
const el = element();
|
|
39
|
+
assert.is(el.persistenceBroken, false);
|
|
40
|
+
|
|
41
|
+
el.reportPersistenceBroken({ detail: '2 messages have not been saved.', source: SESSION });
|
|
42
|
+
assert.is(el.persistenceBroken, true);
|
|
43
|
+
assert.is(el.persistenceBrokenDetail, '2 messages have not been saved.');
|
|
44
|
+
|
|
45
|
+
el.reportPersistenceRecovered(SESSION);
|
|
46
|
+
assert.is(el.persistenceBroken, false);
|
|
47
|
+
assert.is(el.persistenceBrokenMessage, undefined);
|
|
48
|
+
assert.is(el.persistenceBrokenDetail, undefined);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
Suite('one source recovering does NOT withdraw another still-broken source', () => {
|
|
52
|
+
const el = element();
|
|
53
|
+
el.reportPersistenceBroken({ detail: 'session detail', source: SESSION });
|
|
54
|
+
el.reportPersistenceBroken({ message: 'project copy', source: PROJECT });
|
|
55
|
+
|
|
56
|
+
// The session's own save lands. Its warning goes; the project's must not.
|
|
57
|
+
el.reportPersistenceRecovered(SESSION);
|
|
58
|
+
|
|
59
|
+
assert.is(el.persistenceBroken, true, 'modal must stay up while the project store is failing');
|
|
60
|
+
assert.is(el.persistenceBrokenMessage, 'project copy', 'and must still describe THAT failure');
|
|
61
|
+
|
|
62
|
+
el.reportPersistenceRecovered(PROJECT);
|
|
63
|
+
assert.is(el.persistenceBroken, false, 'only once nothing is broken');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
Suite('a later report does not overwrite an earlier source with its own copy', () => {
|
|
67
|
+
const el = element();
|
|
68
|
+
el.reportPersistenceBroken({
|
|
69
|
+
message: 'project copy',
|
|
70
|
+
detail: 'project detail',
|
|
71
|
+
source: PROJECT,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// The session reports with NO message override — it wants the template's session default.
|
|
75
|
+
// Before per-source tracking this assigned `undefined` over the project wording, so the modal
|
|
76
|
+
// claimed "this session has stopped saving" about a failed PROJECT write.
|
|
77
|
+
el.reportPersistenceBroken({ detail: 'session detail', source: SESSION });
|
|
78
|
+
assert.is(el.persistenceBrokenMessage, undefined, 'newest source wins while it is broken');
|
|
79
|
+
assert.is(el.persistenceBrokenDetail, 'session detail');
|
|
80
|
+
|
|
81
|
+
// ...and when the newest recovers, the copy falls BACK to the survivor rather than staying
|
|
82
|
+
// on the recovered source's wording (or reverting to the default).
|
|
83
|
+
el.reportPersistenceRecovered(SESSION);
|
|
84
|
+
assert.is(el.persistenceBrokenMessage, 'project copy');
|
|
85
|
+
assert.is(el.persistenceBrokenDetail, 'project detail');
|
|
86
|
+
assert.is(el.persistenceBroken, true);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
Suite('recovering an unknown or already-recovered source is a no-op', () => {
|
|
90
|
+
const el = element();
|
|
91
|
+
el.reportPersistenceBroken({ message: 'project copy', source: PROJECT });
|
|
92
|
+
|
|
93
|
+
el.reportPersistenceRecovered(SESSION); // never reported
|
|
94
|
+
assert.equal(copy(el), { broken: true, message: 'project copy', detail: undefined });
|
|
95
|
+
|
|
96
|
+
el.reportPersistenceRecovered(PROJECT);
|
|
97
|
+
el.reportPersistenceRecovered(PROJECT); // twice
|
|
98
|
+
assert.equal(copy(el), { broken: false, message: undefined, detail: undefined });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
Suite('re-reporting the same source refreshes its copy without duplicating it', () => {
|
|
102
|
+
const el = element();
|
|
103
|
+
el.reportPersistenceBroken({ detail: '2 messages have not been saved.', source: SESSION });
|
|
104
|
+
el.reportPersistenceBroken({ detail: '5 messages have not been saved.', source: SESSION });
|
|
105
|
+
assert.is(el.persistenceBrokenDetail, '5 messages have not been saved.');
|
|
106
|
+
|
|
107
|
+
// One recovery must clear it — a second entry for the same source would leave it stuck on.
|
|
108
|
+
el.reportPersistenceRecovered(SESSION);
|
|
109
|
+
assert.is(el.persistenceBroken, false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
Suite('a host that omits the source gets a default it can still recover', () => {
|
|
113
|
+
const el = element();
|
|
114
|
+
el.reportPersistenceBroken({ message: 'host copy' });
|
|
115
|
+
assert.is(el.persistenceBroken, true);
|
|
116
|
+
|
|
117
|
+
el.reportPersistenceRecovered();
|
|
118
|
+
assert.is(el.persistenceBroken, false);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
Suite("a host's default source is independent of the session's", () => {
|
|
122
|
+
const el = element();
|
|
123
|
+
el.reportPersistenceBroken({ detail: 'session detail', source: SESSION });
|
|
124
|
+
el.reportPersistenceBroken({ message: 'host copy' });
|
|
125
|
+
|
|
126
|
+
el.reportPersistenceRecovered(); // the host's
|
|
127
|
+
assert.is(el.persistenceBroken, true, 'the session failure is still live');
|
|
128
|
+
assert.is(el.persistenceBrokenDetail, 'session detail');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// GENC-1511 (PR #2472 review) — the deferred show is a separate race from the source tracking.
|
|
132
|
+
// `persistenceBrokenChanged` queues the show via `DOM.queueUpdate`, and the queued callback used
|
|
133
|
+
// not to re-read the flag. A `true → false` inside the same batch runs the `!broken` branch against
|
|
134
|
+
// a modal that was never shown (both statements no-op), and the callback then raised a blocking,
|
|
135
|
+
// NON-DISMISSIBLE modal for a problem that had already fixed itself — with no further change event
|
|
136
|
+
// left to close it, so the only way out was a reload nobody needed.
|
|
137
|
+
//
|
|
138
|
+
// Reachable because `maybeReportBroken` fires before `provider.save` in `persistSession`, so a
|
|
139
|
+
// report and the write that withdraws it can share a tick.
|
|
140
|
+
|
|
141
|
+
/** Minimal stand-in for the design-system modal, recording what the callback did to it. */
|
|
142
|
+
function modalStub() {
|
|
143
|
+
const calls = { show: 0, close: 0 };
|
|
144
|
+
const dialog = document.createElement('dialog');
|
|
145
|
+
return {
|
|
146
|
+
calls,
|
|
147
|
+
modal: {
|
|
148
|
+
open: false,
|
|
149
|
+
mainElement: dialog,
|
|
150
|
+
show() {
|
|
151
|
+
calls.show += 1;
|
|
152
|
+
this.open = true;
|
|
153
|
+
},
|
|
154
|
+
close() {
|
|
155
|
+
calls.close += 1;
|
|
156
|
+
this.open = false;
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Drain the FAST update queue SYNCHRONOUSLY.
|
|
164
|
+
*
|
|
165
|
+
* `DOM.processUpdates()` and not an `await setTimeout(0)`: the queue lands on
|
|
166
|
+
* `requestAnimationFrame`, which a zero-delay timer does not reliably cover. A timer-based flush
|
|
167
|
+
* made these tests pass or fail on scheduling luck — the "does not show" assertion passed for the
|
|
168
|
+
* wrong reason, and its positive control passed only because earlier tests had pumped the queue.
|
|
169
|
+
*/
|
|
170
|
+
const flush = () => DOM.processUpdates();
|
|
171
|
+
|
|
172
|
+
const withModal = (el: FoundationAiAssistant, modal: unknown) => {
|
|
173
|
+
(el as unknown as { persistenceModal: unknown }).persistenceModal = modal;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// POSITIVE CONTROL for the test below. Without it, a queue that never drains in this environment
|
|
177
|
+
// would make the "does not show" assertion pass for entirely the wrong reason.
|
|
178
|
+
Suite('the deferred show DOES raise the modal when the failure is still live', () => {
|
|
179
|
+
const el = element();
|
|
180
|
+
const { calls, modal } = modalStub();
|
|
181
|
+
withModal(el, modal);
|
|
182
|
+
|
|
183
|
+
el.reportPersistenceBroken({ detail: 'session detail', source: SESSION });
|
|
184
|
+
flush();
|
|
185
|
+
|
|
186
|
+
assert.is(calls.show, 1, 'precondition: the queued callback runs in this environment');
|
|
187
|
+
assert.is(modal.open, true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
Suite('a recovery inside the same batch cancels the deferred show', () => {
|
|
191
|
+
const el = element();
|
|
192
|
+
const { calls, modal } = modalStub();
|
|
193
|
+
withModal(el, modal);
|
|
194
|
+
|
|
195
|
+
el.reportPersistenceBroken({ detail: 'session detail', source: SESSION });
|
|
196
|
+
el.reportPersistenceRecovered(SESSION); // lands before the queue flushes
|
|
197
|
+
flush();
|
|
198
|
+
|
|
199
|
+
assert.is(el.persistenceBroken, false);
|
|
200
|
+
assert.is(calls.show, 0, 'must not raise a blocking modal for a resolved failure');
|
|
201
|
+
assert.is(modal.open, false);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
Suite('a recovery of ONE source still shows for the source left broken', () => {
|
|
205
|
+
const el = element();
|
|
206
|
+
const { calls, modal } = modalStub();
|
|
207
|
+
withModal(el, modal);
|
|
208
|
+
|
|
209
|
+
el.reportPersistenceBroken({ detail: 'session detail', source: SESSION });
|
|
210
|
+
el.reportPersistenceBroken({ message: 'project copy', source: PROJECT });
|
|
211
|
+
el.reportPersistenceRecovered(SESSION);
|
|
212
|
+
flush();
|
|
213
|
+
|
|
214
|
+
assert.is(el.persistenceBroken, true);
|
|
215
|
+
assert.is(calls.show, 1, 'the project failure still warrants the modal');
|
|
216
|
+
assert.is(el.persistenceBrokenMessage, 'project copy');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
Suite.run();
|
|
@@ -77,6 +77,7 @@ export type MetaEventType =
|
|
|
77
77
|
| 'session.switch-deferred'
|
|
78
78
|
| 'persistence.toggled'
|
|
79
79
|
| 'persistence.saved'
|
|
80
|
+
| 'persistence.save-failed'
|
|
80
81
|
| 'persistence.suppressed'
|
|
81
82
|
| 'persistence.not-resumable'
|
|
82
83
|
| 'persistence.restored'
|
|
@@ -108,6 +109,9 @@ export const META_EVENT_IMPORTANCE: Record<MetaEventType, MetaEventImportance> =
|
|
|
108
109
|
'context.threshold-crossed': 'high',
|
|
109
110
|
'context.compacted': 'high',
|
|
110
111
|
'persistence.restore-orphan': 'high',
|
|
112
|
+
// A save that did not land is silent data loss in progress: the transcript on screen
|
|
113
|
+
// is no longer backed by the store, and every later turn widens the gap. GENC-1511.
|
|
114
|
+
'persistence.save-failed': 'high',
|
|
111
115
|
|
|
112
116
|
'assistant.connected': 'normal',
|
|
113
117
|
'assistant.disconnected': 'normal',
|