# fix\(desktop\): recover undecryptable connection catalogs safely · PR \#13656 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/13656)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: closed

Source repository: Unavailable fork

Source branch: codex/8341-recover-undecryptable-catalog

Target branch: main

Head commit: 14640edea7d4aaf218e02b2f7a9028428528f754

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/13656)

[Commits](https://git.cafe/pingdotgg/t3code/pull/13656/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/13656/diffs?format=markdown)

## Description

---

## What Changed

When Electron cannot decrypt the saved connection catalog, preserve the encrypted file under a unique `.undecryptable` filename before returning an empty catalog. Local environment discovery can then continue, and the user can register remote connections again.

Serialize catalog reads, writes, and clears so recovery cannot rename a concurrent replacement save within the store. If preservation fails, keep reporting an error and leave the original catalog intact. Encryption remains required; other read, decode, and legacy migration failures retain their existing behavior.

## Why

Fixes #8341.

On Windows with Alpha 0.0.42, a `decrypt-catalog` error left the sidebar empty even though the local server responded and the conversation database passed its integrity check. Renaming the connection file aside restored successful catalog reads. The original crash and reason decryption stopped working are unconfirmed.

Preserving the encrypted file before recovery addresses the potential overwrite/data-loss concern raised on #4454. Saved remote connections may need to be registered again; the original encrypted data remains available for manual recovery.

## Validation

- All 10 `DesktopConnectionCatalogStore` tests pass, including concurrent recovery, exact backup preservation, subsequent encrypted writes, and preservation failure.
- Both new regression cases fail against unmodified main; the recovery case reproduces the `decrypt-catalog` failure.
- Desktop TypeScript check passes.
- Targeted lint, formatting, and `git diff --check` pass.
- A rebuilt packaged desktop application has not been tested. No UI components changed.

## Checklist

- [x] This PR is small and focused
- [x] I explained what changed and why
- UI screenshots/video: not applicable; no UI component or animation changes.

Prepared with GPT-6 in the Codex desktop harness.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Bug Fixes**
  * When a saved connection catalog can’t be decrypted, the app preserves it as a backup and allows a fresh catalog to be saved.
  * Concurrent catalog reads and writes are handled safely. If preserving an unreadable catalog fails, the app reports an error and leaves the original file unchanged.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
