fix(app): snapshot the session before spawning background goroutines - #4230
Merged
Conversation
Start, reEmitStartupInfo and RunSkillFork read a.session from inside the goroutines they spawn, which races with ReplaceSession writing the field from the bubbletea loop. The race detector caught it about one run in five in TestLoadSessionThenClickEditLabel, failing the test-race CI job. Read the field on the caller's goroutine and hand the value to the background work, as Run already does; ReplaceSession re-emits startup info for the new session itself. Adds a regression test that covers all three entry points and fails deterministically under -race without the fix. Fixes #4229
aheritier
enabled auto-merge
September 10, 2026 16:32
trungutt
approved these changes
Sep 11, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4229.
Why
go test -race -shuffle=on ./pkg/tui(thetest-racejob from #4221) still fails about one run in five onTestLoadSessionThenClickEditLabelafter #4228. The race detector points atpkg/app:App.ReplaceSessionwritesa.sessionfrom the bubbletea update loop while the goroutine started byApp.Startreads it to callEmitStartupInfo.reEmitStartupInfoandRunSkillForkhanda.sessionto their goroutines the same way. This is a production race, not a test artifact.What
Start,reEmitStartupInfoandRunSkillForknow reada.sessionon the caller's goroutine and pass the value to the background work, the wayRun/RunWithMessagealready do.ReplaceSessionre-emits startup info for the new session itself, so emitting for the snapshotted session is the intended behavior.TestAppBackgroundWorkSnapshotsSessionBeforeReplacedrives each of the three entry points, callsReplaceSessionright after, and asserts both sessions reach the runtime. Without the fix it fails deterministically under-race(7 race reports across the three subtests).Verification
go test -race -count=3 ./pkg/app: clean.go test -race -count=10 -run TestLoadSessionThenClickEditLabel ./pkg/tui: clean (was ~1 in 5 failing).task lintpasses.Independent of #4228; the two together make
test-racegreen.