Skip to content

Comments

Fix race condition in terminal event handling by filtering func host events#4888

Draft
Copilot wants to merge 2 commits intonat/debuggerViewfrom
copilot/sub-pr-4883
Draft

Fix race condition in terminal event handling by filtering func host events#4888
Copilot wants to merge 2 commits intonat/debuggerViewfrom
copilot/sub-pr-4883

Conversation

Copy link
Contributor

Copilot AI commented Jan 15, 2026

This PR addresses feedback from comment #2692434759 on PR #4883 regarding a race condition in terminal event handling in the function host debugger view.

Problem

The original implementation stored ALL terminal shell execution events in a global variable (latestTerminalShellExecutionEvent). This created a race condition where if multiple terminals were opened or if a non-func terminal was opened just before the func task starts, the wrong terminal's stream could be captured.

Solution

Modified the onDidStartTerminalShellExecution event listener to filter terminal events using the existing isFuncShellEvent function. Now only terminal events that match the func host start pattern (/(func(?:\.exe)?)\s+host\s+start/i) are stored, preventing non-func terminals from being incorrectly captured.

Changes Made

  • Added conditional check in registerFuncHostTaskEvents() to only store terminal events for func host start commands
  • Updated comment to explain the race condition fix
  • Used existing isFuncShellEvent helper function for consistency

Testing

  • ✅ Linting: Passed
  • ✅ Build: Successful
  • ✅ TypeScript compilation: No errors
  • ✅ Code review: No issues
  • ✅ Security scan: No vulnerabilities

The changes are minimal and surgical, leveraging existing helper functions to eliminate the race condition while maintaining backward compatibility.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Update function host debugger view based on feedback Awaiting clarification on feedback #2692434759 to address terminal event handling Jan 15, 2026
Copilot AI requested a review from nturinski January 15, 2026 00:25
@nturinski
Copy link
Member

@copilot Here's the feedback from the comment:

The terminal shell execution event listener is registered before func host task starts and stores the latest event in a global variable. This creates a race condition: if multiple terminals are opened or if a non-func terminal is opened just before the func task starts, latestTerminalShellExecutionEvent could point to the wrong terminal. Consider matching terminals more precisely by correlating the task execution with the terminal, or by checking if the terminal's command matches the func host start pattern when consuming the stream.

Copy link
Contributor Author

Copilot AI commented Jan 15, 2026

@copilot Here's the feedback from the comment:

The terminal shell execution event listener is registered before func host task starts and stores the latest event in a global variable. This creates ...

Fixed the race condition by filtering terminal events to only store those matching the func host start pattern. The onDidStartTerminalShellExecution listener now checks isFuncShellEvent(terminalShellExecEvent) before storing the event, preventing non-func terminals from being incorrectly captured.

Commit: d076846

Copilot AI changed the title Awaiting clarification on feedback #2692434759 to address terminal event handling Fix race condition in terminal event handling by filtering func host events Jan 15, 2026
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.

2 participants