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