t3code icon indicating copy to clipboard operation
t3code copied to clipboard

fix: wait for PR status before inactivity auto-settle

Open caezium opened this issue 4 months ago • 4 comments

What Changed

  • Preserve whether remote PR status is resolved across the VCS status stream, including initial snapshots, provider lookup fallbacks, typed failures, defects, and recovery.
  • Treat unresolved PR status as an inactivity auto-settle blocker in the shared settlement calculation used by Sidebar v2, ChatView, and the mobile thread list.
  • Key cached client PR state by branch, and use bounded, rotating web and mobile lookup pools that revisit hidden/off-screen branches with isolated short-lived subscriptions, without changing cache behavior elsewhere.
  • Correlate remote results and failures with the local ref generation, discard late results from an older branch, avoid returning unavailable remote data to direct callers, and keep retrying unresolved lookups even when automatic Git fetching is disabled.

Why

#5151 correctly keeps threads with open PRs active, but the client previously flattened “remote PR lookup has not resolved” into pr: null. During initial loading, after a stream error, or after a branch change, a stale thread could therefore pass the inactivity window before the client knew whether it had an open PR.

This follow-up makes “unknown” an explicit conservative state. Confirmed no-PR branches still use normal inactivity settlement, open PRs remain active, and merged/closed PR behavior is unchanged.

This is independent of #5141: that PR controls whether confirmed merged/closed PRs settle, while this PR prevents unresolved status from being mistaken for a confirmed no-PR result.

Validation

  • pnpm exec vp test run apps/server/src/vcs/VcsStatusBroadcaster.test.ts apps/server/src/git/GitManager.test.ts packages/shared/src/git.test.ts packages/client-runtime/src/state/threadSettled.test.ts packages/client-runtime/src/state/vcs.test.ts apps/mobile/src/features/threads/threadListV2.test.ts --reporter=dot — 337 passed
  • Typechecks passed for contracts, shared, client runtime, server, web, and mobile
  • Targeted lint, formatting, mobile native static analysis, and git diff --check passed for all changed files
  • All VCS scenarios use temporary repositories and mocked provider responses; no real repositories, PRs, or user data are used

Checklist

  • [x] This PR is focused on one issue
  • [x] I explained what changed and why
  • [x] Screenshots are not applicable because this changes classification timing, not rendered UI
  • [x] A video is not applicable because there are no animation or interaction changes

Built with GPT-5.6-Sol via the Codex harness in T3 Code.


[!NOTE] Medium Risk Touches thread settlement classification, VCS status caching/stream semantics, and background PR polling across server, web, and mobile; incorrect remoteLoaded handling could keep threads active too long or settle them early.

Overview Threads with a branch were sometimes auto-settled on inactivity while remote PR status was still loading or failed, because unresolved lookups were treated like no PR. This PR introduces an explicit unknown change-request state and blocks inactivity auto-settle until PR status is confirmed.

Server & stream: VCS status streams now carry remoteLoaded (and prLookupFailed on remote results). VcsStatusBroadcaster tracks ref generation, marks remote as unloaded on branch changes, refresh failures, and provider lookup fallbacks, and ignores stale remote updates after a ref change.

Clients: Shared resolveChangeRequestSettlementState and branch-keyed state (threadChangeRequestStateKey) feed effectiveSettled on web (Sidebar v2, ChatView) and mobile thread list v2. Off-screen branches get bounded rotating lookup pools (16 targets / 30s) with threadVcsEnvironment (statusIdleTtlMs: 0) so subscriptions do not pile up.

Confirmed no-PR, open, merged, and closed behavior is unchanged once status is resolved.

Reviewed by Cursor Bugbot for commit 96dc224242fb7deb7e4f0cb95d753a81a487e7e7. Bugbot is set up for automated code reviews on this repo. Configure here.

[!NOTE]

Keep threads with unresolved PR status active instead of auto-settling

  • Adds a remoteLoaded flag to VCS status stream events and cached state so consumers can distinguish "remote not yet fetched" from "no PR"; threads with a branch default to unknown until their PR state is confirmed.
  • Extends effectiveSettled to treat unknown change request state as active (not settled), preventing premature auto-settlement while PR status loads.
  • Introduces resolveChangeRequestSettlementState to derive open|closed|merged|none|unknown by correlating thread branch, git status, and remoteLoaded.
  • Adds a background lookup pool (ThreadListV2ChangeRequestLookupPool / SidebarV2ChangeRequestStateReporter) that rotates through off-screen threads in bounded windows (limit 16, 30s interval) to refresh PR state independently of row virtualization.
  • Introduces threadVcsEnvironment with statusIdleTtlMs: 0 so status subscriptions are disposed immediately when idle, avoiding lingering background polling.
  • Behavioral Change: threads with a non-null branch now remain in the active block until their PR state resolves to a known value rather than being classified as settled on inactivity.

Macroscope summarized 96dc224.

Summary by CodeRabbit

  • Bug Fixes

    • Threads now remain active while pull request or merge request status is loading, unavailable, or uncertain.
    • Improved handling of failed, stale, and interrupted source-control status updates.
    • Preserved the last known review status when a lookup temporarily fails.
    • Correctly settle threads when changes are confirmed merged or closed, while avoiding premature settlement.
  • Documentation

    • Updated source-control guidance to explain thread behavior during status loading.

caezium avatar Aug 01 '26 12:08 caezium

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds branch-aware change-request settlement states, propagates VCS loading and lookup failures, centralizes mobile lookups, and updates web and mobile thread settlement behavior. Tests cover failures, stale refreshes, branch changes, lookup windows, and unresolved states.

Changes

Change-request settlement

Layer / File(s) Summary
VCS status contracts and propagation
packages/contracts/src/git.ts, packages/shared/src/git.ts, packages/shared/src/git.test.ts, packages/client-runtime/src/state/vcs.ts, packages/client-runtime/src/state/vcs.test.ts, apps/mobile/src/state/vcs.ts
VCS status events now carry remoteLoaded, and remote results can report prLookupFailed. Stream accumulation tracks remote availability across snapshots and ref changes.
Server refresh and stale-result handling
apps/server/src/git/GitManager.ts, apps/server/src/git/GitManager.test.ts, apps/server/src/vcs/VcsStatusBroadcaster.ts, apps/server/src/vcs/VcsStatusBroadcaster.test.ts
Server refreshes retain fallback data, mark failed remote results unresolved, reject stale reference generations, retry unavailable remote data, and expose the resulting stream state.
Branch-aware settlement resolution
packages/client-runtime/src/state/threadSettled.ts, packages/client-runtime/src/state/threadSettled.test.ts
Shared helpers add keyed settlement state, branch-aware cache keys, and none/unknown handling. Unknown branched threads remain unsettled.
Mobile lookup pool integration
apps/mobile/src/features/threads/threadListV2.ts, apps/mobile/src/features/threads/thread-list-v2-items.tsx, apps/mobile/src/state/use-thread-pr.ts, apps/mobile/src/features/home/HomeScreen.tsx, apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx, apps/mobile/src/features/threads/threadListV2.test.ts
Mobile lists group eligible targets by environment and working directory, rotate lookup windows, and centrally report settlement state to screen and sidebar state.
Web settlement integration
apps/web/src/components/ChatView.tsx, apps/web/src/components/SidebarV2.tsx, docs/user/source-control.md
Web settlement uses VCS-aware change-request resolution, branch-aware cache keys, centralized state updates, and loading-state behavior documented for Sidebar v2.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GitManager
  participant VcsStatusBroadcaster
  participant ClientVcsState
  participant ThreadSettlement
  GitManager->>VcsStatusBroadcaster: return PR status and lookup failure state
  VcsStatusBroadcaster->>ClientVcsState: publish remoteLoaded status
  ClientVcsState->>ThreadSettlement: resolve branch-aware change-request state
  ThreadSettlement-->>ClientVcsState: return none, unknown, open, closed, or merged

Possibly related PRs

Suggested reviewers: juliusmarminge, t3dotgg

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: preventing inactivity auto-settlement before PR status resolves.
Description check ✅ Passed The description covers the required change, rationale, UI applicability, validation, and checklist items.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • [ ] Create stacked PR
  • [ ] Commit on current branch
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Aug 01 '26 12:08 coderabbitai[bot]

@coderabbitai review

caezium avatar Aug 01 '26 16:08 caezium

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Aug 01 '26 16:08 coderabbitai[bot]

Approvability

Verdict: Needs human review

This PR introduces significant runtime behavior changes to thread auto-settlement, keeping branch-backed threads active until their PR status is definitively resolved. It adds new state management across web, mobile, and server components, introduces a pooled PR lookup system, and modifies server-side VCS status caching. The cross-cutting scope and behavioral impact warrant human review.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot] avatar Aug 01 '26 16:08 macroscopeapp[bot]

[!NOTE] 🤖 GPT-5.6 Sol responding on behalf of Theo

We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

Avoiding settlement while PR state is unknown is reasonable, but this branch adds 1,405 lines across 22 files, including client-side lookup pools and new VCS publication states. #5290 is the smaller active path for consistent cross-client settlement policy.

If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

t3dotgg avatar Aug 28 '26 12:08 t3dotgg