Skip to content

Fix five robustness issues in networking, pairing, saved servers and dictation - #1075

Merged
ivanfenenko merged 5 commits into
mainfrom
fix/audit-top-five
Nov 16, 2026
Merged

ivanfenenko merged 5 commits into
mainfrom
fix/audit-top-five

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Five independent robustness fixes from a code audit, one commit each. No issue exists for these.

  • Android, opencode-kit: the process-wide uncaught-exception guard now only drops HTTP-engine-shutdown failures. It never drops on the main thread, always forwards plain socket errors and timeouts, drops Ktor's engine-closed types off-main, and drops a rejected execution only on OkHttp threads. Everything else reaches the previous handler.
  • Android, Hex Code: Dictation gains close(); the home view model calls it from onCleared(), which cancels both dictation scopes and shuts down the hex-audio and hex-vad executors.
  • iOS, Hex Code: pairing applies CleartextPolicy before probing, as Android Hex Code already does, with a new "This address isn't encrypted" failure (copy matches Android).
  • iOS, OpenCodeKit: summarize, v2 compact and v2 generate go through a new longOperation session, so the REST session's 60 s resource timeout no longer ends them early. Ordinary REST calls keep the 60 s cap.
  • iOS, OpenCodeKit: the saved-server catalog is read one record at a time, so one unreadable record no longer empties the list. Unreadable data is copied once to a backup key before anything overwrites it, and a failed write is logged. The stored format is unchanged.

Checks

  • iOS and Android both covered, or the reason one is not: each fix is platform-specific; the Android profile store has the same catalog weakness and is not changed here.
  • Screenshots for UI changes: the new Hex Code iOS pairing failure text has no screenshot yet.
  • Tests run
    • Android: ./gradlew :opencode-kit:testDebugUnitTest :hexcode:testDebugUnitTest :opencode-kit:ktlintCheck passed. opencode-kit 330 tests, hexcode 716 tests, 0 failures.
    • iOS, suites covering the changes passed in every local run: OpenCodeURLSessionsTests, ConnectionProfileStoreTests, CleartextPolicyTests, ServerPairingTests.
    • iOS full unit runs did not go green locally on a heavily loaded machine. Two runs of OpenCode MobileTests failed on different timing-based tests each time (MessageSyncTests, PermissionLiveStoreTests, DisplayMessagePipelineCharacterizationTests) and restarted after a hang. Hex CodeTests failed twice on aStalledAttemptIsStoppedAndTriedAgain, which passed when its suite ran alone. None of those files are touched here; CI is the reference.
    • node scripts/check-string-keys.mjs exits 0.

Risks / Follow-ups

  • Android: an uncaught socket error or timeout, or an engine-closed failure on the main thread, now crashes and is reported where it used to be dropped silently. No record exists of which thread the original engine-shutdown crashes came from, so Ktor's engine-closed types stay dropped on every non-main thread.
  • Android: VoiceEngineDictation.close() and ClipDictation.close() have no direct tests; the shared DictationThreads they use does.
  • iOS: clearAll() also deletes the catalog backup key.
  • iOS: the long-operation session uses a 7-day resource timeout (URLSession's default); no test waits past 60 s against a live server.
  • Nothing was run on a device or simulator UI.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Note

Medium Risk
Changes touch uncaught-exception handling, persistent connection profiles, and pairing security policy; misclassification could hide real crashes or block legitimate pairings, though behavior is heavily unit-tested.

Overview
This PR bundles five robustness fixes across Android and iOS.

Android — dictation teardown: Dictation gains close(); live dictation uses a shared DictationThreads helper that cancels coroutine scopes and shuts down hex-audio / hex-vad in order (mic release runs last on the audio thread). HomeViewModel.onCleared() drops an in-flight take and calls close().

Android — HTTP uncaught exceptions: The process-wide guard is tightened: nothing is swallowed on the main thread; Ktor engine-closed errors are logged off-main; RejectedExecutionException is only swallowed on OkHttp-named threads. Plain socket errors and timeouts always reach the previous handler.

iOS — pairing cleartext: Before probing, pairing URLs are filtered with CleartextPolicy, matching Android. If only untrusted plain HTTP remains, pairing fails with "This address isn't encrypted" and no network requests run.

iOS — long HTTP operations: Summarize, v2 compact, and v2 generate use a dedicated longOperation URLSession (long resource timeout) so the 60s REST pool cap does not cut them off; routine calls still use rest.

iOS — saved server catalog: Loading decodes profiles one record at a time so one bad entry does not wipe the list; unreadable catalog bytes are backed up once before overwrite, with logging on partial skips and write failures.

Reviewed by Cursor Bugbot for commit 030be41. Bugbot is set up for automated code reviews on this repo. Configure here.

@ivanfenenko ivanfenenko mentioned this pull request Nov 16, 2026
3 tasks done
@ivanfenenko
ivanfenenko marked this pull request as ready for review November 16, 2026 12:14
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

@cursor review

@github-actions github-actions 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.

Automated review: no finding that 2+ of 3 passes agreed on.

4 finding(s) from a single pass, not posted
  • ios/OpenCodeKit/Sources/OpenCodeKit/Domain/Connection/ConnectionProfileStore.swift:347 medium: First-only unreadable backup loses servers saved in between (muse-spark-1.3-contributor)
  • android/hexcode/src/main/java/dev/opencode/hexcode/home/HomeViewModel.kt:155 medium: Closing dictation dispatchers makes a late end() crash (muse-spark-1.3-contributor)
  • ios/OpenCodeKit/Sources/OpenCodeKit/Domain/Connection/ConnectionProfileStore.swift:105 medium: Per-record decode recovery fails for wrong-typed fields: one bad record still empties the rest of the list (glm-5.3-flash)
  • ios/OpenCodeKit/Sources/OpenCodeKit/Domain/Connection/ConnectionProfileStore.swift:94 low: Top-level activeId still empties the whole saved-server list (muse-spark-1.3-contributor)

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.080 · 1 pass(es) stopped early

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 030be41. Configure here.

@ivanfenenko
ivanfenenko added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit ea5b6a6 Nov 16, 2026
@ivanfenenko
ivanfenenko deleted the fix/audit-top-five branch November 16, 2026 14:49
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