fix(js): Update execution status on signal interruption (Issue #60)#61
fix(js): Update execution status on signal interruption (Issue #60)#61
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #60
- Add signal handlers for SIGINT, SIGTERM, SIGHUP to update execution status when process is interrupted (Ctrl+C, kill, terminal close) - Add --cleanup flag to clean up stale "executing" records from crashed/killed processes - Add --cleanup-dry-run flag to preview stale records without cleaning - Add cleanupStale() method to ExecutionStore to detect stale records by checking if PID is running or if record exceeds max age (24 hours) - Add unit tests for new cleanup functionality - Add case study documentation Stale records are marked as "executed" with exit code -1 to indicate abnormal termination. This allows users to identify and clean up orphaned records from processes that were killed before normal completion. Closes #60 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
$ --status 14a0e075-3de1-4342-97cd-f87c8cd66dda shows command is still executing, while it actually was Finished at 2026-01-07 19:29:07.663This reverts commit dc7bfa9.
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
Make sure in Rust version of code we have similar logic for status storage and handling. |
|
🤖 AI Work Session Started Starting automated work session at 2026-01-07T23:20:04.388Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait working session to finish, and provide your feedback. |
Implement similar logic to JavaScript version for status storage and handling: 1. Signal Handling (SIGINT, SIGTERM, SIGHUP): - Set up signal handlers that update execution status when interrupted - Exit code follows convention: 128 + signal number (e.g., 130 for SIGINT) - Execution record is updated to "executed" status before exit 2. Cleanup Functionality: - Add --cleanup flag to clean up stale "executing" records - Add --cleanup-dry-run to preview what would be cleaned - Stale detection: process no longer running or age > 24 hours - Cleaned records marked as "executed" with exit code -1 3. ExecutionStore Changes: - Add cleanup_stale() method with CleanupOptions and CleanupResult - Add Clone trait to ExecutionStore for signal handler sharing - Add comprehensive unit tests for cleanup functionality 4. Args Parser Changes: - Add cleanup and cleanup_dry_run flags to WrapperOptions - Add parsing for --cleanup and --cleanup-dry-run - Add unit tests for new flags 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Apply cargo fmt formatting fixes - Add changelog fragment for Issue #60 signal handling feature 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move signal handling code from main.rs to signal_handler.rs module - Move cleanup tests from execution_store.rs to tests/cleanup_test.rs - Compact code to meet file size limits (<1000 lines per file) - No functional changes, only code organization 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Collapse nested if statements in cleanup_stale (clippy::collapsible_if) - Add #[cfg(unix)] to cleanup_execution_on_signal to fix Windows dead code error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Summary
This PR fixes Issue #60 where
$ --status <uuid>shows "executing" for commands that have already finished.Root Cause
When a command is running and the process is interrupted (Ctrl+C, SIGTERM, terminal closed), the execution record in the database was never updated from "executing" to "executed". This left orphaned records with stale status.
Changes
JavaScript Implementation (completed)
--cleanupand--cleanup-dry-runCLI options to clean up stale recordscleanupStale()method to ExecutionStore that detects stale records by:docs/case-studies/issue-60/Rust Implementation (completed)
--cleanupand--cleanup-dry-runCLI options matching JavaScript APIcleanup_stale()method to ExecutionStore with CleanupOptions and CleanupResult typesExit Codes for Signal Interruption
When a command is interrupted by a signal, it's now marked as "executed" with the appropriate exit code:
Stale records cleaned up via
--cleanupare marked with exit code -1 to indicate abnormal termination.Test plan
$ echo 'hi'and verify$ --status <uuid>shows "executed"$ sleep 10, press Ctrl+C, verify status shows "executed" with exit code 130$ --cleanup-dry-runto see stale records$ --cleanupto clean up stale recordsCloses #60
🤖 Generated with Claude Code