Skip to content

fix(ui): preserve an in-flight retry flag in notifyApiFailure - #8754

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-notify-retry-guard-v2
Jul 26, 2026
Merged

fix(ui): preserve an in-flight retry flag in notifyApiFailure#8754
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-notify-retry-guard-v2

Conversation

@kai392

@kai392 kai392 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #8676

Re-file of #8751 (closed on validate-code: the UI workspace's eslint . includes the prettier/prettier rule, and the object literal + a test's inline type needed prettier's multiline formatting). This branch is prettier-clean.

Root cause

notifyApiFailure (apps/loopover-ui/src/lib/api/request.ts) rebuilt the notifier entry from scratch on every call for an id — notifierState.set(id, { …, retrying: false }). Meanwhile runRetryWithProgress guards a double-fired retry by re-entrancy: if (entry?.retrying) return; then mutates the same shared object entry.retrying = true, cleared only in .finally().

Because notifyApiFailure replaced rather than merged, any call for the same label while a retry was in flight (a second component sharing the label, a background poll, or the retry's own failing request) silently reset retrying to false, defeating the guard — so a second Retry click fired a concurrent duplicate retry.

Fix

Preserve the current entry's in-flight flag: retrying: prev?.retrying === true. All other fields (kind, status, lastNotifiedAt, repeatCount) still update exactly as before — a one-field merge, not a behavior change anywhere else.

Tests

  • Double-fire guard: a never-settling retry keeps retrying true; the first Retry click invokes retry once; a mid-retry notifyApiFailure for the same label then a second Retry click must be blocked — retry stays called once. Verified genuinely non-vacuous: reverting the one-field change makes this fail (retry called twice).
  • Regression: two failures for the same label within the dedup window still bump repeatCount (toast description shows "2× in a row").

Validation

  • @loopover/ui test: 2 passed; prettier --check clean on both files; typecheck clean; committed as LF
  • apps/** is outside Codecov's coverage.include, so no patch percentage applies; branch rebased onto current main; git diff --check clean

@kai392
kai392 requested a review from JSONbored as a code owner July 26, 2026 02:50
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

notifyApiFailure replaced the whole notifier entry (retrying: false) on every
call for an id, so a second failure notification arriving while a retry was
already in flight reset the re-entrancy flag runRetryWithProgress relies on —
letting a second Retry click fire a concurrent duplicate retry. Preserve an
existing retrying:true instead of resetting it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 26, 2026
@loopover-orb

loopover-orb Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-26 03:01:07 UTC

2 files · 1 AI reviewer · no blockers · readiness 95/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This is a genuine one-field merge fix: notifyApiFailure previously replaced the notifier entry wholesale (retrying: false always), which raced with runRetryWithProgress mutating the same entry's retrying flag during an in-flight retry, defeating its re-entrancy guard. The new `retrying: prev?.retrying === true` correctly preserves the in-flight flag while still refreshing kind/status/lastNotifiedAt/repeatCount exactly as before. Tracing the object identity through notifierState.set (each call creates a new object, but prev.retrying is read and copied forward) confirms the guard now survives a concurrent notifyApiFailure call, and the added test genuinely reproduces the double-fire scenario (author states reverting the one-line change makes it fail with retry called twice), not a fabricated payload.

Nits — 4 non-blocking
  • request.ts:132-142 — the 4-line inline comment restates the PR description verbatim; a one-line pointer to the issue would suffice given the description already carries the detail.
  • request.ts:141 — `prev?.retrying === true` and `prev?.retrying ?? false` are equivalent here since retrying is always boolean when present; either is fine but the `??` form reads slightly more idiomatically.
  • Consider trimming the block comment at request.ts:132-135 to a single line referencing the issue, since the full rationale already lives in the PR description and commit message.
  • No further action needed on the test file — the double-fire and regression cases both exercise the real code path through the mocked sonner action.onClick.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8676
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 153 registered-repo PR(s), 83 merged, 6 issue(s).
Contributor context ✅ Confirmed Gittensor contributor kai392; Gittensor profile; 153 PR(s), 6 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The diff changes notifyApiFailure to merge fields instead of replacing the entry, explicitly preserving `retrying` when previously true, and adds both a race-condition test (mid-retry notifyApiFailure followed by a second Retry click, asserting retry is called once) and a regression test confirming repeatCount/description still update correctly on repeat failures without an in-flight retry.

Review context
  • Author: kai392
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, Cuda, JavaScript, Kotlin, Perl, TypeScript, Vue
  • Official Gittensor activity: 153 PR(s), 6 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb 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.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit c8eed4c into JSONbored:main Jul 26, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ui): notifyApiFailure clobbers an in-flight retry's guard flag, allowing a double-fired retry

2 participants