Skip to content

Fix #290: discover harness instruction chains for overhead - #534

Open
willwashburn wants to merge 3 commits into
mainfrom
issue-290-overhead-file-discovery
Open

Fix #290: discover harness instruction chains for overhead#534
willwashburn wants to merge 3 commits into
mainfrom
issue-290-overhead-file-discovery

Conversation

@willwashburn

@willwashburn willwashburn commented Aug 3, 2026

Copy link
Copy Markdown
Member

Fixes #290

burn overhead now discovers the default instruction files each supported harness actually injects, instead of checking three fixed paths beneath the requested project directory.

Harness evidence and discovery rules

Harness Primary evidence Implemented startup discovery
Claude Code Official memory docs plus isolated Claude Code 2.1.220 sessions User ~/.claude/CLAUDE.md; CLAUDE.md and CLAUDE.local.md from filesystem root through the requested CWD; .claude/CLAUDE.md at the Git root (or requested CWD without a Git marker)
Codex Official AGENTS.md docs and codex-rs/core/src/agents_md.rs User $CODEX_HOME/AGENTS.override.md or AGENTS.md; one project instruction per directory from Git root through CWD, with override precedence and the default aggregate 32 KiB byte budget
OpenCode Official rules docs and packages/opencode/src/session/instruction.ts / FSUtil.findUp First existing user-global candidate; all project matches in the first winning filename class (AGENTS.md, then Claude-compatible CLAUDE.md) from Git root through CWD

Discovery is deterministic, labels every row as user, ancestor, or project, and merges same-kind physical aliases by device/inode or canonical identity. Missing, empty, and unreadable files do not create overhead rows.

On-demand descendant files are deliberately not scanned recursively: Claude Code and OpenCode inject them only after accessing that directory, while this filesystem-only discovery surface has no per-session activation evidence. Config-dependent fallback names, custom instruction globs/URLs, managed policy/rules/imports, and compatibility-disable flags remain conservative undercounts rather than speculative cost.

The Rust SDK and Node facade accept an optional harnessHome override for hermetic embedding and tests. Scope is included in Rust/Node/CLI/MCP result shapes and trim recommendations, and the CLI human output displays it.

Verification

  • cargo fmt --all -- --check
  • cargo test --workspace
  • cargo clippy --workspace --all-targets -- -D warnings
  • pnpm run test
  • Isolated-ledger CLI smoke test against the live worktree instruction hierarchy

🤖 Generated with Claude Code.

Review in cubic

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@willwashburn, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1270a1ee-e9ae-4e06-9186-32ea34e36cc8

📥 Commits

Reviewing files that changed from the base of the PR and between b68dfc4 and c55b233.

📒 Files selected for processing (5)
  • crates/relayburn-sdk/src/analyze/overhead.rs
  • crates/relayburn-sdk/src/query_verbs/overhead.rs
  • crates/relayburn-sdk/src/query_verbs/tests.rs
  • crates/relayburn-sdk/tests/integration.rs
  • packages/sdk-node/CHANGELOG.md
📝 Walkthrough

Walkthrough

The overhead system now discovers active Claude Code, Codex, and OpenCode instruction chains. It records user, ancestor, and project scopes, supports configurable harness homes, enforces discovery rules, and exposes scope data through the SDK, CLI, and Node API.

Changes

Harness-aware overhead discovery

Layer / File(s) Summary
Instruction-chain discovery and attribution
crates/relayburn-sdk/src/analyze/overhead.rs
Discovery now handles harness-specific roots, ordering, precedence, boundaries, deduplication, scopes, truncation, and Codex byte limits. Tests cover these behaviors and updated attribution fixtures.
SDK options and scoped results
crates/relayburn-sdk/src/analyze.rs, crates/relayburn-sdk/src/lib.rs, crates/relayburn-sdk/src/query_verbs/*, crates/relayburn-sdk/tests/integration.rs
The SDK accepts harness_home, routes home-aware discovery, exposes OverheadFileScope, and includes scope in overhead and trim results. Tests use isolated harness homes.
Node binding and type updates
crates/relayburn-sdk-node/src/lib.rs, packages/sdk-node/src/index.d.ts
Node APIs accept harness_home and forward it as a path. TypeScript declarations expose scope values and scoped result fields.
CLI presentation and release documentation
crates/relayburn-cli/src/commands/overhead.rs, CHANGELOG.md, packages/*/CHANGELOG.md
CLI defaults and messages reflect instruction-chain discovery. Human-readable file headers include scope. Changelogs document the new behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant LedgerHandle
  participant gather_overhead
  participant find_overhead_files
  participant InstructionFiles
  CLI->>LedgerHandle: overhead or overhead_trim with harness_home
  LedgerHandle->>gather_overhead: forward options
  gather_overhead->>find_overhead_files: discover active instruction chains
  find_overhead_files->>InstructionFiles: resolve, order, deduplicate, and limit files
  InstructionFiles-->>gather_overhead: scoped overhead files
  gather_overhead-->>LedgerHandle: scoped summaries or trim recommendations
  LedgerHandle-->>CLI: render scope and overhead data
Loading

Poem

I’m a rabbit with paths in my queue,
Finding CLAUDE.md and AGENTS.md too.
User, ancestor, project in line,
Deduped and scoped by design.
Harness homes now guide where I roam—
Overhead reports bring the results home.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes explicit file loading and injected-prefix handling, while #290 limits the work to discovery changes. Remove the loading behavior changes, or document them as a separate required change with corresponding scope and acceptance criteria.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: discovering harness instruction chains for overhead.
Description check ✅ Passed The description directly explains the discovery rules, API changes, scope metadata, and verification for this changeset.
Linked Issues check ✅ Passed The implementation addresses #290 requirements for ancestor discovery, hidden paths, ordering, empty-state messaging, and expanded tests.
Docstring Coverage ✅ Passed Docstring coverage is 93.18% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-290-overhead-file-discovery

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
crates/relayburn-sdk/src/analyze/overhead.rs (1)

454-463: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider tolerating read failures for individual discovered files.

Discovery now returns user-home and ancestor files. load_overhead_file propagates any io::Error, and gather_overhead in crates/relayburn-sdk/src/query_verbs/overhead.rs (lines 170-173) uses ?. If one discovered file is deleted or becomes unreadable between discovery and load, the whole overhead and overhead trim call fails. Skipping the affected file keeps the report usable.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/relayburn-sdk/src/analyze/overhead.rs` around lines 454 - 463, Update
gather_overhead to tolerate per-file I/O failures from load_overhead_file: skip
files whose loading fails, including files deleted or unreadable after
discovery, while continuing to process the remaining discovered files. Preserve
successful parsing and the existing report behavior, and avoid propagating an
individual load error through the overall overhead and overhead trim commands.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/relayburn-sdk/src/query_verbs/overhead.rs`:
- Around line 14-16: Add a public configuration option alongside harness_home to
bound Claude ancestor discovery, and have DiscoveryRoots::for_harness_home pass
it to find_overhead_files_with_roots instead of leaving claude_ancestor_stop
unset. Update crates/relayburn-sdk/src/query_verbs/overhead.rs#L14-L16 to
document the behavior, then update the fixture assertions in
crates/relayburn-sdk/src/query_verbs/tests.rs#L908-L908 and
crates/relayburn-sdk/tests/integration.rs#L197-L197 (including assertions at
lines 197, 206, 216, and 225) to use the bound or filter results to created
fixture paths.

In `@packages/sdk-node/CHANGELOG.md`:
- Line 5: Update the changelog bullet to name both public APIs, overhead() and
overheadTrim(), and describe their practical effects: discovering and labeling
instruction-chain files by scope, and including scope in trim recommendations
while supporting the harness-home option.

In `@packages/sdk-node/src/index.d.ts`:
- Around line 230-233: Update the OverheadTrimOptions interface to declare the
optional harnessHome string property, matching the Rust overhead_trim binding
and the existing OverheadOptions API so TypeScript callers can configure the
harness home for trim operations.

---

Nitpick comments:
In `@crates/relayburn-sdk/src/analyze/overhead.rs`:
- Around line 454-463: Update gather_overhead to tolerate per-file I/O failures
from load_overhead_file: skip files whose loading fails, including files deleted
or unreadable after discovery, while continuing to process the remaining
discovered files. Preserve successful parsing and the existing report behavior,
and avoid propagating an individual load error through the overall overhead and
overhead trim commands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fb93264d-cf2f-411a-9871-371cb52c21cf

📥 Commits

Reviewing files that changed from the base of the PR and between 5b531d0 and b68dfc4.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • crates/relayburn-cli/src/commands/overhead.rs
  • crates/relayburn-sdk-node/src/lib.rs
  • crates/relayburn-sdk/src/analyze.rs
  • crates/relayburn-sdk/src/analyze/overhead.rs
  • crates/relayburn-sdk/src/lib.rs
  • crates/relayburn-sdk/src/query_verbs/mod.rs
  • crates/relayburn-sdk/src/query_verbs/overhead.rs
  • crates/relayburn-sdk/src/query_verbs/tests.rs
  • crates/relayburn-sdk/tests/integration.rs
  • packages/mcp/CHANGELOG.md
  • packages/relayburn/CHANGELOG.md
  • packages/sdk-node/CHANGELOG.md
  • packages/sdk-node/src/index.d.ts

Comment thread crates/relayburn-sdk/src/query_verbs/overhead.rs
Comment thread packages/sdk-node/CHANGELOG.md Outdated
Comment thread packages/sdk-node/src/index.d.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b68dfc46b7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/relayburn-sdk/src/analyze/overhead.rs
@willwashburn

Copy link
Copy Markdown
Member Author

Review follow-up at ddba562:

  • Addressed the non-threaded read-race observation: an instruction file deleted or made unreadable after discovery is skipped without aborting the remaining overhead report; if every discovered file races away, the existing empty result shape is returned.
  • Validated the out-of-scope warning and retained the injected-prefix handling. It is part of accurate discovery accounting, not a separate explicit-file-loading feature: Codex injects at most 32 KiB across its project instruction chain, so parsing the full final file would charge tokens that never enter context. The shared Codex/OpenCode case now preserves a distinct extent per harness.

All four inline threads have concrete dispositions and are resolved.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/relayburn-sdk/src/analyze/overhead.rs">

<violation number="1" location="crates/relayburn-sdk/src/analyze/overhead.rs:178">
P2: A malformed UTF-8 instruction file makes `burn overhead` fail instead of being skipped as unreadable. Discovery should validate UTF-8 before returning the row, or loading should consistently use the lossy parser.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/relayburn-sdk/src/analyze/overhead.rs
Comment thread packages/mcp/CHANGELOG.md Outdated
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.

Investigate broader CLAUDE.md / AGENTS.md discovery in find_overhead_files

1 participant