Skip to content

Fix startup chat history recovery for Issue #816#821

Merged
ashione merged 2 commits intomainfrom
codex/issue-816-history-startup-retry
Apr 12, 2026
Merged

Fix startup chat history recovery for Issue #816#821
ashione merged 2 commits intomainfrom
codex/issue-816-history-startup-retry

Conversation

@ashione
Copy link
Copy Markdown
Contributor

@ashione ashione commented Apr 10, 2026

Summary

  • recover cold-start chat history loads when the first foreground chat.history request times out during gateway startup readiness
  • scope the longer history timeout to startup foreground recovery only so quiet/background refreshes keep their existing responsiveness
  • add unit coverage for both the modular history actions and the live useChatStore.loadHistory runtime path
  • add an Electron E2E regression spec for startup history retry behavior

Root Cause

On cold startup, ClawX could request chat.history before Gateway was fully ready to serve history. The first foreground history load failed immediately, which left the chat page blank when there was no in-memory history to preserve.

The first attempt at fixing this also stretched timeout behavior into quiet/background refreshes and burned the "first foreground load" marker even on failed or stale loads.

User Impact

  • startup history loading is more resilient when Gateway is still settling
  • background history refresh and send-time polling keep their prior responsiveness
  • a failed or stale first load no longer permanently disables startup retry for that session

Validation

  • pnpm run typecheck
  • pnpm exec vitest run tests/unit/chat-history-actions.test.ts tests/unit/chat-store-history-retry.test.ts

Notes

  • Added an Electron E2E spec at tests/e2e/chat-history-startup-retry.spec.ts
  • I could not complete that Playwright run in this environment because Electron launch timed out before the test body executed

@ashione ashione marked this pull request as ready for review April 10, 2026 07:39
Copilot AI review requested due to automatic review settings April 10, 2026 07:39
@ashione ashione changed the title [codex] Fix startup chat history recovery for Issue #816 Fix startup chat history recovery for Issue #816 Apr 10, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves ClawX chat history recovery on cold startup by adding a targeted retry path for the first foreground chat.history load when Gateway isn’t ready yet, while keeping quiet/background refresh behavior unchanged.

Changes:

  • Add startup-only chat.history retry + timeout override (initial foreground load only), with error classification based on Gateway status and timeout/unavailable signals.
  • Apply the retry logic both in modular chat history actions and the live useChatStore.loadHistory path.
  • Add unit and Electron E2E regression coverage for startup history retry behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/stores/chat/history-startup-retry.ts Introduces shared constants + helpers to classify retryable errors, decide retry eligibility, and provide the startup-only timeout override.
src/stores/chat/history-actions.ts Adds retry loop + startup timeout override to the modular loadHistory, and avoids “burning” the startup path on stale applies.
src/stores/chat.ts Adds parallel retry/timeout behavior in the runtime store path and updates the loading safety timer duration.
tests/unit/chat-history-actions.test.ts Adds unit coverage for retry success, retry exhaustion, and “no retry” cases (quiet + non-retryable errors).
tests/unit/chat-store-history-retry.test.ts Adds unit coverage for the runtime store path (timeout override scoping + stale first attempt not burning retry).
tests/e2e/chat-history-startup-retry.spec.ts Adds an Electron E2E regression spec validating history eventually renders after an initial chat.history timeout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b485486ec5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ashione ashione merged commit 4ff6861 into main Apr 12, 2026
6 checks passed
@ashione ashione deleted the codex/issue-816-history-startup-retry branch April 12, 2026 07:30
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9495c9fac7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1316 to +1317
const isInitialForegroundLoad = !quiet && !_foregroundHistoryLoadSeen.has(currentSessionKey);
const historyTimeoutOverride = getStartupHistoryTimeoutOverride(isInitialForegroundLoad);
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 Badge Gate startup timeout override on actual startup state

isInitialForegroundLoad is keyed only by whether this session has ever been foreground-loaded, so a session opened much later in a long-running app still gets startup settings (35_000 RPC timeout and the extended loading safety timeout) even when gateway startup has long passed. Because retry eligibility is separately gated by connectedAt, this can produce the worst of both worlds for late session switches: no retry, but a much longer stall before surfacing failure if chat.history hangs. Please gate the startup timeout path on gateway startup recency as well (not just per-session first foreground load).

Useful? React with 👍 / 👎.

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