Skip to content

Keep sync process wait within its timeout - #50

Open
vincent0426 wants to merge 2 commits into
basetenlabs:mainfrom
vincent0426:fix/sync-wait-timeout
Open

vincent0426 wants to merge 2 commits into
basetenlabs:mainfrom
vincent0426:fix/sync-wait-timeout

Conversation

@vincent0426

Copy link
Copy Markdown

🚀 What

Sync process.wait(timeout=2s) could take ~15s to time out if one status check got stuck. Async times out at 2s like it should.

💻 How

The sync loop only checked the deadline between checks, and after #40 a check has no read timeout. So one slow check could hold it for as long as the server took.

Async is fine because asyncio.timeout just cancels the stuck check. Sync can't do that, so now each check gets whatever time is left as its timeout (using api_with_timeout, same as the multipart abort).

🔬 Testing

  • Added test_wait_bounds_each_check_by_the_time_left, fails without this change.

  • Local server where every other status check hangs for 15s, wait(timeout=2s):

    Before After
    sync 15.2s 2.0s
    async 2.0s 2.0s

Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The wait deadline is not enforced end to end, since token acquisition, lock waiting, and per-I/O HTTP timeouts can let status checks exceed the caller’s timeout.

2 open issues
What changed in this PR

This PR addresses synchronous sandbox process waits overrunning their timeout after default HTTP read timeouts were disabled.

Changes:

  • Passes the remaining wait budget to each synchronous status request.
  • Handles HTTP timeout exceptions within the wait loop.
  • Adds a regression test for the request’s read-timeout budget and preserved error cause.
File Description
tests/​sandbox/​test_process.py Tests the remaining read-timeout budget and timeout error cause.
baseten/​sandbox/​_process.py Applies per-check timeouts and handles HTTP timeout exceptions.

Review effort: Balanced

Comment on lines +383 to +384
time_left = timedelta(seconds=max(deadline - time.monotonic(), 0))
api_context = self._context.api_with_timeout(time_left)
Comment on lines +383 to +384
time_left = timedelta(seconds=max(deadline - time.monotonic(), 0))
api_context = self._context.api_with_timeout(time_left)
@vincent0426

Copy link
Copy Markdown
Author

Both true. This PR fixes a status check that hangs forever. A token fetch is still capped at its own 30s, and httpx timeouts are per read, so it can still run over a bit in those cases. A hard end-to-end deadline would need changes in the token source too, so I'd rather do that separately.

This branch has not been deployed

No deployments
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