Skip to content

fix(orchestrator): keep unborn-HEAD untracked scoop from evicting agent files - #11836

Merged
lalalune merged 1 commit into
developfrom
fix/rh-3
Jul 3, 2026
Merged

lalalune merged 1 commit into
developfrom
fix/rh-3

Conversation

@NubsCarson

Copy link
Copy Markdown
Member

What

captureChangeSet's unborn-HEAD untracked scoop (introduced in 3781312, #11605 FIX C) could flood the 60-file MAX_CHANGED_FILES cap and evict the agent's real files from the change set.

Failure path (reproduced with a failing test before the fix): fresh repo (git init this session, zero commits), agent scaffolds an app and runs npm install BEFORE writing .gitignore. ls-files --others --exclude-standard has no .gitignore to honor, so it returns thousands of node_modules paths. changedFiles = [...tracked, ...untracked, ...agentWritten].slice(0, 60) spread the highest-signal agentWritten entries LAST — and Set dedupe keeps first-occurrence position — so 60 node_modules paths evicted the agent's index.html/server.js entirely. diffStat and per-file diffs rendered junk, and "what did you change" answered with node_modules noise.

Red run against the unfixed code (exact defect signature):

AssertionError: expected [ 'index.html', …(59) ] to include 'package.json'
AssertionError: expected 'page-00.html' to be 'zzz-server.js'

Fix (structural)

  1. Vendor-dir fallback filter on the unborn-HEAD scoop onlynode_modules, .git, .venv, dist, build, etc. are dropped from the ls-files --others listing. This is a fallback for the missing-.gitignore window only: the born-HEAD path never scoops untracked files (clutter invariant preserved), and explicit tool-written paths are always kept regardless (unioned separately via agentWritten).
  2. agentWritten spread FIRST into the changed-files union, so explicit edit/write tool calls can never be evicted by the cap. Set dedupe keeps first-occurrence order, so leading with them is the durable position.
  3. Truncated-tail guard in parseLsFiles — a listing cut at maxBuffer (ENOBUFS on a huge untracked tree) ends mid-path instead of with a newline; the partial garbage line is dropped instead of surfacing as a phantom changed file.

Tests

Three new tests in __tests__/unit/workspace-diff.test.ts (real git repos, no mocks):

  • filters vendor install output that predates any .gitignore — 120-package node_modules + 3 real app files on an unborn HEAD; asserts all 3 real files survive and zero node_modules paths appear (failed before: index.html + 59 node_modules, package.json/server.js evicted).
  • agent-written files survive the cap ahead of a large scaffold — 70 untracked files + 1 tool-written file sorting last; asserts the tool-written file leads the list (failed before: evicted at position 71).
  • parseLsFiles drops the truncated garbage tail of an over-maxBuffer listing.

Verification (real output)

  • bunx vitest run __tests__/unit/workspace-diff.test.ts24 passed (21 pre-existing + 3 new)
  • Full plugin suite bunx vitest run --config vitest.config.ts150 files passed | 4 skipped, 1577 tests passed | 8 skipped, 0 failed
  • bun run typecheck (tsgo) → clean
  • Biome check on both files → clean

All existing invariants pinned by the suite hold: born-HEAD clutter exclusion, baseline-dirty exclusion, gitignore honoring, tool-path relativization/escape rejection.

Refs 3781312 (#11605), #11578.

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 55d0f29b-6da6-494b-abb9-d228deae725a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rh-3

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.

…nt files

the unborn-HEAD change-set scoop (3781312, #11605) unions
'ls-files --others --exclude-standard' into changedFiles, but a fresh
scaffold that runs npm install BEFORE writing .gitignore has thousands
of untracked node_modules paths (--exclude-standard has nothing to
honor yet). those flooded the 60-file cap, and because agent-written
tool paths were spread LAST (Set dedupe keeps first occurrence), the
flood evicted the agent's real files: 'what did you change' answered
with node_modules noise and diffs rendered junk.

- filter vendor/build dirs (node_modules, .venv, dist, ...) from the
  unborn-HEAD untracked scoop only; born-HEAD never scoops untracked
  and explicit tool-written paths are always kept
- spread agentWritten first so explicit edit/write tool calls survive
  the MAX_CHANGED_FILES cap
- drop the truncated garbage tail line when the ls-files listing was
  cut at maxBuffer (ENOBUFS)

@greptile-apps greptile-apps Bot 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.

Your trial has ended. Reactivate Greptile to resume code reviews.

@lalalune
lalalune merged commit 69c2c3d into develop Jul 3, 2026
37 of 39 checks passed
@lalalune
lalalune deleted the fix/rh-3 branch July 3, 2026 10:22
@claude

claude Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants