Skip to content

test(agents): gate prompt and tool bytes on the Gateway, configured-agent and Codex routes - #206948

Merged
obviyus merged 7 commits into
mainfrom
core/ci-invariants
Nov 27, 2026
Merged

obviyus merged 7 commits into
mainfrom
core/ci-invariants

Conversation

@obviyus

@obviyus obviyus commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

The only prompt byte gate (FRESH_INSTALL_SYSTEM_PROMPT_BUDGET_BYTES, 12,288 B) checks a hand-written fresh-install renderer fixture. Every other surface the model receives can grow without a failing check:

  • the system prompt and the compacted tool definitions that the embedded runtime sends for a Gateway WebChat turn and for a configured channel agent;
  • the Codex app-server prompt layers and dynamic tool specs, which are the default route for native OpenAI.

Tool and prompt bytes are a reported cost (#200920). A 2026-11-27 audit of production first requests measured them at 18–56 KB of tools per request, with no gate on any route except the fresh fixture.

Solution

Gate each route at the owner that already builds it. Each new ceiling is the size measured on main plus 5%, rounded up to 256 B. Growth within that margin passes.

Route Surface Measured on main Ceiling Test
Fresh install (renderer fixture) system prompt 11,395 B 12,288 B (unchanged) system-prompt.inventory-snapshot.test.ts
Gateway WebChat turn, fresh install, embedded runtime system prompt 13,599 B 14,336 B attempt-prompt-budget.test.ts (new)
Gateway WebChat turn, embedded runtime compacted tool definitions 17,927 B 18,944 B same
Configured Telegram agent (workspace files, setup complete) system prompt 13,676 B 14,592 B same
Configured Telegram agent (workspace files, setup complete) compacted tool definitions 21,058 B 22,272 B same
Codex app-server Telegram turn model-bound layer text 12,981 B 13,824 B test/scripts/prompt-snapshots.test.ts
Codex app-server Telegram turn dynamic tool specs 62,551 B 65,792 B same
  • attempt-prompt-budget.test.ts runs the production attempt pipeline:
    1. prepareEmbeddedAttemptToolBase
    2. prepareEmbeddedAttemptBundleTools
    3. prepareEmbeddedAttemptToolCatalog, which compacts the tools as sent
    4. prepareEmbeddedAttemptSystemPrompt, with the tool directory, skills and bootstrap files
  • Installed plugin tools, bundle MCP servers and paired-node probes vary by host, so they are mocked out. The budget covers core output.
  • The workspace path is pinned to /workspace and the docs and source paths to /repo, because the prompt contains them. The Runtime: line (host, OS, Node version) still varies by about 20 B across hosts.
  • The fresh WebChat turn has first-run bootstrap pending. The configured agent has recorded setup complete.
  • Tool bytes are compact JSON of { name, description, parameters } for the compacted set. Deferred tools reach the model by name only, so their schemas are not in these numbers.
  • The Codex prompt is the sum of every non-json fenced layer body in the generated happy-path snapshot, from the layers heading to the end of the file. Renderer prose is not counted, and a relabeled or new layer is still counted.
  • The embedded ceilings live in one table, PROMPT_BUDGET_BYTES, in src/agents/system-prompt-manifest.ts. The Codex pair sits beside its snapshot test.
  • A PR that shrinks a surface should lower its ceiling. Nothing enforces that.

Impact

Contributors only. There is no runtime change. A change that grows a route's prompt or tool bytes past 5% fails CI until the growth is cut or the ceiling is raised on purpose in review.

Evidence

  • Green on main 28b6938f (rebased), final head: inventory 3/3, attempt-prompt-budget 2/2, prompt snapshots 8/8.
  • Red on a synthetic regression against the same code (throwaway edits, removed): +1,512 B in the shared Execution Bias prompt section, +2,016 B in the exec description and +3,990 B in the sessions_spawn description. All 7 gates fail:
    • fresh prompt 12,908 > 12,288
    • WebChat prompt 15,112 > 14,336; WebChat tools 19,944 > 18,944
    • Telegram prompt 15,189 > 14,592; Telegram tools 23,075 > 22,272
    • Codex prompt 14,494 > 13,824; Codex tools 66,540 > 65,792
  • Adversarial review, two rounds. Round 1 found tools measured before compaction, a Gateway fixture without the directory, skills or bootstrap, and a markdown slice with renderer prose. Round 2 found a Codex sum that could drop to 0 B on a relabeled fence, a configured agent measured in first-run state, and host checkout paths in the prompt. All six are fixed here.
  • Known gaps:
    • Deferred tool schemas are not gated on the embedded routes. On the Telegram route, 29 deferred tools (about 84 KB, automations alone 23.7 KB) appear in the prompt by name only. The Codex dynamic-tool gate covers sessions_spawn and the openclaw namespace in full.
    • The Telegram message schema comes from a two-action test channel plugin, not the real Telegram plugin.
    • Plugin, MCP and node tools and new bundled skills are not budgeted.
    • Steps after the catalog are not measured: the listing pin, the prompt-build tool policy and transport serialization.
    • Not covered: the Codex-owned native layers (AGENTS.md, environment, memories) that Codex adds after OpenClaw sends the thread params.
    • A failing gate prints the total only, not a per-tool breakdown.

…l bytes

- Gateway WebChat turn and configured Telegram agent: system prompt and compacted tool definitions, built by the production attempt pipeline (tool base, bundle, catalog, prompt).
- Codex app-server Telegram turn: model-bound layer text and dynamic tool specs from the happy-path snapshot.
- Ceilings are main's measured bytes plus 5%, rounded up to 256 B; one table at the prompt manifest owner for the embedded routes, the Codex pair beside its snapshot test.
- The configured Telegram route records bootstrap complete; the fresh WebChat route keeps it pending.
- Pin docs and source paths, which the prompt contains.
- Count every non-json Codex layer fence so a relabeled layer still counts.
- Ceilings: WebChat prompt 14,336 B, Telegram prompt 14,592 B.
@clawsweeper

clawsweeper Bot commented Nov 27, 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Nov 27, 2026
@clawsweeper clawsweeper Bot added the P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. label Nov 27, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR adds prompt and tool byte ceilings for embedded WebChat, configured Telegram, and Codex snapshot routes.

Example: A contributor increases the embedded WebChat tool definitions to 19,944 bytes.

  • Before: The existing renderer-only prompt budget does not catch tool-definition growth.
  • After: The new WebChat tool gate fails against its 18,944-byte ceiling.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused test coverage with no definite defect found; validation rests on reported harness results, and current-head lint remains unclassified.
Proof confidence 🦐 gold shrimp (3/6) There is no user-visible runtime change; the author reports targeted suite passes and synthetic over-budget failures, and this read-only review executed no tests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes
User problem: Prompt and tool-definition growth can increase request cost without failing CI.
Reason: The maintainer-authored direction extends established byte budgets to additional production preparation boundaries without changing runtime behavior.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it adds useful byte-growth gates absent from main, and inspection found no definite introduced defect.

Reviewed head: 4e265f75b2bab0df19c08d75dfc126f884e47ed4

Before merge

None.

Findings

None.

Agent review details

How this fits together

Agent preparation builds prompts and compacted tools from session, configuration, and workspace facts; these tests measure selected outputs before transport serialization.

flowchart TD
  A[Session and workspace fixtures] --> B[Embedded tool preparation]
  B --> C[Compacted tool catalog]
  C --> D[System prompt preparation]
  C --> E[Embedded byte gates]
  D --> E
  F[Codex snapshot generator] --> G[Codex byte gates]
Loading

Technical review

Best possible solution:

Retain the focused gates at existing preparation and snapshot owners, preserving their explicitly bounded coverage.

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

This is additional test coverage rather than a runtime bug fix; source verifies the ungated surfaces, and the author reports synthetic growth failures without an independent execution in this read-only review.

Is this the best way to solve the issue?

The change extends existing owners with distinct prompt and tool ceilings and avoids duplicating runtime assembly or introducing new configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 4849bb76ca96.

Provenance checked

  • Renderer budget and prompt manifest keeps the original intent (219b6b0: Centralize prompt rendering and prevent renewed prompt growth after reducing first-request size.)
  • Fresh-install ceiling keeps the original intent (e3bf9e7: Tighten the ceiling to 12,288 bytes after moving deferred-tool instructions into tool descriptions.)
  • Codex snapshot generation keeps the original intent (af9d82a: Generate snapshots once under isolated state without accessing the operator's live database.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 219b6b0 adds src/agents/system-prompt-manifest.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 219b6b0f8025; files: src/agents/system-prompt-manifest.ts)

PR surface

Source +15, Tests +259. Total +274 across 4 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 17 2 +15
Tests 3 264 5 +259
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 281 7 +274

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Inspect the failed current-head changed-lint diagnostic and determine whether it requires a branch repair.

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.

Reviewed November 27, 2026, 4:25 PM ET / 21:25 UTC.

obviyus added a commit that referenced this pull request Nov 27, 2026
## Problem

`checks-fast-baseline-ratchets` fails on every PR merged with current main: `provider-branching` asks to shrink 3 allowlist entries. The allowlist from #206878 was taken at `ea77ca3d`. PRs merged later removed provider branches (#206735 deleted `openai-strict-tool-setting.ts`, and others touched `attempt-stream.ts` and `openai-tool-schema.ts`). The shrink-only ratchet fails when a file's count drops below its entry.

## Solution

`--prune` on current main `8a8e0177`:
- `src/agents/openai-strict-tool-setting.ts` 3 → removed (file deleted)
- `src/agents/embedded-agent-runner/run/attempt-stream.ts` 2 → 1
- `packages/ai/src/providers/openai-tool-schema.ts` 1 → removed
- `packages/ai/src/transports/openai-completions-compat.ts` 61 → 63: #206735 moved the strict-mode default from the deleted helper into the compat owner before the ratchet existed. This records main as it is; no branch is added here.

Net: 840 → 837 branches, 218 → 216 files.

## Impact

Contributors only. PRs are no longer red on `provider-branching` for branches that main already removed. There is no runtime change.

## Evidence

- Before: `check-provider-branching-ratchet.mts --base origin/main` on main `8a8e0177` lists the 3 shrink entries (the same list as the CI failure on #206948).
- After: `Provider branching ratchet OK: 216 files, 837 grandfathered branches.`
- Local review on this head: patch is correct, 0 findings.

Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus
obviyus merged commit ae5c570 into main Nov 27, 2026
116 checks passed
@obviyus
obviyus deleted the core/ci-invariants branch November 27, 2026 22:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
## Problem

`checks-fast-baseline-ratchets` fails on every PR merged with current main: `provider-branching` asks to shrink 3 allowlist entries. The allowlist from openclaw#206878 was taken at `ea4af5f4`. PRs merged later removed provider branches (openclaw#206735 deleted `openai-strict-tool-setting.ts`, and others touched `attempt-stream.ts` and `openai-tool-schema.ts`). The shrink-only ratchet fails when a file's count drops below its entry.

## Solution

`--prune` on current main `b5101725`:
- `src/agents/openai-strict-tool-setting.ts` 3 → removed (file deleted)
- `src/agents/embedded-agent-runner/run/attempt-stream.ts` 2 → 1
- `packages/ai/src/providers/openai-tool-schema.ts` 1 → removed
- `packages/ai/src/transports/openai-completions-compat.ts` 61 → 63: openclaw#206735 moved the strict-mode default from the deleted helper into the compat owner before the ratchet existed. This records main as it is; no branch is added here.

Net: 840 → 837 branches, 218 → 216 files.

## Impact

Contributors only. PRs are no longer red on `provider-branching` for branches that main already removed. There is no runtime change.

## Evidence

- Before: `check-provider-branching-ratchet.mts --base origin/main` on main `b5101725` lists the 3 shrink entries (the same list as the CI failure on openclaw#206948).
- After: `Provider branching ratchet OK: 216 files, 837 grandfathered branches.`
- Local review on this head: patch is correct, 0 findings.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…gent and Codex routes (openclaw#206948)

## Problem

The only prompt byte gate (`FRESH_INSTALL_SYSTEM_PROMPT_BUDGET_BYTES`, 12,288 B) checks a hand-written fresh-install renderer fixture. Every other surface the model receives can grow without a failing check:
- the system prompt and the compacted tool definitions that the embedded runtime sends for a Gateway WebChat turn and for a configured channel agent;
- the Codex app-server prompt layers and dynamic tool specs, which are the default route for native OpenAI.

Tool and prompt bytes are a reported cost (openclaw#200920). A 2026-11-27 audit of production first requests measured them at 18–56 KB of tools per request, with no gate on any route except the fresh fixture.

## Solution

Gate each route at the owner that already builds it. Each new ceiling is the size measured on main plus 5%, rounded up to 256 B. Growth within that margin passes.

| Route | Surface | Measured on main | Ceiling | Test |
|---|---|---:|---:|---|
| Fresh install (renderer fixture) | system prompt | 11,395 B | 12,288 B (unchanged) | `system-prompt.inventory-snapshot.test.ts` |
| Gateway WebChat turn, fresh install, embedded runtime | system prompt | 13,599 B | 14,336 B | `attempt-prompt-budget.test.ts` (new) |
| Gateway WebChat turn, embedded runtime | compacted tool definitions | 17,927 B | 18,944 B | same |
| Configured Telegram agent (workspace files, setup complete) | system prompt | 13,676 B | 14,592 B | same |
| Configured Telegram agent (workspace files, setup complete) | compacted tool definitions | 21,058 B | 22,272 B | same |
| Codex app-server Telegram turn | model-bound layer text | 12,981 B | 13,824 B | `test/scripts/prompt-snapshots.test.ts` |
| Codex app-server Telegram turn | dynamic tool specs | 62,551 B | 65,792 B | same |

- `attempt-prompt-budget.test.ts` runs the production attempt pipeline:
  1. `prepareEmbeddedAttemptToolBase`
  2. `prepareEmbeddedAttemptBundleTools`
  3. `prepareEmbeddedAttemptToolCatalog`, which compacts the tools as sent
  4. `prepareEmbeddedAttemptSystemPrompt`, with the tool directory, skills and bootstrap files
- Installed plugin tools, bundle MCP servers and paired-node probes vary by host, so they are mocked out. The budget covers core output.
- The workspace path is pinned to `/workspace` and the docs and source paths to `/repo`, because the prompt contains them. The `Runtime:` line (host, OS, Node version) still varies by about 20 B across hosts.
- The fresh WebChat turn has first-run bootstrap pending. The configured agent has recorded setup complete.
- Tool bytes are compact JSON of `{ name, description, parameters }` for the compacted set. Deferred tools reach the model by name only, so their schemas are not in these numbers.
- The Codex prompt is the sum of every non-`json` fenced layer body in the generated happy-path snapshot, from the layers heading to the end of the file. Renderer prose is not counted, and a relabeled or new layer is still counted.
- The embedded ceilings live in one table, `PROMPT_BUDGET_BYTES`, in `src/agents/system-prompt-manifest.ts`. The Codex pair sits beside its snapshot test.
- A PR that shrinks a surface should lower its ceiling. Nothing enforces that.

## Impact

Contributors only. There is no runtime change. A change that grows a route's prompt or tool bytes past 5% fails CI until the growth is cut or the ceiling is raised on purpose in review.

## Evidence

- Green on main `5128b80d` (rebased), final head: inventory 3/3, `attempt-prompt-budget` 2/2, prompt snapshots 8/8; `check:baseline-ratchets` all ok; `tsgo` for the scripts test config clean.
- Red on a synthetic regression against the same code (throwaway edits, removed): +1,512 B in the shared Execution Bias prompt section, +2,016 B in the `exec` description and +3,990 B in the `sessions_spawn` description. All 7 gates fail:
  - fresh prompt 12,908 > 12,288
  - WebChat prompt 15,112 > 14,336; WebChat tools 19,944 > 18,944
  - Telegram prompt 15,189 > 14,592; Telegram tools 23,075 > 22,272
  - Codex prompt 14,494 > 13,824; Codex tools 66,540 > 65,792
- Adversarial review, two rounds. Round 1 found tools measured before compaction, a Gateway fixture without the directory, skills or bootstrap, and a markdown slice with renderer prose. Round 2 found a Codex sum that could drop to 0 B on a relabeled fence, a configured agent measured in first-run state, and host checkout paths in the prompt. All six are fixed here.
- Local review: round 1 found a closed provider-runtime mock missing its `mock-isolation:` annotation (the mock-exports ratchet would reject it); fixed. CI then caught a capture type error and a lint rule in the Codex fence parser; fixed with named groups. Final head: patch is correct, 0 findings.
- Known gaps:
  - Deferred tool schemas are not gated on the embedded routes. On the Telegram route, 29 deferred tools (about 84 KB, `automations` alone 23.7 KB) appear in the prompt by name only. The Codex dynamic-tool gate covers `sessions_spawn` and the `openclaw` namespace in full.
  - The Telegram `message` schema comes from a two-action test channel plugin, not the real Telegram plugin.
  - Plugin, MCP and node tools and new bundled skills are not budgeted.
  - Steps after the catalog are not measured: the listing pin, the prompt-build tool policy and transport serialization.
  - Not covered: the Codex-owned native layers (`AGENTS.md`, environment, memories) that Codex adds after OpenClaw sends the thread params.
  - A failing gate prints the total only, not a per-tool breakdown.

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

Labels

agents Agent runtime and tooling P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant