Skip to content

Guard the @-mention lookup against a disposed shell - #335

Merged
TheGreatAxios merged 2 commits into
release/tui-bugfixesfrom
cl-5554-use-after-free-when-quitting-during-an-mention-lookup
Aug 7, 2026
Merged

Guard the @-mention lookup against a disposed shell#335
TheGreatAxios merged 2 commits into
release/tui-bugfixesfrom
cl-5554-use-after-free-when-quitting-during-an-mention-lookup

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Check shell.disposed right after each await in openAtMentionSuggestions and in attachClipboardImage — the only two continuations in shell.ts that resume after an await and then unconditionally write into shell/renderable state — and bail out before any further mutation
  • Add regression tests that dispose the shell while each lookup is pending and assert the continuation does not run its post-await writes

Verification

  • shell.ts has exactly three await sites: two in openAtMentionSuggestions, one in attachClipboardImage. All three now check shell.disposed before touching shell state or renderables.
  • Both new tests fail without the corresponding guard (verified by reverting each fix locally and re-running) and pass with it.
  • Caveat: these are headless assertions on return values and shell fields (resolves.toBe(false), overlayKind, pendingAttachments). They show the guarded code path is not reached after dispose, which is strong evidence the writes are prevented — but they do not exercise real native TextBuffer/renderer memory, so they cannot themselves prove the underlying use-after-free/segfault is impossible. Confidence in the fix rests on the code guard (check-before-mutate at every resume point), not on the test alone.
  • bun run typecheck and bun run build pass.
  • bun test: 4314 pass, 1 pre-existing failure unrelated to this change (tests/integration/reactor-permission-multi-turn.test.ts, plus two markdown-rows.test.ts cases in a full run) — reproduces identically on this branch with the fix stashed out, so it predates this work.

Closes CL-5554

Quitting while an @-mention filesystem lookup is in flight let the
resolved promise write suggestions into a torn-down shell, touching
the freed renderer/TextBuffer. Check shell.disposed after each await
in openAtMentionSuggestions and bail before any further write.
@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

CL-5554

attachClipboardImage was the same shape as the mention lookup: it
awaits the clipboard read, then unconditionally attaches into
shell.pendingAttachments and flashes status. Check shell.disposed
right after the await, before any of that runs.

This was the third and last await in shell.ts; the other two (both in
openAtMentionSuggestions) were already guarded.
@TheGreatAxios
TheGreatAxios changed the base branch from main to release/tui-bugfixes August 7, 2026 04:20
@TheGreatAxios
TheGreatAxios merged commit 058c803 into release/tui-bugfixes Aug 7, 2026
2 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-5554-use-after-free-when-quitting-during-an-mention-lookup branch August 7, 2026 06:35
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