twenty/packages
Sonarly Claude Code e87fea949e fix(twenty-front): add eviction to atom family cache and deduplicate AI chat message storage
https://sonarly.com/issue/27119?type=bug

Chrome tab crashes with OOM (error code 5) because the Jotai atom family cache (`atomCache` Map) never evicts entries, and each AI chat message is stored three times (thread-level atom, per-message atom via structuredClone, Apollo InMemoryCache), causing unbounded heap growth during long conversations, rapid workspace switching, or Settings page navigation.

Fix: Three changes that address the two largest memory growth vectors in the AI chat module:

1. **Added `evictFamilyKey` to `ComponentFamilyState`** (`ComponentFamilyState.ts` type + `createAtomComponentFamilyState.ts` implementation): Exposes `atomCache.delete()` so consumers can remove atoms they no longer need. This is the missing primitive — the atomCache Map previously had no way to remove entries.

2. **Evict per-message atoms on thread switch** (`AgentChatStreamingPartsDiffSyncEffect.tsx`): Tracks message IDs seen during diff sync in a ref. When `currentAIChatThread` changes, the cleanup effect fires and calls `evictFamilyKey` for every tracked message ID, removing those atoms from the cache. This prevents the biggest accumulation vector: hundreds of per-message atoms (keyed by UUID) holding large ExtendedUIMessage payloads that were never released.

3. **Remove `structuredClone` from `useUpdateStreamingPartsWithDiff.ts`**: The deep clone was creating a full copy of every message object before storing it in the per-message atom. Since `isDeeplyEqual` already gates updates (preventing unnecessary writes), and the message reference from the thread-level atom is stable within a render cycle, the clone is unnecessary. Removing it eliminates one full copy of every message in memory.

Together these changes bound per-message atom memory to the current thread's messages (instead of all threads ever viewed), and halve the per-message memory footprint by eliminating deep clones.

**Not addressed in this PR** (requires separate, wider-scoped changes):
- Apollo InMemoryCache eviction — needs typePolicies configuration in the shared Apollo factory
- Thread-level family state atoms (10 per thread) — small scalar values, low priority
2026-04-16 15:09:00 +00:00
..
create-twenty-app Release v1.22.0 for twenty-sdk, twenty-client-sdk, and create-twenty-app (#19751) 2026-04-16 08:29:50 +00:00
twenty-apps Upgrade self hosting application (#19680) 2026-04-14 11:21:18 +00:00
twenty-cli 1774 extensibility v1 create an exhaustive documentation readme or dedicated section in twenty contributing doc (#16751) 2025-12-22 15:19:11 +01:00
twenty-client-sdk Link command menu items to specific page layout (#19706) 2026-04-16 12:07:36 +00:00
twenty-companion Migrate twenty-companion from npm to yarn workspaces (#18946) 2026-03-25 10:45:43 +01:00
twenty-docker Add APPLICATION_LOG_DRIVER=CONSOLE to twenty-app-dev container (#19600) 2026-04-12 11:55:38 +02:00
twenty-docs i18n - docs translations (#19710) 2026-04-14 22:35:59 +02:00
twenty-e2e-testing Fix e2e (#19639) 2026-04-13 15:13:11 +02:00
twenty-emails i18n - translations (#18956) 2026-03-25 14:23:30 +01:00
twenty-front fix(twenty-front): add eviction to atom family cache and deduplicate AI chat message storage 2026-04-16 15:09:00 +00:00
twenty-front-component-renderer Add event forwarding stories to the front component renderer (#19721) 2026-04-16 08:55:49 +00:00
twenty-oxlint-rules add workspaceId to indirect entities (#19522) 2026-04-09 19:30:28 +00:00
twenty-sdk Release v1.22.0 for twenty-sdk, twenty-client-sdk, and create-twenty-app (#19751) 2026-04-16 08:29:50 +00:00
twenty-server chore(server): drop api-host branch in OAuth discovery (#19768) 2026-04-16 17:01:55 +02:00
twenty-shared Fix app design 1/2 (#19735) 2026-04-16 09:47:44 +00:00
twenty-ui Fix app design 1/2 (#19735) 2026-04-16 09:47:44 +00:00
twenty-utils Refactor dependency graph for SDK, client-sdk and create-app (#18963) 2026-03-26 10:56:52 +00:00
twenty-website Add AI as a public feature flag in the Lab (#19277) 2026-04-02 15:56:27 +00:00
twenty-website-new [Website] Resolve animations breaking due to renderer context being lost. (#19747) 2026-04-16 08:50:56 +00:00
twenty-zapier Deprecate legacy RICH_TEXT field metadata type (#18623) 2026-03-13 17:25:40 +01:00