Skip to content

fix(status): correct stale context limits after model discovery - #165991

Merged
steipete merged 97 commits into
openclaw:mainfrom
snotty:fix/status-published-context-window
Oct 11, 2026
Merged

steipete merged 97 commits into
openclaw:mainfrom
snotty:fix/status-published-context-window

Conversation

@snotty

@snotty snotty commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Local model discovery, refresh, or a model/runtime switch can leave status and session reports showing an older context limit, another runtime's limit, or a generic denominator.

User Impact

Reports use the selected model/runtime's admitted capacity, configured caps, or a matching verified run budget. Unknown capacity stays ? (null in session-list JSON), without an invented percentage. Spawned workspaces retain their own catalog/budget scope. Execution and compaction budgeting are preserved.

Why This Change Was Made

This preserves @snotty's original reporting repair and consumes the existing model catalog and context-provenance owners. CLI sessions passively reads the inspected local Gateway's prepared catalog; explicit-store and other-workspace rows use scoped saved facts. Failed Gateway reads warn once and retain the offline path. Runtime choices remain tagged so one runtime cannot supply another's capacity.

The branch is independent of Copilot #156636 and retains work already landed in #159731 and #168309. Main 61722c8ecbd27cdb960e7a6f9055f17ad3ae8a04 was merged without rebasing or rewriting contributor history, including @snotty's latest regression commit fbfa840f2b49. The conflict resolution keeps main's configured/fixed-context consolidation and its intentional retirement of redundant status tests. The contributor's captured-cache tests remain.

Evidence

Prior live proof used isolated state and real OpenClaw CLI/Gateway entry points on main c6d71fae0ed1 and repaired head 3366edb5ae30:

  • Ollama qwen3:8b answered a real turn. After selecting discovered qwen3:4b, main CLI sessions reported 200000; repaired CLI reported 32768 before another turn, and the next Qwen turn admitted 32768.
  • A task-owned llama-server answered at 16384, then restarted at 32768. After models.list refresh, main CLI sessions remained 16384; repaired CLI/Gateway rows and /context json reported 32768, and another real turn completed. Main /status already handled this known-capacity refresh correctly.
  • After removing a task-owned Ollama alias and refreshing discovery, main /status reported ?/200k and CLI 200000. Repaired /status reported ?/? and CLI null. The repaired head also completed another real Qwen3:4b turn at 32768.

Main-failing status regressions establish stale-cache and other-runtime errors. A spawned-workspace CLI regression failed before its repair when the parent catalog's 131072 replaced a matching saved 16384 budget; the repaired path preserves workspace ownership.

Main-merged head 01083e250da949544106f0bfebcc520de5c6e185 passes 213 focused tests: nine primary files / 180 cases in 795.55s wall, context/status adapters / 31 cases in 293.68s, and Gateway health scheduling / 2 cases in 224.94s, all with one worker. Cold worker preparation dominates these busy-host wall times; no sleeps, retries or worker pins were added. Core types, all 28 consuming test-type graphs, touched lint/formatting, assertion safety, max-lines, line-cap, timeout-race, mock-export, config-doc and plugin-inventory checks pass. Gateway worktree preparation/build passes. Fresh Codex autoreview is scoped-clean through P2. The reporting change introduces no prompt text/token delta.

Incoming main directly repairs the earlier Bun observer failure in 952c102dde987: invalidate exact row facts after installing the reader observer, while retaining bounded-key, sibling, SQL and reuse assertions. Correction to the previous diagnosis: the recovery case's expected-zero failure was the shared Gateway-work drain assertion, not a membership authorization assertion. The exact-head CI run 38164531708 passed all 62 executed jobs, including openclaw/ci-gate. Blacksmith Testbox verified that source/tree and passed the original nine-file Linux Bun group 101/101 in 86.01s wall, including the observer and both recovery cases. The initial Testbox attempt lacked Bun; its prerequisite was repaired using the repository's checksum-pinned installer, and the successful lease was stopped. No remaining red CI job required a main-base comparison.

ClawSweeper's accepted P2 is fixed in final candidate 1cf9a6c53b953987f503d81814b378c0d4f66337: corrupt, unreadable or unverifiable optional Gateway locks now warn once and fall back to saved/configured capacity without contacting an unverified owner. The CLI boundary regression failed before repair and all 24 session cases passed in 186.23s wall afterward. The real command entry point protects the inspection/transport/offline boundary that smaller resolver tests cannot cover. Core/command-test types, lint, formatting and required ratchets pass again; final-head Codex autoreview is scoped-clean through P2. The Gateway/storage paths from the Linux proof are unchanged. Final-head CI run 38167012438 passed all 62 executed jobs, including openclaw/ci-gate (25 skipped). ClawSweeper reviewed exact head 1cf9a6c53b95 and lists no code findings; its remaining requests are proof-only and covered by the campaign lead’s explicit override. No inherited-CI exception is needed.

Telegram, live spawned-workspace, and real-CLI unverifiable-lock captures remain outside the maintainer-directed proof scope; the campaign lead overrides these proof-only holds. No code finding is waived.

The current diff versus merged main is production +456/-226, tests/support +515/-84, docs +13/-1, and one obsolete mock-baseline entry removed. The net 230 production lines implement passive catalog transport and explicit owner/runtime binding; superseded fallbacks were removed without adding a second capacity owner. No configuration, schema, dependency or protocol change is introduced by this repair.

zhangguiping-xydt and others added 20 commits September 8, 2026 18:08
The exported flush window resolver was reachable only from its own
tests, so the bundled cold-budget fallback could regress in production
while the suite stayed green. Remove the helper and cover the bundled
catalog windows through runMemoryFlushIfNeeded, the actual maintenance
boundary that feeds resolveMemoryFlushPlan.
Embedded runs labeled every run-level context window as legacy resolved, which cold session projections intentionally distrust, so sessions list and /context fell back to the 200k default when synchronous catalog lookup could not see the model. Carry the resolution source from run preparation and persist model- or config-resolved windows as resolved-v1; the generic default keeps the legacy marker.
When Copilot /models omits or reports an invalid max_context_window_tokens,
the mapper filled in the 128k default as if it were a reported native
ceiling. With a real max_prompt_tokens present, that fabricated window
became authoritative and could both clamp the prompt limit and grant
replacement authority over the synthetic fallback.

Mark that default with the same contextWindowSource: "synthetic"
provenance used by the unknown-model branch, never let the estimate sit
below a real prompt limit, and thread the marker through the provider
result copy, persisted catalog schema, model registry and config merge.
Authored contextWindow/contextTokens clear the marker. Supersession now
requires a reported limit: a real prompt limit, or a non-synthetic native
window. A genuinely reported 128k window is unchanged.

Reported-by: snotty <[email protected]>
…ted owner

An existing session whose persisted telemetry came from the synthetic
128k fallback stayed at 128k after discovery until a later run, because
the projector trusted it as runtime telemetry and took min(persisted,
resolved).

- Embedded runs stamp contextTokensSource: "synthetic" when the prepared
  budget is exactly a provider unknown-model estimate (no reported prompt
  limit, authored cap, modelsConfig sizing or narrower caller budget),
  including failed/cancelled attempt metadata.
- Synthetic rows are never trusted telemetry, including locked sessions.
- /status and session_status bind the displayed session to its admitted
  prepared owner (agent + spawned workspace) before choosing capacity. A
  synthetic row takes that owner's accepted capacity (or an authored cap).
  An unbound, retired, failed or model-less owner settles as owner-scoped
  unavailable and renders unknown, never the stale estimate or another
  owner's process-global cache value.
- Genuine (non-synthetic) persisted 128k stays conservative.
Adds a human-run procedure and script that capture /status and
session_status context lines from a patched scratch Gateway for a fresh
session, existing-session recovery and an account switch. Output is
redacted (tokens, IPs, phone numbers, emails, private endpoints, paths,
account/session ids) and the script never starts a Gateway, writes
config or reads credentials. --self-test exercises the redaction rules.
Authored models config windows and caller budget caps are removable operator config. Persisting them as resolved-v1 let cold session projection keep publishing a cap after the operator removed it.
A model that declares context-window options sizes its budget from the session's window selection (or the declared default). The cold session reader matches resolved-v1 rows only by provider, model, and harness, so a persisted 200k selection could outlive a later switch to 1m, and the reverse. Keep those budgets on the legacy resolved marker.
embedded-agent-runner.e2e.test.ts is over the line cap, and the line-cap ratchet rejects any growth there. The provenance cases only need the fast-run mocks, so they live in their own e2e file.
@clawsweeper

clawsweeper Bot commented Oct 6, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR makes context reports use current, runtime-specific model capacity and show unknown capacity explicitly.

Example: Select discovered Ollama qwen3:4b before another turn.

  • Before: CLI session JSON reports contextTokens: 200000.
  • After: CLI session JSON reports contextTokens: 32768.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent reporting repair with resolved findings and successful current-head CI; real runtime coverage remains partial.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Context reports show stale or unrelated capacity and misleading percentages after model discovery, refresh, or runtime changes.
Reason: The demonstrated reporting inconsistency warrants repair, and recorded area-owner implementation separates it from execution-budget changes.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this useful, maintainer-engaged repair open: current main retains the reporting defect, and the previous code findings are resolved.

Priority: P2
Reviewed head: 1cf9a6c53b953987f503d81814b378c0d4f66337

Before merge

  • Add real behavior proof - The body records real CLI/Gateway discovery, refresh, and unknown-capacity results on reporting head 3366edb; the prior completed review inspected HTTP stale-cache receipts. Add redacted output showing a spawned workspace retains 16384 against parent capacity 131072, Telegram /status and /context show the corrected denominator, and the real CLI lists saved sessions with one warning after an unverifiable lock. Alternatively, link an independently recorded maintainer decision waiving those specific scenarios; the body assertion alone does not establish that override. Redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Findings

None.

Tests

  • Missing end-to-end proof: Remaining runtime captures cover spawned-workspace capacity isolation, Telegram status/context replies, and real CLI recovery from an unverifiable Gateway lock.
Agent review details

How this fits together

Status and session readers combine scoped model catalogs, configured limits, runtime selection, and verified session budgets to produce CLI, Gateway, and channel reports.

flowchart TD
A[Scoped model catalog] --> D[Runtime capacity selection]
B[Configured limits] --> E[Context projection]
C[Verified session budget] --> E
D --> E
E --> F[CLI and Gateway reports]
E --> G[Channel status and context replies]
Loading

Technical review

Best possible solution:

Land the reporting repair through the existing catalog and provenance owners after the required proof is supplied or explicitly waived.

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

Current-main source exposes stale-cache clamping and generic denominator fallback, supported by recorded base-failing regressions and real discovery results; no target code was executed during this review.

Is this the best way to solve the issue?

The reporting-specific cache bypass and scoped catalog reads address the demonstrated defect while retaining configured limits, verified provenance, and existing execution resolution.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Cache-based context resolution changes intended behavior with a stated reason (399f5bc: Keep provider-aware context metadata and constrain context to known model windows.)
  • Prepared status capacity keeps the original intent (5f7fa33: Carry prepared selected and active model windows into the canonical resolver while preserving authored caps.)
  • Persisted session provenance keeps the original intent (7c65bbc: Trust session capacity only under the producing model and runtime ownership rules.)
  • Cold-session verified budgets keeps the original intent (d6a7b42: Preserve qualifying model-owned budgets when synchronous discovery is unavailable.)
  • Status cache warmup changes intended behavior with a stated reason (33aef65: Allow cold status readers to observe discovered metadata without delaying Gateway readiness.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1c1affa adds src/agents/context-resolution.ts:292 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1c1affa936f6; files: src/agents/context-resolution.ts)
  • Jason (Json): Raw commit 7c65bbc adds src/status/status-message.ts:768 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7c65bbcee31b; files: src/status/status-message.ts)
  • Vincent Koc: Raw commit 5f7fa33 adds src/status/status-message.ts:746 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5f7fa33f3f0b; files: src/status/status-message.ts)

PR surface

Source +230, Tests +431, Docs +12, Other -1. Total +672 across 28 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 13 456 226 +230
Tests 12 515 84 +431
Docs 2 13 1 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 28 984 312 +672

Review metrics

Metric Value Why it matters
Production versus test growth Production +456/-226; tests and support +515/-84. Production growth carries passive catalog transport and scoped runtime selection; regressions protect cache isolation, unknown capacity, workspace ownership, and offline recovery.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Incorrect denominators and percentages mislead session monitoring; the repair preserves execution and compaction budgeting.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The PR changes context denominators and percentages visible in Telegram /status and /context replies.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-11T05:52:31.988Z sha 07326eb :: needs real behavior proof before merge. :: [P2] Preserve runtimeChoices in the CLI catalog conversion
  • reviewed 2026-10-11T06:13:29.652Z sha 07326eb :: needs real behavior proof before merge. :: [P1] Skip unscoped catalog lookup when aggregate status has no agent owner | [P2] Preserve runtimeChoices in the CLI catalog conversion | [P2] Update existing status regressions for the new capacity contract
  • reviewed 2026-10-11T08:07:45.335Z sha 00d3a17 :: needs real behavior proof before merge. :: [P2] Preserve spawned-workspace ownership in Gateway catalog reads
  • reviewed 2026-10-11T08:48:23.272Z sha 3366edb :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T09:31:36.741Z sha 3366edb :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-11T17:03:24.325Z sha fbfa840 :: needs real behavior proof before merge. :: [P2] Keep optional Gateway lock inspection from aborting session listing
  • reviewed 2026-10-11T18:47:11.128Z sha 01083e2 :: needs real behavior proof before merge. :: [P2] Keep optional Gateway lock inspection from aborting session listing
  • reviewed 2026-10-11T19:22:00.768Z sha 1cf9a6c :: needs real behavior proof before merge. :: none

Reviewed October 11, 2026, 3:45 PM ET / 19:45 UTC (Revision 14).

@snotty

snotty commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added revision-bound running-Gateway before/after proof and inspected captures to the PR body for unchanged head c006ac66e2d8330a909e127025170aec8463d7dd. Native HTTP session_status displays 128k on main / 1.1m on this PR with equal supplied 1,050,000 metadata and the disclosed stale-cache fixture; both keep the 64k cap and unchanged 128,000 execution resolver. Redacted receipts and source/build bindings.

This is isolated local Gateway proof, not Telegram Test Server transport. The repository test-broker prerequisites are unavailable here; that separate gate is explicitly left unfulfilled rather than borrowing production credentials. Please assess the added runtime evidence and route any remaining real-Telegram proof to an environment with the leased broker access. No product-source update, production restart, or merge was performed.

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Oct 6, 2026
@steipete
steipete marked this pull request as draft October 11, 2026 06:03
@steipete
steipete marked this pull request as ready for review October 11, 2026 06:05
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Keep additional Gateway runtime capacities in CLI catalog conversion. Resolve summary defaults only through an available agent owner, and keep namespaced transcript model IDs bound to their current provider catalog. Update neighboring regression fixtures to supply admitted metadata or expect unknown capacity.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Oct 11, 2026
@snotty

snotty commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Narrow regression-only follow-up

Published commit fbfa840f2b49 on this existing PR: only src/agents/context.test.ts, +74/−1, six new cases, zero production changes. Its parent is 3366edb5ae304408f30ccd4e9e3e634a651236c0. This adds coverage for the reporting opt-out already present here, not a duplicate implementation or competing cache/budget owner.

The real resolver reproduces four assertion failures with 12 passing controls when only its two production owners are reverted to base 69d80d5fc82b8d0c177eea453cac2e495d8ba8ca. With this PR's owners: 16/16 context cases and 28/28 unchanged native-window guards pass. Default execution lookup, genuine 128k, authored 64k, fixed contracts, unknown capacity and explicit fallback controls are retained; no existing assertion or mock was weakened.

The consuming agents-root type graph, touched-file lint, format, whitespace/patch checks and independent static review pass. Context-suite cost: 8.42s wall, including cold transform/setup; Hosted product-test CI/cost is not yet verified for this commit.

Proof and patch: https://gist.github.com/snotty/5030d0d5ca970b0ade000e3a9d7b4c64 . Budget controls for the unchanged #138087 head are recorded separately. This is source-only evidence; it does not clear the existing hosted CI, security, live-transport or maintainer gates, and no merge or runtime deployment is claimed.

steipete and others added 2 commits October 11, 2026 10:58
Merge current main into the contributor branch, preserving its history. Keep the reporting-only cache bypass in the refactored resolver and retain main’s removal of superseded status tests.
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 11, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Oct 11, 2026
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants