Skip to content

Harden assign_to_agent concurrency: isolate handler state and serialize MCP stdin dispatch - #52034

Open
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/concurrency-fix-assign-to-agent
Open

Harden assign_to_agent concurrency: isolate handler state and serialize MCP stdin dispatch#52034
pelikhan with Copilot wants to merge 8 commits into
mainfrom
copilot/concurrency-fix-assign-to-agent

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

assign_to_agent relied on module-global mutable results and a check-then-await max gate, which allowed cross-invocation state bleed and a TOCTOU race under concurrent dispatch. In parallel, MCP stdio processing could interleave processReadBuffer executions when clients pipelined requests.

  • State isolation in assign_to_agent

    • Moved assignment result storage from module scope to per-main() closure state.
    • Bound summary/output accessors to the returned handler instance (getAssignToAgentAssigned, getAssignToAgentErrors, getAssignToAgentErrorCount, writeAssignToAgentSummary) so data is scoped to a single handler lifecycle.
  • TOCTOU fix for max enforcement

    • Made max gating atomic with early slot reservation (processedCount++ before any await).
    • Preserved defer behavior by releasing the reserved slot when an unresolved temporary ID causes deferral.
  • Serialized MCP stdio dispatch

    • Updated mcp_server_core.start() to chain processReadBuffer calls through a promise queue, preventing overlapping reads/dispatch from concurrent stdin data events.
  • Handler-manager integration update

    • safe_output_handler_manager now reads assign-to-agent outputs/summaries from the loaded handler instance instead of module-level exported state.
  • Regression coverage

    • Added tests for concurrent assign_to_agent invocation with max: 1.
    • Added tests proving independent main() handlers do not share results.
    • Added test verifying pipelined stdin chunks are processed without overlapping tool handler execution.
// before: check then await created a race window
if (processedCount >= maxCount) return skipped;
await sleep(10000);
processedCount++;

// after: reserve before await (atomic gate)
if (processedCount >= maxCount) return skipped;
processedCount++;
if (processedCount > 1) await sleep(10000);

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 19.7 AIC · ⌖ 5.12 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Run: https://github.com/github/gh-aw/actions/runs/31511130973> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.27 AIC · ⌖ 5.37 AIC · ⊞ 8.5K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11.1 AIC · ⌖ 3.4 AIC · ⊞ 8.5K ·
Comment /souschef to run again


Requested branch update from https://github.com/github/gh-aw/actions/runs/31535473039.> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.59 AIC · ⌖ 5.18 AIC · ⊞ 8.5K ·

Comment /souschef to run again


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 14.9 AIC · ⌖ 5.12 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix concurrency safety in assign_to_agent module Harden assign_to_agent concurrency: isolate handler state and serialize MCP stdin dispatch Aug 11, 2026
Copilot AI requested a review from pelikhan August 11, 2026 12:43
@pelikhan
pelikhan marked this pull request as ready for review August 11, 2026 13:01
Copilot AI balanced review requested due to automatic review settings August 11, 2026 13:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens assign_to_agent and MCP stdio concurrency, addressing #51997.

Changes:

  • Isolates assignment results per handler instance.
  • Atomically reserves assignment slots and serializes MCP dispatch.
  • Adds concurrency and state-isolation regression tests.
Show a summary per file
File Description
actions/setup/js/assign_to_agent.cjs Isolates state and changes max enforcement.
actions/setup/js/assign_to_agent.test.cjs Adds concurrency and isolation tests.
actions/setup/js/mcp_server_core.cjs Queues stdin processing.
actions/setup/js/mcp_server_core.test.cjs Tests serialized dispatch.
actions/setup/js/safe_output_handler_manager.cjs Reads results from handler instances.

Review details

Tip

Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread actions/setup/js/assign_to_agent.cjs Outdated
allResults.push({ issue_number: message.issue_number || null, pull_number: message.pull_number || null, agent: agentNameForSkip, owner: null, repo: null, success: false, skipped: true });
return { success: false, skipped: true };
}
processedCount++;
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please refresh this branch, verify checks, and use the pr-finisher skill before handing back.

No failed checks were reported in the compact candidate set for this run.
Branch update was requested by sous-chef in run https://github.com/github/gh-aw/actions/runs/31497194249.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 19.7 AIC · ⌖ 5.12 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please refresh this branch, verify checks, and use the pr-finisher skill before handing back.

No failed checks were reported in the compact candidate set for this run....

Refreshed the branch with current main in 10d2cbc. Local formatting, lint, unit, full test, recompilation, and final PR validation passed; the cited Sous Chef run completed successfully.

Copilot AI requested a review from gh-aw-bot August 11, 2026 14:34
@pelikhan

Copy link
Copy Markdown
Collaborator

/matt

@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — requesting changes on correctness of the deferral-rollback logic and test coverage gaps.

📋 Key Themes & Highlights

Key Issues

  • Deferral-rollback race (correctness): The processedCount-- on deferral creates a window where two concurrent deferred messages can both decrement back below the max gate and both complete on retry — violating max.
  • Test doesn't exercise the real race: The Promise.all concurrent test uses instant mocks, so the gate is already respected before any await; the pre-fix race is never actually reproduced.
  • Delay guard boundary test missing: The processedCount > 1 change to the delay guard lacks a dedicated test for the 1→2 transition.

Positive Highlights

  • ✅ Moving allResults to closure scope is a clean, correct fix for state isolation — no more module-level bleed between invocations.
  • ✅ Attaching accessors directly to the handler function is an elegant pattern that avoids threading an extra argument through call sites.
  • ✅ Promise-chaining for MCP stdio serialization is the right approach and the new test correctly verifies sequential dispatch.
  • ✅ Extraction of formatAssignedOutput, formatErrorsOutput, countHardFailures, and writeAssignSummary as pure functions improves testability.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 42.7 AIC · ⌖ 7.4 AIC · ⊞ 7.1K
Comment /matt to run again

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please address the open review feedback, refresh the branch if needed, and use the pr-finisher skill before handing back.

Open review threads (newest reviewer feedback first):

No failed checks were reported in the compact candidate set for this run.
Branch update was requested by sous-chef in run https://github.com/github/gh-aw/actions/runs/31511130973.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.27 AIC · ⌖ 5.37 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please address the open review feedback, refresh the branch if needed, and use the pr-finisher skill before handing back.

Open review threads (newest reviewer feedback first):...

Addressed the max-slot review feedback in 2b675e6: validation and deferral occur before reservation, and the delayed concurrent 1→2 boundary is regression-tested. The branch already includes current main; local validation and the pr-finisher checks passed.

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage: #52034

  • Category: bug
  • Risk: medium
  • Priority score: 62/100 (impact 30/50, urgency 20/30, quality 12/20) → high
  • Recommended action: fast_track

Automated triage — see labels for machine-readable classification.

Generated by 🔧 PR Triage Agent · auto · 45 AIC · ⌖ 2.09 AIC · ⊞ 7.8K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please refresh this branch, verify checks, and use the pr-finisher skill before handing back.

Unresolved review threads to address (newest first):

No failed checks were reported in the compact candidate set for this run.

Branch update was requested by sous-chef in run https://github.com/github/gh-aw/actions/runs/31531364207.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 11.1 AIC · ⌖ 3.4 AIC · ⊞ 8.5K ·
Comment /souschef to run again

…ix-assign-to-agent

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please refresh this branch, verify checks, and use the pr-finisher skill before handing back.

Unresolved review threads to address (newest first):...

Refreshed with current main in 5b89af51c0. The unresolved review thread is outdated: 2b675e6 validates and defers before atomically reserving the assignment slot. make fmt, make lint, make test-unit, make test, make recompile, and make agent-report-progress passed; the last referenced CI run completed successfully.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please refresh this branch, verify checks, and use the pr-finisher skill before handing back.

No failed checks were reported in the compact candidate set for this run.

Branch update was requested by sous-chef in run https://github.com/github/gh-aw/actions/runs/31535473039.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.59 AIC · ⌖ 5.18 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please refresh this branch, verify checks, and use the pr-finisher skill before handing back.

No failed checks were reported in the compact candidate set for this run....

The branch already contains current main (c993af6) via 5b89af51c0; no further refresh was needed. The referenced Sous Chef run succeeded with no failed jobs. make fmt, make lint, make test-unit, make test, make recompile, and make agent-report-progress passed.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot This PR looks ready for another finishing pass. Please refresh the branch context, address any remaining reviewer feedback, and run the pr-finisher skill before handing back to maintainers.

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 14.9 AIC · ⌖ 5.12 AIC · ⊞ 8.5K ·
Comment /souschef to run again

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot This PR looks ready for another finishing pass. Please refresh the branch context, address any remaining reviewer feedback, and run the pr-finisher skill before handing back to maintainers....

Finishing pass complete. 5b89af51c0 already includes current main; no actionable reviewer feedback remains. make fmt, make lint, make test-unit, make test, make recompile, and make agent-report-progress passed. Prior CI is green; the current Copilot check is still in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[concurrency] Concurrency safety: assign_to_agent module-level state + unserialized MCP stdio dispatch

4 participants