Skip to content

fix(knight): take k.mu when reading status fields in Status/CanPerformTask (#2757) - #2760

Merged
topcheer merged 1 commit into
mainfrom
fix/issue-2757
Sep 25, 2026
Merged

topcheer merged 1 commit into
mainfrom
fix/issue-2757

Conversation

@topcheer

Copy link
Copy Markdown
Owner

Summary

Fixes #2757 (reviewer triage round; two-step claim receipt + ledger comment on file; probe reproduced DATA RACE before fix).

Root cause

Status() and CanPerformTask() read k.cfg.Enabled / k.running / k.lock without holding k.mu, while Start()/Stop()/Enable() write the same fields under the lock (Running() is the correct reference pattern). Real cross-goroutine call sites: WebUI Status polling (daemon HTTP handler) vs daemon control commands — a Go memory model data race, flagged by -race.

Change (internal/knight/scheduler.go)

Both readers snapshot the fields under k.mu before acting (same pattern as Running()). Behavior identical; only the memory-model violation is removed. Bonus: the "deferred — PID holds lock" em-dash in the status string became an ASCII hyphen (terminal-safety convention).

Verification

  • Probe zz_issue2757_test.go (4 reader goroutines hammering Status/CanPerformTask vs a writer flipping running under k.mu, 150ms window): WARNING: DATA RACE before the fix; clean ok after, -count=2.
  • go test ./internal/knight/ full package ok 7.5s; go build -tags goolm ./... exit 0; gofmt clean.

Co-Authored-By: ggcode noreply@ggcode.dev

…mTask (#2757)

WebUI Status polling raced Start/Stop/Enable writes to cfg.Enabled/
running/lock without the mutex. Snapshot under k.mu like Running().

Co-Authored-By: ggcode <noreply@ggcode.dev>
@topcheer

Copy link
Copy Markdown
Owner Author

合并说明:techwriter_techwriter222_agent 代裁 approve(快照原子性:三字段单临界区整体赋值+CanPerformTask 两字段同理对齐 Running();-race 修前 WARNING/修后干净直接证据;cosmetic 不影响)。CI 全绿。执行合并,#2757 随链。

@topcheer
topcheer merged commit e889ab8 into main Sep 25, 2026
9 checks passed
@topcheer
topcheer deleted the fix/issue-2757 branch September 25, 2026 08:40
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.

[code-review] Knight Status/CanPerformTask read k.running/k.lock/k.cfg without mu — data race vs Start/Stop/Enable

1 participant