fix(api): keep GET /chat under Lambda 6MB limit — truncate toolUse inputs + size cap#198
Merged
Conversation
…puts + size cap
toolResult stripping existed, but toolUse.input was untouched: write_slide
slide JSON bodies and compose slide_groups accumulate in long conversations
and can push the response past the 6MB Lambda limit, failing history load
entirely.
- api/chat_history.py: pure functions (strip toolResult content, truncate
input strings >8KB, drop oldest messages past a 4.5MB budget with a
truncated flag)
- UI: getChatHistory returns {messages, truncated}; ChatPanel shows an
info toast when older messages were omitted
- tests: 9 unit tests for the shaping functions
- drop unused Message / McpServerStatus imports - remove dead deckName prop from ChatPanel (and its call sites) - fix useEffect missing-dependency warning via functional setState
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Roadmap item 3-7: GET /chat could exceed Lambda's 6MB response limit on long conversations, failing history load entirely.
The existing code stripped
toolResultcontent, buttoolUse.inputwas untouched —write_slideslide JSON bodies andcompose_slidesslide_groups accumulate at full size in the history.Changes
Three defenses, extracted into
api/chat_history.pyas pure functions (no boto3/Powertools — unit-testable):strip_tool_result_content— moved from inline code inget_chat(behavior unchanged)truncate_tool_inputs— recursively caps strings insidetoolUse.inputat 8KB. The UI only renders short scalar fields (slide_id,purpose,slide_groups,instruction), so display is unaffectedcap_messages_size— backstop: when the serialized payload exceeds 4.5MB (headroom below 6MB), drop oldest messages and returntruncated: trueUI side:
getChatHistorynow returns{messages, truncated}; ChatPanel shows an info toast when older messages were omitted — no silent failure.Testing
tests/test_chat_history.py) —make test260 passed, 1 skippedmake lintcleantsc --noEmitzero errors, vitest 38 passed,build:cloudsucceeds