Skip to content

feat: add retry for lock in frontend - #1121

Open
sauraww wants to merge 1 commit into
mainfrom
feat/retry-lock
Open

feat: add retry for lock in frontend#1121
sauraww wants to merge 1 commit into
mainfrom
feat/retry-lock

Conversation

@sauraww

@sauraww sauraww commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Problem

Describe the problem you are trying to solve here

Solution

Provide a brief summary of your solution so that reviewers can understand your code

Environment variable changes

What ENVs need to be added or changed

Pre-deployment activity

Things needed to be done before deploying this change (if any)

Post-deployment activity

Things needed to be done after deploying this change (if any)

API changes

Endpoint Method Request body Response Body
API GET/POST, etc request response

Possible Issues in the future

Describe any possible issues that could occur because of this change

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of temporarily locked workspaces by automatically retrying affected requests in the browser.
    • Added progressive delays between retry attempts to improve request reliability.
    • Requests now provide a clear error when all retry attempts are exhausted.
    • Preserved existing error alerts and handling for other request failures.

Copilot AI review requested due to automatic review settings July 29, 2026 13:14
@sauraww
sauraww requested a review from a team as a code owner July 29, 2026 13:14
@semanticdiff-com

semanticdiff-com Bot commented Jul 29, 2026

Copy link
Copy Markdown

@sauraww sauraww changed the title feat: added retry functionality in frontend feat: add retry for lock in frontend Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 412cb56a-5025-4cb6-9d00-9b386da057c6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Frontend HTTP utilities now detect locked-workspace conflict responses in browsers, wait with bounded exponential backoff, and retry requests. Error parsing, SSR cookies, skip-error handling, alerts, and terminal error propagation remain supported.

Changes

Workspace lock retry flow

Layer / File(s) Summary
Retry primitives and error contract
crates/frontend/src/utils.rs
Adds browser detection imports, lock-aware error payloads, retry limits, exponential delay calculation, and asynchronous sleep support.
Request retry and terminal error handling
crates/frontend/src/utils.rs
Retries eligible 409 CONFLICT responses in browsers, then preserves alerting and error propagation for exhausted retries and other response classes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant request_with_skip_error
  participant Backend
  participant sleep
  Browser->>request_with_skip_error: start request
  request_with_skip_error->>Backend: send HTTP request
  Backend-->>request_with_skip_error: 409 response with lock info
  request_with_skip_error->>sleep: wait with exponential backoff
  sleep-->>request_with_skip_error: delay complete
  request_with_skip_error->>Backend: retry request
  Backend-->>request_with_skip_error: success or terminal error
  request_with_skip_error-->>Browser: return response or error
Loading

Suggested reviewers: copilot, avi892nash

Poem

A bunny waits while workspaces lock,
Then hops through retries round the clock.
Backoff blooms, requests try anew,
Alerts still tell what errors do.
When hops run out, the error knocks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main frontend change: adding retry behavior for workspace locks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/retry-lock

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Pull request overview

Adds client-side retry/backoff behavior to frontend HTTP requests when the backend reports a workspace lock conflict (HTTP 409 with a lock payload), reducing transient failures during concurrent workspace write operations.

Changes:

  • Introduces retry constants and an exponential backoff delay helper for workspace-lock conflicts.
  • Adds a browser-only retry loop around request_with_skip_error, retrying conflicted requests before surfacing an error.
  • Adds a small async sleep utility (based on set_timeout) to delay between retries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/frontend/src/utils.rs Outdated
Comment on lines +349 to +352
return Ok(response);
}

Ok(response)
Err(String::from("request attempts exhausted"))

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
crates/frontend/src/utils.rs (2)

203-227: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a unit test for workspace_lock_retry_delay.

This is a small pure function driving the retry backoff schedule; a quick table test (retry 0/1/2 → 250ms/500ms/1000ms) would lock in the exponential-backoff contract and catch regressions if MAX_WORKSPACE_LOCK_RETRIES or the base delay changes later.

✅ Suggested test
#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn workspace_lock_retry_delay_backs_off_exponentially() {
        assert_eq!(workspace_lock_retry_delay(0), Duration::from_millis(250));
        assert_eq!(workspace_lock_retry_delay(1), Duration::from_millis(500));
        assert_eq!(workspace_lock_retry_delay(2), Duration::from_millis(1000));
    }
}
🤖 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 `@crates/frontend/src/utils.rs` around lines 203 - 227, Add a unit-test module
for workspace_lock_retry_delay with a table-style test covering retries 0, 1,
and 2, asserting delays of 250ms, 500ms, and 1000ms respectively.

206-211: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider unifying RequestErrorResponse and ErrorResponse.

RequestErrorResponse (Lines 206-211) duplicates the message field already present on ErrorResponse (used at Line 340) purely to add the optional lock payload. Adding an optional lock field to the existing ErrorResponse (or having RequestErrorResponse wrap/extend it) would avoid maintaining two near-identical error-response shapes going forward.

Also applies to: 300-307, 339-342

🤖 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 `@crates/frontend/src/utils.rs` around lines 206 - 211, Unify
RequestErrorResponse with the existing ErrorResponse type by adding the optional
lock payload to ErrorResponse and reusing it wherever request errors are
deserialized. Remove the duplicate RequestErrorResponse definition and update
the affected parsing and response handling near the existing ErrorResponse
usage, preserving the current message and lock behavior.
🤖 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 `@crates/frontend/src/utils.rs`:
- Around line 203-227: Add a unit-test module for workspace_lock_retry_delay
with a table-style test covering retries 0, 1, and 2, asserting delays of 250ms,
500ms, and 1000ms respectively.
- Around line 206-211: Unify RequestErrorResponse with the existing
ErrorResponse type by adding the optional lock payload to ErrorResponse and
reusing it wherever request errors are deserialized. Remove the duplicate
RequestErrorResponse definition and update the affected parsing and response
handling near the existing ErrorResponse usage, preserving the current message
and lock behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3229b98a-61f1-4b5d-9c1a-13258411a982

📥 Commits

Reviewing files that changed from the base of the PR and between a51032d and 48f0a97.

📒 Files selected for processing (1)
  • crates/frontend/src/utils.rs

@sauraww
sauraww force-pushed the feat/retry-lock branch 2 times, most recently from c45f9a6 to 6171cbd Compare July 30, 2026 13:38

@Datron Datron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you attach a video of a demo

lock: Option<serde_json::Value>,
}

async fn sleep(duration: Duration) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can't a native JS or tokio module do this?

Comment on lines 381 to 416
@@ -301,7 +400,19 @@ pub async fn request<T>(
where
T: serde::Serialize,
{
request_with_skip_error(url, method, body, headers, &[]).await
request_with_policy(url, method, body, headers, &[], RetryPolicy::None).await
}

pub async fn request_with_workspace_lock_retry<T>(
url: String,
method: reqwest::Method,
body: Option<T>,
headers: HeaderMap,
) -> Result<reqwest::Response, String>
where
T: serde::Serialize,
{
request_with_policy(url, method, body, headers, &[], RetryPolicy::WorkspaceLock).await
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need these wrapper functions? Can they be made generic somehow - it is just different ways to call another function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Making callers pass RetryPolicy directly would save a few wrapper lines but add policy arguments everywhere and expose internal behavior.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

request() → normal one shot request.
request_with_skip_error() → one shot with accepted error statuses.
request_with_workspace_lock_retry() → explicit lock retry.

Comment thread crates/frontend/src/utils.rs Outdated
}

#[derive(Deserialize)]
struct RequestErrorResponse {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would WorkspaceLockedErrorResponse be better for this?

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.

3 participants