Skip to content

Fix module-level mutable state in create_agent_session.cjs handler - #52696

Open
pelikhan with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-concurrency-safety-issue
Open

Fix module-level mutable state in create_agent_session.cjs handler#52696
pelikhan with Copilot wants to merge 4 commits into
mainfrom
copilot/fix-concurrency-safety-issue

Conversation

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

create_agent_session.cjs stored per-run results in a module-level let _allResults = [], shared across every main() invocation for the lifetime of the process (due to Node's require() caching). Sequential processing masked the bug today, but any future parallel dispatch or repeated main() call in the same process could cross-contaminate results between runs, corrupting session_number/session_url outputs and step summaries.

State isolation

  • Removed the module-level _allResults array entirely.
  • allResults is now a const declared inside main(), scoped to that invocation's closure.

Accessor relocation

  • getSessionNumber, getSessionUrl, and writeSummary are now attached as properties on the handleMessage function returned by main(), each closing over its own allResults, instead of being exported as module-level functions reading shared state.
  • module.exports now only exposes main.

Caller update

  • safe_output_handler_manager.cjs retrieves the specific handler instance from messageHandlers and invokes the accessors on it directly:
const createAgentSessionHandler = messageHandlers.get("create_agent_session");
const sessionNumber = createAgentSessionHandler.getSessionNumber();
const sessionUrl = createAgentSessionHandler.getSessionUrl();
await createAgentSessionHandler.writeSummary();

Tests

  • Updated existing tests to call the accessors on the handler instance rather than the module.
  • Added a regression test creating two independent main() invocations and interleaving their message processing to verify results never mix between handler instances.

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


Generated by 👨‍🍳 PR Sous Chef · gpt54 · 8.41 AIC · ⌖ 6.61 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 issue in create_agent_session tool Fix module-level mutable state in create_agent_session.cjs handler Aug 14, 2026
Copilot AI requested a review from pelikhan August 14, 2026 11:35
@github-actions

Copy link
Copy Markdown
Contributor

PR Triage\n\n- Category: bug\n- Risk: medium\n- Priority: medium\n- Score: 52/100 (impact 35 + urgency 10 + quality 7)\n- Recommended action: batch_review\n

Generated by 🔧 PR Triage Agent · auto · 62.8 AIC · ⌖ 2.76 AIC · ⊞ 7.8K ·

@pelikhan
pelikhan marked this pull request as ready for review August 14, 2026 16:19
Copilot AI balanced review requested due to automatic review settings August 14, 2026 16:19

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

Isolates agent-session results per handler invocation, preventing cross-run contamination.

Changes:

  • Moves mutable results into main() closure scope.
  • Exposes result accessors on each handler instance.
  • Updates manager integration and adds regression coverage.
Show a summary per file
File Description
actions/setup/js/create_agent_session.cjs Introduces per-instance result state and accessors.
actions/setup/js/safe_output_handler_manager.cjs Reads outputs from the loaded handler instance.
actions/setup/js/create_agent_session.test.cjs Updates accessor tests and verifies state isolation.

Review details

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Branch refresh has been requested for this PR via the update-branch action. Please run the pr-finisher skill, verify the concurrency fix remains covered, and summarize any remaining maintainer-facing blockers in one comment.

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

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Branch refresh has been requested for this PR via the update-branch action. Please run the pr-finisher skill, verify the concurrency fix remains covered, and summarize any remaining maintai...

Ran the pr-finisher pass:

  • ✅ Reviews — No unresolved review threads; nothing to address.
  • ✅ Checks (local) — create_agent_session.test.cjs (26 tests, incl. the concurrency regression test) pass; lint-cjs clean for the changed file (0 errors); fmt-cjs produced no diffs; test-unit has no impacted Go tests since only JS files changed.
  • ❓ Checks (CI) — stale after this pass; only an in-progress copilot check is visible, no other CI has run against the current HEAD (490f8d5). Needs a maintainer re-trigger to get a fresh signal.
  • ❓ Mergeable — GitHub reports mergeable_state: blocked. Branch is up to date with main (already merged) and has no open review threads or conflicts, so this is blocked on required status checks / reviewer approval (pelikhan requested), not on anything the agent can fix.

No code changes were needed in this pass — the concurrency fix and its regression test remain intact and passing.

Still needed: maintainer re-trigger of CI and review/approval from @pelikhan.

@github-actions

Copy link
Copy Markdown
Contributor

PR Triage

  • Category: bug
  • Risk: medium
  • Priority: medium (score: 52/100)
  • Score breakdown: impact 22/50, urgency 12/30, quality 18/20
  • Recommended action: batch_review
  • Batch: bugfix-medium-cluster

Automated triage by PR Triage Agent.

Generated by 🔧 PR Triage Agent · auto · 64.3 AIC · ⌖ 2.94 AIC · ⊞ 7.8K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please run the pr-finisher skill and summarize the maintainer-ready state in one comment, including any review or CI blockers still open.

Run: https://github.com/github/gh-aw/actions/runs/31833406387

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

Copilot AI commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please run the pr-finisher skill and summarize the maintainer-ready state in one comment, including any review or CI blockers still open.

Run: https://github.com/github/gh-aw/actions/run...

Ran another pr-finisher pass:

  • ✅ Reviews — No unresolved review threads. The only review on file is a non-blocking COMMENTED review from copilot-pull-request-reviewer[bot] with 0 comments generated.
  • ✅ Checks (local) — create_agent_session.test.cjs (26 tests, incl. the concurrency regression test) pass; fmt-cjs produces no diff; no Go files changed relative to main, so test-unit's impacted-Go check is a no-op. The branch was already merged with the latest main (including the Firecracker-removal commit) with no conflicts and no changes to the files touched by this PR.
  • ❓ Checks (CI) — The CJS check on the latest commit (98b76b6) shows action_required with 0 jobs run — this is a workflow-approval gate (same status on every prior commit in this PR, including ones before my changes), not a code failure, and isn't something I can resolve as an agent. Needs a maintainer to approve the workflow run.
  • ❓ Mergeable — mergeable_state: blocked, consistent with the pending workflow approval / required reviewer approval (pelikhan, gh-aw-bot requested) rather than any code or conflict issue.

No code changes were needed — the concurrency fix and its regression test remain intact and passing after the merge with main.

Still needed: a maintainer to approve/re-run the gated CI workflows and provide review approval.

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 Issue in create_agent_session tool: module-level mutable state

4 participants