Skip to content

feat(code): import claude code sessions#2873

Draft
adboio wants to merge 1 commit into
posthog-code/import-cc-2-backendfrom
06-11-feat_code_import_claude_code_sessions
Draft

feat(code): import claude code sessions#2873
adboio wants to merge 1 commit into
posthog-code/import-cc-2-backendfrom
06-11-feat_code_import_claude_code_sessions

Conversation

@adboio

@adboio adboio commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🚨 feel free to pull this for testing downstack, but this is not the final UX! PR to be updated soon

Problem

Changes

How did you test this?

Automatic notifications

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

adboio commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit c316286.

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (2)

  1. packages/workspace-server/src/services/agent/agent.ts, line 2534-2570 (link)

    P2 Silent history loss when imported session fails to load

    When loadSession throws, agentSessionId stays undefined and the code falls through to start a fresh session. The import record in the DB is never rolled back, so the source session will continue to show as "imported" in the picker — but the task opened will have no history. The user has no indication that the replay failed; they'll see a blank task conversation and likely assume the import itself failed (it didn't) or that their history is missing permanently.

    Consider surfacing this failure as a task-level error event or a toast notification so users understand the session loaded without history, rather than discovering it silently.

  2. packages/core/src/task-detail/taskCreationSaga.ts, line 859-868 (link)

    P2 Fire-and-forget branch link can leave DB branch unset while workspace.linkedBranch appears linked

    linkImportedSessionBranch fires the linkTaskBranch mutation without awaiting, while the very next line sets workspace.linkedBranch synchronously. If the IPC call fails (and the caught warning is discarded), the persistent task record will have no branch linked — but the in-flight session object sees the branch as linked, so the branch-mismatch prompt won't surface during the current session lifetime. On the next reconnect, with no linked branch in the DB, the prompt will be absent again, silently never firing.

    Since branch linking is described as "best-effort", this may be acceptable, but it is worth documenting why the in-memory assignment still happens when the async call can silently fail.

Reviews (1): Last reviewed commit: "feat(code): import claude code sessions" | Re-trigger Greptile

Comment on lines +56 to +62
export const recordCliImportInput = z.object({
sourceSessionId: z.string(),
importedSessionId: z.string(),
repoPath: z.string(),
taskId: z.string(),
fingerprint: cliSessionFingerprintSchema,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 recordCliImportInput accepts arbitrary strings for sourceSessionId and importedSessionId

Every other endpoint that uses these values as path segments (importCliSessionInput, deleteImportedCliSessionInput, deleteImportRecordInput) enforces z.string().uuid() with the comment "uuid keeps the value safe to use as a path segment." recordCliImportInput does not, even though the importedSessionId is recorded as a DB key and later passed to deleteImportedCliSessionInput / deleteImportRecordInput which do enforce UUID. The inconsistency means a caller that crafts a non-UUID importedSessionId in the record step could produce a row that is un-deletable via the delete endpoints (they'd reject the non-UUID value). In practice both values always come from the import endpoint's output, but adding .uuid() here makes the contract explicit and defends against future callers.

Suggested change
export const recordCliImportInput = z.object({
sourceSessionId: z.string(),
importedSessionId: z.string(),
repoPath: z.string(),
taskId: z.string(),
fingerprint: cliSessionFingerprintSchema,
});
export const recordCliImportInput = z.object({
/** uuid keeps the value safe to use as a path segment. */
sourceSessionId: z.string().uuid(),
/** uuid keeps the value safe to use as a path segment. */
importedSessionId: z.string().uuid(),
repoPath: z.string(),
taskId: z.string(),
fingerprint: cliSessionFingerprintSchema,
});

@adboio adboio requested a review from a team June 23, 2026 19:07
@adboio adboio force-pushed the 06-11-feat_code_import_claude_code_sessions branch 2 times, most recently from 0f599e5 to 2a00a71 Compare June 23, 2026 19:45
@adboio adboio changed the base branch from main to graphite-base/2873 June 23, 2026 20:02
adboio added a commit that referenced this pull request Jun 23, 2026
Client side of importing a Claude Code CLI session: the task-creation
saga step that snapshots and records the import (with rollback
compensation) and links the session's branch, session replay-history
loading on connect, and the new-task picker UI for browsing and
importing recent CLI sessions for the selected repo.

Part 3/3 of splitting #2873 (import Claude Code sessions).

Generated-By: PostHog Code
Task-Id: 6c93b6e8-27b6-45c8-8135-73a09076ea93
@adboio adboio force-pushed the 06-11-feat_code_import_claude_code_sessions branch from 2a00a71 to 1a2fbf6 Compare June 23, 2026 20:02
@adboio adboio changed the base branch from graphite-base/2873 to posthog-code/import-cc-2-backend June 23, 2026 20:02
adboio added a commit that referenced this pull request Jun 24, 2026
Client side of importing a Claude Code CLI session: the task-creation
saga step that snapshots and records the import (with rollback
compensation) and links the session's branch, session replay-history
loading on connect, and the new-task picker UI for browsing and
importing recent CLI sessions for the selected repo.

Part 3/3 of splitting #2873 (import Claude Code sessions).

Generated-By: PostHog Code
Task-Id: 6c93b6e8-27b6-45c8-8135-73a09076ea93
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from 8cbec5f to b944070 Compare June 24, 2026 15:20
@adboio adboio force-pushed the 06-11-feat_code_import_claude_code_sessions branch from 1a2fbf6 to d8f4c50 Compare June 24, 2026 15:20
adboio added a commit that referenced this pull request Jun 24, 2026
Client side of importing a Claude Code CLI session: the task-creation
saga step that snapshots and records the import (with rollback
compensation) and links the session's branch, session replay-history
loading on connect, and the new-task picker UI for browsing and
importing recent CLI sessions for the selected repo.

Part 3/3 of splitting #2873 (import Claude Code sessions).

Generated-By: PostHog Code
Task-Id: 6c93b6e8-27b6-45c8-8135-73a09076ea93
@adboio adboio force-pushed the 06-11-feat_code_import_claude_code_sessions branch from d8f4c50 to d46b00c Compare June 24, 2026 15:40
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from b944070 to e9a736c Compare June 24, 2026 15:40
Client side of importing a Claude Code CLI session: the task-creation
saga step that snapshots and records the import (with rollback
compensation) and links the session's branch, session replay-history
loading on connect, and the new-task picker UI for browsing and
importing recent CLI sessions for the selected repo.

Part 3/3 of splitting #2873 (import Claude Code sessions).

Generated-By: PostHog Code
Task-Id: 6c93b6e8-27b6-45c8-8135-73a09076ea93
@adboio adboio force-pushed the posthog-code/import-cc-2-backend branch from e9a736c to 0253564 Compare June 24, 2026 16:16
@adboio adboio force-pushed the 06-11-feat_code_import_claude_code_sessions branch from d46b00c to c316286 Compare June 24, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant