Skip to content

fix: cache not refresh in some cache#1699

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
May 23, 2026
Merged

fix: cache not refresh in some cache#1699
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented May 23, 2026

Copy link
Copy Markdown
Owner

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request modifies the xcache live cache implementation to execute the OnSwap callback asynchronously in a separate goroutine, preventing potential stalls in the periodic refresh loop. The associated unit tests have been updated to use assert.Eventually to account for this change. Additionally, the StopAutoRefresh methods in DeviceFlowProvider and TokenProvider now utilize a 5-second timeout context during executor shutdown to prevent indefinite blocking. I have no feedback to provide as there were no review comments to evaluate.

devin-ai-integration[bot]

This comment was marked as resolved.

@greptile-apps

greptile-apps Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a cache-refresh issue by running the onSwap callback synchronously (with proper logging) and adding a 5-second timeout to exec.Shutdown in both TokenProvider and DeviceFlowProvider, preventing indefinite blocking of the worker goroutine. It also corrects the test's data race by moving the atomic increment to after the plain writes.

  • cache.go: Adds log.Debug bookends around the synchronous onSwap invocation and a comment explaining why it runs on the worker goroutine with bounded latency.
  • token_provider.go / device_flow_provider.go: Replaces the unbounded context.Background() passed to exec.Shutdown with a context.WithTimeout of 5 s, matching the stated "bounded by timeouts" contract.
  • cache_test.go: Moves atomic.AddInt32 to after the plain oldValue/newValue writes so the atomic increment acts as a release-store, fixing the data race flagged in the previous review.

Confidence Score: 5/5

Safe to merge — all changes are additive logging, a bounded shutdown timeout, and a test race fix.

All four files contain narrow, well-scoped changes: two providers gain a 5-second shutdown timeout that prevents the worker goroutine from blocking indefinitely, the cache gets observability log lines with no logic change, and the test correctly sequences the atomic increment after the plain writes to eliminate the data race from the prior review. No existing behavior is altered in a way that could regress.

No files require special attention.

Important Files Changed

Filename Overview
internal/pkg/xcache/live/cache.go Adds debug logging and an explanatory comment around the synchronous onSwap call; no logic changes.
internal/pkg/xcache/live/cache_test.go Moves atomic.AddInt32 after plain writes, correctly fixing the data race from the prior review cycle.
llm/oauth/token_provider.go Adds a 5-second context timeout to exec.Shutdown and a debug log on success; prevents indefinite blocking during StopAutoRefresh.
llm/oauth/device_flow_provider.go Same bounded-shutdown pattern as token_provider.go applied to DeviceFlowProvider.StopAutoRefresh.

Sequence Diagram

sequenceDiagram
    participant W as Worker goroutine
    participant LI as loadInternal
    participant OS as onSwap callback
    participant SAR as StopAutoRefresh

    W->>LI: doRefresh(ctx, force)
    LI->>LI: "swap c.data & c.lastUpdate"
    LI->>OS: log.Debug "onSwap starting"
    LI->>OS: c.onSwap(old, newData)
    OS->>SAR: exec.Shutdown(ctx 5s timeout)
    SAR-->>OS: shutdown complete / timeout
    OS-->>LI: return
    LI->>LI: log.Debug "onSwap completed"
    LI->>LI: log.Info "cache refreshed"
    LI-->>W: return err
Loading

Reviews (2): Last reviewed commit: "fix: cache not refresh in some cache" | Re-trigger Greptile

greptile-apps[bot]

This comment was marked as resolved.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 new potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review


c.onSwap(old, newData)
}()
log.Debug(ctx, "live cache onSwap completed", log.String("name", c.name))

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.

🟡 "onSwap completed" debug log emitted even when onSwap panicked

If c.onSwap(old, newData) panics, the deferred recover() inside the IIFE catches it and logs an error at line 238. However, because the panic is recovered, the IIFE returns normally, and execution continues to line 246 which unconditionally logs "live cache onSwap completed". This produces a misleading log sequence: first "onSwap callback panicked" (Error), then "onSwap completed" (Debug), falsely indicating success after a failure. For operational debugging, this can mask real issues.

Suggested change
log.Debug(ctx, "live cache onSwap completed", log.String("name", c.name))
log.Debug(ctx, "live cache onSwap finished", log.String("name", c.name))
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@looplj looplj merged commit 57ccc13 into unstable May 23, 2026
5 checks passed
looplj added a commit that referenced this pull request May 23, 2026
yoke233 pushed a commit to yoke233/axonhub that referenced this pull request May 26, 2026
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.

1 participant