t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Force stop can tear down a queued follow-up that starts during cleanup

Open nima20002000 opened this issue 3 weeks ago • 0 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate.
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

Code-derived deterministic interleaving, not executed:

  1. Create running run A and an unheld queued follow-up B on the same application thread, provider thread, and live session. Have no other working application thread share that session.
  2. Call forceStopThread({ threadId, runId: A.id }).
  3. Use a synchronization barrier to pause Force stop after A’s settlement commits, before session release.
  4. Allow the terminal-run reactor to promote B and start its provider turn on the existing session.
  5. Resume Force stop and let it call the real releaseUnlessBusy.

The unheld queue is necessary: this reproduction does not assume that follow-ups already held by an earlier Stop automatically resume.

Expected behavior

Force stop targeting A should not terminate B after B has started. Session teardown should complete before B starts, or reject teardown once B owns the session.

Actual behavior

Force stop validates A and kills its tracked agent under the thread lock, then releases that lock before settlement and session teardown. A’s settlement permits B to start.

The later release guard ignores busy turns belonging to the captured “own” provider-thread IDs. B reuses one of those IDs, so its busy turn does not prevent session removal. Release then fails session subscribers and closes the runtime scope, affecting B.

Impact

Minor bug or occasional failure

Force stop targeting an older run can fail a newer follow-up on the same thread. It needs a provider that doesn't confirm the stop (or the timing described above), so it is occasional rather than constant.

Version or commit

main @ 9e85538535

Environment

Server integration fixture with a live provider session and controlled synchronization. Runtime environment not tested.

Where


Found by reading the code while porting the Stop / Force stop changes (6b1245cced, 5f2c27e706) into a fork. Derived from the code at 9e85538535; not reproduced at runtime.

nima20002000 avatar Nov 04 '26 16:11 nima20002000