镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(work): reject stale AI Work results (#298) - #299

Merged
petertzy merged 2 commits into
petertzy:mainfrom
karaaslanz:fix/298-stale-work-result
Oct 1, 2026
Merged

petertzy merged 2 commits into
petertzy:mainfrom
karaaslanz:fix/298-stale-work-result

Conversation

@karaaslanz

@karaaslanz karaaslanz commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Prevents stale AI Work responses from overwriting newer user edits in the active document.

When a Work request starts, the frontend now snapshots both the active document identity and its content. Before applying the returned modified_content, it verifies that the user is still on the same document and that the document content has not changed. If either changed while the request was in flight, the stale result is rejected and the user is asked to re-run the task against the current document.

Changes

  • Pass the active tab/document ID into useAIActions.
  • Keep the latest active document snapshot available while an async Work request is in flight.
  • Add a small shared freshness guard used by the production Work path.
  • Reject stale results when either:
    • the same document was edited while the request was running, or
    • the user switched to another document before the response returned.
  • Preserve the existing apply behavior when the original document is unchanged.
  • Add focused regression coverage for all three paths.

Validation

Exact-head upstream CI on 8f10762:

Frontend tests: 26 passed, 0 failed

Frontend lint: passed

Frontend production build / TypeScript: passed

Backend tests: 195 passed, 0 failed

Ruff check / format check: passed

CI also reports existing environment/dependency warnings (Node/action deprecation, npm dependency audit output, build-cache warning, and an ffmpeg availability warning); none are introduced by this change.
Closes #298.

Refs #274, #280.

@petertzy

petertzy commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Reviewed against issue #298. The Work request captures the document ID and content, checks the latest snapshot before applying the response, and rejects stale results with a clear retry message. Unchanged documents retain the existing apply behavior.

Regression coverage includes unchanged content, edits during a request, and switching documents. The change stays within the current-document Work flow.

Latest main was merged without conflicts in f1c910e. Validation passed: 26 frontend tests, frontend lint, production build/TypeScript, and 206 backend tests with 13 subtests.

No blocking issues found. Approved for merge.

@petertzy
petertzy merged commit 5911ce1 into petertzy:main Oct 1, 2026
2 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.

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

2 participants