fix(python): raise TimeoutError for exec timeouts#959
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughExecution timeout state is recorded at process termination, propagated through guest, REST, C, Go, runner, and Python layers, and exposed through status responses, WebSocket exit frames, structured wait results, and Python timeout exceptions. ChangesExecution Timeout Propagation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant TimeoutWatcher
participant ExecutionState
participant GuestWait
participant RESTWebSocket
participant GoExecution
participant PythonSimpleBox
TimeoutWatcher->>ExecutionState: kill_for_timeout(SIGTERM)
GuestWait->>ExecutionState: was_timed_out()
GuestWait-->>RESTWebSocket: WaitResponse.timed_out
GoExecution->>GoExecution: WaitResult()
GoExecution-->>PythonSimpleBox: exit_code, timed_out
PythonSimpleBox-->>PythonSimpleBox: raise TimeoutError when timed_out
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
a632483 to
8228bb7
Compare
6284707 to
c0b7c95
Compare
📦 BoxLite review — couldn't completepowered by BoxLite |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/guest/src/service/exec/timeout.rs (1)
37-41: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winRecord the timeout flag in the same critical section as the signal send.
wait()can reap the process and readtimed_out == falsein the gap betweenkill(SIGTERM)returning andmark_timed_out()acquiring the mutex. A small helper that sets the flag and sends SIGTERM under one lock avoids reporting a real timeout as a normal exit.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/guest/src/service/exec/timeout.rs` around lines 37 - 41, Update the timeout handling around exec_state.kill and exec_state.mark_timed_out so the timed-out flag is set and SIGTERM is sent within one shared critical section. Add or use a helper on the execution state that performs both operations atomically, preserving the early return when the process has already exited and avoiding the gap where wait() can observe timed_out as false.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/runner/pkg/boxlite/exec_manager_integration_test.go`:
- Around line 48-49: Register mgr.Stop as the test cleanup callback instead of
invoking it immediately after NewExecManager, so the manager remains active
during the test and is stopped during teardown. Update the setup around
NewExecManager while preserving the existing manager initialization.
In `@sdks/c/include/boxlite.h`:
- Around line 445-449: Document the public boxlite_execution_wait_result API in
sdks/c/include/boxlite.h:445-449, covering each parameter, callback behavior,
return value, and out_error handling; add corresponding Rust documentation for
its implementation in sdks/c/src/exec/execution.rs:171-180, keeping both
descriptions consistent.
In `@sdks/python/boxlite/simplebox.py`:
- Around line 293-297: Defensively format the timeout in the timed-out error
path so a None value cannot trigger TypeError; use a safe fallback or
representation while preserving the existing timeout details for numeric values.
Apply the same change to the corresponding timeout handling in
sdks/python/boxlite/simplebox.py lines 293-297 and
sdks/python/boxlite/sync_api/_simplebox.py lines 254-258.
---
Outside diff comments:
In `@src/guest/src/service/exec/timeout.rs`:
- Around line 37-41: Update the timeout handling around exec_state.kill and
exec_state.mark_timed_out so the timed-out flag is set and SIGTERM is sent
within one shared critical section. Add or use a helper on the execution state
that performs both operations atomically, preserving the early return when the
process has already exited and avoiding the gap where wait() can observe
timed_out as false.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 53f616d1-4a40-4fc1-abaf-df1cc8882bee
📒 Files selected for processing (28)
apps/runner/pkg/api/controllers/boxlite_exec.goapps/runner/pkg/api/controllers/boxlite_exec_attach.goapps/runner/pkg/api/controllers/boxlite_exec_attach_test.goapps/runner/pkg/api/controllers/boxlite_exec_test.goapps/runner/pkg/boxlite/exec_manager.goapps/runner/pkg/boxlite/exec_manager_integration_test.gosdks/c/include/boxlite.hsdks/c/src/event_queue.rssdks/c/src/exec/execution.rssdks/c/src/runtime.rssdks/go/bridge.csdks/go/bridge.hsdks/go/bridge_callback.gosdks/go/exec.gosdks/python/boxlite/exec.pysdks/python/boxlite/simplebox.pysdks/python/boxlite/sync_api/_simplebox.pysdks/python/src/exec.rssdks/python/tests/test_exec_timeout_sigalrm.pysdks/python/tests/test_sync_simplebox.pysrc/boxlite/src/litebox/exec.rssrc/boxlite/src/portal/interfaces/exec.rssrc/boxlite/src/rest/litebox.rssrc/cli/src/commands/serve/mod.rssrc/cli/src/terminal/mod.rssrc/guest/src/service/exec/mod.rssrc/guest/src/service/exec/state.rssrc/guest/src/service/exec/timeout.rs
09019c7 to
f28fa72
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
sdks/go/bridge.c (1)
64-64: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a docstring for the public function.
As per coding guidelines, comprehensive docstrings should be written for all public functions.
💬 Proposed docstring
+// cbExecutionWaitResult returns the C function pointer for the execution wait result callback. CExecutionWaitResultCb cbExecutionWaitResult(void) { return (CExecutionWaitResultCb)goBoxliteOnExecutionWaitResult; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@sdks/go/bridge.c` at line 64, Add a comprehensive documentation comment immediately before the public cbExecutionWaitResult function, describing its purpose, return value, and callback behavior while following the project’s C documentation conventions.Source: Coding guidelines
sdks/go/bridge_callback.go (1)
386-406: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd a docstring to the exported function.
As per coding guidelines, comprehensive docstrings should be written for all public functions. Although this is a cgo callback, it is exported and should have a docstring outlining its purpose.
💬 Proposed docstring
+// goBoxliteOnExecutionWaitResult is the callback invoked by C when execution wait completes, +// sending the exit code, timeout state, and potential error back to the Go channel. //export goBoxliteOnExecutionWaitResult func goBoxliteOnExecutionWaitResult(exitCode C.int, timedOut C.bool, errPtr *C.CBoxliteError, userData unsafe.Pointer) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@sdks/go/bridge_callback.go` around lines 386 - 406, Add a Go doc comment immediately above the exported goBoxliteOnExecutionWaitResult function, describing that it handles execution-wait results from the Boxlite callback and forwards the exit code, timeout state, and error to the waiting channel.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@sdks/go/bridge_callback.go`:
- Around line 386-406: Add a Go doc comment immediately above the exported
goBoxliteOnExecutionWaitResult function, describing that it handles
execution-wait results from the Boxlite callback and forwards the exit code,
timeout state, and error to the waiting channel.
In `@sdks/go/bridge.c`:
- Line 64: Add a comprehensive documentation comment immediately before the
public cbExecutionWaitResult function, describing its purpose, return value, and
callback behavior while following the project’s C documentation conventions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e3f6bfac-5ef5-46c2-9282-606eb90be36c
📒 Files selected for processing (28)
apps/runner/pkg/api/controllers/boxlite_exec.goapps/runner/pkg/api/controllers/boxlite_exec_attach.goapps/runner/pkg/api/controllers/boxlite_exec_attach_test.goapps/runner/pkg/api/controllers/boxlite_exec_test.goapps/runner/pkg/boxlite/exec_manager.goapps/runner/pkg/boxlite/exec_manager_integration_test.gosdks/c/include/boxlite.hsdks/c/src/event_queue.rssdks/c/src/exec/execution.rssdks/c/src/runtime.rssdks/go/bridge.csdks/go/bridge.hsdks/go/bridge_callback.gosdks/go/exec.gosdks/python/boxlite/exec.pysdks/python/boxlite/simplebox.pysdks/python/boxlite/sync_api/_simplebox.pysdks/python/src/exec.rssdks/python/tests/test_exec_timeout_sigalrm.pysdks/python/tests/test_sync_simplebox.pysrc/boxlite/src/litebox/exec.rssrc/boxlite/src/portal/interfaces/exec.rssrc/boxlite/src/rest/litebox.rssrc/cli/src/commands/serve/mod.rssrc/cli/src/terminal/mod.rssrc/guest/src/service/exec/mod.rssrc/guest/src/service/exec/state.rssrc/guest/src/service/exec/timeout.rs
🚧 Files skipped from review as they are similar to previous changes (22)
- src/boxlite/src/litebox/exec.rs
- sdks/go/bridge.h
- sdks/python/boxlite/exec.py
- src/cli/src/terminal/mod.rs
- src/guest/src/service/exec/mod.rs
- apps/runner/pkg/api/controllers/boxlite_exec_attach.go
- src/boxlite/src/portal/interfaces/exec.rs
- apps/runner/pkg/api/controllers/boxlite_exec.go
- apps/runner/pkg/api/controllers/boxlite_exec_test.go
- sdks/python/tests/test_sync_simplebox.py
- sdks/c/src/runtime.rs
- src/boxlite/src/rest/litebox.rs
- apps/runner/pkg/boxlite/exec_manager_integration_test.go
- src/cli/src/commands/serve/mod.rs
- apps/runner/pkg/api/controllers/boxlite_exec_attach_test.go
- apps/runner/pkg/boxlite/exec_manager.go
- sdks/c/src/event_queue.rs
- sdks/python/tests/test_exec_timeout_sigalrm.py
- sdks/c/include/boxlite.h
- sdks/c/src/exec/execution.rs
- sdks/python/boxlite/sync_api/_simplebox.py
- sdks/go/exec.go
|
Gamnaam Song seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
d93b470 to
4f1ab28
Compare
c840ca4 to
3f76bc2
Compare
0e16c88 to
195719a
Compare
195719a to
9d1cdc5
Compare
Raise TimeoutError from Python convenience exec APIs using an explicit timeout signal propagated through local and cloud execution paths.
Test plan:
Summary by CodeRabbit
timed_outflag (alongside exit code) across APIs and SDKs.timed_outterminal outcomes.timed_out.timed_outresponses and updated Python tests to expect timeout exceptions.