Skip to content

Reject overlapping agent returns without blocking provider callbacks - #1971

Merged
oznetmaster merged 1 commit into
nunit:mainfrom
oznetmaster:fix/provider-return-callback
Nov 16, 2026
Merged

oznetmaster merged 1 commit into
nunit:mainfrom
oznetmaster:fix/provider-return-callback

Conversation

@oznetmaster

Copy link
Copy Markdown
Collaborator

TestAgentService.ReturnAgent holds a per-agent ownership monitor while calling the provider. If the provider waits for a callback on another thread and that callback attempts to return the same agent, the callback cannot complete until the first return finishes. The bounded substitute-provider regressions demonstrate this interaction; this is not a report of an observed production hang in the built-in local provider.

Mark the exact owned agent as returning under the short ownership-index lock, then call the originating provider without holding a bookkeeping lock. Remove ownership only after successful return. Reset the in-progress flag on failure so an explicit later retry remains possible. Current upstream ExitMessage and exit-event forwarding are preserved.

The behavior change to review explicitly is that an overlapping return now throws InvalidOperationException promptly instead of waiting for the first provider call. A failed provider return retains ownership, and a successful return still releases exactly once.

This is an independent two-file correction on main 5f1dae55. It adds no remote implementation, dependency/API-package changes, agent process code or session deployment integration.

Windows validation on net462 and net10.0:

  • Both new cases fail against unchanged main production code, using a bounded callback wait rather than hanging the test run.
  • Both pass with the correction, including failed return followed by a successful retry.
  • Each complete Required suite passes 501 cases, with zero failures and eight existing skips (cat != Pending && cat != Acceptance).
  • Release builds enforce the repository's C# 13, signing and analyzer rules and complete with zero warnings/errors.

Before-failure and after-success receipts are preserved locally. No new native Linux/macOS or hardware validation is claimed; hosted CI is separate from these local results.

Draft for @CharliePoole's review. No merge is requested. Session deployment #1968 remains a separate draft pending Neil's discussion with Charlie.

Prepared jointly by Neil Colvin and OpenAI Codex.

Keep provider I/O outside coordinator bookkeeping locks, preserving retry ownership on failed return. Add two independent registered-substitute regressions that fail before and pass after on both engine targets.

Co-authored-by: OpenAI Codex <codex@openai.com>

@CharliePoole CharliePoole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good and well-tested. Thanks.

@oznetmaster
oznetmaster marked this pull request as ready for review November 16, 2026 22:03
@oznetmaster
oznetmaster merged commit b5de455 into nunit:main Nov 16, 2026
2 of 3 checks passed
@oznetmaster
oznetmaster deleted the fix/provider-return-callback branch November 17, 2026 08:29
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