Skip to content

fix(work): prevent stale AI Work results from overwriting newer edits #298

Closed

Description

@karaaslanz

Problem

The current AI Work flow sends a snapshot of the active document to the backend, waits for the AI result, and then applies the returned modified_content.

If the user edits the same document while the request is in flight, the result may be based on an older snapshot and can overwrite those newer edits when it returns.

The merged AI Work Panel feasibility roadmap already identifies this as a stale-document/concurrency safety gap.

Scope

Add a narrow stale-result guard to the current single-document AI Work flow:

  • Capture a document revision, content hash, or equivalent snapshot identity when the Work request is dispatched.
  • Before applying the returned result, verify that the active document still matches that original snapshot.
  • If the document changed while the request was in flight, do not apply the stale result directly.
  • Surface a clear safe state/message so the user can re-run the operation against the current document.
  • Add focused regression coverage for both unchanged-document and changed-during-request cases.

Acceptance criteria

  1. If the document is unchanged while AI Work is running, the returned result applies as it does today.
  2. If the document changes before the result returns, the stale result cannot overwrite the newer content.
  3. Regression coverage proves both paths.
  4. The change stays limited to the current-file AI Work flow.

Out of scope

  • Diff/review UI
  • Three-way merge/conflict UI
  • Undo/redo grouping improvements
  • Project-wide/multi-file Work flows
  • General AI Work Panel redesign

Refs #274 and #280.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions