Skip to content

Remove deepcopy and reduce memory allocations to prevent Lambda OOM#2321

Merged
hiroshinishio merged 1 commit intomainfrom
wes
Feb 24, 2026
Merged

Remove deepcopy and reduce memory allocations to prevent Lambda OOM#2321
hiroshinishio merged 1 commit intomainfrom
wes

Conversation

@hiroshinishio
Copy link
Collaborator

Summary

  • Removed deepcopy(messages) in remove_outdated_apply_diff_to_file_attempts_and_results - this was duplicating the entire conversation history (all messages, diffs, tool results) on every Claude API call. At 38+ rounds with growing history, this alone could account for hundreds of MB.
  • Changed [system_msg] + list(messages) to [system_msg, *messages] in chat_with_claude to avoid an unnecessary intermediate list copy.
  • Added gc.collect() with RSS logging after each agent loop iteration in all 3 handlers to force garbage collection of temporary objects between rounds.
  • Extracted get_rss_mb() into a shared utility (utils/memory/get_rss_mb.py) to deduplicate RSS measurement logic between is_lambda_oom_approaching and the new gc_collect_and_log utility.

@hiroshinishio hiroshinishio self-assigned this Feb 24, 2026
@hiroshinishio hiroshinishio merged commit 241b9f1 into main Feb 24, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch February 24, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant