Skip to content

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

Closed
kai392 wants to merge 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-notify-retry-guard
Closed

fix(ui): preserve an in-flight retry flag in notifyApiFailure#8751
kai392 wants to merge 1 commit into
JSONbored:mainfrom
kai392:fix/critical-issue-notify-retry-guard

Conversation

@kai392

@kai392 kai392 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Fixes #8676

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 — this is 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; npm --workspace @loopover/ui run typecheck clean; oxlint clean on the changed line
  • 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:42
@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

Caution

🛑 LoopOver review result - fixes required

Review updated: 2026-07-26 02:49:00 UTC

2 files · 1 AI reviewer · no blockers · CI failing · blocked

🛑 Suggested Action - Fix Blockers

Review summary
This is a correct, well-traced re-entrancy fix: `notifyApiFailure` previously replaced the notifier entry wholesale on every call, silently resetting `retrying` to `false` even while `runRetryWithProgress`'s guard (`if (entry?.retrying) return`) depended on that same shared object staying `true` mid-retry — a second failure notification for the same label during an in-flight retry defeated the guard and let a second Retry click fire a concurrent duplicate. The one-line change to `retrying: prev?.retrying === true` is a minimal merge instead of a replace, and the added test genuinely exercises the real callback wiring (mocked `sonner` toast action, a never-resolving retry to hold `retrying` true, then a second `notifyApiFailure` + Retry click) rather than fabricating state — the PR description's claim that reverting the fix makes the test fail (`retry` called twice) is plausible given the traced logic. Scope is tight and matches the linked issue #8676.

Nits — 4 non-blocking
  • `prev?.retrying === true` is functionally identical to `prev?.retrying ?? false` and slightly clearer given `retrying` is always a plain boolean when `prev` exists (apps/loopover-ui/src/lib/api/request.ts:135).
  • The four-line inline comment above the fix is verbose for a one-field change; the PR description already carries this context and a shorter one-liner would suffice.
  • Consider trimming the comment at request.ts:131-134 to a single line referencing fix(ui): notifyApiFailure clobbers an in-flight retry's guard flag, allowing a double-fired retry #8676 and the invariant (merge, don't replace) rather than re-deriving the whole root-cause narrative inline.
  • Optionally add a case where `prev` is undefined (first-ever notification for a label) confirming `retrying` defaults to `false` — not strictly needed since the type default is implied, but it would make the merge behavior fully explicit in tests.

CI checks failing

  • validate
  • validate-code

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 rather than replace, preserving prev?.retrying === true while still updating kind/status/lastNotifiedAt/repeatCount as before, matching the issue's core requirement. It also adds a test simulating a mid-retry notifyApiFailure call verifying retry is invoked only once, plus a regression test confirming repeatCount still updates normally, covering all three

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 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (CI is failing (validate, validate-code)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

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