Skip to content

[server] Retry rev-mismatched code-sync inserts server-side#21319

Open
geropl wants to merge 1 commit intomainfrom
fix/code-sync-412-retry-loop
Open

[server] Retry rev-mismatched code-sync inserts server-side#21319
geropl wants to merge 1 commit intomainfrom
fix/code-sync-412-retry-loop

Conversation

@geropl
Copy link
Member

@geropl geropl commented Feb 27, 2026

Fixes CLC-2223

Problem

Customers see "Settings sync is suspended temporarily because the current device is making too many requests" banners. Logs show repeated 412 responses from /code-sync/v1/resource/globalState until the client hits its rate limit.

Root cause: When the VS Code client POSTs to update a resource, it sends If-Match: <last-known-rev>. If the server's latest rev has changed (e.g. another workspace wrote to the same resource), the server returns 412. The VS Code client handles 412 by re-fetching remote data and retrying performSync — with no recursion limit. In a multi-workspace scenario (or with rapidly-changing globalState), the rev keeps changing between the client's GET and POST, creating a cascading retry loop. Each retry cycle costs 2+ HTTP requests (GET + POST), and the client's RequestsSession budget is 100 requests per 5 minutes. The loop exhausts this budget, triggering the suspension banner.

Fix

Retry the db.insert call up to 3 times server-side when a rev mismatch occurs, using the server's current latest rev for each attempt. This absorbs transient concurrency conflicts before they reach the client, breaking the unbounded retry loop.

The retry is scoped: it only applies when the initial insert fails due to a rev mismatch (latestRev was provided but didn't match), and is skipped for editSessions resources which use a different error code (400).

Changes

  • components/server/src/code-sync/code-sync-service.ts: Server-side retry loop in postResource for rev-mismatched inserts
  • components/gitpod-db/src/typeorm/code-sync-resource-db.ts: New getLatestRevision() method to fetch the current rev without a full resource list
  • components/gitpod-db/src/typeorm/code-sync-resource-db.spec.db.ts: Tests for getLatestRevision()

When multiple workspaces sync globalState concurrently, the If-Match
rev becomes stale between the client's GET and POST. The VS Code client
retries 412 responses with no recursion limit, exhausting its
100-request/5-min budget and triggering 'Settings sync is suspended'.

Retry the insert up to 3 times server-side with the current latest rev,
absorbing transient concurrency conflicts before they reach the client.

Co-authored-by: Ona <no-reply@ona.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant