Skip to content

feat(task-input): cache cloud default branch for instant "start on trunk"#3496

Merged
trunk-io[bot] merged 5 commits into
mainfrom
posthog-code/cache-cloud-trunk-branch
Jul 16, 2026
Merged

feat(task-input): cache cloud default branch for instant "start on trunk"#3496
trunk-io[bot] merged 5 commits into
mainfrom
posthog-code/cache-cloud-trunk-branch

Conversation

@pauldambra

Copy link
Copy Markdown
Member

Problem

Launching the app and opening the branch picker for a cloud repo means waiting on a slow live branch list (thousands of branches) before anything is usable — even for the common case of just wanting to start on trunk. Raised in a Slack thread.

Changes

Persist the last-known default ("trunk") branch per cloud repo (keyed by owner/repo) in the settings store, alongside the existing cached repository map. The branch picker already auto-selects the default branch when nothing is selected, so on a cold start we feed it the cached value and trunk gets pre-selected with zero wait. The fresh value from the live query takes over the moment it arrives and is written back to the cache.

  • New persisted cachedCloudDefaultBranchMap + setCachedCloudDefaultBranch in the settings store (no-ops when the value is unchanged).
  • TaskInput serves the cached default until the live branch list resolves, and persists fresh defaults for the next cold start.

How did you test this?

  • pnpm --filter @posthog/ui typecheck (clean)
  • pnpm --filter @posthog/ui test settingsStore BranchSelector (40 passing, including new tests for caching, persistence, no-op-on-unchanged, and rehydration)
  • biome check on the changed files

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog from a Slack thread

…unk"

Persist the last-known default ("trunk") branch per cloud repo so a cold
start can pre-select trunk in the branch picker immediately, instead of
waiting on the slow live branch list to resolve.

The picker already auto-selects the default branch when nothing is
selected; feeding it a cached value makes that fire with zero wait. The
fresh value from the live query takes over the moment it arrives and is
written back to the cache.

Generated-By: PostHog Code
Task-Id: 562fb90f-d823-425d-b53c-5f482b55a8b2
@trunk-io

trunk-io Bot commented Jul 16, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

React Doctor found 4 issues in 2 files · 4 warnings.

4 warnings

src/features/git-interaction/components/BranchSelector.tsx

src/features/task-detail/components/TaskInput.tsx

Reviewed by React Doctor for commit dc1f75f.

Seed the known default ("trunk") branch as a real, pickable list item in
the cloud branch picker while the remote branch list is still loading, with
a "Loading branches…" row rendered directly below it. This makes the open
dropdown usable for the common "start on trunk" case with zero wait, and
signals that the rest of the branches are still on the way.

Only seeds when there's no active search — once the user types, the list is
purely what the remote returns.

Generated-By: PostHog Code
Task-Id: 562fb90f-d823-425d-b53c-5f482b55a8b2
@pauldambra
pauldambra marked this pull request as ready for review July 16, 2026 10:37

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 593d7444c6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/ui/src/features/task-detail/components/TaskInput.tsx
Comment thread packages/ui/src/features/task-detail/components/TaskInput.tsx
@veria-ai

veria-ai Bot commented Jul 16, 2026

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Multi-perspective review (paul + xp + security-audit) surfaced low/nit items;
this addresses the actionable ones:

- Extract the duplicated "Loading branches…" literal into a shared
  LOADING_BRANCHES_LABEL const so the two render sites can't drift.
- Clarify the TaskInput comment: the cached default is best-effort — a
  default branch renamed since it was cached stays seeded until the user
  picks another (the auto-select only fires while nothing is selected).
- Lock the empty-state gating with a test asserting "No branches found."
  keeps the `hidden` class when the seeded trunk row makes the list
  non-empty, so it never flashes above the seeded row.

security-audit: 0 findings (API-derived branch name → auto-escaped React
text + the pre-existing selection path; no new sink).

Generated-By: PostHog Code
Task-Id: 562fb90f-d823-425d-b53c-5f482b55a8b2
Generated-By: PostHog Code
Task-Id: 562fb90f-d823-425d-b53c-5f482b55a8b2
@pauldambra pauldambra added the Stamphog This will request an autostamp by stamphog on small changes label Jul 16, 2026 — with PostHog
github-actions[bot]
github-actions Bot previously approved these changes Jul 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No showstoppers. The stale-cache/wrong-branch concern from both bot comments is real but acknowledged in the diff's own code comments as an accepted trade-off, is visible to the user (who can correct it before submitting), and only bites in a rare renamed-default-branch scenario. All other aspects are clean: correct layer placement, no API contract changes, good test coverage.

Four reviewers (qa-swarm's paul + xp, plus the org Codex and veria-ai bots)
independently flagged that a stale cached default branch never self-corrects:
the picker auto-selects the cached "trunk", and the existing effect's
`!selectedBranch` guard then blocks re-selection once the live default arrives,
so a task could start on a branch that is no longer the default.

Track the branch we auto-selected in a ref and re-select when the default
changes out from under our own auto-pick — while never clobbering a branch the
user chose deliberately. Adds tests for both the self-heal and the
user-choice-preserved paths, and updates the TaskInput comment to match.

Generated-By: PostHog Code
Task-Id: 562fb90f-d823-425d-b53c-5f482b55a8b2
@github-actions
github-actions Bot dismissed their stale review July 16, 2026 10:54

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The inline bot comments about stale-cache mis-selection are addressed in the current diff: the autoSelectedBranchRef mechanism lets BranchSelector distinguish its own auto-picks from user picks, and the updated effect re-selects the live default when it arrives and differs from a stale auto-selection. The new test "re-selects the default when a stale cached default is replaced by the live one" verifies this path. The worst case is a brief wrong pre-selection that self-corrects on live data arrival — visible to the user, not silent corruption. No showstoppers.

Copy link
Copy Markdown
Member Author

/trunk merge

@trunk-io
trunk-io Bot merged commit 9dad295 into main Jul 16, 2026
32 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/cache-cloud-trunk-branch branch July 16, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant