Skip to content

fix(ai): prevent stale agent edit overwrites - #309

Open
arhxam wants to merge 1 commit into
getopenscreen:mainfrom
arhxam:codex/prevent-stale-agent-overwrites
Open

fix(ai): prevent stale agent edit overwrites#309
arhxam wants to merge 1 commit into
getopenscreen:mainfrom
arhxam:codex/prevent-stale-agent-overwrites

Conversation

@arhxam

@arhxam arhxam commented Aug 8, 2026

Copy link
Copy Markdown

Summary

  • capture the project document and revision atomically when an AI turn starts
  • refuse to apply a returned full-document edit when any local document mutation advanced that revision
  • leave the user's live document and on-disk project untouched on conflict, while still retaining the assistant's chat response
  • show a localized warning explaining why the agent edits were not applied
  • preserve intentional chat rewind behavior by allowing that confirmed action to replace the current revision

Related issue

Fixes #284

Type of change

  • Bug fix
  • Feature
  • Enhancement
  • Documentation
  • Refactor / maintenance
  • Performance
  • Security

Release impact

  • Patch
  • Minor
  • Major / breaking change
  • No release note needed

Desktop impact

  • Windows
  • macOS
  • Linux
  • Installer / packaging
  • Not platform-specific

Screenshots / video

Not included; the visible change is a localized warning toast on a concurrent-edit conflict.

Testing

  • Started with a failing regression test before the revision guard existed
  • npx vitest --run src/lib/ai-edition/store/agentDocumentApply.test.ts (3 passed)
  • npm run test (1,680 passed, 1 skipped across 141 files)
  • npx tsc --noEmit
  • npx tsc -p tsconfig.test.json --noEmit
  • npx biome check on the implementation, test, component, and locale files
  • npm run docs:check
  • npm run i18n:check
  • npm run build-vite

Authored with Codex assistance and manually verified against the issue's concurrent-edit reproduction.

Summary by CodeRabbit

  • New Features

    • Agent-generated edits are now protected from overwriting newer manual project changes.
    • Conflicting edits trigger a warning instead of being applied.
    • Rewind actions continue to replace the current project content as expected.
  • Localization

    • Added conflict warnings across all supported languages.
  • Bug Fixes

    • Improved reliability when agent processing overlaps with project edits.

@arhxam
arhxam requested a review from EtienneLescot as a code owner August 8, 2026 18:26
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b834f314-0582-4d7b-96b2-1715d71a4a8b

📥 Commits

Reviewing files that changed from the base of the PR and between 4e7a85b and 3a2255d.

📒 Files selected for processing (16)
  • src/components/ai-edition/LeftPanel.tsx
  • src/i18n/locales/ar/editor.json
  • src/i18n/locales/en/editor.json
  • src/i18n/locales/es/editor.json
  • src/i18n/locales/fr/editor.json
  • src/i18n/locales/it/editor.json
  • src/i18n/locales/ja-JP/editor.json
  • src/i18n/locales/ko-KR/editor.json
  • src/i18n/locales/pt-BR/editor.json
  • src/i18n/locales/ru/editor.json
  • src/i18n/locales/tr/editor.json
  • src/i18n/locales/vi/editor.json
  • src/i18n/locales/zh-CN/editor.json
  • src/i18n/locales/zh-TW/editor.json
  • src/lib/ai-edition/store/agentDocumentApply.test.ts
  • src/lib/ai-edition/store/agentDocumentApply.ts

📝 Walkthrough

Walkthrough

Changes

Agent document conflict handling

Layer / File(s) Summary
Document application helper and tests
src/lib/ai-edition/store/agentDocumentApply.ts, src/lib/ai-edition/store/agentDocumentApply.test.ts
Added applyAgentDocumentIfCurrent and its result type. The helper validates documents, checks optional revisions, updates project state, persists documents, and supports rewind behavior. Tests cover application, conflicts, and rewinds.
Chat revision checks and localized feedback
src/components/ai-edition/LeftPanel.tsx, src/i18n/locales/*/editor.json
LeftPanel captures the document revision before each chat run. Returned agent documents apply only when the revision is unchanged. Conflicts show a localized warning, while rewinds remain revisionless.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LeftPanel
  participant chatRun
  participant applyAgentDocumentIfCurrent
  participant useProjectStore
  LeftPanel->>useProjectStore: Capture document and revision
  LeftPanel->>chatRun: Start agent run
  chatRun-->>LeftPanel: Return agent document
  LeftPanel->>applyAgentDocumentIfCurrent: Apply with expected revision
  applyAgentDocumentIfCurrent->>useProjectStore: Check current revision
  alt Revision unchanged
    applyAgentDocumentIfCurrent->>useProjectStore: Set and save document
    applyAgentDocumentIfCurrent-->>LeftPanel: Return applied
  else Revision changed
    applyAgentDocumentIfCurrent-->>LeftPanel: Return conflict
    LeftPanel->>LeftPanel: Show warning toast
  end
Loading

Suggested reviewers: etiennelescot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: preventing stale AI agent edits from overwriting current document changes.
Description check ✅ Passed The description follows the repository template and includes the change summary, issue link, classifications, impact, and detailed testing information.
Linked Issues check ✅ Passed The implementation detects revision conflicts, preserves local and saved changes, shows localized warnings, retains chat responses, and preserves rewind behavior for issue #284.
Out of Scope Changes check ✅ Passed The changes are limited to revision-safe agent document application, conflict localization, and regression tests required by issue #284.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

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.

[Bug]: edits made while the AI agent is running are overwritten when it answers

1 participant