| ... | ... | @@ -31,7 +31,6 @@ const BUFFERED_MESSAGE_TEXT_BY_MESSAGE_ID_TTL = Duration.minutes(120); |
| 31 | 31 | const BUFFERED_ASSISTANT_MESSAGE_SPILLED_CACHE_CAPACITY = 20_000; |
| 32 | 32 | const BUFFERED_ASSISTANT_MESSAGE_SPILLED_TTL = Duration.minutes(120); |
| 33 | 33 | const MAX_BUFFERED_ASSISTANT_CHARS = 24_000; |
| 34 | | const BUFFERED_ASSISTANT_KEEP_CHARS = 8_000; |
| 35 | 34 | |
| 36 | 35 | type TurnStartRequestedDomainEvent = Extract< |
| 37 | 36 | OrchestrationEvent, |
| ... | ... | @@ -245,12 +244,9 @@ const make = Effect.gen(function* () { |
| 245 | 244 | return ""; |
| 246 | 245 | } |
| 247 | 246 | |
| 248 | | // Safety valve: spill oldest text as a persisted assistant delta to cap memory. |
| 249 | | const spillChars = Math.max(1, nextText.length - BUFFERED_ASSISTANT_KEEP_CHARS); |
| 250 | | const spillChunk = nextText.slice(0, spillChars); |
| 251 | | const retainedTail = nextText.slice(spillChars); |
| 252 | | yield* Cache.set(bufferedAssistantTextByMessageId, messageId, retainedTail); |
| 253 | | return spillChunk; |
| 247 | // Safety valve: spill full buffered text as a persisted assistant delta to cap memory. |
| 248 | yield* Cache.invalidate(bufferedAssistantTextByMessageId, messageId); |
| 249 | return nextText; |
| 254 | 250 | }), |
| 255 | 251 | ), |
| 256 | 252 | ); |