Skip to content

feat(workspace): support comparison-side code access - #1915

Merged
lizhengfeng101 merged 1 commit into
mainfrom
feat/workspace-sides
Nov 14, 2026
Merged

lizhengfeng101 merged 1 commit into
mainfrom
feat/workspace-sides

Conversation

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Description

Extend the comparison-side tools introduced in #1903 to workspace reviews.

  • Add optional side: "old" | "new" to file_read, code_search, and file_find. The default/new side retains its existing output and reads the live working tree; the old side reads HEAD frozen at initialization, not HEAD's parent.
  • Share the frozen base between the diff, old-side tools, and manifest. Only a genuinely unborn branch uses an empty old tree; corrupt or unavailable HEAD remains an error. Shallow workspaces do not require HEAD's parent.
  • Use the same workspace provider for preview and actual review. Remove the staged fallback: staged-then-edited files use working-tree content, and a zero net workspace diff stays empty. Disable Git's optional index refresh so diff collection does not modify the index.
  • Add workspace-specific tool descriptions without changing commit/range or scan schemas, and update the five localized tool guides.

The new side is deliberately not snapshotted. Workspace resume remains unsupported. This changes the previous staged fallback behavior rather than adding a staged-only review mode.

Type of Change

  • Bug fix
  • New feature
  • Documentation update

How Has This Been Tested?

  • make check
  • make test (full suite, including the race detector)
  • make coverage (91.6% total coverage; 90% required)
  • ocr review --audience agent --background "..." --format json: completed all 8 selected source files with no comments and no failed files.
  • Regression tests for SHA-1/SHA-256 repositories, unborn branches, shallow HEAD, corrupt HEAD, frozen baselines, staged/working-tree divergence, zero net diff, and index preservation.
  • Tool tests for both sides, unchanged default output, invalid arguments, untracked/deleted/renamed paths, concurrent calls, and schema isolation.
  • Mocked-model CLI integration tests covering tool declarations, old/new reads, and the persisted workspace manifest.

No model-quality benchmark was run for this change.

Checklist

  • Code follows the project's style and passes formatting, vet, license, and English-only checks.
  • Tests cover the new behavior and existing tests pass.
  • Documentation is updated.
  • The contributor has personally reviewed and understands the generated changes, and will answer maintainer questions from their own understanding.
  • CLA status confirmed.

AI/LLM Disclosure

Implementation and test/documentation preparation used OpenAI Codex with gpt-6-astra. The pre-commit review used OpenCodeReview v1.13.8 with gpt-6-astra via idealab-responses. No AI attribution or co-author trailers are included in the commit.

Related Issues

Follow-up to #1903.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 2 issue(s) in this PR.

  • ✅ Successfully posted inline: 2 comment(s)

Comment thread internal/diff/git.go
Comment on lines +180 to +181
resolution, _ := p.ResolveWorkspaceComparison(ctx)
return resolution

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.

bug · high
Bug: The error from ResolveWorkspaceComparison is silently discarded. While ResolveInput documents that it never returns an error, the previous workspace implementation (resolveCommit("HEAD")) could only "fail" by returning an empty string when HEAD doesn't exist — a benign case. The new ResolveWorkspaceComparison can fail for other reasons (e.g., git binary not found, permission errors, repository corruption), and those failures are now silently swallowed.

This matters because ResolveInput is called in agent.go to populate a.inputResolution for the run manifest. If ResolveWorkspaceComparison fails transiently here but succeeds later during GetDiffSet → workspaceTrackedDiff, the manifest will record empty/zero endpoints while the diff was generated against a real base — an inconsistency that could mislead downstream consumers of the manifest.

Consider logging the error or restructuring so the resolution is performed once and reused consistently.

if current.Mode != ModeWorkspace || current.Ref != "" {
return nil, fmt.Errorf("workspace code access requires a live working tree")
}
if (previous.Mode != ModeCommit || previous.Ref == "") && (previous.Mode != ModeEmpty || previous.Ref != "") {

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.

maintainability · low
This compound boolean expression is correct but hard to read and verify. It uses a double-negation structure ((NOT valid-commit) AND (NOT valid-empty)) that requires careful mental evaluation of each sub-condition.

Consider extracting the validity checks into named variables for clarity and consistency with how NewComparisonCodeAccess structures its validation:

validCommit := previous.Mode == ModeCommit && previous.Ref != ""
validEmpty := previous.Mode == ModeEmpty && previous.Ref == ""
if !validCommit && !validEmpty {
    return nil, fmt.Errorf("workspace code access requires a pinned base or an empty tree")
}

This makes each accepted state explicit and reduces the risk of future modification errors.

@css521

css521 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

lgtm

@MuoDoo MuoDoo left a comment

Copy link
Copy Markdown
Collaborator

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 abd6416 into main Nov 14, 2026
16 checks passed
@lizhengfeng101
lizhengfeng101 deleted the feat/workspace-sides branch November 14, 2026 03:29
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.

3 participants