Skip to content

feat(chats): carry the Pi journal into forks - #344

Merged
sambitcreate merged 4 commits into
mainfrom
feat/chat-fork-journal
Oct 5, 2026
Merged

sambitcreate merged 4 commits into
mainfrom
feat/chat-fork-journal

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

Summary

Stacked on #343 (PR 2 of docs/plans/chat-fork-plan.md).

  • A fork reuses the source's model-side journal up to the cut, so tool results and compaction checkpoints from before the forked message survive.
  • The reused part is the source's active branch through the last copied message's marker. It is extended to the commits that close every Aiden transaction open there, because a reply's marker sits inside its generation envelope.
  • PiSessionPort.importBranch writes that one root-to-tip path into an empty journal. Pi's own fork doesn't fit: the branch scope needs an AgentLane, and the tree scope copies data from after the cut.
  • Copied messages get fresh markers under their new ids, so the fork's next sync appends only new prompts.
  • Fallback: with no source journal, the rollout gate closed, or no provable boundary, nothing is created and the fork rebuilds context from visible history, as before.
  • A journal error in the IPC handler is logged as a chat-degraded diagnostic and never fails the fork. A failed chat install removes the target journal unless the error requires reconciliation.

Tests

  • New main/services/pi-journal-fork.test.ts, registered in test:compaction and the CI registry. It covers:
    • context through the cut, including after a reopen and recovery;
    • no duplicate sync;
    • the cases where no boundary is provable;
    • the importBranch guards.
  • chat-session-copy.test.ts now checks the source-to-copy id pairing that beforeInstall receives.
  • Run locally, all passing: type-check, eslint, test:compaction (405), test:ci-policy, and the chat copy suites.

🤖 Generated with Claude Code

sambitcreate and others added 2 commits October 5, 2026 12:05
A fork now reuses the source's model-side journal up to the cut, so tool
results and compaction checkpoints before the forked message survive.
The prefix runs through the commits that close the last copied reply's
transactions and is imported into an empty journal as one path. Copied
messages get fresh markers under their new ids so the next sync does
not duplicate them.

Without a provable boundary nothing is created and the fork rebuilds
context from visible history as before. A journal error never fails the
fork, and a failed chat install removes the target journal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

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.

Important

Forking an earlier inherited reply in an already-forked chat silently discards the richer journal context. The copied markers need to retain their original cut boundaries.

Reviewed changes: Reviewed the journal carryover implementation, desktop copy integration, persistence adapter, and focused behavioral coverage.

  • Journal boundary selection: Reuses the active source prefix through a copied message and its closing transaction commits, with visible-history fallback when no boundary is provable.
  • Import and installation: Imports a branch into a private target journal, pairs copied message identities, and cleans up dependent journals on failed installation.
  • Behavioral coverage: Adds direct-fork, reopen, synchronization, fallback, and import-guard tests, registered in the compaction suite and CI registry.

Validation passed: npm run test:compaction (405 tests), the focused copy/journal/adapter tests (13 tests), npm run test:ci-policy (55 tests), and npm run type-check. A separate repeated-fork reproduction confirmed the inline finding.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6.1-sol | 𝕏

@very-hermes-bot very-hermes-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.

Comment on lines +1208 to +1216
await session.importBranch(prefix);
await appendPiTransaction(session, async () => {
for (const message of input.messages) {
if (!synchronized.has(message.sourceId)) continue;
await session.appendCustomEntry(AIDEN_CHAT_MESSAGE_MARKER, {
chatMessageId: message.id,
} satisfies ChatMessageMarker);
}
});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1 · logic] Trailing marker batch breaks journal preservation for subsequent forks from earlier turns
Confidence: 0.95

In forkChat, appending fresh message markers in a trailing transaction at the tip causes piJournalForkPrefix to return undefined on any subsequent fork from an intermediate message because non-commit markers separate the target marker from the transaction boundary.

Repair: Remap AIDEN_CHAT_MESSAGE_MARKER entries in place within prefix using input.messages before calling session.importBranch, and eliminate the trailing appendPiTransaction block.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 432c374: copied markers are now renamed in place inside the imported prefix, so each inherited reply keeps its original transaction boundary; the trailing marker transaction is gone. pi-journal-fork.test.ts adds a fork-of-a-fork at an earlier inherited reply after reopening the store, checks it against the same cut taken in the original chat, and checks the next sync appends only the new prompt.

@very-hermes-bot

very-hermes-bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 432c3744a50c475b555e6bd76d8e5dcc9ff96550
Generated: 2026-10-05T17:33:58+00:00
Reviews: 1

Summary

Carries over the model-side Pi journal (including tool results and compaction checkpoints) up to the selected fork cut point when copying or forking a workspace chat. During copyVisibleHistory, the beforeInstall callback invokes PiCompactionSessionStore.forkChat, which calculates the exact active root-to-tip branch prefix up to the closing envelope of the cut message via piJournalForkPrefix, renames copied message markers to match the new message IDs, and writes the branch into a fresh journal via PiSessionPort.importBranch. If no provable boundary exists, rollout is inactive, or journal copying fails, the system logs a chat-degraded diagnostic and gracefully falls back to visible-history context reconstruction without failing the user's fork. Maintainers should double-check that future changes to generation turn envelopes preserve the invariant that only transaction commits separate AIDEN_CHAT_MESSAGE_MARKER from its enclosing turn boundary.

Confidence Score: 5/5

Fully traced and verified across main/handlers/chats.ts, PiCompactionSessionStore, PiSessionPort, transaction boundaries, fallback error handling, and the test suite.

📁 Important Files Changed
  • main/services/pi-compaction-session-store.ts: Implements piJournalForkPrefix to identify the settled branch boundary through closing transaction commits, and forkChat to clone the branch with remapped marker IDs.
  • main/services/pi-session-port.ts: Extends PiSessionPort with importBranch to insert a linear root-to-tip entry sequence into an empty journal with fresh storage sequences and timestamps.
  • main/handlers/chats.ts: Hooks beforeInstall during chat copying to fork the Pi journal, logs degraded diagnostics on failures, and ensures orphaned target journals are cleaned up on aborts.
  • main/services/chat-store-core.ts: Extends copyVisibleHistory's beforeInstall callback to provide sourceMessageIds aligned with copied messages.
  • main/services/pi-journal-fork.test.ts: Integration test suite covering cut points, tool output and compaction survival, nested forks of forks, sync deduplication, uncommitted turn boundaries, and empty journal import constraints.
  • .memory/chat-fork.md & docs/plans/README.md: Updates project memory and roadmap status for PR 2 of the chat fork plan.
  • package.json & scripts/ci-test-registry.json: Registers the new test suite in test:compaction and the CI test registry.

Findings

No findings.

Sequence Diagram

sequenceDiagram
    autonumber
    participant Client as Renderer / IPC
    participant Handler as ChatsHandler
    participant ChatStore as ChatStore
    participant PiStore as PiCompactionSessionStore
    participant Session as PiSessionPort

    Client->>Handler: chats:copyVisibleHistory(forkAt)
    Handler->>ChatStore: copyVisibleHistory(forkAt, beforeInstall)
    ChatStore->>Handler: beforeInstall(copiedChat, sourceMessageIds)
    Handler->>PiStore: forkChat(sourceId, targetId, messages)
    PiStore->>Session: openChatIfEligible(sourceId)
    PiStore->>PiStore: piJournalForkPrefix(branch, messages)
    PiStore->>Session: repo.create(targetId)
    PiStore->>Session: importBranch(remappedPrefix)
    PiStore-->>Handler: true (journalForked)
    ChatStore->>ChatStore: installNewChat(copiedChat)
    ChatStore-->>Handler: copiedChat
    Handler-->>Client: chatForRenderer(copiedChat)
Loading
[]

Last reviewed commit: 432c3744a50c
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

Base automatically changed from feat/chat-fork-desktop to main October 5, 2026 16:37
A fork appended every copied message marker in one trailing transaction,
so an inherited reply's marker was followed by another marker before any
commit. piJournalForkPrefix then refused that boundary, and forking a fork
at an earlier inherited reply (or editing an earlier inherited prompt in a
fork) silently fell back to visible history and lost pre-cut tool results
and compaction context.

Rename each copied marker in place inside the imported prefix instead, so
every inherited reply keeps the transaction boundary it had in the source.
The new test forks a fork at an earlier reply after reopening the store,
compares it with the same cut taken in the original chat, and checks the
next sync appends only the new prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

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.

✅ No new issues found.

Reviewed changes: Reviewed the marker-boundary fix and nested-fork regression coverage added since the previous Pullfrog review.

  • Preserved inherited cuts: Remapped copied message IDs in their original journal marker entries instead of appending aliases at the tail, keeping earlier inherited replies forkable without altering transaction boundaries.
  • Added nested-fork coverage: Exercised an earlier inherited cut after reopening the store, compared its context with the corresponding direct fork and exact expected messages, and verified that the next synchronization appends only the new prompt.

Validation passed at 432c3744: focused journal/copy/adapter tests (14), npm run test:compaction (406), npm run test:ci-policy (55), and npm run type-check.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

@sambitcreate
sambitcreate merged commit 3856687 into main Oct 5, 2026
25 checks passed
@sambitcreate
sambitcreate deleted the feat/chat-fork-journal branch October 5, 2026 17:44
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.

2 participants