Skip to content

fix(gateway): retain thinking facts across partial catalog rows - #170659

Merged
steipete merged 1 commit into
mainfrom
dbasync/redmain-metadata-thinking-cache
Oct 13, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/redmain-metadata-thinking-cache

Conversation

@steipete

@steipete steipete commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session list rows can lose custom thinking labels or resolve the same policy twice when later catalog rows omit model metadata. This started after #170589 added configured reasoning to the cache key.

Keep thinking facts in their existing row-context cache, whose owner replaces the context on config and catalog publication. Configured reasoning still reaches policy resolution. Add a regression that selects a real runtime route, then reads through an empty prepared catalog while retaining the same owner.

Evidence

Two Codex reviews found no actionable issues; changed-file formatting, type-aware lint, and diff checks pass. Exact-file hosted proof: https://github.com/openclaw/openclaw/actions/runs/38349301790 (7/7 tests, zero skips, 33.45s Vitest). PR CI run 38349551198 passed (45 successful jobs, 26 skipped), including the aggregate gate, types, lint, and architecture checks. Madge found zero cycles; T1 remained 455 live / 9 compatibility calls and every dialect group remained zero. The corrected PR-context run also passed. The local attempt stopped during sparse-checkout setup before executing any tests (151.57s); no local pass is claimed.

This changes no database operation, schema, or security boundary. No SQL or T1 savings are claimed; no SQL harness run. Two files, +41/-3 lines, including production +2/-1. Accepted edge: partial catalog rows reuse the context owner’s last complete thinking facts until its normal publication invalidation.

Keep prepared thinking facts keyed by their row-context owner when later rows
omit configured reasoning metadata. Config and catalog publication already
replace that context; configured reasoning remains an input to policy resolution.

Add a runtime-route donor regression alongside the existing missing-catalog and
identity-only cases. This retains the reasoning-disabled route behavior from
#170589 while repairing its metadata cache regression.
@clawsweeper

clawsweeper Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T05:07:42.226251Z 33506c3 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Oct 13, 2026
@steipete
steipete merged commit 7b871cd into main Oct 13, 2026
137 of 138 checks passed
@steipete
steipete deleted the dbasync/redmain-metadata-thinking-cache branch October 13, 2026 05:23
steipete added a commit that referenced this pull request Oct 13, 2026
## What Problem This Solves

Interrupted provider streams could save generated text with zero or partial token counters and present them as complete usage. A cancelled Ollama `/v1` stream reproduced `Context: 0/33k` despite saving text.

## User Impact

Interrupted or unmeasured responses report usage as unavailable in status, session metadata, accounting, and usage summaries. Complete measured-zero usage remains zero, and successful streams retain exact provider accounting. Known historical subtotals remain visible without being presented as complete totals. Compatible HTTP responses omit unavailable usage while completing their normal lifecycle.

No configuration, database migration, or protocol version change is required. The optional completeness fact preserves legacy producer and stored-transcript interpretation; it cannot reconstruct missing historical usage.

## Why This Change Was Made

The transport owns accounting completeness. The same fact flows through normalization, run aggregation, the existing session snapshot and abort-partial transaction, then reporting consumers. Terminal usage survives a later transport error. Transcript-backed status and session rows preserve authoritative zero instead of substituting an estimate.

This preserves @OWWZO's commits and credit. Main `a59427ccc909c8cc6077ef7c9826e2ba4953f73a` was merged without rebasing or force-pushing. Current head: `c75898aa34c7c55aacfcc451c4e36dfa0e08f38d`.

Against that merged base: production +858/-484 (net +374), tests/fixtures +1098/-148, docs +10/-1. The necessary growth carries one completeness fact through existing typed consumers; superseded partial handling is removed. Prompt/tool text is unchanged; token delta is zero.

## Evidence

- Real CLI → isolated Gateway → Ollama `/v1`, `llama3.2:latest`, on main `706e08c4431947585166891a60c616366c87cf64`: cancellation saved 945 characters with zero/fresh usage and `/status` showed `Context: 0/33k`. Successful control: exact 2605 input / 19 output tokens.
- Repaired generation at `87fa95081e10f082b7caa6543207b8563a3759f7` saved 4607 characters after interruption with unavailable usage. Successful `/v1` and native controls retained exact provider accounting (1809/4 and 1808/10).
- Real CLI `/status`, `chat.history`, and `sessions.list` readback at `8dd5b2bea6f9a6a8f4c43bcaa5414b8dce0e58f9` reopened that saved interruption: `Tokens: unavailable (incomplete response)`, `Context: ~4.2k/33k (13% est)`, null totals, false freshness. This is later persistence/status readback of the real generation, not a fresh-generation claim for the final head.

Focused local validation of the merged implementation (the final commit only removes a stale max-lines exemption):

| Suite | Result | Wrapper wall time |
| --- | --- | --- |
| Lane controllers | 36 passed | 178.95 s |
| Original 28-file Bun group | 500 passed | 230.82 s |
| Storage and yielded Stop | 21 passed | 410.74 s |
| Usage/readers and metadata | 30 passed | 340.90 s |
| CLI/transport siblings | 72 passed | 225.23 s |

Repository build, scoped core/UI/agent/Gateway types, lint, formatting, and all seven ratchet/config checks pass. The max-lines gate correctly identified the now-unneeded CLI exemption; it was removed and the check passed. No test assertion or deadline was weakened. The package-boundary declaration compiler used its supported 900-second budget, based on the prior cold-build timing; it completed successfully.

## CI and review

Main was merged without conflicts. Its landed fixes now cover the two inherited failures from the prior CI run:

- Workboard asset manifest: `faa8ad8e59833d23d606dbc3b73a7258265f094a`. On a fresh detached main checkout, the repository generator passed in 1.89 seconds and left the manifest unchanged.
- Partial-catalog thinking metadata: `7b871cd72f219d94f27f7e4b3ddc9bbb12a0f544` (#170659). The exact metadata suite passed 7/7 on fresh main in 60.64 seconds. Both checks used main `89a3addb0de424ee46409938d81b289a34166470`; the relevant owners are unchanged in the merged main base.

The prior task-suggestion scroll failure was classified as unrelated: head and exact main base each passed ten complete bundled UI E2E file runs (100 cases each), with identical summary scroll dimensions at all three viewports. The unchanged suggestion renderer, controller, and CSS do not consume usage in that empty-transcript fixture. The original Linux browser/timing trigger remains unobserved on macOS.

Independent Codex review of the committed branch was scoped-clean through P2. The final one-line max-lines baseline deletion received a separate scoped-clean P2 review. The worktree contains no uncommitted source changes.

Exact-head [CI run 38372789852](https://github.com/openclaw/openclaw/actions/runs/38372789852) completed successfully: 101 jobs passed, 21 skipped, zero failures. The exact-head combined CI gate and applicable security review also passed.

The earlier ClawSweeper review found no code defects. Its Telegram Test Server and latest-stable upgrade proof requests remain explicitly accepted limitations. Historical CLI/Gateway/Ollama proof above is reused without claiming fresh generation on this merge head.

Before (synthetic mock-Gateway fixture):

![Before: incomplete usage appears as a confident total](https://github.com/user-attachments/assets/f4ede639-5775-420e-96c1-1dc2db10d054)

After (same synthetic fixture):

![After: incomplete usage is unavailable while known session data remains visible](https://github.com/user-attachments/assets/450274c5-47be-45f4-9288-3eabb381cda7)

Co-authored-by: OWWZO <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…claw#170659)

Keep thinking-policy memoization under its existing row-context owner while retaining configured reasoning as resolver input. Partial catalog rows reuse complete facts until normal config or catalog publication invalidates the context.

Regression proof: hosted exact file 7/7; PR CI 38349551198 passed with unchanged T1 and dialect counts. Two scoped Codex reviews found no actionable issues.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
## What Problem This Solves

Interrupted provider streams could save generated text with zero or partial token counters and present them as complete usage. A cancelled Ollama `/v1` stream reproduced `Context: 0/33k` despite saving text.

## User Impact

Interrupted or unmeasured responses report usage as unavailable in status, session metadata, accounting, and usage summaries. Complete measured-zero usage remains zero, and successful streams retain exact provider accounting. Known historical subtotals remain visible without being presented as complete totals. Compatible HTTP responses omit unavailable usage while completing their normal lifecycle.

No configuration, database migration, or protocol version change is required. The optional completeness fact preserves legacy producer and stored-transcript interpretation; it cannot reconstruct missing historical usage.

## Why This Change Was Made

The transport owns accounting completeness. The same fact flows through normalization, run aggregation, the existing session snapshot and abort-partial transaction, then reporting consumers. Terminal usage survives a later transport error. Transcript-backed status and session rows preserve authoritative zero instead of substituting an estimate.

This preserves @OWWZO's commits and credit. Main `63bc8291bdc629f00803ccb14c591def212b37b3` was merged without rebasing or force-pushing. Current head: `c75898aa34c7c55aacfcc451c4e36dfa0e08f38d`.

Against that merged base: production +858/-484 (net +374), tests/fixtures +1098/-148, docs +10/-1. The necessary growth carries one completeness fact through existing typed consumers; superseded partial handling is removed. Prompt/tool text is unchanged; token delta is zero.

## Evidence

- Real CLI → isolated Gateway → Ollama `/v1`, `llama3.2:latest`, on main `17b55930758797692cecae98ec0e7a254d06563b`: cancellation saved 945 characters with zero/fresh usage and `/status` showed `Context: 0/33k`. Successful control: exact 2605 input / 19 output tokens.
- Repaired generation at `87fa95081e10f082b7caa6543207b8563a3759f7` saved 4607 characters after interruption with unavailable usage. Successful `/v1` and native controls retained exact provider accounting (1809/4 and 1808/10).
- Real CLI `/status`, `chat.history`, and `sessions.list` readback at `8dd5b2bea6f9a6a8f4c43bcaa5414b8dce0e58f9` reopened that saved interruption: `Tokens: unavailable (incomplete response)`, `Context: ~4.2k/33k (13% est)`, null totals, false freshness. This is later persistence/status readback of the real generation, not a fresh-generation claim for the final head.

Focused local validation of the merged implementation (the final commit only removes a stale max-lines exemption):

| Suite | Result | Wrapper wall time |
| --- | --- | --- |
| Lane controllers | 36 passed | 178.95 s |
| Original 28-file Bun group | 500 passed | 230.82 s |
| Storage and yielded Stop | 21 passed | 410.74 s |
| Usage/readers and metadata | 30 passed | 340.90 s |
| CLI/transport siblings | 72 passed | 225.23 s |

Repository build, scoped core/UI/agent/Gateway types, lint, formatting, and all seven ratchet/config checks pass. The max-lines gate correctly identified the now-unneeded CLI exemption; it was removed and the check passed. No test assertion or deadline was weakened. The package-boundary declaration compiler used its supported 900-second budget, based on the prior cold-build timing; it completed successfully.

## CI and review

Main was merged without conflicts. Its landed fixes now cover the two inherited failures from the prior CI run:

- Workboard asset manifest: `31dfabbb3230d76c696f34bf91a554c6819f9b89`. On a fresh detached main checkout, the repository generator passed in 1.89 seconds and left the manifest unchanged.
- Partial-catalog thinking metadata: `8740cb3b96da88ef10b55d77cd6457ba7fb26bde` (openclaw#170659). The exact metadata suite passed 7/7 on fresh main in 60.64 seconds. Both checks used main `7c05506250656f245f7d01394b78ab4e6ee832bc`; the relevant owners are unchanged in the merged main base.

The prior task-suggestion scroll failure was classified as unrelated: head and exact main base each passed ten complete bundled UI E2E file runs (100 cases each), with identical summary scroll dimensions at all three viewports. The unchanged suggestion renderer, controller, and CSS do not consume usage in that empty-transcript fixture. The original Linux browser/timing trigger remains unobserved on macOS.

Independent Codex review of the committed branch was scoped-clean through P2. The final one-line max-lines baseline deletion received a separate scoped-clean P2 review. The worktree contains no uncommitted source changes.

Exact-head [CI run 38372789852](https://github.com/openclaw/openclaw/actions/runs/38372789852) completed successfully: 101 jobs passed, 21 skipped, zero failures. The exact-head combined CI gate and applicable security review also passed.

The earlier ClawSweeper review found no code defects. Its Telegram Test Server and latest-stable upgrade proof requests remain explicitly accepted limitations. Historical CLI/Gateway/Ollama proof above is reused without claiming fresh generation on this merge head.

Before (synthetic mock-Gateway fixture):

![Before: incomplete usage appears as a confident total](https://github.com/user-attachments/assets/f4ede639-5775-420e-96c1-1dc2db10d054)

After (same synthetic fixture):

![After: incomplete usage is unavailable while known session data remains visible](https://github.com/user-attachments/assets/450274c5-47be-45f4-9288-3eabb381cda7)

Co-authored-by: OWWZO <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant