Skip to content

feat(core): add timeout-aware runtime shutdown - #299

Merged
saivishwak merged 4 commits into
liquidos-ai:mainfrom
Parikalp-Bhardwaj:feat/runtime-shutdown-timeout
Aug 6, 2026
Merged

feat(core): add timeout-aware runtime shutdown#299
saivishwak merged 4 commits into
liquidos-ai:mainfrom
Parikalp-Bhardwaj:feat/runtime-shutdown-timeout

Conversation

@Parikalp-Bhardwaj

@Parikalp-Bhardwaj Parikalp-Bhardwaj commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an optional timeout-aware shutdown API for AutoAgents runtimes.

RuntimeManager::stop() currently waits for every registered runtime to finish
its stop() operation without a deadline. If one runtime never completes,
shutdown can wait indefinitely.

This PR adds an opt-in bounded shutdown path while preserving the existing
RuntimeManager::stop() and Environment::shutdown() behaviour.

Related #295

Changes

Add RuntimeError::ShutdownTimeout

RuntimeError::ShutdownTimeout {
    runtime_ids: Vec<RuntimeID>,
    timeout: Duration,
}

Greptile Summary

The PR adds an opt-in timeout-aware runtime shutdown API while preserving the existing unbounded shutdown behavior.

  • Adds timeout and incomplete-shutdown errors with runtime IDs and timeout details.
  • Retains timed-out or cancellation-interrupted stop tasks so later shutdown attempts can observe them.
  • Prevents environment relaunch until detached stop work and the managed run task have completed.
  • Adds lifecycle, timeout, recovery, error-precedence, and cancellation tests.

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported relaunch-state and cancellation-tracking failures are addressed: timed-out stop handles remain tracked, later shutdowns drain them, managed run handles are preserved, and relaunch remains blocked until recovery completes.

Important Files Changed

Filename Overview
crates/autoagents-core/src/environment.rs Adds timeout-aware shutdown state handling, preserves managed run handles across cancellation and timeout, and blocks unsafe relaunch until recovery completes.
crates/autoagents-core/src/runtime/manager.rs Tracks stop tasks and observed outcomes in place so timed-out or cancelled shutdown calls leave pending lifecycle work recoverable.
crates/autoagents-core/src/runtime/mod.rs Adds the structured ShutdownTimeout runtime error carrying stable runtime IDs and the requested timeout.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Environment running] --> B[shutdown_with_timeout]
  B --> C[RuntimeManager stop_with_timeout]
  C -->|All stops finish| D[Await managed run task]
  C -->|Deadline missed| E[ShutdownIncomplete]
  D -->|Run task finishes| F[Idle]
  D -->|Deadline missed| E
  E -->|run or run_background| G[Reject relaunch]
  E -->|Later shutdown drains retained stops and joins run task| F
Loading

Reviews (6): Last reviewed commit: "fix(core): retain pending shutdown tasks..." | Re-trigger Greptile

Context used:

@deepsource-io

deepsource-io Bot commented Aug 3, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in f319567...572b299 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Aug 5, 2026 4:05p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Comment thread crates/autoagents-core/src/environment.rs Outdated
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.62366% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/autoagents-core/src/runtime/manager.rs 93.65% 4 Missing ⚠️
crates/autoagents-core/src/environment.rs 96.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@saivishwak

saivishwak commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@greptileai review

Comment thread crates/autoagents-core/src/environment.rs
Comment thread crates/autoagents-core/src/runtime/manager.rs Outdated
@Parikalp-Bhardwaj

Copy link
Copy Markdown
Contributor Author

@saivishwak lgtm now. Please review when you get a chance

@saivishwak

Copy link
Copy Markdown
Contributor

@greptileai review

@saivishwak
saivishwak merged commit 6686655 into liquidos-ai:main Aug 6, 2026
15 checks passed
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.

2 participants