Skip to content

fix(compiler): leave tail -n +N to the VFS shell instead of printing the last N lines - #441

Open
breken-ai wants to merge 1 commit into
activeloopai:mainfrom
breken-ai:fix/tail-plus-n-from-line
Open

breken-ai wants to merge 1 commit into
activeloopai:mainfrom
breken-ai:fix/tail-plus-n-from-line

Conversation

@breken-ai

@breken-ai breken-ai commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary

tail -n +N prints a file from line N onward. The compiled Bash fast path (src/hooks/bash-command-compiler.ts, parseHeadTailStage) read +N as N and returned the last N lines instead.

So when an agent pages a memory file with tail -n +3 ~/.deeplake/memory/summaries/…, the pre-tool-use hook answers from the compiled path with the wrong part of the file, and nothing tells the agent.

Reproduction on ce30de7, with a file holding l1…l8:

command GNU tail / just-bash compiled fast path before after
tail -n +3 /a.md l3 … l8 l6 l7 l8 declines, so the VFS shell answers with l3 … l8

Fix: parseHeadTailStage returns null for tail -n +N. The compiler then declines the command, and the VFS shell handles it. Its just-bash tail implements the +N form. I checked that tail -n +3 there prints l3…l8. The other fast paths in pre-tool-use.ts don't match +N (their regex is -?\d+), so nothing else picks up the command before the shell does. cat f | tail -n +N was already rejected by isValidPipelineHeadTailStage.

This PR adds a regression test in tests/claude-code/bash-command-compiler.test.ts. It fails on main because the parser returns a cat segment, and it passes with the fix.

Version Bump

Not bumped. This is a patch-level bug fix, so I've left the release decision to you.

Test plan

  • Tests pass locally (npm test): 5823 passed. The 17 failures are the same on the untouched main checkout and come from the environment: cowork-queue-leak, install-cowork, skillify-state, plugin-cache-gc-bundle, and two graph suites.
  • Relevant new tests added: does not compile tail -n +N…. It fails on main and passes on this branch.
  • npm run typecheck and npm run dup pass.
  • Version bumped in package.json, or no release needed for this change

An AI agent (breken-ai) found this and wrote the fix and test. I reviewed and ran everything above before opening the PR.

Summary by CodeRabbit

  • Bug Fixes
    • tail -n +N commands now use shell handling to return lines from line N onward, rather than being interpreted as a last-N-lines window.

…the last N lines

tail -n +N prints from line N onward. The compiled fast path read +N as N and
returned the last N lines, so an agent paging a memory file with tail -n +3
got the wrong part of it. Decline the +N form so the VFS shell, whose tail
implements it, answers instead.
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: activeloopai/hivemind/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: a69644b5-5331-485f-8142-b43e764f8db9

📥 Commits

Reviewing files that changed from the base of the PR and between ce30de7 and 2ba92c1.

📒 Files selected for processing (2)
  • src/hooks/bash-command-compiler.ts
  • tests/claude-code/bash-command-compiler.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The bash command compiler now rejects tail -n +N commands. A test verifies that the compiled parser rejects the command and that compiled execution returns null without reading virtual-path contents.

Changes

Tail from-line handling

Layer / File(s) Summary
Reject +N tail syntax
src/hooks/bash-command-compiler.ts, tests/claude-code/bash-command-compiler.test.ts
parseHeadTailStage returns null for tail -n +N. The test checks that parsing and compiled execution return null, and that execution does not read virtual-path contents.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 2ba92

tail -n +N is routed to the virtual shell rather than producing the incorrect compiled output. No merge-blocking issue is established.

Architecture Summary

Architecture risk: 🔵 Low · up to 2ba92

The change affects 2 systems.

Changed systems: src, tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in src/hooks/bash-command-compiler.ts: parseHeadTailStage now returns null for tail -n +N; previously this case continued into numeric parsing and could be represented as a last-N-lines window. The added comment states that the VFS shell handles the +N form.
  • observed — Modified behavior in tests/claude-code/bash-command-compiler.test.ts: Added a test for tail -n +3 /a.md: it expects parseCompiledSegment to return null, and compiled execution to return null without reading virtual-path contents.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: deferring tail -n +N handling to the VFS shell instead of compiling it incorrectly.
Description check ✅ Passed The description includes the required Summary, Version Bump, and Test plan sections. It explains the bug, fix, regression test, validation results, and the absence of a version bump. The release decis…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

This branch has not been deployed

No deployments
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.

1 participant