Repository navigation
fix(gateway): chat history retries forever for sessions in skipped agent stores - #165408
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
@clawsweeper review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 3:15 AM ET / 07:15 UTC. ClawSweeper reviewWhat this changesChat 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests +79. Total +84 across 3 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
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: |
…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.
What Problem This Solves
Fixes:
chat.history/chat.startupkeep returning the retryableUNAVAILABLE"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 honorretryablespin: 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 matchessessions.list(row omitted) andsessions.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.historyselects 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 gethiddenSessionNotFound. 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:
hiddenSessionNotFoundrefusal 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
sessionIdread a transcript from the skipped store.Provenance:
9074545b17aa, "skip registered agent stores no configured agent owns", Refs [Bug]: After a version change, agents admit one by one for minutes past ready and the unconfigured system-agent DB is refused (readyz 503 until restart) #164799) added the configured-store predicate shared by preflight, the Gateway session projection and startup maintenance. It is kept as is.624f379b86e0, "reuse prepared rows for chat history") added the excluded-row refusal for durable rows deliberately absent from the resident roster. Its refusal-only invariant is kept.Related, out of scope (unchanged here)
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 suggestsagents.entries, even for ACP harness dirs whereacp.allowedAgentsis the configured owner.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 templateinsessions-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, healthyagents/geministore holding an unarchived, empty ACP rowagent:gemini:acp:11111111-…(our setup hit the same shape after an update). Built Gateways atorigin/main3dc4128bdfefand at this branch ran on separate copies of the same state. Both log the #164929 skip warning at startup.origin/mainsessions.list {limit:1000}chat.history {sessionKey}UNAVAILABLE"session changed while reading history; reload the conversation",retryable: trueINVALID_REQUESTSession "agent:gemini:acp:…" was not found.chat.startup {sessionKey}chat.historyfor a genuinely absent keymessages: []messages: [](unchanged)openclaw tui --session agent:gemini:acp:…history failed: session changed while reading history; reload the conversationhistory failed: Session "agent:gemini:acp:…" was not found./chat?session=agent:gemini:acp:…Telegram and other channels don't call
chat.historyfor 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 foundboots a Gateway under startup admission and seeds a registered unconfigured store. It assertssessions.liststill omits the row and that bothchat.historyandchat.startupreturn the not-found refusal. Onorigin/mainit 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 readcreates the row while the reader prepares sharing facts and still gets the retryableUNAVAILABLE. It passes on bothorigin/mainand this branch and guards against the new branch swallowing real mid-read changes.Scoped suites. All 19
chat-history*/chat-startup*method suites andsession-sharing-preparation.test.tspass (184 tests). Scopedoxfmt --check,oxlint --type-aware --deny-warningsandgit diff --checkare clean.Bounded cost
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.