Skip to content

fix(server): repeated imports reach older worktree history - #36608

Merged
juliusmarminge merged 6 commits into
pingdotgg:mainfrom
StiensWout:t3/native-import-worktree-budget
Nov 14, 2026
Merged

juliusmarminge merged 6 commits into
pingdotgg:mainfrom
StiensWout:t3/native-import-worktree-budget

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Repeated native-history imports can keep rereading completed linked-worktree sessions, leaving older history missing. The importer filtered completion records by project-root cwd, while worktree imports correctly save their worktree cwd for resume.

Use the imported thread's project ownership for completion records. Preserve worktree cwd and Pi resume identity. Missing owners may be rescanned; other ownership-read failures now surface as AgentSessionScanError instead of silently consuming the budget again. No schema, client, or recovery-path change.

Proof

Found by the native-history bughunt; independently confirmed by Claude Opus 5.5 at 947c056894886a4301e3977096cdfb4853d5fdad. Reproduced again on upstream d2bdd58eef0410f08de0cfd1e48de51c6893acd0 using the supplied repro.

  • pnpm exec vp test run apps/server/src/project/AgentSessionImporter.test.ts: the same real-scanner/SQLite worktree-budget regression fails without the source fix and passes with it. Its fixture has one more eligible transcript than the batch limit; repeated import now reaches the oldest thread and retains its worktree path.
  • The ownership-error test fails before the error-handling fix and passes after it. It exercises missing owners, malformed projections and SQL read failures. The missing-owner fixture was corrected after review to record its marker through the repository API; the focused suite passes.
  • pnpm exec vp run check:changed: passed on the final rebased head, including format, lint, knip, GraphQL, affected typechecks and focused tests.
  • Rebased onto upstream b4c1bd106d994c4c51cfa8b3a1999d3b11566c83; range-diff preserves the reviewed production patches.

Proof limits: local service-level proof only. No browser or scenarios:prove run; Welcome page import calls this server path. Real-scanner coverage is Codex; Claude/Pi share the ownership filter and existing Pi resume tests remain unchanged. Cross-project exclusion is verified by inspection. No performance claim or measurement is made.

Small fast-lane fix: focused importer logic, no new storage, module interface or UI flow. Design lens replaces the hidden cwd/root coupling with thread project ownership. No auth, transport, connection-mode or client contract changed. The separate missing-identity recovery fix remains independent.

Council review

Reviewer Round 1 Round 2
GPT 6.1 Sol 8/10 9/10
Claude Opus 5.5 8.5/10 9/10

The shared ownership-read failure finding was fixed. No blockers or shoulds remain. Local cubic reported a P2 sequential-read cost nit and P3 swallowed-error nit; the latter is fixed. Retained nits/follow-ups: bulk project ownership reads, moved-project completion accounting, the local schema guard, and overlapping read-error assertions. These do not affect the ordinary worktree import regression; widening storage/query APIs is outside this fix. Opus reviews were source-only because isolated checkouts lacked dependencies; Sol reran focused tests.

Created with GPT 6.1 Sol (lead, fixer, review) in Codex and Claude Opus 5.5 (builder, simplifier, verifier, review) in Claude Code, through T3 Code.

Closes #36607

StiensWout and others added 4 commits November 14, 2026 10:01
…he scan budget

Imported worktree sessions record the worktree as their runtime cwd, so the
importer never counted them as completed for the main checkout and every retry
spent the 100-transcript budget re-reading them. Completed transcripts now
belong to the project that owns the imported thread.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.1 Sol <codex@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.1 Sol <codex@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.1 Sol <codex@openai.com>

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 14, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 14, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at b0c2009

Macroscope's review found this PR approvable — Repeated imports now recognize transcripts belonging to the project even when their recorded directory is a linked worktree. The change is limited to import bookkeeping and retains existing import limits and project-ownership safeguards.

Notes:

  • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 14, 2026
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The importer now selects completed transcript sources by the owning thread’s project instead of matching the runtime payload’s working directory. Tests cover missing thread records, projection read errors, and repeated imports from a linked worktree.

Changes: Agent transcript imports

Layer / File(s) Summary
Select transcripts by thread ownership
apps/server/src/project/AgentSessionImporter.ts
The importer selects completed transcript sources when the owning thread belongs to the requested project. It ignores missing thread records and maps other lookup failures to AgentSessionScanError.
Validate ownership and repeated imports
apps/server/src/project/AgentSessionImporter.test.ts
Tests cover missing thread records, projection read failures, and importing 101 linked-worktree transcripts in two successive runs. The tests verify that the first run imports 100 sessions and skips one, while the second imports the remaining session without skips.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: juliusmarminge, only21mil

Merge Risk: Minimal · up to b0c20

Repeated native-history imports should now move on to older sessions instead of re-spending the batch on already-imported worktree transcripts. Tests cover the main cases, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the server fix and the affected behavior: repeated imports now reach older linked-worktree history. It matches the main change in AgentSessionImporter.ts, which switches completion fil…
Description check Passed The description follows the template's main sections. It gives the problem, the change, the scope (a bug fix with linked issue #36607), and detailed verification. It also explains the local, service-l…
Linked Issues check Passed [#36607] Requires repeated imports to advance past completed linked-worktree transcripts. At head, importRecentAgentThreads builds completedSources from each runtime row's decoded `importedTranscr…
Out of Scope Changes check Passed The source change is limited to apps/server/src/project/AgentSessionImporter.ts. It adds a ProjectionStore import and an isProjectionStoreThreadNotFoundError guard, replaces the cwd-based comple…
Full details: Title check

Explanation

The title names the server fix and the affected behavior: repeated imports now reach older linked-worktree history. It matches the main change in AgentSessionImporter.ts, which switches completion filtering from project-root cwd to thread project ownership. The title follows conventional commit form and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template's main sections. It gives the problem, the change, the scope (a bug fix with linked issue #36607), and detailed verification. It also explains the local, service-level proof limits and the retained follow-ups. The Problem section is implicit in the first paragraph rather than under a labeled heading, and the Scope section does not state the bug is obvious. These gaps are minor. The description is mostly complete.

Full details: Linked Issues check

Explanation

[#36607] Requires repeated imports to advance past completed linked-worktree transcripts. At head, importRecentAgentThreads builds completedSources from each runtime row's decoded importedTranscripts. It keeps a row only when orchestrator.getThreadRecords returns a thread whose projectId equals input.projectId. The old filter compared the runtime-payload cwd to the project root, so worktree completion records (saved with the worktree cwd) were missed and consumed the batch again. The new ownership filter counts those records as complete, so the scanner can reach older sessions. Missing thread records (ProjectionStoreThreadNotFoundError) map to no completed sources. Other lookup failures map to AgentSessionScanError. The incremental diff from the previous reviewed head shows no source change in AgentSessionImporter.ts, so the earlier source conclusion still holds. The PR reports a real-scanner/SQLite regression test with 101 Codex worktree transcripts (first import 100, second import 1). I did not read the test file hunks in this pass, so the test result relies on the PR report. Non-coding items (Welcome page run, browser scenario) do not apply.

Full details: Out of Scope Changes check

Explanation

The source change is limited to apps/server/src/project/AgentSessionImporter.ts. It adds a ProjectionStore import and an isProjectionStoreThreadNotFoundError guard, replaces the cwd-based completion filter with a thread project-ownership filter, and converts other ownership-read failures to AgentSessionScanError. Each change serves the issue requirement. The PR states that no schema, client, recovery-path, or public module interface changed. The test file changes add the scanner and workspace helpers and the regression and ownership-error tests for this behavior. I did not inspect the test file diff in this pass. No unrelated source change was found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3c8b162 and b0c2009.

Files selected for processing: 1

  • apps/server/src/project/AgentSessionImporter.test.ts

Limit details: You’ve used all 10 included reviews currently available.

@macroscopeapp
macroscopeapp Bot dismissed their stale review November 14, 2026 09:10

Dismissing prior approval to re-evaluate b0c2009

@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Seed 101 readable Codex conversations in a linked worktree. Import the repository through Settings → About → Welcome → Open → Review all, reopen Welcome, and import again. Open an imported thread on both commits, search for 101, then open the oldest conversation on head.

Environment: Linux Chromium web client, 1440×1000, dark theme, fresh database per commit. Independently rebuilt apps; identical final scenario. Stable stills without warning overlays or result toasts.

Evidence Before: 28f1786829 After: b0c2009f33
First import: opened readable history Before: imported conversation 001 After: imported conversation 001
Second import: settled count Before: 100 threads After: 101 threads
Search for 101 Before: no threads found After: oldest conversation found
Open oldest conversation Missing After: oldest prompt and assistant reply visible, linked-history branch retained
Recording Before interaction After interaction

Scenario and seed driver · Startup patch · Reproduction instructions · Runner proof report · Runner transcript

The final comparison exited 0: failsOnBase=true, passesOnHead=true. The oldest thread's text is visible in both its still and the after recording's final frame. First-import captures have different MD5 hashes.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 14, 2026
@juliusmarminge
juliusmarminge merged commit 13f89ae into pingdotgg:main Nov 14, 2026
53 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Repeated history imports stall behind completed worktree sessions

2 participants