Skip to content

feat(review): support --resume for workspace mode - #1922

Merged
lizhengfeng101 merged 4 commits into
alibaba:mainfrom
Walternater:feat/workspace-resume
Nov 14, 2026
Merged

lizhengfeng101 merged 4 commits into
alibaba:mainfrom
Walternater:feat/workspace-resume

Conversation

@Walternater

Copy link
Copy Markdown
Contributor

Description

Closes #1880.

Workspace mode — the default ocr review with no --from/--to/--commit — can now resume an interrupted session. Previously loadReviewResumeState rejected it outright, so the only way to finish a large uncommitted review was to start over.

The rules are strict, and follow the existing resume contract:

  • the parent must have a run manifest (same as range/commit resumes);
  • the worktree must be unchanged: the base commit and the selected uncommitted changes must both match. A workspace run has no commit ref to pin, so the base commit and the source-artifact digest are compared instead;
  • per-file checkpoints are reused through the existing reviewItemFingerprint / manifest coverage path, so only files the parent settled as completed are skipped;
  • a changed worktree is rejected with a workspace-specific error and writes nothing, like every other rejected resume.

Because workspace input cannot be sealed the way agent.SealedInput seals commit endpoints, the admission check is the sole guarantee; this is documented in validateInputIdentity. Edits made during a resumed run are outside the contract (there is nothing to pin them to).

Docs updated in all five locales (en, zh, ja, ko, ru).

Type of Change

  • New feature (non-breaking change that adds functionality)

How Has This Been Tested?

  • make test passes locally (go test ./..., all 26 packages)
  • go vet ./... and gofmt -l are clean
  • New tests:
    • TestValidateOptions_WorkspaceMatches / TestValidateOptions_RejectsWorkspaceMismatch
    • TestValidateResume cases for workspace accepted, changed content, changed base
    • TestLoadReviewResumeState/workspace_resume_loads_session
    • TestValidateResumeIdentityWorkspace (real git worktree: accepted when unchanged, rejected and persists nothing after an edit)
    • TestApplyResumeWorkspaceReusesCompletedItems

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI disclosure: implementation was drafted with DeepSeek Harness (deepseek-v4.1-flash) and reviewed/tested by the author; no AI co-author trailer.

Related Issues

Closes #1880

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 3 selected item(s).

@lizhengfeng101

lizhengfeng101 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for updating this on top of #1915. Strict/static workspace resume is the intended scope: unchanged HEAD and review input, reuse completed checkpoints, and retry unfinished work. Incremental reuse after edits and protection against edits during execution remain out of scope.

I tested a binary built from cedbeb1aace5b221a6d8d1c5c6b8ac480ea297fa against a real configured LLM, using a disposable Git repository. Unchanged-workspace recovery works, but there is one correctness issue to address before merging, together with regression coverage and a documentation correction.

1. Reject resume after a tracked-file deletion

Reproduced with two independently dispatched workspace changes:

  1. HEAD contains a.go, b.go, and c.go; a.go calls Helper() from b.go.
  2. Modify a.go and c.go, leaving b.go unchanged. Review with --concurrency 1, then send SIGINT after a.go completes. The saved manifest records completed=[a.go] and failed=[c.go].
  3. Delete b.go, without changing HEAD, the two existing patches, or review configuration.
  4. Resume the original session.

Actual: exit 0, terminal state complete, reused_files=1, rerun_files=1. The child reuses a.go, reviews only c.go, and lists b.go as excluded with reason deleted. The source-artifact digest is identical to the parent's, despite the dependency disappearing.

Expected: reject before creating a child session or issuing an LLM request, and ask for a fresh review. This is an input change before admission, not a concurrent-edit or incremental-resume requirement.

The identity currently relies on the review-item digest, and sourceArtifactSHA256() in internal/agent/agent.go explicitly skips deleted diffs. Please make workspace admission and the persisted identity consistently cover this change in input, without requiring deleted files to become review tasks. Keep the existing checkpoint reuse mechanism; there is no need to introduce snapshots or incremental recovery. If the identity format changes, unverifiable older sessions should fail closed.

2. Add an end-to-end regression

Please add a deterministic CLI-level test using a temporary Git repository and a controlled fake LLM, covering a saved partially completed workspace session and its resume. Assert:

  • Unchanged input reuses the completed file, calls the LLM only for unfinished work, and records correct coverage and parent lineage.
  • Editing a selected file, deleting a previously unchanged tracked file, restoring a file that was deleted in the parent's input, or changing HEAD rejects the resume before a child session or LLM request. Returning the workspace exactly to the parent's input should remain acceptable.
  • Identity checks derive their input from actual Git changes, rather than manually substituting a different digest.

The live test already confirmed the unchanged-input case and rejection after a selected-file edit or HEAD change. The deletion case is the failing one; please retain the passing behavior and existing range/commit coverage.

3. Synchronize the tool guides

pages/src/content/docs/{en,zh,ja,ko,ru}/tools.md still says workspace resume is unsupported, while this PR updates the CLI references to support it. Please update all five tool guides to describe the same strict/static contract, including the unchanged-input requirement and the boundary around edits during execution.

AI assistance disclosure: Codex assisted with review/test preparation and this summary; the live OCR tests used gpt-6-astra.

Workspace identity hashed only non-deleted diffs, so deleting an otherwise
unchanged tracked file left source_artifact_sha256 identical to the parent's
and a resumed session silently reviewed a different workspace: the deleted
file was excluded while its dependent edits were reused.

Include deleted diffs in the workspace digest. Range and commit reviews keep
skipping them because their comparison endpoints already seal the old side;
workspace reviews have no such seal, so a deletion or restoration of a tracked
file must change the admitted identity and fail closed on resume.

Add a deterministic CLI-level regression: a real Git repository plus a fake LLM
produce a partially completed workspace session, and the test asserts that
unchanged input reuses completed files and retries only unfinished ones, while
editing a selected file, deleting an unchanged tracked file, restoring a file
deleted in the parent input, or moving HEAD is rejected before a child session
or LLM request. Returning the workspace exactly to the parent input is accepted
again.

Update all five tool guides to describe the strict/static workspace resume
contract instead of claiming it is unsupported.
@Walternater

Copy link
Copy Markdown
Contributor Author

Thanks — all three points are addressed in 60ceb8e (pushed to feat/workspace-resume, on top of cedbeb1).

1. Tracked-file deletion is now part of the workspace identity. sourceArtifactSHA256() includes deleted diffs in workspace mode (internal/agent/agent.go). Range/commit keep skipping them, since their comparison endpoints already seal the old side. Your reproduction now rejects before admission with the "workspace changed since session" error, and no child session or LLM request is created. Sessions persisted before this change that contain deletions fail closed (their digest no longer matches); deletion-free older sessions still match.

2. Deterministic CLI-level regression added as cmd/opencodereview/workspace_resume_e2e_test.go — a real temporary Git repository plus the package's fake LLM, not hand-built identities. One parent session is partially completed (one file fails); the test asserts:

  • unchanged input reuses the completed files without re-requesting them, retries only the failed file, and records correct coverage/lineage;
  • editing a selected file, deleting a previously unchanged tracked file, restoring a file deleted in the parent's input, or moving HEAD is rejected before a child session or LLM request (session count and fake-LLM attempt counts are unchanged);
  • returning the workspace exactly to the parent input (delete → restore → delete) is accepted again.

I also verified the deletion subtest fails on the pre-fix code and passes with the fix.

3. All five tool guides synchronized (pages/src/content/docs/{en,zh,ja,ko,ru}/tools.md): removed "workspace resume is unsupported" and documented the strict/static contract — resume only while HEAD and the review input (including deletions/restorations of tracked files) are unchanged, reuse completed checkpoints, retry unfinished work, and edits after or during execution are out of scope.

Verification: TMPDIR=/private/tmp go test ./... all packages pass; go vet ./... and gofmt clean.

AI disclosure: the implementation and tests above were produced with DeepSeek Harness (deepseek-v4.1-flash); I reviewed the diff and ran the suite.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for the update. I checked 60ceb8e2a53e7094ee1442e69eb26a9b102810ec against the previous feedback: workspace deletions now participate in the identity, the real-Git/fake-LLM regression tests are present, and all five tool guides describe strict/static resume. Those address the substance of the previous requests. This follow-up is based on static inspection; I have not rerun your test suite.

Could you make two focused documentation/test follow-ups?

1. Make the normalized-input boundary explicit and test it

The current identity compares the selected, parsed/normalized diff, not a byte-identical snapshot of the selected files. For example, an untracked file without a final LF and the same file with a final LF can produce the same synthesized patch (untrackedFileDiffs); splitDiffLines also strips trailing CR, so LF/CRLF-only changes can preserve the fingerprint. HEAD and configuration can remain unchanged throughout.

Please clarify that distinction wherever the resume contract could imply byte-for-byte worktree equality, including the CLI references/tool guides and the introductory comment in workspace_resume_e2e_test.go. Keep the affected localized documentation consistent. The existing deletion/restoration and concurrent-edit explanations do not need to be redone.

Please add deterministic cases with a real untracked file and the fake LLM to pin the intended behavior for adding/removing its final LF and converting LF/CRLF. If normalized-diff equality is the intended contract, assert that these equivalent inputs may resume and reuse completed work, while a substantive content edit still rejects before creating a child session or issuing an LLM request. If byte-exact equality is intended instead, the identity needs to preserve those distinctions rather than documenting the stronger guarantee over the current fingerprint.

This is a contract clarification and regression request, not a request for incremental recovery, workspace snapshots, or protection against edits during execution.

2. Tighten the existing zero-request assertion

In assertWorkspaceResumeRejected (cmd/opencodereview/workspace_resume_e2e_test.go:163), the test compares only len(got) with len(beforeAttempts). That checks the number of file keys, not the number of HTTP attempts: an extra request for an already-seen file still passes. Please compare the complete per-file counts (or a monotonic total request count), so the test actually enforces the previous request that rejected resumes issue no additional LLM calls.

AI assistance disclosure: Codex assisted with this follow-up review and comment.

The workspace resume identity covers the selected, parsed diff rather than a
byte-for-byte worktree snapshot. Document that boundary in the CLI references
and tool guides (all five locales) and pin it with an end-to-end test: an
untracked file that gains or loses its final newline, or switches between LF
and CRLF, normalizes to the same diff and reuses completed checkpoints, while
a substantive edit is still rejected before a child session or LLM request.

Also tighten the rejected-resume assertion to compare complete per-file
attempt counts; comparing only the number of file keys would miss a second
request for an already-seen file.
@Walternater

Copy link
Copy Markdown
Contributor Author

Addressed both follow-ups in 1e75163 (pushed on top of 60ceb8e).

1. Normalized-input boundary. I kept the contract as normalized-diff equality — identity is the selected, parsed diff — rather than byte-exact worktree equality, and made the distinction explicit:

  • cli-reference.md (en/zh/ja/ko/ru): the workspace resume bullet now says identity is computed from the selected, parsed diff, not from a byte-for-byte snapshot of the worktree; adding or removing an untracked file's final newline, or an LF/CRLF-only line-ending change, normalizes to the same diff and still resumes, while a substantive content edit is rejected.
  • The same clarification is in the five tools.md guides.
  • The introductory comment in workspace_resume_e2e_test.go now states the normalized-diff boundary instead of byte-for-byte.
  • New TestWorkspaceResumeE2E_NormalizedInputBoundary (real untracked file + fake LLM) pins the behavior: (1) untracked file gains its final newline, (2) loses its final newline, (3) LF→CRLF, (4) CRLF→LF — all four resume successfully and reuse a.go, d.go and u.go while only the failed c.go is retried; (5) a substantive edit of the untracked file still rejects before a child session or LLM request.

2. Zero-request assertion. assertWorkspaceResumeRejected now compares the complete per-file attempt counts with maps.Equal instead of only len(got) != len(beforeAttempts), so a second request for an already-seen file fails the test.

Verification: TMPDIR=/private/tmp go test ./... (26 packages pass), go vet ./..., gofmt clean (macOS arm64, Go 1.26.10). I confirmed the new boundary subtests fail if the normalized-diff behavior is not what the contract claims; the substantive-edit subtest exercises the zero-child/zero-LLM assertion.

AI assistance disclosure: implementation and wording were drafted with DeepSeek Harness (deepseek-v4.1-flash) and verified locally as described above.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 94893d9 into alibaba:main Nov 14, 2026
15 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.

feat(review): support --resume for workspace-mode reviews

2 participants