Repository navigation
Conversation
Move selectForkTranscriptPrefix into forkBoundary.ts as the single home for fork and rewind boundary resolution. Fork execution keeps calling the same function with identical behavior; the forkTranscript module and its tests move with it, so the next boundary consumers (preview, token validation) extend one resolver instead of forking the rules.
Add POST /sessions/:id/fork-preview: the hub resolves the preview mode from the live session (a running Codex with a verified completed turn previews through it), runs the same admission guards as confirm without taking the history-action lock, and answers with the kept tail rows, the excluded rows, counts, and a boundary token. Confirm accepts the token back on fork and rewind. The public wrappers re-check it right after the history-action lock: an epoch change, new invoked rows, or a source that started running since the preview reject with 409 boundary_moved so the caller re-previews instead of forking a transcript it never saw. Clients that send no token keep the legacy behavior, and a latestCompleted preview fails closed on runners that do not advertise the forkPreview capability, because answering it from hub rows is the drift this replaces.
Add the PreviewForkBoundary RPC: the shared runtime reads its native history and answers where each fork mode cuts - latestCompleted through latestCompletedForkCutoff, current through the last turn (falling back to the completed cut once a turn runs), message through the projected turn with the steered-cut clientId rule - and names the first excluded hub row so the hub cuts its preview tail at the same place. Confirm accepts a preview-pinned lastTurnId: the runtime re-verifies the turn still exists with a completed native prefix and forks through that fixed inclusive cutoff instead of re-deriving a moving one, so a turn that starts between preview and confirm cannot drift the boundary. The capability is advertised as conversationHistory.forkPreview.
Replace the web-side fork boundary mirror with the hub's preview answer: useForkFlow asks POST /sessions/:id/fork-preview, renders the returned kept tail and excluded boundary through the regular normalize/reduce pipeline, and confirms by echoing the boundary token. A 409 boundary_moved refreshes the preview in place and demands a re-confirmation, a source that starts running while the dialog is open re-answers through the hub, and an older hub (404) falls back to the legacy confirm dialog. forkPreview.ts keeps only the compact text shaping; its cut rules are gone. SessionChat and SessionList share the flow, the MessageActions fork button invokes it directly under the message-fork testid, and the dialog's confirm stays accessible as Fork. en and zh-CN locales and the e2e fixture/spec come along.
Route rewind through the same hub-fed preview: the MessageActions rewind button opens the rewind variant of the fork preview dialog, which emphasizes the region the source would delete (destructive styling, struck-through rows, and a truncation count) before confirming with the boundary token. The runner-side fork-safe ambiguity still offers the fork-at-boundary fallback, an older hub falls back to the legacy rewind confirm, and the inline rewind confirmation dialog is removed now that the preview gates the destructive action.
There was a problem hiding this comment.
Review mode: initial
Requirement — Pass
Previewing copied or deleted history addresses a clear gap in the existing confirmation dialogs. Using the authoritative fork boundary is necessary for running Codex sessions.
Evidence
- The fixed PR description explains the missing preview and native-history boundary mismatch.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx provides generic confirmations without transcript previews.
- cli/src/codex/shared/root.ts:789 selects the last successfully completed native turn.
Approach — Pass
A read-only preview from the boundary owner, shared hub boundary resolution, and confirmation tokens form a viable approach. The consistency and error-handling defects below can be fixed within this design.
Evidence
- hub/src/sync/syncEngine.ts:2482 requests native boundary information from preview-capable Codex runtimes.
- hub/src/sync/forkBoundary.ts:89 centralizes transcript boundary resolution.
- hub/src/sync/syncEngine.ts:2532 validates confirmation tokens before dispatch.
Code — Reviewed
Reviewed the entire fixed merge-base diff. Found a preview consistency race and missing chat-side preview error feedback. No PR code was executed.
- [Major] Reject transcript changes during the native preview RPC —
hub/src/sync/syncEngine.ts:2488 - [Minor] Display preview failures in the chat —
web/src/components/SessionChat.tsx:2159
Testing
Not run (automation; PR code execution is prohibited).
- For fixed head 5a51beb, drift-gate, integration, and windows-codex-mcp passed; test remained in progress when checked.
- Added tests cover boundary selection, stale confirmations, native pins, and dialog behavior, but do not cover transcript changes during the preview RPC or chat preview failures.
- Tests, builds, and scripts were not run under the read-only review constraints.
HAPI Bot
# Conflicts: # web/src/components/AssistantChat/messages/MessageActions.tsx # web/src/components/SessionList.tsx
The message-mode preview answered boundaries the confirm would refuse: a historical cut whose completed-turn prefix contains an unfinished turn only failed after the user confirmed. PreviewForkBoundary now applies ForkConversation's terminal-status rule on the assertBoundary snapshot it already fetched, so both sides inspect one history state. The latestCompleted preview could also name an empty-text userMessage as the cut row, but the projection never emits a hub row for those, so the hub resolved a boundary that does not exist and failed with 'Fork boundary message not found'. firstExcludedUserLocalId now skips items without hub-visible display text, sharing the projection's rule through userMessageDisplayText.
The inactive-session preview branch answered a boundary without any of the guards the confirm enforces in forkArchivedCodexSession: an archived Claude or OpenCode session, a diverged history, queued messages, or an offline Runner all rendered a preview dialog that could only fail on confirm. The admission guards now live in assertArchivedForkEligible and run in both paths. A latestCompleted token is only minted for a running source, so a runner exit before the confirm used to fail with the unactionable 'No verified completed turn' answer instead of refreshing; boundaryMovedReason now returns boundary_moved when the source went inactive, and the client re-previews under the archived rules.
…r the thinking edge A preview refresh that failed with a non-404 error left the previous ForkPreviewDialog mounted, so the error dialog — gated on errorMessage && !preview — never appeared and the stale boundary token stayed confirmable. The non-404 catch now drops the stale preview first. The thinking-edge effect also consumed an edge that landed while the first preview request was still in flight: neither the state nor the legacy request existed yet, so the stale idle-time answer opened the dialog after the turn had already started. The in-flight request intent is now tracked in a ref the effect can re-issue from, and an edge during a confirm RPC no longer mutates the dialog behind the mutation.
confirmLegacy awaited the fork/rewind RPC without any pending flag, and all three legacy confirm dialogs bind isPending to the preview-loading state, so the confirm button never showed its confirming label and both buttons stayed enabled: a double click submitted the fork twice and the dialog could be dismissed mid-request. A dedicated confirming state now covers the legacy RPC in useForkFlow and drives the three dialogs.
SessionList's error dialog ignored the retry affordance the chat already had: connect-level preview failures showed only Dismiss with the buttons unbound to any pending state. Both components now share the same dialog contract: Retry for connect failures, Dismiss otherwise, one action and no duplicate Cancel, and the pending state bound to the retry fetch. The chat's error dialog also introduced every failure as a fork even when the failed request came from openRewind; useForkFlow now records the failing intent and the dialog titles itself accordingly. Finally, HappyThread's historyActionPending was hardcoded false after the preview flow replaced the direct fork callbacks, so per-message Fork/Rewind buttons stayed enabled while a preview request was in flight and another click would supersede it via requestSeq; the loading state now locks them like the pre-preview flow locked them during its RPCs.
… footer
A failed confirm quoted the raw ApiError message ('HTTP 409 Conflict:
{...}') inside the dialog while the rest of the flow extracts the hub's
error text; the dialog now shares useForkFlow's apiErrorText. The error
also survived a background view refresh, quoting a stale boundary under
the refreshed one, and a rewind whose excluded rows were all non-text
hid the deletion summary because the section was gated on excludedTurns
being non-empty even though counts.excluded was not zero.
There was a problem hiding this comment.
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or deleted history addresses a clear gap in the existing confirmations. Matching the authoritative native boundary is justified for running Codex sessions.
Evidence
- The fixed PR description identifies missing fork/rewind previews and native-history boundary drift.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx provides generic confirmations without transcript previews.
- cli/src/codex/shared/root.ts:800 selects the last successfully completed native turn.
Approach — Pass
Boundary-owner previews, shared transcript slicing, and confirmation tokens provide a viable design. The remaining defects can be fixed within this approach.
Evidence
- hub/src/sync/syncEngine.ts:2565 requests the native boundary from preview-capable Codex runtimes.
- hub/src/sync/forkBoundary.ts:89 centralizes transcript boundary resolution.
- hub/src/sync/syncEngine.ts:2618 validates confirmation tokens before fork dispatch.
Code — Reviewed
Reviewed the entire fixed merge-base diff. The follow-up adds transcript fingerprint checks and chat error feedback. Three remaining defects affect preview correctness and older-hub fallback behavior.
- [Major] Reject native preview RPC error envelopes —
hub/src/sync/rpcGateway.ts:686 - [Minor] Read completed-fork capability from session summaries —
web/src/hooks/useForkFlow.ts:184 - [Minor] Preserve the rewind-to-fork fallback in legacy confirmation —
web/src/hooks/useForkFlow.ts:177
Testing
Not run (automation; PR code execution is prohibited).
- Tests, builds, and scripts were not executed under the read-only review constraints.
- For fixed HEAD 64b2563, drift-gate, integration, and windows-codex-mcp passed; test remained in progress when last checked.
- Added coverage does not exercise serialized native-preview error envelopes, running-list 404 fallback, or legacy rewind fork-safe recovery.
HAPI Bot
…or envelope
RpcHandlerManager serializes a thrown handler error as a RESOLVED
{error} envelope, so previewForkBoundary's cast answered the preview
with undefined nativeTurnId/cutBeforeLocalId and the runtime failure
was silently swallowed. Unwrap the envelope and throw so the hub
surfaces the failure like any other preview error.
…allback SessionSummary flattens conversationHistory onto metadata while the full hub Session nests it under metadata.capabilities; the legacy confirm only read the nested shape, so a 404 fallback from the list sent a plain current fork for a running session that supports the latest-completed fork. Accept both shapes.
The legacy rewind confirm dropped the ambiguous-native-boundary fork fallback that the preview confirm and the pre-preview dialog had: a 409 ambiguous_native_boundary_fork_safe surfaced as a dialog error instead of offering fork-at-boundary. Mirror the preview confirm's handling on the legacy path.
…nfirm The boundary token did not record the source's active state, so a transition between preview and confirm bypassed boundary_moved: a stopped runner sent the confirm into the archived-fork path (uncoded admission failure for non-Codex sources, or an archived fork that silently ignores the previewed live cut), and a reopened session ran the live fork with a token minted on the archived path. The rewind and non-Codex message confirms also failed as uncoded 'Session must be active' / 'Session is busy' on thinking edges. ForkBoundary now carries sourceActive and boundaryMovedReason rejects the mismatch across all modes; the rewind and live non-Codex message cases also reject a thinking edge. latestCompleted keeps its existing runner-exit guard for tokens minted before this field existed.
…confirm confirmLegacy set confirmingRef but confirmPreview did not, so a thinking edge landing while the confirm RPC was in flight re-answered the preview behind the confirm: the dialog's view was replaced (or unmounted into the error dialog) under a pending confirm, and the confirm then navigated over it or threw against a dead dialog. Lock the confirm the same way the legacy path does, and release it before the boundary_moved re-preview so the refresh behaves like any other in-flight preview.
… running turn A shared Codex runtime answers mode 'current' with the last completed turn while a turn is already running in the CLI (before the hub saw thinking), so the preview carries an excluded running turn and confirm pins lastTurnId. The dialog gated the fork-point marker and boundary box on kind !== 'current' and showed the full-copy footer, hiding the cut the confirm would apply. Show the boundary section whenever the preview carries a cut and use the latest-completed footer for a current preview with exclusions.
…rds would forkConversation rejects a confirm outright while a Codex resume is unconfirmed or an archived-fork child binding is pending on an active source, but forkPreview ran neither check and opened a dialog whose confirm always failed. The archived message preview also answered without the conversationHistoryTurns entry (or pending attempt) that forkArchivedCodexSession resolves the native turn from. Mirror all three guards on the fork preview paths; rewind keeps its own, since the rewind confirm runs different guards.
…ccept The idle current-mode preview pinned the last native turn without checking its terminal prefix, so a thread holding a non-terminal turn previewed a 200 whose confirm always failed verifyPinnedTurn with 'The pinned fork turn no longer has a completed native history prefix'. Validate the pin before answering and omit it when invalid: preview and confirm then agree on the unpinned whole-history cut. Message mode also fetched the thread twice per preview (once up front, once inside assertBoundary); the up-front read now lives only in the branches that need it.
The rewind route tests never sent a boundary token, so the claim that the route maps a moved rewind boundary to a coded 409 had no coverage. Mirror the fork route test: the boundary reaches the engine and the structured code is returned on a 409.
…s pending The legacy confirm dialogs lost the old handlers' pending guard when they moved onto ConfirmDialog: its Cancel button honors isPending, but Escape and the dialog's close button reach onClose unconditionally, so dismissing mid-RPC unmounted the flow while the fork or rewind kept running, and a later failure had nowhere to surface. Guard the legacy fork and rewind dismissals with !confirming in the list and the chat; the preview-route dialog already guards dismissal through its own pending state.
# Conflicts: # hub/src/sync/syncEngine.ts
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Showing copied or deleted history before confirmation addresses a clear usability gap. Native boundary resolution is justified for running Codex sessions.
Evidence
- The fixed PR description explains missing previews and disagreement between hub rows and native completed-turn boundaries.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx provides generic confirmations without transcript previews.
- cli/src/codex/shared/root.ts:814 resolves the authoritative completed-turn cutoff.
Approach — Pass
Boundary-owner previews, shared transcript slicing, and confirmation tokens provide a viable mechanism for keeping previews consistent with execution.
Evidence
- cli/src/codex/shared/root.ts:662 registers the native boundary preview RPC.
- hub/src/sync/forkBoundary.ts:88 centralizes transcript boundary resolution.
- hub/src/sync/syncEngine.ts:2815 validates the preview boundary before fork dispatch.
Code — Reviewed
Reviewed the entire fixed merge-base diff. No actionable defects found. The previous legacy-dialog dismissal finding is addressed in both callers, with regression coverage.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- For fixed HEAD cfb0182, integration, drift-gate, and windows-codex-mcp passed; test was still running when checked.
- New tests cover Escape and close-button dismissal during pending legacy fork and rewind confirmations.
- Tests, builds, and scripts were not executed under the read-only review constraints. Browser coverage uses fixtures rather than a live CLI/hub stack.
HAPI Bot
# Conflicts: # shared/package.json # shared/src/index.ts
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or removed history before confirmation addresses a clear usability gap. Using native Codex history is justified because hub rows alone cannot establish its completed-turn boundary.
Evidence
- The fixed PR description explains the missing previews and native-versus-hub boundary mismatch.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx uses generic confirmations without transcript previews.
- cli/src/codex/shared/root.ts:814 resolves the authoritative completed-turn cutoff.
Approach — Pass
Boundary-owner previews, shared transcript slicing, and confirmation tokens provide a viable way to keep the displayed boundary consistent with execution.
Evidence
- hub/src/sync/syncEngine.ts:2753 requests the native Codex boundary and checks for concurrent transcript changes.
- hub/src/sync/forkBoundary.ts:88 centralizes transcript boundary resolution.
- hub/src/sync/syncEngine.ts:2816 validates the preview token before fork dispatch.
- web/src/hooks/useForkFlow.ts:237 refreshes stale previews and requires confirmation again.
Code — Reviewed
Reviewed the entire fixed merge-base diff and relevant surrounding code. No actionable defects found. The prior legacy-dialog dismissal fix remains present with regression coverage.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- For HEAD 0038a18, integration, windows-codex-mcp, and drift-gate passed; test remained in progress when checked.
- Added coverage addresses boundary resolution, stale tokens, native turn pinning, dialog errors, refreshes, and legacy fallback behavior.
- Tests, builds, and scripts were not executed under the read-only review constraints. Browser coverage uses fixtures rather than a live CLI/hub stack.
HAPI Bot
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or deleted history addresses a clear usability gap. Native Codex boundary resolution is justified because hub rows alone cannot determine the completed-turn cutoff.
Evidence
- The fixed PR description explains the missing previews and native-versus-hub boundary mismatch.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx:129 provides generic confirmations without transcript previews.
- cli/src/codex/shared/root.ts:814 resolves the completed-turn cutoff from native history.
Approach — Pass
Boundary-owner previews, shared transcript slicing, and confirmation tokens provide a viable mechanism for keeping previews consistent with execution.
Evidence
- hub/src/sync/syncEngine.ts:2753 requests the native boundary and rejects concurrent transcript changes.
- hub/src/sync/forkBoundary.ts:88 centralizes transcript boundary resolution.
- hub/src/sync/syncEngine.ts:2816 validates confirmation tokens before fork dispatch.
- web/src/hooks/useForkFlow.ts:237 refreshes stale previews and requires confirmation again.
Code — Reviewed
Reviewed the entire fixed merge-base diff and relevant surrounding code. No actionable defects found. Previous fixes remain present, including pending legacy-dialog dismissal guards.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- For HEAD 962abb1, integration, windows-codex-mcp, and drift-gate passed; test remained in progress when checked.
- Added coverage addresses boundary resolution, stale tokens, native pinning, dialog refreshes, errors, and legacy fallback behavior.
- No PR code, tests, builds, or scripts were executed. Browser coverage uses fixtures rather than a live CLI/hub stack.
HAPI Bot
# Conflicts: # cli/src/codex/shared/root.ts # hub/src/sync/syncEngine.ts
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or deleted history addresses a clear usability gap. Using native Codex history is justified because hub rows cannot reliably determine the completed-turn cutoff.
Evidence
- The snapshot PR description establishes the missing previews and boundary mismatch.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx:129 provides confirmation without a transcript preview.
Approach — Pass
Boundary-owner previews, shared transcript slicing, native turn pinning, and confirmation-token checks provide a viable mechanism for keeping previews consistent with execution.
Evidence
- cli/src/codex/shared/root.ts:734 resolves previews from native history.
- hub/src/sync/syncEngine.ts:2753 checks transcript stability around the native preview RPC.
- hub/src/sync/syncEngine.ts:2821 validates confirmation tokens before dispatch.
- web/src/hooks/useForkFlow.ts:237 refreshes moved boundaries and requires confirmation again.
Code — Reviewed
Reviewed the entire fixed merge-base diff and relevant surrounding code. No actionable defects found; earlier reported issues are addressed in the current implementation.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- For HEAD b5a7c13, integration, windows-codex-mcp, and drift-gate passed; test remained in progress when checked.
- Added coverage addresses boundary resolution, stale tokens, native pinning, dialog refreshes, errors, and legacy fallback behavior. Browser coverage uses fixtures rather than a live CLI/hub stack.
- No PR code, tests, builds, or scripts were executed, as required by the read-only review boundary.
HAPI Bot
# Conflicts: # hub/src/web/routes/sessions.ts # web/src/api/client.ts # web/src/components/SessionChat.tsx
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or deleted history addresses a clear usability gap. Native Codex history is needed to identify the actual completed-turn cutoff.
Evidence
- The snapshot PR description establishes the missing previews and possible disagreement between hub rows and native history.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx:129 provides confirmation without a transcript preview.
Approach — Pass
Boundary-owner previews, shared transcript slicing, native turn pinning, and confirmation-token validation provide a viable way to keep execution consistent with the preview.
Evidence
- cli/src/codex/shared/root.ts:734 resolves preview boundaries from native history.
- hub/src/sync/syncEngine.ts:2887 checks transcript stability around the native preview RPC.
- hub/src/sync/syncEngine.ts:2943 validates confirmation tokens before dispatch.
- web/src/hooks/useForkFlow.ts:239 refreshes moved boundaries and requires confirmation again.
Code — Reviewed
Reviewed the entire fixed merge-base diff and relevant surrounding code. No actionable defects found. Previously reported issues are addressed; verification remains incomplete because the CI test job failed before running the main suites.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- For HEAD 4a34404, typecheck, integration, windows-codex-mcp, and fixture drift checks passed.
- The test job failed in the passkey browser regression with a 15-second waitForFunction timeout. That code is outside this diff; subsequent E2E and root test steps were skipped.
- Added coverage addresses boundary resolution, stale tokens, native pinning, dialog refresh, errors, and legacy fallback. Browser coverage uses fixtures rather than a live CLI/hub stack.
- No PR code, tests, builds, or scripts were executed during this read-only review.
HAPI Bot
# Conflicts: # cli/src/codex/shared/projection.ts
There was a problem hiding this comment.
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or deleted history addresses a clear usability gap. Using native Codex history is justified because hub rows alone cannot establish the completed-turn cutoff.
Evidence
- The snapshot PR description establishes the missing previews and possible disagreement with native history.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx provides confirmation without a transcript preview.
Approach — Pass
Boundary-owner previews, shared transcript slicing, native turn pinning, and confirmation-token validation form a viable approach. The defect below can be fixed within this design.
Evidence
- cli/src/codex/shared/root.ts:753 resolves preview boundaries from native history.
- hub/src/sync/syncEngine.ts:2887 checks transcript stability around the preview RPC; :2943 validates confirmation tokens.
- web/src/hooks/useForkFlow.ts:237 refreshes moved boundaries and requires confirmation again.
Code — Reviewed
Reviewed the entire fixed merge-base diff and relevant surrounding code. Found one regression that prevents running-session forks for ordinary queued Codex prompts.
- [Major] Resolve native batch IDs to original hub message IDs —
cli/src/codex/shared/root.ts:820
Testing
Not run (automation; PR code execution is prohibited).
- No PR code, tests, builds, or scripts were executed during this read-only review.
- For HEAD 9603c25, integration, windows-codex-mcp, and fixture drift checks passed. The main test job remained in progress; its typecheck, passkey browser regression, and selected E2E steps had passed.
- Added preview tests use direct native message IDs and do not cover the synthetic batch-ID mapping described in the finding.
HAPI Bot
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Previewing copied or deleted history addresses a clear usability gap. Native Codex history is needed to establish the completed-turn boundary accurately.
Evidence
- The snapshot PR description explains the missing previews and potential disagreement between hub rows and native history.
- Base web/src/components/AssistantChat/messages/MessageActions.tsx provides confirmation without a transcript preview.
Approach — Pass
Boundary-owner previews, shared transcript slicing, native turn pinning, and confirmation-token checks provide a viable mechanism.
Evidence
- cli/src/codex/shared/root.ts:753 resolves preview boundaries from native history; :716 uses the previewed native pin during confirmation.
- hub/src/sync/syncEngine.ts:2887 checks transcript stability around the preview RPC; :2945 validates the confirmation token.
- web/src/hooks/useForkFlow.ts:237 refreshes moved boundaries and requires confirmation again.
Code — Reviewed
Reviewed the entire fixed merge-base diff and relevant surrounding code. The previously reported batch-ID defect is addressed through originalBoundaryId with regression coverage. No actionable findings remain.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- No PR code, tests, builds, or scripts were executed during this read-only review.
- For HEAD bb8c31a, integration, windows-codex-mcp, and fixture drift checks passed.
- The main test job remained in progress. Its typecheck, passkey browser regression, and selected E2E steps had passed; the full test suite had not finished.
HAPI Bot
Supersedes #1673 (rebuilt so the preview comes from whoever decides the fork boundary).
Problem
Solution
POST /api/sessions/:id/fork-previewreturns the rows the new session keeps, the first row it leaves out, and a boundary token. The hub picks the fork mode from the live session. For a Codex shared runtime it asks the CLI (PreviewForkBoundaryRPC), which cuts the native history the same way the fork does. Every other flavor is answered by the hub, using the same boundary code the fork uses.409 boundary_movedinstead of forking something the user did not see, and the dialog refreshes the preview in place and asks to confirm again. A Codex fork pins the previewed native turn, re-checked against native history before forking.conversationHistory.forkPreview, the last-completed-turn preview is refused rather than guessed.Screenshots
Fork
Fork of a running Codex session
The conversation changed while the dialog was open
Rewind and the forked session
Tests
hub/src/sync/forkBoundary.test.ts: one boundary resolver for fork, rewind and preview.hub/src/sync/forkPreview.test.ts: preview modes, the token check (including a source that stops running or is reopened between preview and confirm), the pending-fork guards the confirm applies, and legacy confirm without a token.hub/src/web/routes/sessions.test.ts,hub/src/sync/rpcGateway.test.ts:409 boundary_movedon the fork and rewind routes, and a CLI error answer to the preview RPC.cli/src/codex/shared/root.test.ts: the CLI preview cuts (last completed turn with an interrupted or failed trailing turn, current, at a message), the pinned-turn fork, and an idle preview that only pins a turn the confirm accepts.web/src/lib/forkPreview.test.ts,web/src/components/AssistantChat/ForkPreviewDialog.test.tsx,web/src/components/SessionChat.fork-mode.test.tsx,SessionChat.fork-error.test.tsx,SessionList.fork-error.test.tsx,SessionList.directory-action.test.tsx,MessageActions.test.tsx,UserMessage.test.tsx: dialog rendering and the rewind removed region, refresh onboundary_moved, re-answer when the source starts or stops running, errors and retry in the chat and the list, the confirm lock while a fork is in flight, and the 404 fallback for an older hub.e2e/fork-preview.spec.ts: the dialog's rendering on a fixture page.e2e/session-list-fork-menu.spec.ts,opencode-fork-buttons.spec.ts: the fork entry points.