Skip to content

refactor: replace raw u64 timeouts with Duration for type-safe time handling#68

Merged
yishuiliunian merged 1 commit intomainfrom
refactor/replace-u64-timeout-with-duration
Apr 3, 2026
Merged

refactor: replace raw u64 timeouts with Duration for type-safe time handling#68
yishuiliunian merged 1 commit intomainfrom
refactor/replace-u64-timeout-with-duration

Conversation

@yishuiliunian
Copy link
Copy Markdown
Contributor

Summary

  • Replace all internal timeout_ms: u64 / timeout: u64 parameters with std::time::Duration across Backend trait, error types, shell execution, and Bash tool
  • Fix test timeout values that were incorrectly specified (seconds mistaken as milliseconds), eliminating a 200s slow test
  • TimeoutSecs output changed from to_millis_clamped(u64) to to_duration_clamped(Duration), making unit confusion a compile error

Changes

Core types (4 files):

  • loopal-tool-api/src/backend_types.rsTimeoutSecs: to_millis_clampedto_duration / to_duration_clamped
  • loopal-tool-api/src/backend.rsBackend trait + ExecOutcome::TimedOut use Duration
  • loopal-error/src/io_error.rsToolIoError::Timeout(Duration)
  • loopal-error/src/errors.rsToolError::Timeout(Duration)

Backend (5 files):

  • loopal-backend/src/{limits,shell,shell_stream,local,net}.rs — Accept/forward Duration directly

Bash tool (3 files):

  • tools/process/bash/src/{lib,bg_ops,format}.rsMAX_TIMEOUT: Duration, full Duration pipeline

Test fixes (3 files):

  • background_task_test.rs"timeout": 50005 (was 5000 seconds, not ms)
  • background_task_edge_test.rs"timeout": 2001 (was 200s, root cause of slow test)
  • error_conversion_test.rs — Adapt to Duration type

Test plan

  • bazel test //... — 48/48 pass
  • bazel build //... --config=rustfmt — clean
  • background-test dropped from 200s to 1.1s

…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
@yishuiliunian yishuiliunian merged commit b0e13f7 into main Apr 3, 2026
3 checks passed
@yishuiliunian yishuiliunian deleted the refactor/replace-u64-timeout-with-duration branch April 3, 2026 21:50
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.

1 participant