Skip to content

[codex] Fix migration recovery and switch races - #27

Merged
ygsgdbd merged 1 commit into
mainfrom
codex/fix-migration-and-switch-races
Jul 21, 2026
Merged

[codex] Fix migration recovery and switch races#27
ygsgdbd merged 1 commit into
mainfrom
codex/fix-migration-and-switch-races

Conversation

@ygsgdbd

@ygsgdbd ygsgdbd commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

This change makes the unreleased legacy app-rule migration conservative, cancels stale programmatic input-method switches, and refreshes the README screenshots for the current grouped menu layout.

Problem and user impact

The v2 migration still read legacy input-method mappings without considering whether the original migration had already completed. On upgrade, that could overwrite an explicit default (.none) choice, recreate a legacy rule the user had deleted, or replace useful current metadata while recovering a placeholder.

Programmatic switching also had no shared cancellation identity. When apps were activated in quick succession, an older effect could continue after the foreground app changed. A related termination window existed when the input-method selection notification cleared pending state before the switch effect sent its completion action, allowing a terminated app to receive an incorrect switch count.

The README composites additionally still showed the previous section separators after the menu groups were consolidated.

Root cause

The migration merge treated every missing key and every .none rule as recoverable legacy data, without the old didMigrateLegacyAppRules completion context or a way to distinguish untouched placeholders from user-modified rules.

The switching effect was not cancellable and relied only on pending state to associate completion. Pending state can be cleared by system selection notifications before the effect itself finishes, so termination could miss the in-flight task.

Changes

  • Read the old Boolean migration marker and pass it into a pure merge function.
  • Keep current non-empty stores authoritative after the original migration completed, while still recovering an empty store when the old migration did not persist.
  • Recover legacy data only into untouched .none placeholders (createdAt == updatedAt) and preserve current timestamps and valid metadata, using legacy metadata only when current metadata is missing.
  • Keep the v2 completion marker write after a successful rules-store save.
  • Add a shared programmaticSwitch cancellation ID, cancel previous work on activation, and explicitly cancel for ignored/no-target apps, ignored current apps, and terminated apps.
  • Re-check task cancellation before switching and before sending completion so canceled tasks do not update statistics.
  • Add regression coverage for migration upgrade states and activation/ignore/termination races, including the window where a selection notification has already cleared pending state.
  • Regenerate the 8 raw and 4 composite README screenshots without changing README text or asset paths.

This branch is rebased on the current main and preserves the metadata regression coverage added by PR #26 while applying the stricter recovery rules above.

Validation

  • rtk just check
  • git diff --check
  • ./script/validate_readme_screenshots.sh
  • Manual inspection of all four README composite screenshots

@ygsgdbd ygsgdbd changed the title Fix migration recovery and switch races [codex] Fix migration recovery and switch races Jul 21, 2026
@ygsgdbd
ygsgdbd marked this pull request as ready for review July 21, 2026 12:30
@ygsgdbd
ygsgdbd merged commit ba0bdb1 into main Jul 21, 2026
2 checks passed
@ygsgdbd
ygsgdbd deleted the codex/fix-migration-and-switch-races branch July 21, 2026 12:30

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9cacda232d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +10 to +11
guard !didCompleteLegacyMigration || currentRules.isEmpty else {
return currentRules

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recover missing legacy rules despite old completion flag

When a user already has the old didMigrateLegacyAppRules flag set and their current app-rules store contains any rule, this early return discards every loaded legacy rule. That misses the version-2 recovery path for legacy mappings that the original migration could mark complete without actually writing (for example unavailable apps that were previously dropped), and the caller then marks version 2 complete because mergedRules == state.appRules, making those rules unrecoverable. The merge should still add absent legacy entries while avoiding overwrites of existing rules.

Useful? React with 👍 / 👎.

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