Skip to content

Keep valid automation history when repairing a damaged profile - #37336

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/lu-profile-automation-repair
Nov 2, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/lu-profile-automation-repair

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​366 $\color{#cf222e}{\Huge{\mathbf{−}}}$​25 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​341
Prod 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​85 $\color{#cf222e}{\Huge{\mathbf{−}}}$​38 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

ELI5

Repairing a damaged profile could replace perfectly good recent automation runs with an older backup. If the history's own metadata was damaged instead, Orca could not offer or complete the section repair. This keeps verified current runs when only their bookkeeping is damaged and lets the existing approved backup repair handle damaged history metadata.

What Changed

  • When current automation history passes its full checks, Repair rebuilds its damaged placeholder from that history. Updated runs and runs newer than the last backup survive, including when there is no backup. Explicitly empty or absent history stays empty or absent.
  • The existing startup dialog says “Automation history: your current runs will be kept” for this case. The line is translated in all bundled languages, and the CLI reports that current runs were kept.
  • Repair approvals distinguish keeping current history from replacing it with a backup or starting empty. That distinction survives the desktop recovery relaunch. If the history becomes unreadable after the user approves keeping it, repair refuses without substituting an older copy under that approval.
  • Database opening checks structure and identity; ordinary reads still validate history contents. Complete replacement validates the incoming state and revision without first requiring the damaged destination metadata to be readable. Invalid aggregate metadata still uses the existing explicit backup/empty-section choice; individually plausible rows are not treated as a complete valid history.
  • Repair still archives the original damaged database, writes one revision-fenced transaction and verifies that the repaired profile opens normally. Healthy newer sections remain current when another section needs a backup.

Why

The history's normalized records are authoritative; its document placeholder is derived bookkeeping. Treating placeholder damage as damage to the history discarded data that Orca had already independently verified. Requiring corrupt destination metadata to pass validation before replacing it also made recovery depend on the fault it needed to remove.

The common pattern reconstructs storage from known current values. This applies that mechanism through the existing complete replacement path rather than adding recovery-specific validation exceptions or another writer.

Linked Issue

Tracked in STA-11671: https://linear.app/stably/issue/STA-11671/profile-section-repair-mishandles-damaged-automation-history-30931

Visual Proof

Same damaged profile (valid history with two runs, damaged history placeholder, an older backup holding only the first run), repaired, then opened:

Before (main) After (this PR)
main: newer run lost branch: both runs kept

The startup Repair dialog's new "your current runs will be kept" line is covered by dialog tests in English and Japanese. Test copies run as background launches, where Orca deliberately never shows that dialog, so the running-app checks started from the exact repair request the dialog's Repair button sends.

Testing

  • Failing-first coverage reproduced both original defects on main. The keep-current cases also failed on the intermediate metadata-only fix before the preservation change.
  • Five focused files passed 104 tests: real-database section repair, dialog copy, desktop recovery relaunch, strict request schemas and the offline CLI. Coverage includes recent history with and without a backup, null/absence, mixed damaged sections, source drift, original-byte quarantine and normal reopen.
  • A subsequent two-file startup/relaunch batch passed 26 tests, including an explicit assertion that relaunch serialization retains the current source.
  • The earlier metadata-only commit passed 117 tests across repair, import, database opening, authority bootstrap and storage migration. Its import tests cover strict ordinary reads, stale revision rejection and rollback after an injected replacement failure; its migration-corruption coverage remains unchanged by the preservation change.
  • Review fixes added output coverage for the changed repair guidance (English and a translation) and for the bundled CLI route printing both a kept-history line and a backup line, and moved the read-consistency and corrupt-metadata guarantees from database opening to the ordinary reads that still enforce them.
  • All 11 locale catalogs contain the new key with the expected interpolation contract. Normal commit hooks run for both commits.
  • Running-app repair and restart QA completed (desktop repair relaunch, restart and CLI repair, compared with main on the same saved profile).
  • Automated tests added/updated.

Review

Full path. The plan received independent architecture reviews before implementation, and the PR went through the review loop (see the status comment).

  1. Small: 89 changed production lines across nine production files before final hook formatting; the file count exceeds the light-path limit. Locale catalogs and tests are excluded from that count.
  2. Outside risky areas: no; this changes saved-profile recovery, complete import and its transient approval contract.
  3. Not a repeat: no; it repairs defects in the section-repair mechanism introduced in Repair only the damaged parts of a profile instead of rolling back the whole profile #30931.
  4. Local effect: no; the approval crosses the desktop recovery relaunch and determines which saved values survive repair.

Agent skill upstream boundary

  • Not applicable: no upstream skill-installer source, fixtures, registry entries or path tables are copied or translated.

Notes

  • Intended difference from the common pattern: recovery remains an explicit user action and preserves the damaged database in quarantine. Rebuilding valid bookkeeping does not silently clear user data.
  • Intended difference from the common pattern: persisted history must pass metadata, identity, ordering, revision and aggregate checks before it can serve as the current source. Unlike a complete live cache, individually valid saved rows cannot prove that a trailing run is not missing.
  • Intended difference from the common pattern: a damaged history placeholder still stops normal startup and asks for Repair, even though the runs themselves are fine and are kept. The common pattern has no separate placeholder record to check. Kept because this exact case was approved with the visible "your current runs will be kept" line in the existing Repair dialog; opening without asking at all would be a separate user-facing change.
  • Intended compatibility constraint: retain the existing normalized history format and incremental writer. There is no database schema change, new saved field or export-format change. The new source tag exists only in the bundled recovery request/result; old backup/empty requests remain supported. No temporary divergence is introduced.
  • Recovery targets the profile on the machine executing it. No new remote-server capability, minimum version, agent behavior, workspace-path assumption or mobile interaction is introduced.

Checklist

  • The PR addresses the two failures in one profile-repair mechanism.
  • The problem, resulting behavior, mechanism and alternatives are explained.
  • Running-app visual proof attached.
  • Self-reviewed for data preservation, approval drift and atomicity.
  • Cross-platform, remote and saved-format impact considered.
  • CI checks pass; local validation used focused tests and normal commit hooks.

@brennanb2025
brennanb2025 marked this pull request as ready for review November 2, 2026 05:56
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 38463b7f-3afc-4028-abda-6054fe75bf0c
Commits

Reviewing files that changed from the base of the PR and between 33e7582 and 53694fd.

Files selected for processing: 30
  • src/cli/handlers/profile-state.test.ts
  • src/cli/handlers/profile-state.ts
  • src/main/index.ts
  • src/main/persistence/profile-state/profile-state-automation-storage-upgrade.test.ts
  • src/main/persistence/profile-state/profile-state-database-validation.ts
  • src/main/persistence/profile-state/profile-state-documents.test.ts
  • src/main/persistence/profile-state/profile-state-documents.ts
  • src/main/persistence/profile-state/profile-state-read-concurrency.test.ts
  • src/main/persistence/profile-state/profile-state-recovery-required.ts
  • src/main/persistence/profile-state/profile-state-section-repair.test.ts
  • src/main/persistence/profile-state/profile-state-section-repair.ts
  • src/main/persistence/profile-state/profile-state-startup-failure.test.ts
  • src/main/persistence/profile-state/profile-state-startup-failure.ts
  • src/main/persistence/profile-state/profile-state-startup-recovery-dialog.test.ts
  • src/main/persistence/profile-state/profile-state-startup-recovery-dialog.ts
  • src/main/startup/profile-state-recovery-preflight.test.ts
  • src/renderer/src/i18n/locales/de.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/renderer/src/i18n/locales/ru.json
  • src/renderer/src/i18n/locales/tr.json
  • src/renderer/src/i18n/locales/zh-Hant.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/plugins/languages/protected-copy-keys.json
  • src/shared/profile-state-recovery-command.test.ts
  • src/shared/profile-state-recovery-command.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…story

Schema verification no longer reads automation history metadata, so the
read-concurrency tests now assert that open succeeds without reading it and
that ordinary reads still keep snapshots consistent and refuse corrupt
metadata. Add output coverage for the recovery-required message, the
startup failure text (English and a translation) and the bundled CLI
recovery route printing kept and backup-restored sections.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review loop status

The problem. When part of a saved profile was damaged, Orca's section repair could throw away good automation history. If only the history's small placeholder record was damaged, repair treated the whole history as broken and replaced it with the last backup (or emptied it when no backup existed), so every run since that backup disappeared. If the history's own bookkeeping was damaged instead, Orca refused to open the database at all and offered no section repair, only a whole-profile restore.

What changes for users.

  • Damaged placeholder, history itself fine: the Repair dialog now says "Automation history: your current runs will be kept", and after repair every run is still there, with or without a backup. The CLI prints repaired automationRuns: current runs kept.
  • Damaged history bookkeeping: Orca now offers section repair for history from the newest readable backup and keeps every other part of the profile current, instead of refusing to open the profile.
  • The guidance text says "repair only the damaged parts" instead of promising backups.

Review. Full path, one review round (three reviewers), one fix round, repair check agreed.

  • Fixed: four existing read-consistency tests assumed database opening still checked history contents; they now check that opening stays structural and that ordinary reads still refuse corrupt history and keep consistent snapshots. Added output coverage for the changed guidance text (English and a translation) and for the bundled CLI route printing a kept-history line next to a backup line.
  • Refuted: three backup-rotation tests time out on this Mac whether or not this PR's changes are applied; CI runs them green.
  • Deferred, for Brennan: a damaged placeholder still stops normal startup and asks for Repair, even though the runs are fine and are kept. Orca could instead open normally and quietly rebuild that bookkeeping record, with no dialog at all. That would remove the dialog line approved for this case, so it is a separate user-facing choice, not built here.
  • Not part of this PR (same on main): after a repair that restores history from a backup, the automation's Overview can still say "Last run" at a time whose run is no longer in the history.

Verified. CI green on the head. Real running-app QA on the M4Air with a profile the app itself created (real automation runs, a real backup, a setting changed afterwards), damaged by hand, then repaired, compared with main on the same saved profile:

  • Placeholder damage: main's repair restored the backup and lost the newer run. This PR's desktop repair relaunch kept both runs and the newer setting, reopened normally, and a later restart needed no recovery. The bundled CLI did the same and printed the kept-history line.
  • History bookkeeping damage: main said the whole database was unreadable and its CLI refused. This PR offered section repair, restored history from the backup and kept the newer setting.
  • Approval drift: when the history became unreadable after "keep current" was approved, repair refused with nothing changed (database bytes identical, no quarantine).
  • The original damaged database is kept in a quarantine folder after each repair.

Not verified. The startup Repair dialog itself: test copies run as background launches, where Orca never shows it, so QA started from the exact request its Repair button sends. Its text is covered by dialog tests in English and Japanese. The dialog is a native message box with no app-controlled layout.

Since QA. QA ran on 79e4ef38a78; 53694fdcc26 then merged main to pick up #37370 (main's own Mobile check fix). That merge touches none of this PR's files.

For Brennan's review

Before (main): newer run lost After (this PR): both runs kept
M-A-after.png A-after-repair.png

Damaged history bookkeeping, repaired from the backup, newer setting kept: B-after-repair.png

Where judgment matters:

  1. profile-state-section-repair.ts: how history is judged current: valid history is kept even when its placeholder is damaged; history that fails its own checks still needs a backup or explicit empty consent.
  2. profile-state-database-validation.ts: opening no longer reads history contents: ordinary reads still validate it.
  3. profile-state-recovery-command.ts: the new "keep current" approval: approving "keep current" can't later authorize a backup or empty replacement.

@brennanb2025
brennanb2025 merged commit 9df4559 into main Nov 2, 2026
68 checks passed
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