Skip to content

Held-key check reads HID state and names a key it waits on - #1335

Merged
malpern merged 1 commit into
masterfrom
claude/keypath-space-stuck-mini-fa6e52
Oct 22, 2026
Merged

malpern merged 1 commit into
masterfrom
claude/keypath-space-stuck-mini-fa6e52

Conversation

@malpern

@malpern malpern commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Problem

On the mini on 2026-10-20, KeyPath started without its engine three times (11:01, 14:09, 14:18). Each start refused Caps activation with physicalKeysHeld, and the wake recovery loop logged held-keys once and then waited silently for hours. All you could see was "Remapping will resume when your keyboard session is ready."

requirePhysicalAllUp() read .combinedSessionState, which reported Space (keycode 49) held. .hidSystemState did not. No keyboard was holding Space: pressing it on the cl80 and unplugging the fixture and the X2A changed nothing. One posted Space key-up at the session tap cleared it.

Change

  • requirePhysicalAllUp reads .hidSystemState, which was clear throughout the incident. The check exists so a Caps Lock hidutil mapping never changes mid-press, and hidutil acts on HID events. The key-state reader is injectable for tests.
  • A posted press can also set HID state (verified live with F16), so switching records alone doesn't rule out a silent wait. After 5 seconds on held-keys, the wake recovery loop now logs the key codes and warns: "Remapping is waiting because macOS reports the “space” key as held down. Press and release it to resume."
  • docs/bugs/stale-synthetic-key-blocks-startup.md records the incident, what is and isn't established, and how to clear it by hand.

Verification

  • SessionCapsRuntimeSupportTests, SessionFailureRecoveryMessageTests, ServiceLifecycleCoordinatorTests: 52 passed (run-tests-safe.sh).
  • Live on the mini: combined [49] vs hid [] during the incident, and the posted-event behaviour of both records.
  • Not verified live: the 5-second warning in the running app. That needs a deployed build and a deliberately stuck key.

Review gate

./Scripts/review-gate.sh could not run locally (the Claude login expired), so the remote review gate is selected. Do not merge until GitHub claude-review passes.

🤖 Generated with Claude Code

Startup refused Caps activation with physicalKeysHeld three times on the
mini on 2026-10-20. Combined session state reported Space held while HID
state and every keyboard had released it, and the wake recovery loop
waited on it silently for hours.

The check now reads HID state, which was clear throughout. Because a
posted press can still hold HID state, the wake recovery loop names the
held key after 5 seconds and asks for it to be pressed and released.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T22:42:26.784569Z e5ebf3e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 20, 2026

Copy link
Copy Markdown

Review of PR 1335: no blocking issues. Three things worth checking:

  1. Gate and warning must read the same state. The wake-recovery warning calls SessionCapsRuntimeSupport.heldKeys(), which now reads HID state. The "held-keys" blocker comes from a gate that the diff doesn't show. If that gate still reads .combinedSessionState (or any source other than requirePhysicalAllUp/heldKeys), the incident in the bug doc would still block recovery. heldKeys() would then return [], so the !held.isEmpty guard would suppress the warning and the loop would stay silent. Please confirm the gate goes through heldKeys/requirePhysicalAllUp. If it doesn't, route it through them.

  2. The warning is never retracted. onWarning fires once the held set has been stable for 5s. The diff doesn't clear that warning when the key is released and recovery resumes, or when the loop exits for another reason. A stale "Press and release it to resume" message could stay visible after a successful start. Consider clearing it on the blocker == nil path, or confirm that onWarning is superseded by the next state change.

  3. Test gap. The new tests cover heldKeys, requirePhysicalAllUp and the message text. The new loop logic has no test: the 5s threshold, the dedupe on namedHeldKeys, and the reset when the blocker changes. If Date() can't be injected cheaply, extracting that decision into a small pure helper would make it testable without sleeping.

Minor: the docs say posted presses can still reach HID state and the root cause is unestablished. The fix therefore narrows the failure rather than removing it, and the 5s warning is the only mitigation for that case. That seems acceptable, but it's worth keeping the bug doc open or linked to a follow-up.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e5ebf3ef0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if Date().timeIntervalSince(since) >= 5, !held.isEmpty, held != namedHeldKeys {
namedHeldKeys = held
AppLogger.shared.warn("[SessionRuntime] Wake recovery waiting on held key codes \(held)")
onWarning?(Self.heldKeysWarning(held))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Publish the named held-key warning

When a key remains held for five seconds, this updates lastWarning through onWarning but never calls onStateChanged. The UI is event-driven—StatePublisherService emits a new snapshot only when notifyStateChanged() is called—and the lifecycle warning callback in RuntimeCoordinator only assigns the value. Consequently, during the indefinite held-key wait the user continues seeing the generic warning, and a successful resume clears the named warning before the next state publication. Trigger onStateChanged after replacing the warning so the new actionable message is actually shown.

Useful? React with 👍 / 👎.

@malpern
malpern merged commit 112c0b1 into master Oct 22, 2026
9 of 10 checks passed
@malpern
malpern deleted the claude/keypath-space-stuck-mini-fa6e52 branch October 22, 2026 03:21
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.

1 participant