Skip to content

F-002: refactor(app): make hook and clipboard methods non-blocking#11

Open
Sephyi wants to merge 1 commit intodevelopmentfrom
audit/f-002-async-command-hook-clipboard
Open

F-002: refactor(app): make hook and clipboard methods non-blocking#11
Sephyi wants to merge 1 commit intodevelopmentfrom
audit/f-002-async-command-hook-clipboard

Conversation

@Sephyi
Copy link
Copy Markdown
Owner

@Sephyi Sephyi commented Apr 22, 2026

Summary

refactor(app): make hook and clipboard methods non-blocking.

Audit context

Closes audit entry F-002 from #3.

Verification

  • cargo fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-targets

Note: one pre-existing test porcelain_exits_within_timeout_with_no_staged_changes is a known macOS cold-start flake that reproduces on unmodified development — unrelated to this change.

Replace synchronous std::process::Command and arboard calls with
non-blocking alternatives so the tokio runtime isn't blocked:

- handle_hook, hook_dir, hook_path, hook_install, hook_uninstall, and
  hook_status are now async; hook_dir uses tokio::process::Command with
  an explicit std::process::Output annotation (CLAUDE.md gotcha).
- copy_to_clipboard wraps arboard::Clipboard::new() and set_text() in
  tokio::task::spawn_blocking; its signature changes from &str to String
  to satisfy the 'static bound.

Closes audit entry F-002 from #3.
Copilot AI review requested due to automatic review settings April 22, 2026 19:50
@Sephyi Sephyi added the audit Codebase audit cleanup (issue #3) label Apr 22, 2026
@Sephyi Sephyi self-assigned this Apr 22, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the app’s hook and clipboard paths to avoid blocking the async runtime, addressing audit finding F-002 (sync process/clipboard calls on the tokio runtime).

Changes:

  • Make hook command handling async and run git rev-parse --git-dir via tokio::process::Command.
  • Offload clipboard writes (arboard) to tokio::task::spawn_blocking and make clipboard helper async.
  • Update command dispatch / clipboard flow to await the new async helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app.rs
Ok(())
})
.await
.map_err(|e| Error::Config(format!("Clipboard task panicked: {e}")))?
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The JoinError from spawn_blocking can represent either a panic or task cancellation (e.g., runtime shutdown). This error message always says "panicked", which can be misleading. Consider branching on e.is_panic() / e.is_cancelled() and wording the message accordingly (or avoid claiming panic unless is_panic() is true).

Suggested change
.map_err(|e| Error::Config(format!("Clipboard task panicked: {e}")))?
.map_err(|e| {
Error::Config(if e.is_panic() {
format!("Clipboard task panicked: {e}")
} else if e.is_cancelled() {
format!("Clipboard task was cancelled: {e}")
} else {
format!("Clipboard task failed to join: {e}")
})
})?

Copilot uses AI. Check for mistakes.
Comment thread src/app.rs
Comment on lines +993 to +994
// Annotated type per CLAUDE.md gotcha: tokio::process::Command output
// needs explicit std::process::Output typing when used with `?`.
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

This comment references the CLAUDE.md gotcha but says the std::process::Output annotation is needed when using ?. The documented gotcha is specifically about .ok()? (type inference failure); with .await? and subsequent output.status usage, the annotation isn't required. Consider either removing the comment or rewording it to match the actual gotcha to avoid confusing future readers.

Suggested change
// Annotated type per CLAUDE.md gotcha: tokio::process::Command output
// needs explicit std::process::Output typing when used with `?`.
// Keep the explicit type annotation for clarity; it is not required by `.await?` here.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit Codebase audit cleanup (issue #3)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants