Repository navigation
fix(sandbox): keep the session key hash in sync when a resume fails on the app server but completes on the runtime API (OHE-3850) - #1151
Merged
hieptl merged 2 commits intoNov 5, 2026
Conversation
…n the app server but completes on the runtime API (OHE-3850) The runtime API rotates a sandbox's session key on resume and returns the new key only in the /resume response. resume_sandbox stored the new hash only after a 2xx. When the response was lost (a transport error or the client timeout) or failed late with a 5xx, it raised a 502 without looking at the runtime again, even though the runtime API had already moved the runtime to STARTING and went on to start the pod with the new key. The stored hash stayed on the old key, or empty after the pause, so valid_sandbox rejected every webhook post from the resumed pod with 401 until a later resume succeeded, and the agent server dropped those events. - Reading a RUNNING runtime now refreshes the stored hash from the key on the runtime record when it differs. This covers get_sandbox, the batch and search reads, and the session key lookup. Paused and starting runtimes are left alone: a paused record still carries the key the pause invalidated, and a starting one may not carry the rotated key yet. - A /resume that raises or returns a 5xx re-checks the runtime once. If it is already STARTING or RUNNING, the resume is reported as a success instead of a 502, and the next read of the running sandbox, such as the wait for it after the resume, refreshes the hash. Otherwise the 502 is raised as before. Tests cover both resume failure branches, the immediate refresh when the re-check already sees RUNNING, the RUNNING-only refresh on read, and the reported scenario on a real table: after a lost resume response and one read of the running runtime, the webhook key lookup accepts the rotated key and rejects the old one.
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Closed
2 of 6 tasks
hieptl
marked this pull request as ready for review
November 4, 2026 07:34
…erver-but-completes-on-the
hieptl
deleted the
hiep/ohe-3850-resume-that-fails-on-the-app-server-but-completes-on-the
branch
November 5, 2026 14:31
Contributor
|
🚀 Released in 1.87.0. |
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.
HUMAN:
AGENT:
Why
The runtime API rotates a sandbox's session key on resume and returns the new key only in the
/resumeresponse.RemoteSandboxService.resume_sandboxstored the newsession_api_key_hashonly after a 2xx. When the response was lost (a transport error or the client timeout) or failed late with a 5xx, it raised a 502 without looking at the runtime again, even though the runtime API had already moved the runtime to STARTING and went on to start the pod with the new key.From then on the stored hash belonged to the old key, or was empty because the pause clears it.
valid_sandboxauthenticates webhook posts with a database-only hash lookup, so it rejected every event the resumed pod posted with 401 until a later resume succeeded. The agent server gives up after its retries, so those events were lost: the reported conversation has a 155-minute hole in its history.Summary
get_sandbox, the batch and search reads, and the session key lookup. Paused and starting runtimes are left alone: a paused record still carries the key the pause invalidated, and a starting one may not carry the rotated key yet./resumethat raises or returns a 5xx now re-checks the runtime once, like the existing 409 handling. If it is already STARTING or RUNNING, the resume is reported as a success instead of a 502, and the next read of the running sandbox refreshes the hash. Otherwise the 502 is raised as before.tests/unit/app_server/test_remote_sandbox_service.pycover both failure branches, the immediate refresh when the re-check already sees RUNNING, the RUNNING-only refresh on read, and the reported scenario on a real table.Issue Number
OHE-3850. Fixes #1030.
How to Test
143 tests pass (one of them starts Postgres through Docker), and 5 of the 7 new tests fail on
main. The other 2 check that paused and starting runtimes leave the hash alone, so they pass on both.ruff0.12.5, the version pre-commit pins, is clean, and mypy reports nothing new on the touched file.The lost-response path is hard to trigger by hand, because the runtime API has to take longer than the app server's HTTP client timeout to answer
/resume. To check the recovery on a test environment with the remote runtime:session_api_key_hashtoNULLinv1_remote_sandbox. The agent server's webhook posts now get 401.I have not run this on a deployed environment yet.
Video/Screenshots
Backend only.
Type
Notes
Enterprise server image for this PR: