Skip to content

[Bug]: Data race in debug key capture (DebugKeysCommand.CaptureSequence) #342

@ben-ranford

Description

@ben-ranford

Bug Description

Concurrent calls to DebugKeysCommand.CaptureSequence() can race on dkc.sequences appends/writes, causing non-deterministic behaviour and race detector failures.

Steps to Reproduce

Steps to reproduce the behaviour:

  1. Check out branch main before PR [bug] debug-keys-capture-sequence-race #341.
  2. Run command go test -race ./internal/keybindings -run TestDebugKeysCommand_ConcurrentAccess -count=1.
  3. See WARNING: DATA RACE with stack traces pointing to CaptureSequence() in internal/keybindings/parser.go.

Expected Behavior

Concurrent key capture should be thread-safe and deterministic, with no race detector warnings.

Screenshots

N/A

Environment

  • OS: Darwin 25.2.0
  • Go Version: go1.25.7 darwin/arm64
  • ggc Version: v7 (source build)
  • git Version (run git --version): git version 2.39.5 (Apple Git-154)

Additional Context

  • Root cause: shared mutable fields (capturing, sequences) were read/written across StartCapture, CaptureSequence, StopCapture, and IsCapturing without synchronisation.
  • Fix is in PR [bug] debug-keys-capture-sequence-race #341, which adds mutex protection, snapshots sequences in StopCapture(), and updates save/read paths accordingly.
  • Validation after fix:
    • go test -race ./internal/keybindings -run TestDebugKeysCommand_ConcurrentAccess -count=1
    • go test ./internal/keybindings

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions