Files
cg33 5e2d501f27 fix(core): align drainPendingMessages agentSession capture with #1436
Follow-up to #1436. The third call site in drainPendingMessages was
modeled correctly in spirit (capture into local var before goroutine)
but missed two details that #1436 applied to the first two sites:

1. The capture `as := state.agentSession` happened without holding
   state.mu, so the same race the PR set out to fix could still nil
   the field between the unlock above and the capture.
2. The Send goroutine did not have a defensive `if as == nil` check,
   unlike the other two sites; a nil capture would still panic when
   the goroutine ran.

Also folds the existing nil/Alive check into the post-capture path so
the gating uses the local copy (consistent with the new contract).

No behavior change for the happy path; in the racy path the goroutine
returns an error instead of dereferencing nil, which the existing
error handling already covers.

Verified locally:
- go vet ./... clean
- go build clean
- go test -race ./core -run TestCUJ_H2_TwoPlatformsConcurrentNoBleed -count=10 PASS
- go test ./core -run "Drain|Queue" PASS
2026-06-28 20:56:25 +08:00
..