Skip to content

Audit timeout and delay patterns for correctness#79

Merged
kmatzen merged 2 commits intomainfrom
refactor/audit-timeout-patterns
Feb 22, 2026
Merged

Audit timeout and delay patterns for correctness#79
kmatzen merged 2 commits intomainfrom
refactor/audit-timeout-patterns

Conversation

@kmatzen
Copy link
Copy Markdown
Owner

@kmatzen kmatzen commented Feb 22, 2026

Summary

  • Replace all magic-number delays across 7 files with named, documented constants
  • Categorize each delay as protocol-mandated, empirical, or cosmetic
  • Convert sleep/power-down fire-and-forget asyncAfter to cancellable DispatchWorkItems
  • Align BLEConnectionManager.connectionTimeout (was 30s, now 15s) to eliminate conflicting values
  • Document dead retry code in BLEDeviceStateManager and flag three overlapping retry systems for consolidation

Delay Inventory

Constant Value Category Purpose
commandQueueInterval 0.2s Protocol GoPro BLE spec ≤5 cmd/s
connectionStaggerDelay 0.5s Empirical Avoid overwhelming BLE stack
settingsQueryDelay 0.5s Empirical Camera needs time after settings write
controlReleaseDelay 0.5s Empirical Wait for control-release ACK
commandRetryDelay 1.0s Empirical Pause before resending timed-out command
errorRecoveryDelay 1.0s Empirical Base delay for error recovery backoff
authReconnectDelay 2.0s Empirical BLE stack teardown after auth error
wifiCredentialFetchDelay 2.0s Empirical Wait for WiFi AP to activate
shutdownCommandTimeout 3.0s Empirical Force-disconnect if no sleep/power ACK
multipartResponseTimeout 3.0s Empirical Incomplete BLE response reassembly
deviceScanInterval 3.0s Empirical Scan duty cycle
deviceQueryInterval 5.0s Empirical Periodic status polling
connectionTimeout 10.0s Empirical CoreBluetooth didConnect timeout
stragglerRetryInterval 15.0s Empirical Check for dropped cameras
Auto-sync timer 10.0s Cosmetic Periodic config sync check
Sync indicator 2.0s Cosmetic Visual feedback duration
Connecting spinner 10.0s Cosmetic UI spinner timeout
Haptic stagger 0.1s Cosmetic Double-tap haptic feel
Bug report submit 1.0s Cosmetic Fake network delay

Architectural Finding

Three independent connection retry systems exist with conflicting timeout values:

  1. BLEManagerconnectionTimeout = 10.0s, own retry timers and backoff
  2. BLEConnectionManagerconnectionTimeout was 30.0s (now aligned to 15.0s), own retry timers
  3. BLEDeviceStateManagerconnectionTimeout = 10.0s, full retry system but entirely unused (only sleep-state tracking is called)

Consolidation is recommended as a follow-up.

Test plan

  • Build succeeds on iOS Simulator
  • Verify cameras connect and reconnect normally (timeouts unchanged in practice)
  • Verify sleep/power-down commands still work (now cancellable)
  • Verify auto-sync and UI spinners behave normally

Closes #69

Made with Cursor

@kmatzen kmatzen force-pushed the refactor/audit-timeout-patterns branch from c0b1ad7 to 2607ace Compare February 22, 2026 22:14
Replace all magic-number delays with named constants, categorized as:
- Protocol: commandQueueInterval (GoPro BLE spec ≤5 cmd/s)
- Empirical: connection timeouts, retry delays, query intervals
- Cosmetic: UI spinner timeouts, sync indicator durations

Convert sleep/power-down fire-and-forget asyncAfter to cancellable
DispatchWorkItems so timeouts are cancelled when responses arrive.

Align BLEConnectionManager.connectionTimeout (was 30s, now 15s) with
the rest of the codebase to eliminate conflicting timeout values.

Document that BLEDeviceStateManager's retry logic is dead code and
flag all three overlapping connection retry systems for consolidation.

Closes #69

Co-authored-by: Cursor <cursoragent@cursor.com>
@kmatzen kmatzen force-pushed the refactor/audit-timeout-patterns branch from 6710650 to 7a15b78 Compare February 22, 2026 22:19
- Draft App Store listing copy with features, compatibility, disclaimer
- Privacy policy URL: repo PRIVACY_POLICY.md
- Support URL: repo Issues page
- Update README to specify HERO10 Black + GoPro Labs as tested config
- Add GoPro trademark disclaimer to README per brand policy

Co-authored-by: Cursor <cursoragent@cursor.com>
@kmatzen kmatzen force-pushed the refactor/audit-timeout-patterns branch from 7a15b78 to ea5cb80 Compare February 22, 2026 22:25
@kmatzen kmatzen merged commit 0dc65e1 into main Feb 22, 2026
1 check passed
@kmatzen kmatzen deleted the refactor/audit-timeout-patterns branch February 22, 2026 22:29
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.

Audit timeout and delay patterns for correctness

1 participant