slopus/happy · error · Error

The chosen rewind point is no longer present in the source C

Error message

The chosen rewind point is no longer present in the source Codex thread — try forking without truncation

What it means

This error is thrown by the Codex fork RPC handler in setRPCHandlers when the underlying Codex SDK raises CodexForkRewindPointNotFoundError. It means the item the user selected as a rewind point (identified by cutAfterItemId) no longer exists in the source Codex thread, so the fork-with-truncation cannot be performed. The library re-maps the SDK error to a user-actionable message suggesting forking without truncation.

Source

Thrown at packages/happy-cli/src/api/apiMachine.ts:312

                    points: listCodexRewindPoints(thread),
                };
            });
        });

        this.rpcHandlerManager.registerHandler('codex-duplicate-thread', async (params: any) => {
            const directory = requireNonEmptyString(params?.directory, 'directory');
            const codexThreadId = requireNonEmptyString(params?.codexThreadId, 'codexThreadId');
            const cutAfterItemId = requireNonEmptyString(params?.cutAfterItemId, 'cutAfterItemId');

            try {
                return await withCodexAppServerClient((client) => forkCodexThread(client, {
                    threadId: codexThreadId,
                    cwd: directory,
                    cutAfterItemId,
                }));
            } catch (error) {
                if (error instanceof CodexForkRewindPointNotFoundError) {
                    throw new Error(
                        'The chosen rewind point is no longer present in the source Codex thread — try forking without truncation',
                    );
                }
                throw error;
            }
        });

        // Register stop daemon handler
        this.rpcHandlerManager.registerHandler('stop-daemon', () => {
            logger.debug('[API MACHINE] Received stop-daemon RPC request');

            // Trigger shutdown callback after a delay
            setTimeout(() => {
                logger.debug('[API MACHINE] Initiating daemon shutdown from RPC');
                requestShutdown();
            }, 100);

            return { message: 'Daemon stop request acknowledged, starting shutdown sequence...' };

View on GitHub (pinned to b824cd0a46)

Solutions

  1. Retry the fork without passing cutAfterItemId so the whole thread is forked instead of truncated
  2. Re-fetch the current thread items and let the user pick a rewind point that still exists
  3. Restart or re-open the session to get a fresh thread state, then fork again

Example fix

// before
await machine.forkSession({ threadId, cutAfterItemId: staleItemId });
// after
try {
  await machine.forkSession({ threadId, cutAfterItemId: staleItemId });
} catch {
  await machine.forkSession({ threadId }); // fork without truncation
}
Defensive patterns

Strategy: fallback

Validate before calling

// Verify the rewind point still exists before forking
const items = await getThreadItems(threadId);
if (!items.some(i => i.id === cutAfterItemId)) {
  cutAfterItemId = undefined; // fork without truncation
}

Type guard

function hasRewindPoint(items: { id: string }[], id?: string): boolean {
  return typeof id !== 'string' || items.some(i => i.id === id);
}

Try / catch

try {
  await forkSession({ threadId, cutAfterItemId });
} catch (e) {
  if (e.message.includes('rewind point is no longer present')) {
    await forkSession({ threadId }); // fallback: no truncation
  } else throw e;
}

Prevention

When it happens

Trigger: Calling the fork/resume RPC for a Codex thread with a cutAfterItemId whose item has been removed, compacted away, or belongs to a different/older thread state; the source thread was truncated or garbage-collected between listing and forking.

Common situations: User picks a rewind point from a stale session list; the Codex thread was compacted/trimmed since the UI snapshot was taken; concurrent edits to the same thread from another machine; pointing at a thread ID that was recreated.

Related errors


AI-assisted analysis of slopus/happy@b824cd0a46 (2026-08-31). Data as JSON: /api/errors/71cb1d8bf64411dd. Report an issue: GitHub.