* fix(ai): persist AI sessions per record in IndexedDB instead of a 2MB localStorage blob
Closes#4123.
The legacy store serialized every session into one localStorage JSON key
under a 2MB byte budget. Each write re-serialized the whole store, and the
degradation ladder dropped whole oldest sessions when the budget was
exceeded — silently destroying capped chats (~1MB each) on every write.
- add aiSessionIdbStorage: db netcatty_ai_sessions, one record per session
(keyPath id) plus a meta store (schemaVersion, lastWriteAt, mirrored
active-session map); BroadcastChannel replaces the localStorage storage
event for cross-window sync
- one-time boot migration from netcatty_ai_sessions_v1; the legacy key
stays untouched for one release as a read-only fallback
- writeSessionsForStorage now diffs against the last persisted set and
writes only changed records through a serialized queue; the 2MB budget
and its degradation ladder are removed (the global re-serialization cost
they defended no longer exists)
- retention becomes a pure session-count cap (raised 50 -> 1000); the
per-session 200-message cap is unchanged
- when the cap evicts sessions, a pre-eviction backup generation is
written before the records are dropped, closing the #4018 mirror blind
spot; explicit deletions and cloud-authoritative removals do not
trigger it
- boot restore chain: IndexedDB -> legacy localStorage (migration) ->
#4018 disk backup generations; a corrupt/unavailable IndexedDB falls
back to legacy localStorage writes
- tests: IDB roundtrip/migration/active-map mirror via a minimal fake
indexedDB, per-record put/delete diffing, count-cap eviction with
pre-eviction generation, explicit-delete suppression, synced-history
no-prune, corrupt-IDB fallback; byte-ladder tests removed with the
ladder
* test(ai): update fork/undo reload tests to the IndexedDB persistence contract
Issue #4123: session persistence moved to IndexedDB per-record writes; the
persisted set no longer lands in the legacy localStorage key (read-only
fallback for one release) and the retention cap is a session count of 1000
instead of 50.
- fork/undo reload tests read the persisted set via
getPersistedAiSessionsSnapshot() instead of parsing localStorage
- cap-boundary assertions (49/50 newer chats) become preservation
assertions (newerCount + 2 records survive; the 1000-cap boundary is
covered by aiStateSnapshots.test.ts)
- the reload step seeds the read-only legacy store with the persisted set,
the stand-in for what the migration persists on a profile without
IndexedDB
* feat(ai): make the per-session message cap user-configurable
* fix(ai): sequence session sync after boot hydration
Cloud-sync collection (collectAiSessionsForSync) could run before the
IndexedDB boot hydration settled and writeSessionsForStorage() the stale
legacy localStorage list over newer per-record IndexedDB data. The
collection now skips the sync round until the boot load settles; the next
auto-sync picks up the hydrated store.
The hydration signal lives in aiStateSnapshots (isAiSessionsHydrationComplete
/ markAiSessionsHydrationComplete) and is shared with useAIState's boot
effect and the cross-window refresh handler.
* fix(ai): make the legacy session migration one-shot via a persisted marker
The migration keyed on 'IndexedDB empty + legacy populated'. Because the
legacy key is intentionally kept for one release as a read-only fallback,
any boot whose store was empty re-ran the migration and resurrected chats
the user had deleted (P1②).
A migrationCompleted marker is now persisted in the meta store after the
migration data is durable. Once present, the legacy key is never consulted
again: an empty store is authoritative. The marker also records a store
that was already populated by a pre-marker build, and an uninitialized
empty store, so 'intentionally empty' is distinguishable from 'uninitialized'.
* fix(ai): harden boot persistence failure paths
Four review findings around the boot load's failure modes:
- P2①: when IndexedDB fails at boot and sessions come from the legacy
store, the diff baseline was seeded even though nothing was persisted,
so a later edit diff-wrote only the edited record and the rest were
lost after recovery. The legacy set is now persisted best-effort (one
re-open retry) before seeding; if that fails the baseline stays unset
so the next edit rewrites every record.
- P2②: the active-pointer validation effect ran against the
initially-empty in-memory session array and nulled every pointer
before the async load finished. It now waits for the hydration signal.
- P2③: when IndexedDB stayed unopenable and the legacy store was
missing/corrupt, the unconditional recheck threw into the swallowing
outer catch and the #4018 disk backup was never applied. The recheck
failure is now contained (one retry already happens inside open()),
the newest backup generation is applied as the recovery source, and
the error is surfaced via console.warn.
- P2④: a cross-window empty getAll (another window deleted the last
chat) hit an early return, kept the deleted session alive locally and
resurrected it on the next edit. After hydration an empty store is
adopted; the early-return only covers the pre-hydration window.
Scenario regression tests live in useAIState.bootHydration.test.ts;
fakeIndexedDb gains failOpenTimes for counted open failures.
* fix(ai): gate session maintenance and migrate legacy overflow history
* fix(ai): skip backup restore of empty IDB and resume failed overflow migration
* ci: retrigger lint-and-test after runner shutdown
The previous Actions runner received a shutdown signal during plugin-contract
verification; lint had already passed and unit tests never started.
---------
Co-authored-by: GOUKI9999 <GOUKI9999@users.noreply.github.com>
Co-authored-by: 陈大猫 <16399091+binaricat@users.noreply.github.com>
* perf(renderer): cut the startup bundle by a third
Every window parsed ~6.1 MB of JavaScript before the first render. The entry
chunk carried all five UI locales, and the whole AI SDK chunk was preloaded
even though the AI panel is lazy.
- i18n: only English stays in the entry; other dictionaries load on demand
(plus their same-base fallback, e.g. zh-TW -> zh-CN). index.tsx awaits the
saved language before the first render, and I18nProvider re-renders when a
runtime switch finishes loading.
- AI runtime: aiStateSnapshots cleaned up chats through getAgentRuntime(),
and the plugin AI/agent hosts created their runtimes on mount, which pulled
the Catty harness and @ai-sdk providers into startup. Cleanup now goes
through a light handle that the runtime registers (the reversible privacy
flag and main-process privacy mapping are still cleared without a runtime),
and both plugin hosts create their runtime on the first request, re-checking
liveness after the async load.
- Chunking: manualChunks' object form also moved Vite's dynamic-import
preload helper into vendor-ai (the AI SDK itself uses import()), so the
entry imported it from there and vendor-ai (649 KB) was preloaded on every
launch. Vendor chunks now use the function form and the helper gets its own
1 KB chunk.
- jsqr is loaded when a QR image is imported instead of with the host editor.
- startupBundle.architecture.test.ts guards these invariants.
Startup JS (index.html): 5.29 MB entry + 649 KB vendor-ai + 138 KB radix ->
3.80 MB entry + 1 KB helper + 174 KB radix (-35%). Startup harness, 2000 hosts,
10 runs, warm p50: loadURL -> renderer entry evaluated 321 -> 207 ms,
loadURL -> renderer ready 481 -> 323 ms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(i18n): preload locale messages before static rendering
* test(i18n): preload locales in remaining zh-CN UI tests
Non-English dictionaries now load lazily, so I18nProvider can initially render English before its effect finishes loading zh-CN. Explicitly await loadLocaleMessages before rendering these localized UI tests to fix the remaining CI failures without timing-based waits or production changes.
* chore: retrigger CI after locale preload fix
Previous tip 38108ce66 was on the branch but the PR head stayed
stuck on d49ad024e after a GitHub 500 during push. Empty commit
to refresh the PR head and re-queue checks.
* chore: retrigger CI after plugin-contract runner cancel
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Move infrequent Tool Access / MCP / privacy / HTTP setup into focused dialogs; keep status and clear actions on the main page. Rebased onto current main after locale/settings conflicts.
Codex CLEAN (gpt-6.1-terra). CI lint-and-test green. Focused privacy/MCP/guidance tests passed on rebase tip. No release.
Gate ModelSelector discovery on settled error; preserve explicit Refresh and config resets. Component regressions included.
Codex CLEAN (gpt-6.1-terra) vs main. CI green on tip. No release.
Reuse the selection-token snapshot comparison for list and install, including a rejected stale or withdrawn selection. Preserve synchronous unavailable-source validation before the asynchronous list operation. The loaded-row regression rejects installation without downloading or executing a package.
Apply the exact six-file patch from implement_plugin_row_layout, based on 0c05a96fa1. Patch SHA-256: 5c58150fc3a7f72169b1a23ad1410cf37c51051b29bd6600bf30e848a9f366d6. Native visual acceptance remains pending.