Skip to content

fix(grep): respect cancellation token#1839

Closed
LING71671 wants to merge 1 commit into
Hmbown:mainfrom
LING71671:fix/grep-files-cancel
Closed

fix(grep): respect cancellation token#1839
LING71671 wants to merge 1 commit into
Hmbown:mainfrom
LING71671:fix/grep-files-cancel

Conversation

@LING71671

@LING71671 LING71671 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make grep_files observe the active ToolContext cancellation token while collecting files and scanning lines
  • return a clear cancellation error instead of continuing a broad recursive search after the user cancels
  • add regression coverage for a cancelled grep_files invocation

Related issue

#1791 tracks cancellation for synchronous search tools. This PR covers the grep_files part; #1790 covers file_search separately.

Validation

  • cargo fmt --all -- --check
  • cargo test -p deepseek-tui tools::search::tests::test_grep_files_respects_cancel_token
  • earlier full local pass on this branch: cargo test -p deepseek-tui tools::search::tests
  • earlier full local pass on this branch: cargo clippy -p deepseek-tui --all-targets --all-features (passes with pre-existing warnings in schema_migration.rs and tui/ui.rs)

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements cancellation support for the GrepFilesTool by passing a CancellationToken through the file collection and search logic. It includes a new test case to ensure the tool respects cancellation. The reviewer suggested generalizing the error message in the check_cancelled helper function to improve its reusability across different search tools.

Comment on lines +350 to +357
fn check_cancelled(cancel_token: Option<&CancellationToken>) -> Result<(), ToolError> {
if cancel_token.is_some_and(CancellationToken::is_cancelled) {
return Err(ToolError::execution_failed(
"grep_files cancelled before search completed",
));
}
Ok(())
}

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.

medium

The check_cancelled helper function uses a hardcoded error message that specifically mentions grep_files. Since the recursive file collection logic and this helper might be reused by other search tools in this module (such as the file_search tool mentioned in the PR description), it would be better to use a more generic message to avoid misleading error messages in the future.

Suggested change
fn check_cancelled(cancel_token: Option<&CancellationToken>) -> Result<(), ToolError> {
if cancel_token.is_some_and(CancellationToken::is_cancelled) {
return Err(ToolError::execution_failed(
"grep_files cancelled before search completed",
));
}
Ok(())
}
fn check_cancelled(cancel_token: Option<&CancellationToken>) -> Result<(), ToolError> {
if cancel_token.is_some_and(CancellationToken::is_cancelled) {
return Err(ToolError::execution_failed(
"Search operation cancelled before completion",
));
}
Ok(())
}

@LING71671 LING71671 marked this pull request as ready for review May 20, 2026 15:40
@LING71671

Copy link
Copy Markdown
Contributor Author

Addressed the Gemini review suggestion in 04b5781 by generalizing the cancellation helper error message from grep-specific wording to a reusable search cancellation message.

@Hmbown Hmbown added this to the v0.8.41 milestone May 21, 2026
@Hmbown Hmbown modified the milestones: v0.8.41, v0.8.43, v0.8.45 May 24, 2026
@Hmbown Hmbown mentioned this pull request May 24, 2026
reidliu41 pushed a commit to reidliu41/CodeWhale that referenced this pull request May 24, 2026
- grep_files now respects cancellation token (Hmbown#1839, thanks @LING71671)
- Ctrl+Z restores last cleared composer draft (Hmbown#1911, thanks @LING71671)
- Clipboard works on non-wlroots Wayland via wl-copy (Hmbown#1938, thanks @ousamabenyounes)
aboimpinto pushed a commit to aboimpinto/CodeWhale that referenced this pull request May 24, 2026
…c, receipt truncation fix

- SWE-bench: codewhale swebench run/export writes prediction JSONL
  from working-tree diff, with untracked-file inclusion via git add -N
- CLI: --workspace / -C global flag forwards to TUI for file ops
- CLI: codewhale exec --auto semantics clarified in help text
- Markdown: table pipes inside inline code no longer create phantom columns
  (split_table_cells with backtick-awareness)
- Receipt: floor_char_boundary prevents multibyte UTF-8 slice panic
- Contributors: Ling (LING71671 Hmbown#1839 Hmbown#1911), Ben Younes (ousamabenyounes Hmbown#1938),
  jeoor npm fix (Hmbown#1860) credited across all 3 READMEs
- ja-JP README: 19 contributors synced to parity with EN/zh-CN (80 each)
- Docs: SWEBENCH.md, RECURSIVE_SELF_IMPROVEMENT.md, MODES.md exec clarification
- Sub-agent footer: Alt+V hint now says 'details' not 'raw'
@Hmbown

Hmbown commented May 24, 2026

Copy link
Copy Markdown
Owner

Thanks @LING71671 — this landed in #1988 and is on main via commit 8878ac0. The shipped change makes grep_files observe the ToolContext cancellation token and includes the regression test test_grep_files_respects_cancel_token.\n\nI am closing this PR now that the code is on main. The release notes and README Thanks list both credit you for #1839. Apologies that the harvest commit missed the exact 'Harvested from PR #1839 by @LING71671' trailer, which is why the auto-close workflow did not close this at merge time.

@Hmbown Hmbown closed this May 24, 2026
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.

2 participants