Repository navigation
Conversation
|
@FrostGod tagging you since you filed #5697. The PR takes it end to end: the server now keeps ErrorInfo/RetryInfo through failed-create cleanup (and the SSH identity step carries the reason), the SDK has opt-in retrying create methods, and the CLI retries by default within a bounded budget. The parts I'd most like your eyes on are the retry policy in openshell-core/src/create_retry.rs and the two client loops. One deliberate deviation from the issue: the budget is wall-clock with a 5-attempt cap rather than attempts-only, to bound lock-pool re-entry under saturation. |
|
@EmilienM can we repurpose this PR to fix for other SDKs ( not rust or CLI ) if its okay |
|
Happy to take the other SDKs, but I'd rather do that as a follow-up PR than repurpose this one. This PR carries the server-side signal fixes (ErrorInfo/RetryInfo surviving compensation, the SSH identity step carrying the reason) and the core retry policy that any other SDK would build on, and it's fully reviewed. Repurposing it would throw that away. Proposal: merge this as the Rust/CLI/server base, then I'll take the TypeScript retry as the next PR on top. Go and Python live in the ai-openshell repos now, so those need PRs there anyway (python/ is frozen in-tree, Branch Checks fails changes to it). One thing worth deciding before the follow-up: Eric's #5725 adds a server-side SANDBOX_DELETING reason for the AlreadyExists race. We went with a client-side phase poll here to avoid a public API change in this PR; happy to switch to a server-side signal in the follow-up if you prefer that design. |
There was a problem hiding this comment.
Tested this locally on a 2-replica HA gateway (external Postgres, Envoy) by holding the advisory locks by hand. Retry works on both paths: 5/5 creates recovered for the creation guard and for the SSH identity step, and --no-create-retry failed fast as expected. Nice work.
A few comments inline. General ones:
- Could we settle client-side phase polling vs. a server-side
SANDBOX_DELETINGreason (#5725) before merge? If we switch later, most of the AlreadyExists code gets replaced. - Splitting out the server fix (keeping ErrorInfo/RetryInfo, SSH step reason) would make this much easier to review and land.
- An e2e that holds the lock and checks the retry would guard this better than mocks alone.
c4ab3d1 to
4c8c94b
Compare
|
On the three general points:
|
|
can you rebase it once, I can merge this LGTM |
…sion layer Add the shared primitives that let clients retry sandbox creates that lose the gateway mutation lock budget. rpc_error gains the MUTATION_LOCK_TIMEOUT reason constant, an exact-match predicate that also requires UNAVAILABLE (so DATABASE_UNAVAILABLE and other transient failures never select a mutation retry), and rebuild_with_message, which rewrites a status message at the google.rpc.Status envelope level so every error detail, known or unknown, survives message appends. The new create_retry module holds the pure retry policy shared by the SDK and the CLI: a delay floor from the server's RetryInfo (1s when absent), proportional jitter (at most half the delay) derived from an injected per-client seed so a burst that times out together spreads its retries, a wall-clock budget that stops instead of overrunning, and the AlreadyExists disambiguation for named creates: a Deleting holder waits, a Provisioning holder waits only when an earlier attempt of the same call may have left it (HolderProvenance), NotFound resends the create up to three times, and a live holder is terminal. Every wait and retry requires room for one more create attempt, so a spent attempt cap stops instead of polling toward a conflict already determined. Signed-off-by: Emilien Macchi <emacchi@redhat.com>
…s in create compensation A create that loses the SSH identity mutation lock budget returned a bare UNAVAILABLE with no machine-readable reason, so clients could not tell it apart from any other transient failure. Both identity lock acquisitions now route PersistenceError::LockTimeout through persistence_error_to_status, reporting the shared MUTATION_LOCK_TIMEOUT reason and a 1s RetryInfo like the creation guard does; other persistence failures keep the previous bare status. compensate_failed_create rebuilt every status it returns with Status::new, dropping the ErrorInfo and RetryInfo the create failure carried and silently disabling client retry once cleanup appended to the message. Every rebuild branch now goes through the core rebuild_with_message helper, which rewrites the message at the google.rpc.Status envelope level and keeps every error detail. The begin-delete supersession arm now reports the original create failure with the begin-delete outcome appended instead of replacing the status outright, so the retry contract survives that branch too. Signed-off-by: Emilien Macchi <emacchi@redhat.com>
Add opt-in retrying entry points for all four create surfaces: create_sandbox_with_retry and create_sandbox_from_template_with_retry on both OpenShellClient and WorkspaceScopedClient, backed by one shared loop over the core create-retry policy. SdkError gains mutation_lock_timeout(), an exact-match predicate on the shared reason; retryable() keeps its auth-only contract. Each attempt waits at least the server's RetryInfo delay plus per-call jitter and shares one wall-clock budget (CreateRetryOptions, default 60s) with the AlreadyExists cleanup wait. request_id stays empty on every attempt so mutation replay never surfaces a recorded failure. A named create that hits AlreadyExists polls the holder's phase in the create's workspace: a Deleting holder is waited out, a missing record resends the create up to three times, and a live, recovered, or different-id holder is a terminal conflict. Budget exhaustion surfaces the last error annotated with the attempt count and the original lock-timeout cause, keeping the raw status intact. Signed-off-by: Emilien Macchi <emacchi@redhat.com>
sandbox create now retries while the gateway mutation lock is busy, using the same openshell-core decision layer as the SDK: each attempt waits at least the server's RetryInfo delay plus per-invocation jitter inside one wall-clock budget, and only MUTATION_LOCK_TIMEOUT retries; every other failure may have persisted the create, so it stays terminal. The budget defaults to 60s, follows OPENSHELL_CREATE_RETRY_TIMEOUT, and is set with --create-retry-timeout <SECONDS>; --no-create-retry restores the fail-fast behavior. Progress lines go to stderr only, so structured stdout output stays parseable. A named create that hits AlreadyExists polls the holder's phase in the create's workspace: a Deleting holder is waited out, a missing record resends the create up to three times, and a live or recovered holder stops with the delete-first hint. Budget exhaustion surfaces the last error annotated with the attempt count and the original lock-timeout cause. Signed-off-by: Emilien Macchi <emacchi@redhat.com>
Document the create-retry contract end to end: the SDK's opt-in retrying create methods and the mutation_lock_timeout accessor on the api-errors page (with the retry conditions, delay floor, jitter bound, budget, and the AlreadyExists cleanup-wait matrix), the automatic CLI and Rust SDK retry on the high-availability page, the CLI flags and cleanup-wait behavior in the openshell-cli skill, and the retrying entry points in the SDK README. Correct the high-availability page for the SSH identity step now carrying the MUTATION_LOCK_TIMEOUT reason. Closes ai-openshell#5697 Signed-off-by: Emilien Macchi <emacchi@redhat.com>
4c8c94b to
2b595fc
Compare
A burst that times out together on the gateway's 10s mutation-lock wait retried within half a second, because the jitter window was half the 1s retry delay. Size the window by the failed attempt's wait when that is longer, so those retries spread over about five seconds. Signed-off-by: divesh <dgude@nvidia.com>
|
/ok to test 4bbccc3 |
|
Thanks for addressing the comments on the PR @EmilienM , I had to rebase this codebase, and the file which is in question changes very frequently and top of that we noticed the CNCF runners are pretty slow 🙃 |
Signed-off-by: divesh <dgude@nvidia.com>
Summary
sandbox createand the Rust SDK's create methods now retry a create that loses the gateway mutation lock, so burst creation under contention no longer needs a retry loop in every caller. The gateway keeps the machine-readable retry signal when failed-create cleanup rewrites the error, and both lock-timeout producers carry it.Related Issue
Closes #5697
Changes
LockTimeouttoUNAVAILABLE+MUTATION_LOCK_TIMEOUT+RetryInfo, andcompensate_failed_createpreservesErrorInfo/RetryInfoon every rebuilt statustonic::Status, a detail-preserving rebuild helper, and the retry policy itself (delay floor with proportional jitter, backoff, 5-attempt cap, wall-clock budget, AlreadyExists phase decisions with holder provenance), shared by the SDK and the CLIcreate_sandbox_with_retry/create_sandbox_from_template_with_retryon both clients,CreateRetryOptionswith a 60s default budget, andSdkError::mutation_lock_timeout();retryable()keeps its auth-only contract--create-retry-timeout,--no-create-retry, andOPENSHELL_CREATE_RETRY_TIMEOUT(60s default, 24h clamp); progress on stderr only; a named create waits out a holder that is deleting, or still provisioning when an earlier attempt of the same command may have left itRelease Notes
sandbox createnow retries for up to 60 seconds when the gateway mutation lock is busy and waits out a same-name sandbox that is still being cleaned up. The Rust SDK gains opt-in retrying create methods.MUTATION_LOCK_TIMEOUTfailures keep their reason and retry delay even after failed-create cleanup rewrites the message.Retry is on by default, so a contended create can now take up to ~70 seconds where it previously failed at ~10 seconds, and callers with their own retry loop can nest up to five create attempts inside it.
--no-create-retrykeeps the fail-fast behavior.Testing
Tests cover the reason predicate, detail survival through every compensation branch, retry timing (floor, proportional jitter, backoff, attempt cap), budget exhaustion, the AlreadyExists phase matrix (deleting, own-attempt provisioning, foreign provisioning, missing, live, different-id holder, holder change across conflict episodes), and deadline-bounded holder polls. The PostgreSQL lock suite passed 48/48. The one local failure is a pre-existing z3 solver timeout in
openshell-prover, reproduced on cleanorigin/main. No e2e lane: this is client retry policy plus server error mapping, covered by the SDK/CLI mock suites and the server compensation tests.Checklist