patch cache authoritatively after merge/close/toggle-draft#30
Merged
Conversation
GitHub's search/list APIs are eventually consistent — for several seconds after a merge or draft-toggle they may still return the old state. The mutation route's fire-and-forget resync was picking up that stale data and overwriting the client's optimistic update on the next 10s poll, so merged PRs reappeared. Now the route patches the cache directly with the known outcome and records a mutation marker (60s TTL). Subsequent resyncs filter their GitHub response through the marker, so a stale fetch can't resurrect the PR. The marker expires once GitHub has caught up.
There was a problem hiding this comment.
Pull request overview
This PR prevents stale dashboard state after PR mutations by synchronously updating server cache on merge/close/toggle-draft and by adding a short-lived mutation marker that filters out eventually-consistent GitHub search results during subsequent resyncs.
Changes:
- Add an in-memory mutation marker (60s TTL) and apply it during resync so stale GitHub results can’t “resurrect” removed/old PR state.
- Patch cached
prs/reviewsimmediately after successful merge/close, and patch cachedprsafter successful toggle-draft. - Add tests that simulate stale GitHub responses and assert the cache remains correct.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/server/src/sync.ts | Tracks recent mutations and filters resync results to prevent stale GitHub search results from reintroducing old state. |
| packages/server/src/routes.ts | Patches cache immediately after merge/close/toggle-draft and records mutation markers before scheduling background resync. |
| packages/server/src/routes.test.ts | Adds regression tests covering stale GitHub responses after merge/close/toggle-draft. |
| packages/server/src/cache.ts | Introduces patchCache helper for in-place cache updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+39
| return (data: CachedListItem[] | null): CachedListItem[] => | ||
| (data ?? []).filter( | ||
| (item) => !(item.repo === repo && item.number === number), | ||
| ); | ||
| } | ||
|
|
||
| function setDraftInList(repo: string, number: number, draft: boolean) { | ||
| return (data: CachedListItem[] | null): CachedListItem[] => | ||
| (data ?? []).map((item) => | ||
| item.repo === repo && item.number === number ? { ...item, draft } : item, | ||
| ); |
Comment on lines
+36
to
+39
| return (data: CachedListItem[] | null): CachedListItem[] => | ||
| (data ?? []).map((item) => | ||
| item.repo === repo && item.number === number ? { ...item, draft } : item, | ||
| ); |
Comment on lines
+58
to
+60
| export function patchCache<T>(key: string, fn: (data: T | null) => T): void { | ||
| setCached(key, fn(getCached<T>(key))); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes stale dashboard state after mutations: previously, merged PRs would reappear on the next poll because the post-mutation fire-and-forget resync re-fetched from GitHub's search index, which is eventually consistent and often still returned the just-merged PR as open.
pulls.merge,close, andtoggle-draftsucceed.pulls.mergefails on queue-enabled repos, no marker recorded, fallback path arms auto-merge as before.Test plan
routes.test.tssimulate stale GitHub responses for merge/close/toggle-draft and assert the cache stays correct (these failed before the fix).