Skip to content

Avoid main-thread hangs by size-capping and lazily indexing known files for edit path inference - #3430

Open
sentry[bot] wants to merge 2 commits into
mainfrom
seer/fix-tool-envelope-main-thread-hang
Open

sentry[bot] wants to merge 2 commits into
mainfrom
seer/fix-tool-envelope-main-thread-hang

Conversation

@sentry

@sentry sentry Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where ChatSession.rebuildVisibleBlocks (called on the main actor via completeRunCleanup when a run finishes) hangs the UI for over 3 seconds parsing multi-megabyte file_read tool payloads via ToolEnvelope.successPayload.

Changes

  • Behavior change
  • UI change
  • Refactor / chore
  • Tests
  • Docs
  1. Cap file_read payload parsing: In ContentBlock.knownFileContents, guard result.utf8.count <= knownFileParseByteLimit (1 MB) before invoking ToolEnvelope.successPayload. The index only retains the first 256 KB of text per file anyway, so parsing multi-megabyte JSON payloads on the main actor was wasteful and caused UI hangs.
  2. Memoize known-files index per rebuild: In ContentBlock.generateBlocks, build the known-files index lazily at most once per rebuild instead of re-evaluating it for every failed or streaming file edit.
  3. Defer known-files evaluation: In FileDiff.inferredEditPath, make knownFiles an @autoclosure so the index is only evaluated when the streaming old_string excerpt is actually long enough (≥24 chars) to disambiguate a path.
  4. Unit tests: Added regression tests covering deferral in FileDiffStreamingPreviewTests and size-cap filtering in FileReadImageAndFormatContractTests.

Test Plan

Regression tests were added in FileDiffStreamingPreviewTests (deferral of known-files evaluation) and FileReadImageAndFormatContractTests (size-cap filtering).

Checklist

  • I have read CONTRIBUTING.md
  • I added/updated tests where reasonable
  • I updated docs/README as needed
  • I verified build on macOS with Xcode 16.4+

Fixes APPLE-MACOS-3VR

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry at no cost. You can adjust this setting at any time.

This branch has not been deployed

No deployments
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.

0 participants