Skip to content

fix: preserve recentlyHandledRequestsCache across watchdog reset to p…#3505

Open
dearlordylord wants to merge 1 commit intoapify:masterfrom
dearlordylord:worktree-fix-v3-handled-refetch
Open

fix: preserve recentlyHandledRequestsCache across watchdog reset to p…#3505
dearlordylord wants to merge 1 commit intoapify:masterfrom
dearlordylord:worktree-fix-v3-handled-refetch

Conversation

@dearlordylord
Copy link
Copy Markdown

…revent handled request refetch

  • _reset() in request_provider.ts cleared recentlyHandledRequestsCache on watchdog timeout (5min inactivity)
  • This cache is the only local guard preventing _ensureHeadIsNonEmpty from re-adding handled requests to queueHeadIds when server listHead() returns stale data
  • After clearing, handled requests get re-dequeued and re-processed silently (data duplication via double pushData())

Why removing the clear is safe

recentlyHandledRequestsCache is only populated in two places, both after server confirmation:

  1. markRequestHandled()
  2. fetchNextRequest()

No code path adds a pending/unhandled request to this cache. Preserving it across reset cannot cause a stuck queue because every entry genuinely represents a handled request.

Additionally fetchNextRequest has a secondary server-side guard: even if a request somehow passes the cache filter, getRequest() checks request.handledAt and returns null. But relying solely on this is wasteful (unnecessary server roundtrips)

The cache is LRU-bounded at 1000 entries, no memory concern from preserving it.

@janbuchar janbuchar self-requested a review March 23, 2026 15:07
@janbuchar
Copy link
Copy Markdown
Contributor

Hi @dearlordylord, I did not examine this carefully yet. Do I understand it right that the race condition you describe happens because after resetting the queue here?

@dearlordylord
Copy link
Copy Markdown
Author

Hi @dearlordylord, I did not examine this carefully yet. Do I understand it right that the race condition you describe happens because after resetting the queue here?

Yes exactly. Specifically: it's not the whole _reset() that's the problem, it's the recentlyHandledRequestsCache.clear() inside it. The other clears (queueHeadIds, counters, requestCache) are fine and serve the unsticking purpose.

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.

3 participants