Skip to content

fix: prevent unobserved SocketException in ServerManager.CheckServerRunning#192

Merged
PureWeen merged 4 commits intomainfrom
fix/polypilot-has-an-assistant-mobile-app-co-20260223-1330
Feb 23, 2026
Merged

fix: prevent unobserved SocketException in ServerManager.CheckServerRunning#192
PureWeen merged 4 commits intomainfrom
fix/polypilot-has-an-assistant-mobile-app-co-20260223-1330

Conversation

@StephaneDelcroix
Copy link
Collaborator

Problem

ServerManager.CheckServerRunning() uses the legacy BeginConnect/EndConnect APM pattern but doesn't call EndConnect() when the connection is refused or times out. This leaves the internal Task's exception unobserved, causing TaskScheduler.UnobservedTaskException to fire during GC and spam crash.log with SocketException (Connection refused) entries.

Fix

  • ServerManager.cs: Replace BeginConnect/EndConnect with modern ConnectAsync + CancellationToken. The cancellation token handles the 1-second timeout, and the synchronous .GetAwaiter().GetResult() properly observes any exception.
  • WsBridgeClient.cs: Observe the abandoned connectTask in the 15-second timeout path via ContinueWith(OnlyOnFaulted) to prevent the same class of unobserved exception.

Tests

  • Added ServerManagerTests.cs with 5 tests covering: connection refused, successful connection, no unobserved exceptions after GC, unreachable host timeout, and default port usage.
  • Added ServerManager.cs compile include to test project.

StephaneDelcroix and others added 2 commits February 23, 2026 14:35
…unning

Replace BeginConnect/EndConnect APM pattern with modern ConnectAsync +
CancellationToken. The old code didn't call EndConnect when the connection
was refused or timed out, leaving the internal Task's exception unobserved.
When GC collected these Tasks, TaskScheduler.UnobservedTaskException fired,
spamming crash.log with SocketException (Connection refused) entries.

Also observe the abandoned connectTask in WsBridgeClient's timeout path
via ContinueWith to prevent the same class of unobserved exception.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace Thread.Sleep(200) with ManualResetEventSlim.Wait(500ms) in
  NoUnobservedTaskException test so the assertion fires immediately if
  the event occurs rather than relying on an arbitrary sleep window
- Remove CheckServerRunning_ReturnsFalse_WhenHostUnreachable: the
  192.0.2.1 address is unreliable across VPN/container environments
  and blocks for the full 1s CTS timeout; the false-return behavior
  is already covered by WhenNoServerListening
- Change 'return client.Connected' to 'return true': ConnectAsync
  either throws or returns with the connection established, so
  Connected can never be false on the success path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PureWeen added a commit that referenced this pull request Feb 23, 2026
## Summary

Two changes to improve the Squad-based PR review workflow.

### How to use

1. Click **+** in the sidebar → select **PR Review Squad** from "📂 From
Repo"
2. Click the **orchestrator** session
3. Send: `Review PRs #194, #193, #191, #192, #190`
4. The orchestrator assigns 1 PR per worker, each worker dispatches 5
sub-agents across different models, and the orchestrator produces a
summary table with verdicts

The mode is automatically set to **Orchestrator** via `mode:
orchestrator` in `team.md` — no manual mode selection needed.

### Example output

The orchestrator produces a summary table like:

| PR | Verdict | Key Issues |
|----|---------|------------|
| #194 | ⚠️ Needs changes | cursor:pointer without click handler,
brittle test regex |
| #193 | ⚠️ Needs changes | Incomplete state sync → infinite unthrottled
renders |
| #191 | ✅ Ready to merge | Clean — concerns were pre-existing patterns
|
| #192 | ⚠️ Needs changes | GC-finalization test unreliable, flaky IP
test |
| #190 | ⚠️ Needs changes | Tests don't guard actual regression |

Each worker's detailed report includes only issues flagged by 2+ models
(consensus filter), with file:line references and severity ratings.

---

### 1. Restructure PR Review Squad for multi-model consensus

Replaces 5 specialized reviewers (bug-hunter, security-analyst, etc.)
with 5 generic reviewers that each independently perform a full
multi-model consensus review.

Each worker:
1. Fetches the PR diff via `gh pr diff` / `gh pr view`
2. Dispatches 5 parallel sub-agent reviews across different models:
   - 2× `claude-opus-4.6` (deep bug analysis + architecture review)
   - 1× `claude-sonnet-4.6` (correctness + edge cases)
   - 1× `gemini-3-pro-preview` (security focus)
   - 1× `gpt-5.3-codex` (code quality + logic errors)
3. Synthesizes findings using a consensus filter (2+ models must flag an
issue)
4. Produces a severity-ranked report with file:line references and a
verdict

### 2. Support `mode:` field in team.md

`SquadDiscovery` now reads an optional `mode:` line from `team.md` to
set the multi-agent mode automatically. Previously hardcoded to
`OrchestratorReflect`.

Supported values: `broadcast`, `sequential`, `orchestrator`,
`orchestrator-reflect`

```markdown
# My Team
mode: orchestrator
```

### Tests
- 6 new tests for `ParseMode` covering all modes + case insensitivity +
default behavior
- All tests pass

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PureWeen and others added 2 commits February 23, 2026 11:10
- CheckServerRunning_DefaultPort test now actually asserts return value
  instead of discarding it
- ContinueWith in WsBridgeClient uses TaskScheduler.Default to avoid
  marshaling to ambient SynchronizationContext

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add assertion on defaultResult so the variable is not dead code.
The server may or may not be running on 4321, so we verify the call
completed without throwing rather than asserting a specific value.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PureWeen PureWeen merged commit 2b40adc into main Feb 23, 2026
@PureWeen PureWeen deleted the fix/polypilot-has-an-assistant-mobile-app-co-20260223-1330 branch February 23, 2026 17:33
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