Agent skill

REST API Optimistic Update Race Condition

by divinevideo in divinevideo/divine-mobile

Fix "content disappears after publishing" bugs caused by REST API indexing lag.

MPL-2.0Auto-check passedBackend & APIs

Install REST API Optimistic Update Race Condition

skills CLI
$ npx skills add divinevideo/divine-mobile --skill rest-api-optimistic-update-race-condition -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install divinevideo/divine-mobile rest-api-optimistic-update-race-condition --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/divinevideo/divine-mobile.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/rest-api-optimistic-update-race-condition .claude/skills/rest-api-optimistic-update-race-condition && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
rest-api-optimistic-update-race-condition
GitHub stars
266
Token cost
~1.3k tokens
SKILL.md length
330 words
Files
1
Skills in repo
103
Repo updated
First seen
Licence
MPL-2.0

At a glance

Fix "content disappears after publishing" bugs caused by REST API indexing lag.

  • Works in 5 steps: Publish new content → Immediately navigate to the listing… → Verify new content appears at the top → …
  • User publishes content but it doesnt appear in their feed/profile
  • SKILL.md covers Problem, Context / Trigger Conditions, Solution and Verification, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

REST API Optimistic Update Race Condition is an agent skill from divinevideo/divine-mobile. Fix "content disappears after publishing" bugs caused by REST API indexing lag. Use when: (1) User publishes content but it doesn't appear in their feed/profile, (2) REST API returns stale data immediately after write operations, (3) Async indexing backends (ClickHouse, Elasticsearch, etc.) haven't processed new events, (4) Content shows briefly then vanishes on refresh. Applies to any system with separate write path (WebSocket/direct DB) and read path (REST API with async indexing).

Its SKILL.md is about 1.3k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Backend & APIs, covering REST APIs, Async programming and Search implementation. It works with ClickHouse and Elasticsearch. The licence is MPL-2.0.

When your agent uses it

  • User publishes content but it doesnt appear in their feed/profile
  • REST API returns stale data immediately after write operations
  • Async indexing backends (ClickHouse
  • Etc.) havent processed new events

Example prompts

  • “content disappears after publishing”
  • “/rest-api-optimistic-update-race-condition”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. Publish new content
  2. Immediately navigate to the listing (profile, feed, etc.)
  3. Verify new content appears at the top
  4. Refresh page after 30+ seconds - content should still be there
  5. Check that duplicate prevention works (publish same content twice)

What it can do on your machine

Read from SKILL.md and the folder at commit 6487b05. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are dart).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • apollographql.com
    • martinfowler.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

REST API Optimistic Update Race Condition loads about 1.3k tokens when it runs. Until then it costs about 133 tokens; SKILL.md has 330 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~133
When it runs · the whole SKILL.md, loaded when a task matches
~1.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from divinevideo/divine-mobile at commit 6487b05, republished under its MPL-2.0 licence (© divinevideo). 330 words, ~1,299 tokens.

Download SKILL.mdSave it as .claude/skills/rest-api-optimistic-update-race-condition/SKILL.md (or your agent's skills folder).
name
rest-api-optimistic-update-race-condition
description
Fix "content disappears after publishing" bugs caused by REST API indexing lag. Use when: (1) User publishes content but it doesn't appear in their feed/profile, (2) REST API returns stale data immediately after write operations, (3) Async indexing backends (ClickHouse, Elasticsearch, etc.) haven't processed new events, (4) Content shows briefly then vanishes on refresh. Applies to any system with separate write path (WebSocket/direct DB) and read path (REST API with async indexing).
author
Claude Code
version
1.0.0
date
2026-02-01

REST API Optimistic Update Race Condition

Problem

When an application uses a dual architecture with:

  • Write path: Direct database writes or WebSocket/event publishing
  • Read path: REST API backed by async indexing (ClickHouse, Elasticsearch, etc.)

Content can "disappear" after publishing because the read path hasn't indexed the new content yet, but the UI re-fetches from the REST API expecting fresh data.

Context / Trigger Conditions

  • User publishes content (video, post, comment, etc.)
  • Content briefly appears, then disappears on refresh or navigation
  • REST API returns N items when N+1 expected
  • Logs show successful write but stale read
  • Backend uses async indexing (ClickHouse, Elasticsearch, Algolia, etc.)
  • Symptoms worsen under load or with slow indexing pipelines

Log pattern example:

✅ Event successfully published to relays
📊 Fetching from REST API: found 59 videos  // Expected 60!

Solution

Instead of re-fetching from REST API after publishing, optimistically add the new content directly to the local state:

dart
// BEFORE (broken): Re-fetch from potentially stale API
void onNewContentPublished(Content newContent) {
  refreshFromRestApi(); // API hasn't indexed yet = stale data
}

// AFTER (fixed): Optimistic local update
void onNewContentPublished(Content newContent) {
  final currentItems = state.items;

  // Skip if duplicate
  if (currentItems.any((item) => item.id == newContent.id)) return;

  // Add to front of list (most recent first)
  final updatedItems = [newContent, ...currentItems];

  state = state.copyWith(
    items: updatedItems,
    lastUpdated: DateTime.now(),
  );
}
Option 2: Hybrid Approach

For long-lived sessions, periodically reconcile local state with REST API:

dart
void onNewContentPublished(Content newContent) {
  // Immediate: optimistic update
  _addToLocalState(newContent);

  // Delayed: reconcile with API after indexing lag
  Future.delayed(Duration(seconds: 30), () {
    _reconcileWithRestApi();
  });
}
Option 3: Write-Through Cache

If your REST API supports it, use write-through caching:

dart
// POST to API returns the created item, cache it immediately
final response = await api.createContent(content);
_cache.put(response.id, response);

Verification

After implementing the fix:

  1. Publish new content
  2. Immediately navigate to the listing (profile, feed, etc.)
  3. Verify new content appears at the top
  4. Refresh page after 30+ seconds - content should still be there
  5. Check that duplicate prevention works (publish same content twice)

Example

Real-world case: OpenVine video upload

dart
// ProfileFeedProvider - fixed version
final unregisterNew = videoEventService.addNewVideoListener((
  newVideo,
  authorPubkey,
) {
  if (authorPubkey == userId && ref.mounted) {
    // CRITICAL FIX: Optimistically add the new video to state immediately
    // instead of re-fetching from REST API which may have stale data.
    _addNewVideoToState(newVideo);
  }
});

void _addNewVideoToState(VideoEvent newVideo) {
  final currentState = state.asData?.value;
  if (currentState == null) return;

  // Check for duplicates
  if (currentState.videos.any((v) => v.id == newVideo.id)) return;

  // Add new video to the front of the list
  final updatedVideos = <VideoEvent>[newVideo, ...currentState.videos];

  state = AsyncData(VideoFeedState(
    videos: updatedVideos,
    hasMoreContent: currentState.hasMoreContent,
    isLoadingMore: false,
    lastUpdated: DateTime.now(),
  ));
}

Notes

  • This pattern applies to any system with async indexing, not just Nostr/ClickHouse
  • Consider adding a "pending" or "uploading" visual state for published content
  • The optimistic update should include all metadata the UI needs to render
  • For content that requires server-side processing (thumbnails, transcoding), consider showing a placeholder until processing completes
  • If the write actually failed, the next REST API fetch will correct the state
  • Optimistic UI: Show changes before server confirmation
  • CQRS: Command Query Responsibility Segregation (separate read/write models)
  • Event Sourcing: Events as source of truth with materialized views for reads
  • Cache Invalidation: The "two hard problems" - this is one of them

References

© divinevideo, MPL-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in .agents/skills/rest-api-optimistic-update-race-condition of divinevideo/divine-mobile.

Open the folder on GitHubat commit 6487b05

Compare with similar skills

REST API Optimistic Update Race Condition next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

REST API Optimistic Update Race Condition compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
REST API Optimistic Update Race Condition this skilldivinevideo/divine-mobile266—~1.3kAutomated safety check: PassMPL-2.0
Whodbxiaoyuge886/aigc198—~894Automated safety check: PassMIT
Backend Dev Guidelineslangfuse/langfuse36k—~1.9kAutomated safety check: PassCustom licence
Backend Dev Guidelineslitefuse/litefuse1001 repos~5.8kAutomated safety check: PassCustom licence
iOS Networkingdpearson2699/swift-ios-skills1.2k—~4.2kAutomated safety check: PassCustom licence
Profiling Slow API EndpointsPostHog/posthog40k—~1kAutomated safety check: PassCustom licence

Similar skills

  • Whodb

    xiaoyuge886/aigc

    Database operations including querying, schema exploration, and data analysis.

    198 GitHub stars~894 tokensUpdated 2 mo ago
    DatabasesAuto-check passed
  • Backend Dev Guidelines

    langfuse/langfuse

    Build or review Langfuse backend code. An agent skill from langfuse/langfuse.

    36k GitHub stars~1.9k tokensUpdated today
    Backend & APIsAuto-check passed
  • Backend Dev Guidelines

    litefuse/litefuse

    Comprehensive backend development guide for Litefuse's Next.js 14/tRPC/Express/TypeScript monorepo.

    100 GitHub starsUsed in 1 repo~5.8k tokens
    Backend & APIsAuto-check passed
  • iOS Networking

    dpearson2699/swift-ios-skills

    Build, review, or improve networking code in iOS/macOS apps using URLSession with async/await, structured concurrency, and modern Swift patterns.

    1.2k GitHub stars~4.2k tokensUpdated 2 mo ago
    Backend & APIsAuto-check passed
  • Official

    Profiles slow PostHog API endpoints when the main cost is in Postgres or Python.

    40k GitHub stars~1k tokensUpdated today
    DatabasesAuto-check passed
  • Querying Tempo

    tempoxyz/tidx

    Query indexed Tempo chain data via tidx HTTP API and CLI. An agent skill from tempoxyz/tidx.

    107 GitHub stars~3.1k tokensUpdated today
    DatabasesAuto-check passed

More from divinevideo/divine-mobile

All 103 skills in this repo
  • Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y".

    266 GitHub stars~931 tokensUpdated today
    Auto-check passed
  • Art Direct

    divinevideo/divine-mobile

    Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language.

    266 GitHub stars~4.8k tokensUpdated today
    Auto-check passed
  • Async Await Null Race Condition

    divinevideo/divine-mobile

    Fix "Null check operator used on a null value" errors when an object is set to null during an async await.

    266 GitHub stars~881 tokensUpdated today
    Auto-check passed
  • AWS V4 Signing Custom Headers Gcs

    divinevideo/divine-mobile

    Add custom metadata headers (x-amz-meta-) to AWS v4 signed requests for GCS S3-compatible API.

    266 GitHub stars~1k tokensUpdated today
    Auto-check passed
  • Bash Herestring Newline Secrets

    divinevideo/divine-mobile

    Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings.

    266 GitHub stars~791 tokensUpdated today
    Auto-check passed
  • Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp).

    266 GitHub stars~1.1k tokensUpdated today
    Auto-check passed

Categories

Questions about REST API Optimistic Update Race Condition

What does REST API Optimistic Update Race Condition do?

Fix "content disappears after publishing" bugs caused by REST API indexing lag. REST API Optimistic Update Race Condition is an agent skill from divinevideo/divine-mobile. Fix "content disappears after publishing" bugs caused by REST API indexing lag.

When should I use REST API Optimistic Update Race Condition?

REST API Optimistic Update Race Condition fits situations like: user publishes content but it doesnt appear in their feed/profile; REST API returns stale data immediately after write operations; async indexing backends (ClickHouse; etc.) havent processed new events.

How do I install REST API Optimistic Update Race Condition in Claude Code?

Run `npx skills add divinevideo/divine-mobile --skill rest-api-optimistic-update-race-condition -a claude-code`. Or copy the skill folder (.agents/skills/rest-api-optimistic-update-race-condition in divinevideo/divine-mobile) into .claude/skills/rest-api-optimistic-update-race-condition in your project. Claude Code loads it when a task matches its description.

How do I install REST API Optimistic Update Race Condition in Codex?

Run `npx skills add divinevideo/divine-mobile --skill rest-api-optimistic-update-race-condition -a codex`. Or copy the skill folder (.agents/skills/rest-api-optimistic-update-race-condition in divinevideo/divine-mobile) into .agents/skills/rest-api-optimistic-update-race-condition in your project. Codex loads it when a task matches its description.

Can I use REST API Optimistic Update Race Condition in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add divinevideo/divine-mobile --skill rest-api-optimistic-update-race-condition -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/rest-api-optimistic-update-race-condition, .gemini/skills/rest-api-optimistic-update-race-condition, .github/skills/rest-api-optimistic-update-race-condition and .opencode/skills/rest-api-optimistic-update-race-condition in your project.

What does REST API Optimistic Update Race Condition need to run?

SKILL.md names no scripts, command-line tools or credentials: REST API Optimistic Update Race Condition is instructions for the agent only.

Does REST API Optimistic Update Race Condition access the network?

SKILL.md names 2 domains. As links in the text: apollographql.com and martinfowler.com. This is read from the text; nothing was executed.

Is REST API Optimistic Update Race Condition safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does REST API Optimistic Update Race Condition use?

REST API Optimistic Update Race Condition is published under the MPL-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does REST API Optimistic Update Race Condition use?

About 1.3k tokens (SKILL.md is roughly 5.2k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to REST API Optimistic Update Race Condition?

Skills that share tags, products or a category with REST API Optimistic Update Race Condition: Whodb (xiaoyuge886/aigc, 198 stars), Backend Dev Guidelines (langfuse/langfuse, 36k stars), Backend Dev Guidelines (litefuse/litefuse, 100 stars) and iOS Networking (dpearson2699/swift-ios-skills, 1.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains REST API Optimistic Update Race Condition?

divinevideo (a GitHub organization) maintains it in divinevideo/divine-mobile, which has 266 GitHub stars. The repository holds 103 skills in this directory. The repository was last updated on October 9, 2026.

Source: divinevideo/divine-mobile on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.