fix(server): find newly opened pull requests after agent turns #9125
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 6 commits into
main fromrefs/pull/9125/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/git/GitManager.ts line 1033OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1014,7 +1014,20 @@10141014 // merge from main and auto-settle an unrelated feature thread.1015+ //1016+ // The branch may still have been pushed under its own name by a plain1017+ // `git push origin feature` that never moved the upstream. When a1018+ // remote-tracking ref for the local name exists, look the PR up by1019+ // that name instead of giving up. Without the ref there is nothing to1020+ // ask the host about, so no API call is spent.10151021 if (10161022 headContext.headBranch !== details.branch &&10171023 upstreamHeadIsDefault &&10181024 !headContext.isCrossRepository10191025 ) {1020- return { latest: null, headContext };1026+ const publishedUnderOwnName = yield* hasRemoteTrackingRef(cwd, details.branch);1027+ if (!publishedUnderOwnName) {1028+ return { latest: null, headContext };1029+ }1030+ const ownNameContext = yield* resolveBranchHeadContext(cwd, {1031+ branch: details.branch,1032+ upstreamRef: null,1033+ remoteName: headContext.remoteName ?? "origin",apps/server/src/vcs/VcsStatusBroadcaster.ts line 402OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -379,3 +388,15 @@379388 return yield* updateCachedStatus(cwd, local, remote, { publish: true });380389 });381390391+ const refreshPullRequestStatus: VcsStatusBroadcaster["Service"]["refreshPullRequestStatus"] =392+ Effect.fn("VcsStatusBroadcaster.refreshPullRequestStatus")(function* (rawCwd) {393+ const cwd = yield* withFileSystem(normalizeCwd(rawCwd));394+ const cached = yield* getCachedStatus(cwd);395+ if (cached?.remote === null || cached?.remote === undefined) return null;396+ if (cached.remote.value?.pr != null) return cached.remote.value;397+ // invalidateStatus bumps GitManager's PR lookup epoch, so the read below398+ // skips the negative "no PR yet" entry that a poll may have cached399+ // moments before the agent opened the pull request.400+ yield* workflow.invalidateStatus(cwd);401+ const remote = yield* workflow.remoteStatus({ cwd });402+ return yield* updateCachedRemoteStatus(cwd, remote, { publish: true });
- apps/server/src/git/GitManager.ts lines 1372 to 1372OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1353,3 +1369,4 @@13531369 * because then every branch looks unpublished; it, and any failed probe,13541370 * keeps the lookup.13551371 */1372+ // True when any remote holds a ref named after the local branch.
- apps/server/src/vcs/VcsStatusBroadcaster.ts line 512Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -379,3 +388,16 @@379388 return yield* updateCachedStatus(cwd, local, remote, { publish: true });380389 });381390391+ const refreshPullRequestStatus: VcsStatusBroadcaster["Service"]["refreshPullRequestStatus"] =392+ Effect.fn("VcsStatusBroadcaster.refreshPullRequestStatus")(function* (rawCwd) {393+ const cwd = yield* withFileSystem(normalizeCwd(rawCwd));394+ const cached = yield* getCachedStatus(cwd);395+ if (cached?.remote === null || cached?.remote === undefined) return null;396+ if (cached.remote.value?.pr != null) return cached.remote.value;397+ // invalidateStatus bumps GitManager's PR lookup epoch, so the read below398+ // skips the negative "no PR yet" entry that a poll may have cached399+ // moments before the agent opened the pull request.400+ yield* workflow.invalidateStatus(cwd);401+ const remote = yield* workflow.remoteStatus({ cwd });402+ return yield* updateCachedRemoteStatus(cwd, remote, { publish: true });403+ });apps/server/src/git/GitManager.ts line 1036OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -1015,6 +1017,20 @@1017+ // `git push origin feature` that never moved the upstream. When a1018+ // remote-tracking ref for the local name exists, look the PR up by1019+ // that name instead of giving up. Without the ref there is nothing to1020+ // ask the host about, so no API call is spent.10151021 if (10161022 headContext.headBranch !== details.branch &&10171023 upstreamHeadIsDefault &&10181024 !headContext.isCrossRepository10191025 ) {1020- return { latest: null, headContext };1026+ const publishedUnderOwnName = yield* hasRemoteTrackingRef(cwd, details.branch);1027+ if (!publishedUnderOwnName) {1028+ return { latest: null, headContext };1029+ }1030+ const ownNameContext = yield* resolveBranchHeadContext(cwd, {1031+ branch: details.branch,1032+ upstreamRef: null,1033+ remoteName: headContext.remoteName ?? "origin",1034+ });1035+ const latest = yield* findLatestPrForHeadContext(cwd, ownNameContext);1036+ return { latest, headContext: ownNameContext };apps/server/src/orchestration/Layers/CheckpointReactor.ts line 579OutdatedResolvedby t3dotgg(GitHub profile, opens in a new tab)@@ -556,3 +560,21 @@560+ });556561 }557562 });558563564+ // Agents usually push and open the pull request inside one turn. The sidebar565+ // learns about it from the remote status poll, which caches "no PR" for the566+ // branch and often asks just before `gh pr create` finished. Re-ask once at567+ // turn end when the checked-out branch is the thread's own feature branch568+ // and no pull request is known yet. The broadcaster skips cwds nobody has569+ // loaded, so this replaces a poll lookup rather than adding one.570+ const refreshPullRequestAfterTurn = Effect.fn("refreshPullRequestAfterTurn")(function* (input: {571+ readonly threadId: ThreadId;572+ readonly cwd: string;573+ readonly local: VcsStatusLocalResult;574+ }) {575+ const checkedOutBranch = input.local.refName;576+ if (checkedOutBranch === null || input.local.isDefaultRef) return;577+ const thread = yield* projectionSnapshotQuery578+ .getThreadShellById(input.threadId)579+ .pipe(Effect.map(Option.getOrUndefined));580+ if (!thread || thread.branch !== checkedOutBranch) return;
- @@ -1342,0 +1400,21 @@1400+ (details.defaultBranch === null &&1401+ (headContext.headBranch === "main" || headContext.headBranch === "master"));1402+ if (1403+ headContext.headBranch === details.branch ||1404+ !upstreamHeadIsDefault ||1405+ headContext.isCrossRepository1406+ ) {1407+ return { headContext, lookup: true };1408+ }1409+ const remoteName = yield* findRemoteTrackingRemote(cwd, details.branch, headContext.remoteName);1410+ if (remoteName === null) {1411+ return { headContext, lookup: false };1412+ }1413+ const ownNameContext = yield* resolveBranchHeadContext(cwd, {1414+ branch: details.branch,1415+ upstreamRef: null,1416+ remoteName,1417+ });1418+ return { headContext: ownNameContext, lookup: true };1419+ });1420+
t3dotgg(GitHub profile, opens in a new tab) changed the title
- apps/server/src/orchestration/Layers/CheckpointReactor.ts line 556Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -553,3 +553,4 @@553553 cwd: sessionRuntime.value.cwd,554554 local,555555 });556+ yield* refreshPullRequestAfterTurn({
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed