Skip to content

fix(codex): avoid repeated session catalog timeout waits - #149378

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-catalog-list-admission-20260915
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-catalog-list-admission-20260915

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #149030, #148631, #148639, #148984.

What Problem This Solves

Fixes repeated catalog timeout waits when a local Codex source keeps failing. On team.openclaw.ai (2026-09-15, serving 7bdca7d8d1b), 370 sessions.catalog.list calls across 18 connections had p50 90,263 ms, p90 216,506 ms, and max 410,415 ms. One sampled call waited 146,596 ms for admission and then spent 65,669 ms in its single admitted step.

User Impact

After two source failures, later catalog refreshes reuse the failure during bounded backoff instead of repeatedly waiting for the same source timeout. Failed cold hosts remain present with their existing unavailable/error state; healthy sources and previously cached pages remain available. The first failure and its immediate recovery retry retain their existing timeout budgets; backoff applies after repeated failure. Recovery can then be deferred by up to 60 seconds, plus the caller's refresh interval. Slow successful scans and unrelated providers can still occupy admission slots.

Why This Change Was Made

The Gateway already shares identical lists within each connection's authority partition, and Codex already shares pending native pages across matching source/query scopes. The missing behavior was failure reuse: settling a failed cold page immediately removed the pending producer, allowing the next admitted wave to retry it. Keep that ownership and result sharing intact, allow one immediate recovery retry, then back off 5/10/20/40/60 seconds per runtime config, agent, and source home. Only one recovery probe runs per source; successful recovery creates a fresh source-state generation so older overlapping failures cannot reopen the outage. Invalid-request errors do not trip host backoff.

The source-health state machine is extracted into the private, typed session-catalog-source-backoff.ts sibling; session-catalog-control.ts remains its consumer and owns page sharing and delivery. This keeps the control file within its unchanged 700-line lint limit. Gateway FIFO admission, caller visibility, native pending-request custody, late host publication, and diagnostic fields keep their existing contracts. hostCountsComplete still means every returned host was counted, not that discovery succeeded. No protocol, configuration, or persistent-state changes.

The sample does not prove which host consumed 66 seconds. A local control timeout is consistent with its disconnected error host and the 60-second default; paired-node foreground listing is already bounded to eight seconds. Correlated phase logs are still needed to confirm the production bottleneck, and this change has not been deployed to the Team Gateway.

Evidence

  • New registered-provider regression: 18 concurrent lists share one native result; repeated source failures preserve unavailable hosts without another native invocation during backoff. Before the fix, the backoff assertion failed: expected 2 native calls, received 3. The concurrency assertion already passed before the fix.
  • Direct source-state tests cover exponential delay/cap, one probe, agent/home/config isolation, reset on success, and invalid catalog parameters. Control/registered-provider regressions retain concurrent result sharing, unavailable-host delivery, invalid-request handling, and a late failure arriving after successful recovery. The late-failure regression reproduced the independent review finding before its repair.
  • node scripts/run-vitest.mjs src/gateway/server.catalog-startup.test.ts src/gateway/server-methods/session-catalog*.test.ts extensions/codex/src/session-catalog*.test.ts: 34 files, 416 tests passed (178 Gateway, 238 Codex).
  • node scripts/check-changed.mjs: passed fully, including production/test types, lint, unchanged line limits and ratchets, dependency/boundary guards, and import cycles.
  • pnpm check:docs: passed, including 1,309 MDX files, 13,910 internal links (zero broken), and 1,241 validated config examples.
  • Fresh independent Codex review after extraction: clean at P2; the earlier source-generation race was reproduced and fixed. git diff --check passed.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 15, 2026 19:41
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 6:59 PM ET / 22:59 UTC (Revision 3).

ClawSweeper review

What this changes

Adds bounded retry backoff for repeatedly failing local Codex session catalogs while preserving shared pending reads and cached pages.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains useful, distinct work, but the previously reported malformed-response cursor case is still unfixed. The related catalog repairs do not supersede it.

Priority: P2
Reviewed head: 0fc8edef8b220d7828e71f464094a2845a7b4b91

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The implementation is focused and supported by useful regression coverage, but the existing cursor-classification blocker remains.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored internal retry change, so the external-contributor proof gate does not apply. Registered-provider tests mock control requests; the production sample predates the fix, and the inspected related screenshots do not demonstrate this backoff.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a maintainer-authored internal retry change, so the external-contributor proof gate does not apply. Registered-provider tests mock control requests; the production sample predates the fix, and the inspected related screenshots do not demonstrate this backoff.
Evidence reviewed 10 items Introduced failure-classification defect: The new rejection handler exempts every CatalogParamsError. readControlCursor throws that class for malformed request cursors and malformed upstream response cursors; listPage validates backwardsCursor and nextCursor after receiving the response.
Existing response-validation contract: The existing table-driven cases reject upstream nextCursor and backwardsCursor strings of 4,097 characters. They establish the malformed-response path but do not check repeated-failure backoff.
Prior feedback remains applicable: The supplied completed review and #149378 (comment) identify the cursor exemption and inaccurate native-write wording. GitHub reports the earlier backoff file blob as 73cf91f33f0b4fc04e5521051923e67d762089aa, matching the current checkout. Local comparison of the earlier commit was unavailable; the GitHub blob identity supplied the comparison.
Findings 1 actionable finding [P2] Count malformed response cursors as source failures
Security None None.

How this fits together

The Codex plugin supplies native session listings to OpenClaw’s session catalog. Its local control layer reads App Server pages and returns cached sessions or host errors to callers.

flowchart TD
  A[Session catalog refresh] --> B[Local Codex page cache]
  B -->|Cached or pending page| F[Sessions or host error]
  B -->|New page attempt| C[Source backoff check]
  C -->|Retry allowed| D[Codex App Server]
  C -->|Backoff active| F
  D --> E[Validate page and update source health]
  E --> F
Loading

Before merge

  • Count malformed response cursors as source failures (P2) - The previously reported case remains: a valid list request receiving an oversized nextCursor or backwardsCursor throws CatalogParamsError from readControlCursor after the control response. This blanket exemption prevents those repeated upstream failures from opening backoff, so every refresh can repeat the failing attempt. Distinguish caller validation from response validation and extend the existing cases for both response fields.
  • Resolve merge risk (P1) - The observed production latency has not been causally attributed to repeated local-source failures, so the real latency improvement remains unmeasured.
  • Complete next step (P2) - Correct the response-cursor error classification, verify repeated-failure backoff for both cursor fields, and update the PR evidence to describe control attempts accurately.

Findings

  • [P2] Count malformed response cursors as source failures — extensions/codex/src/session-catalog-source-backoff.ts:57-60
Agent review details

Security

None.

PR surface

Source +91, Tests +201, Docs +15. Total +307 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 2 91 0 +91
Tests 2 201 0 +201
Docs 2 15 0 +15
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 307 0 +307

Review metrics

Metric Value Why it matters
Recovery delay One immediate retry; subsequent backoff grows from 5 to 60 seconds Recovery can be deferred by the backoff cap plus the caller’s refresh interval, as the PR body acknowledges.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep source health beside the existing page owner, count malformed upstream pages as source failures, and preserve caller-validation exemptions and cached-page delivery.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep source health beside the existing page owner, count malformed upstream pages as source failures, and preserve caller-validation exemptions and cached-page delivery.

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

Yes, from source: repeatedly return an oversized nextCursor or backwardsCursor to a valid local list request; each response fails validation without advancing backoff. No runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

The owner placement and bounded retry strategy are appropriate, but the blanket caller-error exemption also excludes upstream response failures and needs correction.

Full review comments:

  • [P2] Count malformed response cursors as source failures — extensions/codex/src/session-catalog-source-backoff.ts:57-60
    The previously reported case remains: a valid list request receiving an oversized nextCursor or backwardsCursor throws CatalogParamsError from readControlCursor after the control response. This blanket exemption prevents those repeated upstream failures from opening backoff, so every refresh can repeat the failing attempt. Distinguish caller validation from response validation and extend the existing cases for both response fields.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded catalog reliability improvement with a remaining response-error classification defect.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The supplied repository state identifies a maintainer-authored internal retry change, so the external-contributor proof gate does not apply. Registered-provider tests mock control requests; the production sample predates the fix, and the inspected related screenshots do not demonstrate this backoff.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/codex/src/session-catalog-backoff.test.ts extensions/codex/src/session-catalog-source-backoff.test.ts extensions/codex/src/session-catalog-listing-cache.test.ts.
  • [P1] node scripts/check-changed.mjs.
  • [P1] git diff --check.

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Separate upstream cursor-validation failures from caller-input errors and cover repeated failures for both response cursor fields.
  • Describe the mocked regression counts as control/page attempts rather than physical native writes.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-15T19:54:34.637Z sha 2beda6245c381334b47f822a9c7bc08aa6938f4e :: blocked before merge. :: none
  • reviewed 2026-09-15T20:54:32.712Z sha 100c5fe :: needs changes before merge. :: [P2] Count malformed response cursors as source failures

@steipete

Copy link
Copy Markdown
Contributor Author

Source review of 2beda6245c381334b47f822a9c7bc08aa6938f4e found one missed failure case and one evidence wording issue:

  • P2: malformed upstream cursors bypass source backoff. CodexCatalogSourceBackoff.rejected() exempts every CatalogParamsError, but readControlCursor() also throws that class for invalid native nextCursor and backwardsCursor values. A valid request followed by { data: [], nextCursor: 42 } therefore fails in session-catalog-control.ts after the native response, yet repeated failures never advance source backoff. Please distinguish caller validation failures from malformed upstream responses and cover both response cursor fields. This is a source-traced finding; I have not executed a reproduction against this branch.
  • Name the measured request boundary in the proof. The new registered-provider regression counts mocked codexControlRequest calls. These establish control/page attempts, not distinct native writes: CodexAppServerClient.requestOnce() can join an existing attempt before allocating an ID or writing, and written attempts can survive waiter expiry. The “expected 2 native calls, received 3” and “without another native invocation” wording should reflect that boundary.

The config/agent/home partitioning, cached/pending precedence, and late-failure generation fence look coherent. The separate completed-node scheduling repair in #149396 tracks node publication lifetimes; it does not replace this local-source backoff work.

@steipete
steipete force-pushed the steipete/perf-catalog-list-admission-20260915 branch from 2beda62 to 100c5fe Compare September 15, 2026 20:30
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Sep 15, 2026
Back off repeatedly failing catalog sources so newly admitted callers do not
restart the same timeout on every page. Keep retry health in a typed sibling
module while the control owner retains page sharing and stale delivery.

Preserve one immediate retry, bound recovery delays to 60 seconds, and keep
older overlapping failures from undoing a successful recovery.
@steipete
steipete force-pushed the steipete/perf-catalog-list-admission-20260915 branch from 100c5fe to 0fc8ede Compare September 15, 2026 22:14
@steipete
steipete merged commit f52355e into main Sep 16, 2026
100 checks passed
@steipete
steipete deleted the steipete/perf-catalog-list-admission-20260915 branch September 16, 2026 00:38
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
…9378)

Back off repeatedly failing catalog sources so newly admitted callers do not
restart the same timeout on every page. Keep retry health in a typed sibling
module while the control owner retains page sharing and stale delivery.

Preserve one immediate retry, bound recovery delays to 60 seconds, and keep
older overlapping failures from undoing a successful recovery.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant