Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions apps/staged/src/lib/features/branches/BranchCardPrButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
// PR status polling state
let prStatusPollTimer: ReturnType<typeof setInterval> | null = null;
let prStatusRefreshing = $state(false);
let lastImmediateRefreshPrNumber = $state<number | null>(null);

// PR status fields (local state, updated via events)
let prStatusState = $state<string | null>(null);
Expand Down Expand Up @@ -281,6 +282,26 @@
};
});

// Kick off an immediate refresh whenever this branch gains a PR number.
// This covers branches hydrated after mount, such as project/repo creation from an existing PR.
$effect(() => {
const prNumber = branch.prNumber;

if (!prNumber) {
lastImmediateRefreshPrNumber = null;
return;
}

if (!isWindowFocused || prStatusRefreshing || lastImmediateRefreshPrNumber === prNumber) {
return;
}

lastImmediateRefreshPrNumber = prNumber;
commands
.refreshPrStatus(branch.id)
.catch((e) => console.error('Failed to fetch initial PR status:', e));
});

onMount(() => {
window.addEventListener('keydown', handleOptionDown);
window.addEventListener('keyup', handleOptionUp);
Expand All @@ -298,12 +319,6 @@
};
window.addEventListener('focus', handleFocus);
window.addEventListener('blur', handleBlur);

if (branch.prNumber) {
commands
.refreshPrStatus(branch.id)
.catch((e) => console.error('Failed to fetch initial PR status:', e));
}
});

onDestroy(() => {
Expand Down
10 changes: 9 additions & 1 deletion apps/staged/src/lib/listeners/sessionStatusListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ async function handlePrCompletion(sessionId: string, branchId: string, status: s
try {
await commands.updateBranchPr(branchId, prNumber);
} catch (storageError) {
console.error('Failed to persist PR number to storage:', storageError);
console.error('Failed to persist PR state after creation:', storageError);
prStateStore.setPrError(branchId, 'Failed to save PR details after creation.');
return;
}

try {
await commands.refreshPrStatus(branchId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not block PR completion on status refresh

handlePrCompletion now waits for commands.refreshPrStatus(branchId) before marking the PR as created, but that backend call can take up to 60 seconds (the gh wrapper enforces a 60s timeout). Because handleSessionEnd awaits this function before running prStateStore.clearSessionTracking, sessionRegistry.unregister, and drainQueuedSessions, a slow GitHub response can leave the branch stuck in "creating" and delay queued work even though the PR was already created. This refresh should be non-blocking (or moved after cleanup) so completion state is not held behind network latency.

Useful? React with 👍 / 👎.

} catch (refreshError) {
console.error('Failed to refresh PR state after creation:', refreshError);
}
}
prStateStore.setPrCreated(branchId, foundUrl);
Expand Down