Skip to content

docs(integrations): size Pi and OpenClaw context windows for the gateway ceiling - #2892

Merged
zhanghuidinah merged 2 commits into
oceanbase:masterfrom
Fengzdadi:docs/gateway-ceiling-pi-openclaw
Nov 30, 2026
Merged

zhanghuidinah merged 2 commits into
oceanbase:masterfrom
Fengzdadi:docs/gateway-ceiling-pi-openclaw

Conversation

@Fengzdadi

@Fengzdadi Fengzdadi commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

Part of #2250 (step 5: hosts behind the gateway).

Rationale for this change

The Pi and OpenClaw guides show a model entry with contextWindow: 400000 for running behind the PowerContext gateway. The gateway accepts at most 1 MiB of model input, measured after it injects context and adds its cost guidance, and configuration cannot raise that ceiling (Gateway byte capacity). A request that arrives larger fails with HTTP 413. One that grows past the ceiling through injection or cost guidance fails with HTTP 403 request_payload_too_large. In both cases the model is never called. Both hosts resend the session's whole history on every request. At a 400000-token window, a long session therefore reaches 1 MiB long before the host compacts: at about four bytes per token, Pi's trigger at that window is about 1.5 MB.

The Pi guide has a second, tighter limit. Its Core example is an enforcing target with context_window_tokens: 400000 and max_output_tokens: 32000. Core's window check counts each byte of the request as a token. It withholds with context_window_exceeded when the request's bytes plus the output limit plus a 64-token protocol reserve exceed the window, which for that target means more than 367,936 bytes (_budget in src/powercontext/builtin/inference/privacy.py). This check applies only under an enforcing Core (context_check.py). With the merged example, an enforcing Core starts withholding a Pi session at roughly 92k tokens, long before Pi compacts at 383,616.

What changes are included in this PR?

Docs only, en and zh:

  • integrations/pi.md: the example's contextWindow goes from 400000 to 80000. New paragraphs state the 1 MiB ceiling (with a link), the 413/403 outcomes, and the enforcing window check, which with the example target withholds requests over about 368,000 bytes. They explain how the value was derived:
    • Pi 0.82.1 compacts when the context the model last reported exceeds contextWindow minus compaction.reserveTokens, which defaults to 16384 (shouldCompact in dist/core/compaction/compaction.js; default in settings-manager.js).
    • That reported context includes the tool definitions and system prompt.
    • Pi checks after a prompt's run ends and before the next prompt (_checkCompaction in agent-session.js), not between tool-loop requests.
    • So 80000 compacts above 63,616 tokens, about 254 KB at four UTF-8 bytes per token, under the 367,936 bytes the example target admits.
    • With a non-enforcing Core only the 1 MiB ceiling applies, and 128000 compacts above 111,616 tokens, about 446 KB.
    • A note warns against going much smaller: after compaction, a request still carries the tool definitions, system prompt, summary, and about 20000 recent tokens (compaction.keepRecentTokens).
  • integrations/openclaw.md: the example's contextWindow goes from 400000 to 128000. The same ceiling paragraph is added, plus the derivation:
    • OpenClaw 2026.8.1-beta.2's embedded agent runs the same check, contextTokens > contextWindow - reserveTokens (checkCompaction in dist/sessions-*.js, shouldCompact in dist/agent-core-*.js).
    • OpenClaw raises the reserve to at least 20000 tokens (DEFAULT_AGENT_COMPACTION_RESERVE_TOKENS_FLOOR in dist/openclaw-runtime-*.js).
    • By default it checks after each run and before the next prompt. Mid-turn precheck is opt-in in OpenClaw's docs.
    • So 128000 compacts by 108,000 tokens at the latest, about 432 KB.
    • The guide already requires a non-enforcing Core for OpenClaw, so the window check does not apply.
  • Both guides say the values are derived from the host's source and the limits, not measured.

Decision: the four-bytes-per-token figure matches the Kimi Code guide's assumption on its gateway branch. The values leave room for the gateway's additions, which are small: a prepared context of at most 8192 bytes (default_max_bytes in pc-gateway-types/src/prepare.rs) and steering instructions of at most 4,096 bytes. The rest of the margin covers JSON overhead and the tool results that one prompt or run adds before the host's next check.

Overlap with open PRs: #2893 edits pi.md and #2895 edits openclaw.md, both in the same gateway sections, and #2889 and #2735 also edit these guides. None of them changes the model entries or the paragraphs this PR adds. Against this branch, git merge-tree is clean for #2889 and for the current heads of #2893 (f7cd8a5) and #2895 (6ed8bea), which merge master too. #2735 conflicts only in release/upgrade-support.json, as it does against master; this PR does not touch that file.

Are there any user-facing changes?

Yes, docs only. The Pi and OpenClaw gateway examples now use a smaller contextWindow and explain the gateway's input ceiling. Users who copied 400000 should lower it. No code, API, or persisted-format changes.

How was this change tested?

  • pnpm check:links in website/, run offline (no network in the sandbox, existing node_modules, UV_OFFLINE=1): link tests pass, and links are validated in 379 public pages and 672 repository files.
  • The compaction triggers were read in the host packages already on disk, without running the hosts:
    • Pi: @earendil-works/pi-coding-agent 0.82.1, the version installed for the package's devDependencies range (^0.82.0).
    • OpenClaw: openclaw 2026.8.1-beta.2, the plugin's peerDependencies floor.
  • The Core window check was read in src/powercontext/builtin/inference/privacy.py and src/powercontext/builtin/runtime/context_check.py.
  • No host or model was run, and the byte sizes at the triggers are estimates.

AI usage statement

Written with Claude Code (Claude Opus 5.5). It read the host sources and Core code, derived the values, and drafted the en and zh text. Another Claude Code session (Claude Opus 5.5) reviewed the commit and checked this description's claims against the guides, the Core and gateway code, and the overlapping PRs before it was opened. After #2630 merged, the first session merged master into the branch and reran the docs checks, and the reviewing session checked the merge, the merged guides, and this description's overlap claims before the push.

…way ceiling

The gateway accepts at most 1 MiB of model input after injection and cost
guidance, and both hosts resend the whole history on every request. At the
examples' 400000-token window, a long session reached that ceiling before the
host compacted, so its requests failed with 413 or 403
request_payload_too_large.

State the ceiling in both guides and derive the example contextWindow from
each host's compaction trigger: 128000 for OpenClaw (20000-token reserve) and,
for Pi, 80000, so it also fits the byte-counted window check of the guide's
enforcing example target; 128000 applies to Pi with a non-enforcing Core.

Part of oceanbase#2250.

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 997eb6b. No blocking defect found in this documentation-only change. The smaller example windows and estimated compaction thresholds are consistent with the referenced host implementations and the Core/Gateway limits. No new database tables, migrations, or public interfaces. Merge score: 85/100.

Validation covered host-source inspection, bilingual examples and link targets, link-validation tests, and a conflict-free merge-tree check. No live host/LLM long-session acceptance was performed; the documented byte estimates are not a hard guarantee. CI remains blocked by the persistence compatibility digest check: the same failure reproduces on the base and head with identical managed-input digests. Required CI still needs to pass before merging.

@hireview001 hireview001 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhanghuidinah zhanghuidinah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@zhanghuidinah
zhanghuidinah merged commit 45ef918 into oceanbase:master Nov 30, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants