Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(server): settle branch threads immediately on pull request merge#9528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
maria-rcks
merged 4 commits into
pingdotgg:main
from
maria-rcks:t3code/fix-thread-pr-merge-settlingSep 4, 2026
+150
−13
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f2e2c4c
fix(server): settle branch threads immediately on pull request merge
maria-rcks 69ff5ea
fix(server): format settlement sweep
maria-rcks 9eebe09
fix(server): only settle threads linked to the merged pull request
maria-rcks 85d76cc
fix(server): refresh branch pull request lookups every minute
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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
114 changes: 113 additions & 1 deletion
114 apps/server/src/orchestration/ThreadSettlementReactor.test.ts
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -46,16 +46,11 @@ export const make = Effect.gen(function* () { | ||
| const snapshot = yield* snapshots.getShellSnapshot(); | ||
| const now = DateTime.formatIso(yield* DateTime.now); | ||
| const projects = new Map(snapshot.projects.map((project) => [project.id, project])); | ||
| const candidates = snapshot.threads.filter( | ||
| (thread) => | ||
| isAutoSettlementCandidate(thread, now) && | ||
| (mergedPullRequest === null || | ||
| (thread.linkedPullRequest != null && | ||
| thread.linkedPullRequest.projectId === mergedPullRequest.projectId && | ||
| thread.linkedPullRequest.repository.toLowerCase() === | ||
| mergedPullRequest.repository.toLowerCase() && | ||
| thread.linkedPullRequest.number === mergedPullRequest.number)), | ||
| ); | ||
| // A merge event re-sweeps every candidate, not just the threads linked to | ||
| // the merged pull request: most threads carry no link and settle from | ||
| // their branch lookup, which would otherwise wait for the next minute's | ||
| // sweep on a possibly stale cached answer. | ||
| const candidates = snapshot.threads.filter((thread) => isAutoSettlementCandidate(thread, now)); | ||
| // Use the same cwd as the sidebar so both paths share GitManager's PR cache. | ||
| const lookupCwdByThreadId = new Map<string, string>(); | ||
| yield* Effect.forEach( | ||
| @@ -76,6 +71,19 @@ export const make = Effect.gen(function* () { | ||
| }), | ||
| { concurrency: 8, discard: true }, | ||
| ); | ||
| if (mergedPullRequest !== null) { | ||
| // The merge just confirmed a terminal state the lookup caches can still | ||
| // call open (branch answers live two minutes, the sweep runs every | ||
| // minute). Drop the swept checkouts' cached answers so the merge settles | ||
| // its branch threads now instead of on a later sweep. Threads linked to | ||
| // the merged pull request settle from the event itself below and need no | ||
| // lookup, so they are absent from this map by construction. | ||
| const cwds = [...new Set(lookupCwdByThreadId.values())]; | ||
| yield* Effect.forEach(cwds, (cwd) => git.invalidateStatus(cwd), { | ||
| concurrency: 8, | ||
| discard: true, | ||
| }); | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const lookupKey = (thread: (typeof candidates)[number]) => { | ||
| if (thread.linkedPullRequest != null) { | ||
| return JSON.stringify([ | ||
| @@ -97,7 +105,18 @@ export const make = Effect.gen(function* () { | ||
| thread: (typeof candidates)[number], | ||
| ) { | ||
| if (thread.linkedPullRequest != null) { | ||
| if (mergedPullRequest !== null) { | ||
| // The event carries the merged state, so only the threads linked to | ||
| // that exact pull request settle from it. Every other linked thread | ||
| // falls through to a fresh summary lookup below: the merge sweep | ||
| // covers all candidates, and an unrelated merge must never settle | ||
| // them. | ||
| if ( | ||
| mergedPullRequest !== null && | ||
| thread.linkedPullRequest.projectId === mergedPullRequest.projectId && | ||
| thread.linkedPullRequest.repository.toLowerCase() === | ||
| mergedPullRequest.repository.toLowerCase() && | ||
| thread.linkedPullRequest.number === mergedPullRequest.number | ||
| ) { | ||
| return { | ||
| state: "merged", | ||
| updatedAt: mergedPullRequest.mergedAt, | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.