Skip to content

Fix #1898: consult auto-detects slugless builder worktrees; errors never list projects - #1899

Merged
waleedkadous merged 8 commits into
mainfrom
builder/bugfix-1898
Nov 15, 2026
Merged

waleedkadous merged 8 commits into
mainfrom
builder/bugfix-1898

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

From a slugless builder worktree (.builders/bugfix-N, .builders/spir-N), a hand-run consult -m <model> --protocol <p> --type <t> exited 1 with Multiple projects found: <every project dir> — one line of ~95k characters in a repo with ~2300 project dirs, and no hint to pass --issue. Consult now resolves the worktree's project exactly as porch does, and every not-found error is one short line.

Fixes #1898

Root Cause

getBuilderProjectState() in packages/codev/src/commands/consult/index.ts disambiguated multiple project dirs with its own regex, /\.builders\/[^/]*?-?(\d+)-([^/]+)/, which requires a -<slug> after the number. Spec 653 made worktrees ID-only, so the regex matched no current worktree, and the code fell through to a throw that joined every dir name. Porch already had a correct resolver for the same job (detectProjectIdFromCwd()); consult kept a second, drifted copy. Porch-driven runs were unaffected because porch passes --project-id.

Reproduced with the installed consult 3.3.7 from this worktree: exit 1, a 13,250-char line listing 341 dirs. Seven earlier builder threads in codev/state/ record the same failure.

Fix

  • getBuilderProjectState() calls detectProjectIdFromCwd() and matches the dir with porch's <id> / <id>-<slug> rule. Both ad-hoc regexes are gone. This covers slugless and slugged worktrees, subdirectories, and tracker keys.
  • detectProjectIdFromCwd() moved verbatim into the pure lib/worktree-project-id.ts, and porch/state.ts re-exports it, so porch callers and tests are unchanged. Importing porch/state.ts from consult directly pulled in its load-time promisify(execFile), which broke 70 tests in suites that mock node:child_process.
  • All three not-found throws are now one line: what was tried (--project-id, the worktree ID, or the cwd), <count> projects in codev/projects/, and pass --issue <N> or --project-id <id>. The project list is never printed.
  • A dir counts as a project only if it holds a status.yaml, as in porch's findProjectInDir. A leftover name-matching dir can't shadow the real project, and the error's count covers projects only. (CMAP follow-up)
  • Side fix: a bugfix worktree resolves to its bugfix-N-… project only. The old code tried N-… first and could pick a same-numbered SPIR project. The slugged-worktree test pins this.

Behaviour note: worktree prefixes porch does not recognise (for example a legacy .builders/experiment-12-slug) used to match consult's generic regex. They now get the short error, the same as porch. No current (Spec 653) worktree matched that regex anyway.

Test Plan

  • Regression test added: consult/__tests__/bugfix-1898-builder-project-detect.test.ts covers a slugless root, a subdirectory, a slugged worktree, a SPIR worktree and a tracker-key worktree, each among several projects. It also bounds each error's length with 2,300+ project dirs. 7 of the original 8 fail on the old code; the tracker-key case already worked and stays as a guard. A 9th test, a status-less dir not shadowing the real project, fails without the CMAP follow-up. All 9 pass.
  • Build passes (pnpm --filter @cluesmith/codev build)
  • All tests pass: 7,247 passed, 49 skipped, 0 failed
  • End-to-end: the built CLI, run with the adopter's command from this worktree's root and from codev/specs and codev-skeleton/protocols/bugfix, gets past detection to No PR found for branch (expected before the PR existed). A simulated .builders/task-abcd gives one 338-char line.

CMAP

All three lanes ran through this PR's own build with no --issue, so they exercised the fixed path, and each auto-persisted into codev/projects/bugfix-1898-…/.

Lane Verdict
gemini APPROVE (HIGH)
codex APPROVE (HIGH)
claude APPROVE (HIGH): two non-blocking notes, both addressed in the follow-up commit

The claude lane on the local build first failed with API 400 "thinking.type.enabled" is not supported. The worktree lockfile installs @anthropic-ai/claude-agent-sdk 0.2.105; the installed consult ships 0.2.141. It was re-run with the installed consult and --project-id. That failure is unrelated to this PR.

Flaky Tests

One of three full runs exited 1 on an unhandled Node-internal ERR_INTERNAL_ASSERTION (http2 teardown in MockTunnelServer.stop) from agent-farm/__tests__/tunnel-edge-cases.test.ts, with all tests passing. It is unrelated to consult and ran clean 5 of 5 times in isolation. The test is not skipped.

Not fixed, and unrelated: from .builders/<id>/packages/, findWorkspaceRoot() stops at packages/ because it contains this repo's own codev package dir. That comes from this repo's layout and predates this change.

🤖 Generated with Claude Code

…ver list projects

getBuilderProjectState() disambiguated multiple project dirs with a regex that
required a -<slug> after the worktree number. Spec 653 worktrees are ID-only
(.builders/bugfix-N, .builders/spir-N), so every hand-run `consult --type ...`
in a builder worktree fell through to a throw that joined every project dir
name into one line (~95k chars at ~2300 dirs).

Consult now resolves the worktree's project with porch's own
detectProjectIdFromCwd(), moved verbatim into the pure lib/worktree-project-id.ts
(porch/state.ts re-exports it) so consult does not import porch's state module.
All three not-found errors are one short line: what was tried, the project
count, and "pass --issue <N> or --project-id <id>".

A bugfix worktree now resolves to its bugfix-N project only; the old code tried
N-... first and could pick a same-numbered SPIR project.
…mment the --project-id fallback

Mirror porch's findProjectInDir: a leftover name-matching dir without status.yaml
no longer shadows the real project, and the error hint's count is projects only.
Comment why --project-id keeps the bugfix-<id> fallback while a worktree-derived
ID does not. Thread: CMAP verdicts (all APPROVE) and the tunnel teardown flake.
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.

consult: project auto-detect fails in slugless builder worktrees (.builders/bugfix-N) and dumps every project name

1 participant