refactor: replace raw u64 timeouts with Duration for type-safe time handling#68
Merged
yishuiliunian merged 1 commit intomainfrom Apr 3, 2026
Merged
Conversation
…andling Timeout values were passed as raw u64 (milliseconds or seconds depending on context) across Backend trait, error types, shell execution, and the Bash tool. This caused unit confusion bugs — notably tests passing 200 (seconds, not ms) causing a 200s test wait. Replace all internal timeout parameters with std::time::Duration: - Backend trait: exec/exec_streaming now accept Duration - ToolIoError::Timeout and ToolError::Timeout now hold Duration - ResourceLimits: default_timeout_ms/fetch_timeout_secs → Duration fields - Shell/shell_stream: accept Duration directly, no from_millis conversion - Bash tool: MAX_TIMEOUT as Duration, bg_ops/format use Duration - TimeoutSecs: output changed from to_millis_clamped to to_duration_clamped Fix test timeout values that were incorrectly specified as milliseconds: - background_task_test: 5000 → 5 (seconds) - background_task_edge_test: 200 → 1 (seconds), fixing 200s slow test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
timeout_ms: u64/timeout: u64parameters withstd::time::Durationacross Backend trait, error types, shell execution, and Bash toolTimeoutSecsoutput changed fromto_millis_clamped(u64)toto_duration_clamped(Duration), making unit confusion a compile errorChanges
Core types (4 files):
loopal-tool-api/src/backend_types.rs—TimeoutSecs:to_millis_clamped→to_duration/to_duration_clampedloopal-tool-api/src/backend.rs—Backendtrait +ExecOutcome::TimedOutuseDurationloopal-error/src/io_error.rs—ToolIoError::Timeout(Duration)loopal-error/src/errors.rs—ToolError::Timeout(Duration)Backend (5 files):
loopal-backend/src/{limits,shell,shell_stream,local,net}.rs— Accept/forwardDurationdirectlyBash tool (3 files):
tools/process/bash/src/{lib,bg_ops,format}.rs—MAX_TIMEOUT: Duration, full Duration pipelineTest fixes (3 files):
background_task_test.rs—"timeout": 5000→5(was 5000 seconds, not ms)background_task_edge_test.rs—"timeout": 200→1(was 200s, root cause of slow test)error_conversion_test.rs— Adapt toDurationtypeTest plan
bazel test //...— 48/48 passbazel build //... --config=rustfmt— cleanbackground-testdropped from 200s to 1.1s