Skip to content

fix: propagate ripgrep failures from glob - #187

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
mikemikimike:fix/propagate-rg-glob-failures
Aug 31, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
mikemikimike:fix/propagate-rg-glob-failures

Conversation

@mikemikimike

Copy link
Copy Markdown
Contributor

Related issue

Closes #186.

Background

The glob operation pipes ripgrep into head without preserving the producer status. Because the shell reports the last pipeline command, an invalid ripgrep pattern can return an empty result with exit code 0, hiding a real search failure.

Changes

  • Preserve rg's status with Bash PIPESTATUS[0].
  • Treat the expected 141 status from head closing a full pipe as success.
  • Raise an error for other non-zero statuses instead of returning a misleading empty result.
  • Add a regression test for ripgrep failure and update command-shape assertions.

Compatibility

Successful searches and normal limit truncation remain unchanged. The command runs through the existing bash -c kubectl transport, and only genuine ripgrep failures now reject.

Validation

  • git diff --check — passed.
  • pnpm install --frozen-lockfile — blocked by Windows EPERM while copying packages from the pnpm store.
  • Retried with --child-concurrency=1 --network-concurrency=1 — same EPERM class of failure.
  • Focused Vitest and package typecheck could not run because dependencies were not installed.

Known limitation

The full repository test, lint, typecheck, and build commands were not run because the required pnpm workspace dependencies could not be installed in this Windows environment. CI provides the authoritative validation once the fork workflow is approved.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the clean, well-scoped fix and for the detailed write-up in the PR body — the PIPESTATUS[0] approach is the right one and matches the prescription in #186.

Two things verified in the process, both good news:

  • The bashism is safe. bash -c is confirmed on all three transports: exec.ts:15 (kubectl), persistent-exec.ts:10 (bare bash), and the Go remote worker (per remote-worker/DESIGN.md).
  • glob really is the only op piping to head, which closes the "scope note" question at the end of #186.

CI is fully green (all 10 checks).

Blocking issue: the guard rejects rg's exit 1, which means "no matches" — not a failure. Verified against ripgrep: -g '*.ts' (match) exits 0, -g '*.zzz' (no match) exits 1, -g '[' (malformed) exits 2. The shell guard propagates the 1 (producer_rc=1 -> shell_rc=1), and the new JS check then throws. So glob("*.go", ...) in a tree with no Go files now throws glob failed in pod instead of returning [] — a routine case, and a regression against main.

This package already encodes the correct contract in grep-tool.ts:44-50:

if (r.exitCode !== 0 && r.exitCode !== 1) { ... }
// rg exits 1 with no output when there are no matches.

Importantly, tolerating 1 does not reopen #186 — the malformed-pattern case that issue targets is exit 2, which still rejects. So the fix stays intact.

Details inline, plus two test suggestions that would have caught this.

Comment thread packages/k8s-sandbox/src/operations.ts Resolved
Comment thread packages/k8s-sandbox/src/operations.ts Resolved
@mikemikimike

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in commit efba9ea:

  • rg exit 1 (no matches) is now accepted by both the shell guard and the JavaScript result check.
  • Genuine failures such as exit 2 remain rejected.
  • Added a regression test with exitCode: 1 asserting that glob() resolves to [].
  • Removed the unreachable JavaScript-side 141 check; the shell guard still tolerates the expected SIGPIPE status.

Validation: operations.test.ts passes all 18 tests. The package suite passes 84 tests across 11 suites, with the remaining extension suite blocked locally because the repository's pi-fork submodule could not be fully restored on Windows; the existing PR CI was green before this follow-up. git diff --check passes.

@pdettori

Copy link
Copy Markdown
Member

@mikemikimike thank you for promptly addressing the review comments. There were other changes in main, so a rebase is now needed - thanks!

@mikemikimike

Copy link
Copy Markdown
Contributor Author

Addressed all four review findings in the current head efba9ea:

  • rg exit code 1 is treated as the valid no-match result in both the shell guard and the JS operation path.
  • The test suite now explicitly covers exit 1 returning [] and exit 2 rejecting.
  • The shell-side 141 handling remains intentional because the pipeline can terminate through head; the JS-side behavior accepts the normalized result.

The current branch also contains the corresponding malformed-pattern and no-match regression cases. I verified the source and tests against the PR head; local Vitest execution was blocked by pnpm's build-script approval policy for esbuild/protobufjs, not by a test failure.

@pdettori

Copy link
Copy Markdown
Member

thank you @mikemikimike , but there are still conflicts that need to be resolved in the file operations.ts

@mikemikimike
mikemikimike force-pushed the fix/propagate-rg-glob-failures branch from efba9ea to 30901f9 Compare August 31, 2026 07:09
@mikemikimike

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and resolved the operations.ts conflict while preserving both upstream truncation protection and this PR's PIPESTATUS handling. Empty rg results remain valid (exit 1); malformed patterns still fail. New head: 30901f9.

@mikemikimike

Copy link
Copy Markdown
Contributor Author

Fixed in 30901f9. The current guard allows rg exit 1 for no matches, while exit 2 still fails. CI was green before the rebase and the PR is now mergeable.

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@pdettori
pdettori merged commit effa7d9 into rossoctl:main Aug 31, 2026
10 checks passed
pdettori added a commit to pdettori/moca that referenced this pull request Aug 31, 2026
rossoctl#187 (propagate ripgrep failures from glob) merged to main while this branch was
in review, touching the same `createPodFindOps.glob`. The two changes are
complementary and both are kept.

rossoctl#187 adds a shell guard so `rg`'s own status survives the pipe to `head`, which
would otherwise mask it:

    rc=${PIPESTATUS[0]}; [ "$rc" = 0 ] || [ "$rc" = 1 ] || [ "$rc" = 141 ] || exit "$rc"

plus the matching `r.exitCode !== 1` tolerance, since rg exits 1 for "no
matches". That is about the SEARCH failing.

This branch splits truncation into its own `truncated` flag, because a cap trip
is a property of the seam and can happen while rg is perfectly happy — reporting
it as "rg exited N" blames the wrong component.

Resolution keeps rossoctl#187's exec command verbatim and checks `truncated` first, then
the null exit code, then rossoctl#187's `!== 0 && !== 1` guard. A naive resolution that
took this branch's side would have silently dropped rossoctl#187's `!== 1` tolerance,
reintroducing the "no matches reads as an error" bug it fixed.

Verified the two compose in the pod, not just on paper: `glob` runs over the
persistent channel, so the merged command is rossoctl#187's guard nested inside this
branch's `{ … } | head -c <cap+1> | base64` wrapper. Inside the brace group
`${PIPESTATUS[0]}` still resolves to the inner `rg | head -n` pipeline, and the
group's own status becomes the outer `PIPESTATUS[0]`. Live gate 7/7 on the merged
tree, with Claim 4 returning ["top.ts","src/keep.ts"] — the result SMOKE.md
documents.

make typecheck EXIT 0; k8s-sandbox 129 passed / 11 skipped; harness 226 passed /
3 skipped.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
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.

glob masks rg failures: head's exit status hides a failed search behind an empty result

2 participants