Skip to content

fix(gateway): chat history retries forever for sessions in skipped agent stores - #165408

Merged
obviyus merged 1 commit into
mainfrom
fix/skipped-store-chat-history
Oct 5, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/skipped-store-chat-history

Conversation

@obviyus

@obviyus obviyus commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: chat.history / chat.startup keep returning the retryable UNAVAILABLE "session changed while reading history; reload the conversation" for a session whose agent store the Gateway deliberately skips (a registered agent database that no configured agent owns, #164929). The condition is permanent, so clients that honor retryable spin: the TUI retries for its full 60 s startup budget and then shows the misleading "reload" error.

User Impact

Opening such a session now fails immediately with the existing non-retryable Session "<key>" was not found.. That matches sessions.list (row omitted) and sessions.describe (session: null). #164929's skip is unchanged: the store still is not listed, opened at startup, or served.

Why This Change Was Made

chat.history selects the row through the session row projection. If the projection has no row and the key is not incognito, #156055 makes the reader prepare storage-backed sharing facts. When storage still holds an excluded row, "excluded metadata can refuse a read, never authorize transcript delivery". Unauthorized callers get hiddenSessionNotFound. Authorized callers got the retryable "session changed" error, which only makes sense when the row appeared during the read.

Since #164929, a registered store with no configured owner is excluded from the projection for the whole Gateway lifetime. Storage still returns its rows, so every read of those keys took the "changed mid-read" branch.

The reader now separates the two cases using the projection read it already does:

  • the fresh projection serves the row → it really changed mid-read → retryable reload (unchanged);
  • the fresh projection still omits it → the Gateway does not serve that row → the same hiddenSessionNotFound refusal the branch already returns for unauthorized callers.

The excluded row still never authorizes transcript delivery, which keeps #156055's invariant. The response is a refusal, not the empty absent-key result, because falling through to the absent path would let an explicit sessionId read a transcript from the skipped store.

Provenance:

Related, out of scope (unchanged here)
  • The startup warning Skipped openclaw-agent.sqlite: unconfigured agent database; run openclaw doctor to inspect retained data. points to Doctor. Doctor's retained-database check skips default-path stores (agents/<id>/agent/openclaw-agent.sqlite), and its generic "agent directories without a matching agents.entries entry" advice suggests agents.entries, even for ACP harness dirs where acp.allowedAgents is the configured owner.
  • Gateway method tests for retired/unconfigured stores (sessions.describe reads an unconfigured agent with rows in a fixed store, sessions.search searches a retired per-agent store, session reads find a retired store only reachable through its deterministic template in sessions-read.test.ts) pass because they run outside the Gateway's startup admission scope. In a running Gateway, fix(gateway): skip registered agent stores no configured agent owns #164929's skip makes those stores unreadable. Which of the two is the intended product behavior is a maintainer decision.

Evidence

Real Gateway, synthetic state. An isolated HOME/state has one configured agent (main) and a registered, healthy agents/gemini store holding an unarchived, empty ACP row agent:gemini:acp:11111111-… (our setup hit the same shape after an update). Built Gateways at origin/main 3dc4128bdfef and at this branch ran on separate copies of the same state. Both log the #164929 skip warning at startup.

RPC / client origin/main this PR
sessions.list {limit:1000} main row only (gemini row skipped) same
chat.history {sessionKey} UNAVAILABLE "session changed while reading history; reload the conversation", retryable: true INVALID_REQUEST Session "agent:gemini:acp:…" was not found.
chat.startup {sessionKey} same retryable error same not-found
chat.history for a genuinely absent key messages: [] messages: [] (unchanged)
openclaw tui --session agent:gemini:acp:… spinner "starting up … subscribing to session events" for ~60 s of retries, then history failed: session changed while reading history; reload the conversation immediately history failed: Session "agent:gemini:acp:…" was not found.
Control UI /chat?session=agent:gemini:acp:… "Session not found" page (route resolution reads the projection first) same; no UI change

Telegram and other channels don't call chat.history for this key, so no channel proof applies.

Regression through the real Gateway RPC. server-agent-database-startup.test.ts › reports history in a skipped unconfigured agent store as not found boots a Gateway under startup admission and seeds a registered unconfigured store. It asserts sessions.list still omits the row and that both chat.history and chat.startup return the not-found refusal. On origin/main it fails with exactly the shipped error (UNAVAILABLE / "session changed while reading history; reload the conversation"); on this branch it passes.

Boundary kept. chat-history-registry.test.ts › asks for a reload when an absent session is created during the read creates the row while the reader prepares sharing facts and still gets the retryable UNAVAILABLE. It passes on both origin/main and this branch and guards against the new branch swallowing real mid-read changes.

Scoped suites. All 19 chat-history* / chat-startup* method suites and session-sharing-preparation.test.ts pass (184 tests). Scoped oxfmt --check, oxlint --type-aware --deny-warnings and git diff --check are clean.

Bounded cost

  • Production: +10/−5 in one file. No new state, config, schema, worker read, or message text. The new branch reuses the projection read and the error shape the reader already had.
  • Request cost: unchanged. It is one condition on an already-computed value, so it adds no extra RPCs or reads.
  • Tests: +80 lines in two existing files.
    • pnpm test src/gateway/server-agent-database-startup.test.ts -t "skipped unconfigured agent store" --maxWorkers=1: 9.7 s test, 34.3 s wall. It boots a Gateway because the skip only exists under the Gateway's startup-admission scope, which no cheaper layer reproduces.
    • pnpm test src/gateway/server-methods/chat-history-registry.test.ts --maxWorkers=1: new case 1.2 s, file 36.4 s wall.

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@obviyus

obviyus commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 5, 2026
@obviyus
obviyus marked this pull request as ready for review October 5, 2026 07:11
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 3:15 AM ET / 07:15 UTC.

ClawSweeper review

What this changes

Chat history and startup reads return a non-retryable not-found error for sessions whose agent stores the Gateway excludes, with regressions for excluded stores and sessions created during a read.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still returns a retryable error for permanently excluded sessions. The focused fix preserves transcript refusal and genuine mid-read retries; no actionable patch defect was found.

Priority: P2
Reviewed head: 20f2df73b0e5145e0e704f48898372230219d02a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant real Gateway evidence and two distinct regressions; no blocking correctness or security concern was found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured before/after real Gateway RPC and TUI results exercise the changed history reader with a registered skipped store: both history methods become terminal not-found and the TUI stops retrying immediately. The new admission-scoped RPC regression and mid-read creation case supplement that proof. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured before/after real Gateway RPC and TUI results exercise the changed history reader with a registered skipped store: both history methods become terminal not-found and the TUI stops retrying immediately. The new admission-scoped RPC regression and mid-read creation case supplement that proof. No stored-data contract changes.
Evidence reviewed 7 items Pinned introduced change: The introduced production hunk changes only the authorized excluded-row refusal: a fresh projected entry retains the retryable error; continued exclusion returns hiddenSessionNotFound. Both branches terminate before transcript delivery.
Current main still needs the fix: Fetched main unconditionally returns the retryable reload error when storage finds an excluded entry and sharing authorization succeeds. The requested distinction is absent.
Existing admission boundary: Startup-scoped physical-store selection excludes stores without configured owners. The merged #164929 explicitly preserves standalone-reader behavior; this PR retains that admission decision rather than restoring skipped-store access.
Findings None None.
Security None None.

How this fits together

The Gateway history reader combines the resident session roster with storage-backed sharing facts before serving conversation history to clients such as the TUI. Startup admission determines which agent stores enter that roster.

flowchart TD
  A[Client history request] --> B[Gateway session roster]
  B --> C[Storage sharing facts]
  C --> D{Row now served?}
  D -->|Appeared during read| E[Retryable reload error]
  D -->|Still excluded| F[Not-found refusal]
  B -->|Existing served row| G[Authorized transcript response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +79. Total +84 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 10 5 +5
Tests 2 80 1 +79
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 90 6 +84

Review metrics

Metric Value Why it matters
Production and test growth production +10/-5; tests +80/-1 Production growth adds one decision using existing facts; the tests cover startup exclusion and genuine mid-read creation.

Technical review

Best possible solution:

Keep the existing admission and sharing owners authoritative, returning terminal not-found for excluded rows and retryable reload only when the projected session changes.

Do we have a high-confidence way to reproduce the issue?

Yes: a registered unconfigured store containing a session remains excluded from the Gateway roster while storage-backed sharing preparation finds its row, causing current main to return retryable UNAVAILABLE repeatedly. Source inspection establishes the path; this reviewer did not execute it.

Is this the best way to solve the issue?

Yes: the branch uses the existing fresh projection result to distinguish permanent exclusion from mid-read creation, without adding reads or allowing excluded transcript access.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fdd3a97f23ef.

Labels

Label changes:

  • add P2: The fix removes repeated failed history reads for a bounded class of excluded sessions.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after real Gateway RPC and TUI results exercise the changed history reader with a registered skipped store: both history methods become terminal not-found and the TUI stops retrying immediately. The new admission-scoped RPC regression and mid-read creation case supplement that proof. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured before/after real Gateway RPC and TUI results exercise the changed history reader with a registered skipped store: both history methods become terminal not-found and the TUI stops retrying immediately. The new admission-scoped RPC regression and mid-read creation case supplement that proof. No stored-data contract changes.

Label justifications:

  • P2: The fix removes repeated failed history reads for a bounded class of excluded sessions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured before/after real Gateway RPC and TUI results exercise the changed history reader with a registered skipped store: both history methods become terminal not-found and the TUI stops retrying immediately. The new admission-scoped RPC regression and mid-read creation case supplement that proof. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after real Gateway RPC and TUI results exercise the changed history reader with a registered skipped store: both history methods become terminal not-found and the TUI stops retrying immediately. The new admission-scoped RPC regression and mid-read creation case supplement that proof. No stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The introduced production hunk changes only the authorized excluded-row refusal: a fresh projected entry retains the retryable error; continued exclusion returns hiddenSessionNotFound. Both branches terminate before transcript delivery. (src/gateway/server-methods/chat-history-session-read.ts:168, 20f2df73b0e5)
  • Current main still needs the fix: Fetched main unconditionally returns the retryable reload error when storage finds an excluded entry and sharing authorization succeeds. The requested distinction is absent. (src/gateway/server-methods/chat-history-session-read.ts:168, fdd3a97f23ef)
  • Existing admission boundary: Startup-scoped physical-store selection excludes stores without configured owners. The merged fix(gateway): skip registered agent stores no configured agent owns #164929 explicitly preserves standalone-reader behavior; this PR retains that admission decision rather than restoring skipped-store access. (src/config/sessions/combined-store-gateway.ts:484, 20f2df73b0e5)
  • Real behavior evidence: The captured PR body reports built Gateways on separate copies of isolated synthetic state, comparing base 3dc4128 with this branch. Both omit the gemini session from sessions.list; after the fix, chat.history and chat.startup return INVALID_REQUEST/not-found, and the TUI fails immediately instead of retrying for approximately 60 seconds. Genuinely absent history remains empty. This is direct reported runtime output, supplemented by tests. (20f2df73b0e5)
  • Distinct regression boundaries: The startup regression seeds an unconfigured registered store and exercises both history methods through Gateway RPC under admission. The registry regression creates a session during sharing preparation and preserves retryable UNAVAILABLE. These cover separate lifecycle contracts without new production test seams; the body records baseline failure and scoped validation. (src/gateway/server-agent-database-startup.test.ts:771, 20f2df73b0e5)
  • Feature-history routing: Bounded current-main history identifies Peter Steinberger's retained-history and runtime refactors and Shakker's scoped-session reading work. The provided merged metadata connects the prepared-row implementation to perf(sessions): reuse prepared rows for chat history #156055. Deeper follow/blame inspection encountered unavailable historical objects and HTTP 403; no source-line introduction attribution is claimed. (src/gateway/server-methods/chat-history-session-read.ts, fdd3a97f23ef)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@obviyus
obviyus merged commit f12c30c into main Oct 5, 2026
243 of 250 checks passed
@obviyus
obviyus deleted the fix/skipped-store-chat-history branch October 5, 2026 07:38
@obviyus

obviyus commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Landed as f12c30c.

Checked on the exact head 20f2df7: fresh gpt-6-astra reviewer LAND, ClawSweeper ready, live real-Gateway/TUI before/after in the body, and every test shard green (the fail-fast-cancelled shard passed on rerun). Admin merge past one inherited red: check-test-types-core-5 fails on clean main because #165331 (cebf83f) added a runGatewayStartupObservers call in server-lifecycle.catalog-write.test.ts without the two parameters #165218 (ddf95b6) made required. This PR does not touch that file.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…ent stores (openclaw#165408)

chat.history and chat.startup for a session in an agent store skipped by startup admission (openclaw#164929) now return the existing non-retryable not-found refusal instead of a retryable "reload the conversation" error that clients retried forever. A row created mid-read still gets the retryable reload.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant