Skip to content

Fix Keychain unavailability handling in sign-in and renewal - #361

Merged
alexkroman merged 5 commits into
mainfrom
claude/ecstatic-franklin-qtt7pa
Nov 25, 2026
Merged

alexkroman merged 5 commits into
mainfrom
claude/ecstatic-franklin-qtt7pa

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

What & why

This PR fixes several issues around Keychain unavailability (e.g., when locked at launch):

  1. Session renewal with locked Keychain: When a Mac is locked at launch, the session can be read again after unlock, but the API key status wasn't refreshed. This caused the UI to show "Signed in as …" while hasAPIKey remained false, keeping the wizard in onboarding. Now refreshStatus() is called after a successful session read to sync the key status.

  2. Sign-in over unreadable session: When a session item can't be read (.unavailable), attempting to sign in would try to roll back to nil, effectively deleting the unreadable session. This is unsafe — that session may be the only way to renew or revoke an earlier grant. Now sign-in refuses outright if the current session can't be read, preserving it.

  3. Press claim race condition: A quick release command could be accepted before the session claims the press, but the claim would overwrite the stop recipient. Now the claim preserves an already-set recipient, allowing the release to land first without losing where the dictation's words should go.

  4. Cancelled dictation cleanup: When a dictation is cancelled while waiting for the keyboard to take the result, the result was left in the App Group, and the keyboard would still insert it. Now cancellation cleans up the result if it's still the one being waited for.

  5. Voice Arena baseline tooling: Added _host_tag() to safely generate cache filenames for non-default hosts, and write_csv() to ensure consistent column ordering in baseline output.

How it was tested

  • Added LockableKeyStore test fixture to simulate locked Keychain scenarios

  • Added test signInOverUnreadableSession() verifying sign-in refuses and doesn't delete unreadable sessions

  • Added test relayCancelledTakesResultBack() verifying cancelled dictations clean up their results

  • Added test releaseBeforeClaim() verifying press claim preserves recipient set by earlier release

  • Added tests for _host_tag() and write_csv() in Voice Arena baseline

  • scripts/check.sh passes (or CI will, if I'm not on a Mac)

  • I read AGENTS.md and this doesn't reintroduce anything deliberately removed

  • Docs updated if behavior changed

…CSV column (#344)

- AssemblyAIAccount: a session item that reads again refreshes the API-key
  model too, so a Mac locked at launch doesn't show "Signed in as …" while
  hasAPIKey stays false and the wizard holds the user in onboarding.
- AssemblyAIAccount.storeSignIn: refuse over an unreadable session item
  instead of rolling back to nil, which deleted it.
- DictationCoordinator.claimPress: keep a stop recipient a fast release set
  before the session claimed the press.
- KeyboardRelayInjector: a dictation cancelled mid-delivery takes its result
  back out of the App Group, so the keyboard can't insert it later.
- voicearena_baseline.py: write each CSV column once, and give non-default
  hosts a cache tag that neither crashes on a dotless host nor collides
  across *.assemblyai.com (staging keeps its existing tag).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DS5B1S9WP9RXzy9e669hiB
@alexkroman
alexkroman enabled auto-merge November 24, 2026 22:50
A result was addressed to a keyboard process only, so a keyboard over a
different field in the same process — the user tapped field B while the
words for field A were still being transcribed, with iOS keeping the
controller or bringing up a new one — inserted them there.

The press and stop commands now carry the field's
UITextDocumentProxy.documentIdentifier beside the controllerID they
already sent; the coordinator keeps a ResultAddress (process, controller,
document) for the press and for the accepted stop, and the relay puts it
on the DictationResult. A keyboard inserts only when the result names its
controller and document; otherwise it leaves the result, and the app
copies the words out at its delivery timeout ("Copied"), as when no
keyboard takes them. A part left nil by an older build matches anything.

Fixes #346

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman added this pull request to the merge queue Nov 24, 2026
@alexkroman
alexkroman removed this pull request from the merge queue due to a manual request Nov 24, 2026
@alexkroman
alexkroman added this pull request to the merge queue Nov 24, 2026
# Conflicts:
#	App/BlurtiOS/BlurtiOSTests/DictationCoordinatorTests+Dictation.swift
alexkroman pushed a commit that referenced this pull request Nov 25, 2026
Matches KeyInjector.insert's default, so a test calling the relay directly
describes an ordinary field without restating it (and #361's new relay
test keeps compiling once this lands).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman removed this pull request from the merge queue due to a manual request Nov 25, 2026
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
# Conflicts:
#	App/BlurtiOS/BlurtiOSTests/DictationCoordinatorTests+Dictation.swift
#	App/BlurtiOS/BlurtiOSTests/ProtocolTests.swift
@alexkroman
alexkroman removed this pull request from the merge queue due to a manual request Nov 25, 2026
@alexkroman
alexkroman enabled auto-merge November 25, 2026 00:37
#378 adds its own test at the same spot; apart, the two merge in either
order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
@alexkroman
alexkroman removed this pull request from the merge queue due to a manual request Nov 25, 2026
@alexkroman
alexkroman added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 73a1fae Nov 25, 2026
13 checks passed
@alexkroman
alexkroman deleted the claude/ecstatic-franklin-qtt7pa branch November 25, 2026 02:12
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.

3 participants