Skip to content

fix(api): keep GET /chat under Lambda 6MB limit — truncate toolUse inputs + size cap#198

Merged
ShotaroKataoka merged 2 commits into
mainfrom
fix/api-chat-6mb
Jul 8, 2026
Merged

fix(api): keep GET /chat under Lambda 6MB limit — truncate toolUse inputs + size cap#198
ShotaroKataoka merged 2 commits into
mainfrom
fix/api-chat-6mb

Conversation

@ShotaroKataoka

Copy link
Copy Markdown
Contributor

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 toolResult content, but toolUse.input was untouched — write_slide slide JSON bodies and compose_slides slide_groups accumulate at full size in the history.

Changes

Three defenses, extracted into api/chat_history.py as pure functions (no boto3/Powertools — unit-testable):

  1. strip_tool_result_content — moved from inline code in get_chat (behavior unchanged)
  2. truncate_tool_inputs — recursively caps strings inside toolUse.input at 8KB. The UI only renders short scalar fields (slide_id, purpose, slide_groups, instruction), so display is unaffected
  3. cap_messages_size — backstop: when the serialized payload exceeds 4.5MB (headroom below 6MB), drop oldest messages and return truncated: true

UI side: getChatHistory now returns {messages, truncated}; ChatPanel shows an info toast when older messages were omitted — no silent failure.

Testing

  • 9 new unit tests (tests/test_chat_history.py) — make test 260 passed, 1 skipped
  • make lint clean
  • tsc --noEmit zero errors, vitest 38 passed, build:cloud succeeds
  • Pre-existing eslint warnings on ChatPanel/deckService are unchanged (verified via stash comparison)

…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
@ShotaroKataoka ShotaroKataoka added the blog:skip ブログ対象外 label Jul 8, 2026
- drop unused Message / McpServerStatus imports
- remove dead deckName prop from ChatPanel (and its call sites)
- fix useEffect missing-dependency warning via functional setState
@ShotaroKataoka ShotaroKataoka merged commit ccc43e7 into main Jul 8, 2026
11 checks passed
@ShotaroKataoka ShotaroKataoka deleted the fix/api-chat-6mb branch July 8, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blog:skip ブログ対象外

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant