Harness usage optimization#6
Conversation
…hten tool caps Stop embedding pretty-printed tool JSON schemas in the system prompt (schemas still go via the provider tools field, matching OpenCode/Codex/Grok Build). Send session-scoped prompt_cache_key on OpenAI Responses and chat-completions, set store=false for xAI, and mark Anthropic system blocks with ephemeral cache_control. Cap bash/terminal model output at 20k and generic tool output at 40k to cut SuperGrok burn on long tool loops. Co-authored-by: Carlo Taleon <Blankeos@users.noreply.github.com>
Deploying crabcode with
|
| Latest commit: |
5400518
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3e765aa8.crabcode.pages.dev |
| Branch Preview URL: | https://cursor-xai-harness-efficienc.crabcode.pages.dev |
…er defaults - Soft-trim / hard-clear stale tool outputs in the live agent loop (keep 6 recent) - Drop duplicated <available_skills> from the skill tool description - Lower read default to 1000 lines and AGENTS.md cap to 32KiB - Compact JSON for observation/question args; shrink history args cap to 4k Co-authored-by: Carlo Taleon <Blankeos@users.noreply.github.com>
Add xAI Grok Build request overrides (base URL, model, auth headers, user agent/version) and hook them into OAuth request configuration. Introduce a response-level retry policy for OpenAI provider requests to refresh and resend with updated x-grok protocol version on 426 responses, and add unit tests for version validation and policy/header contracts.
PR Review: #6 — xAI / harness token-efficiencyBranch:
Diff size: ~+445 / −107 across 20 files (mostly Merge confidence: 4/5Solid, well-scoped efficiency work with unit tests for the new prune/cache paths, clean compile, and no migrations. Docked one point for: (1) mid-stream prune mutates the in-loop message history that may feed session persistence / compaction, (2) subagents get CI ( Body (GitHub comment paste)## Summary
Cuts SuperGrok / long-session token burn by aligning the harness with OpenCode / Grok Build patterns:
1. **Stop double-sending tool schemas** — system prompt now lists tool *names* only; JSON schemas stay on the API `tools` field.
2. **OpenAI prompt cache** — stable `prompt_cache_key` (`crabcode:session:{id}`) + `store: false` for Responses API (primary + compaction paths).
3. **Mid-session tool-output prune** — keep last 6 full; soft-trim older; hard-clear beyond 12; drop attached images on pruned outputs.
4. **Dedupe skills** — skill catalog lives only in system prompt (`<available_skills>`), not re-embedded in the `skill` tool description every step.
5. **Tighter caps** — bash 20k, terminal model-facing 20k, bridge 30k, read default 1000 lines, rules 32KiB.
## Test plan
- [x] `cargo check -p crabcode` / `cargo check -p aisdk`
- [x] `cargo test -p aisdk prune_stale` / `soft_trim` / `responses_body_includes_prompt_cache_key`
- [x] `cargo test --bin crabcode truncate_tool_output`
- [ ] Manual multi-step agent turn (bash + read + skill) — confirm prune metadata + no tool-use regression
- [ ] Confirm OpenAI Responses request body has `prompt_cache_key` + `store: false`
- [ ] Long session: older tool outputs show `[Old tool result content cleared]` without breaking later stepsWhat changed (by area)
Regressions / risksMedium
Low
Not regressions (good)
Migrations?None.
Pre-merge checklist
Checks I ran (non-mutating)
Note: local WIP on this branch ( VerdictApprove with nits — safe to merge after the persistence/prune sanity check and the one-line PARITY fix. Core idea is correct and tested; biggest unknown is whether pruned tool outputs leak into stored session history. |
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
f13805e to
5400518
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f13805e1d5
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if provider_name == "xai" { | ||
| // Match Grok Build / ZDR: do not persist Responses server-side. | ||
| request_config.openai_options.force_store_false = true; |
There was a problem hiding this comment.
Preserve xAI no-store behavior for agent mentions
This xAI-only store: false setup runs only on the primary stream_llm_with_cancellation path. The @agent flow in src/app.rs instead calls configure_subagent_llm_session, which builds its session through build_subagent_llm_session and leaves force_store_false at its default for API-key xAI users (OAuth happens to set it separately). Consequently, agent-mention subagent requests can be persisted server-side even though normal xAI turns use the new ZDR/no-store behavior; apply the same xAI option in the common subagent session setup.
Useful? React with 👍 / 👎.
Summary
Harness usage optimization for crabcode’s agent loop — cut SuperGrok / API burn by aligning request shape, retention, and caps with OpenCode, Codex, and Grok Build.
Compaction stays manual (
/compact) on purpose.Ranked changes
Ordered by estimated impact on a typical multi-step coding session (tool-heavy, 20–100+ steps). Savings are relative to crabcode before this PR; ranges vary with session length and repo instruction size.
tools[][Old tool result content cleared]; drop attached images on pruned outputsprompt_cache_key = session_id· Grok Build sticky session/cache keys · Anthropic ephemeral system cacheprompt_cache_key = session_id; xAI: alsostore: false; Anthropic:cache_control: ephemeralon last system block<available_skills>stays in the system promptreadlimitlimit/offsetDEFAULT_MAX_RULE_BYTES = 32 * 1024Intentionally not in this PR
/compactkept by designcli-chat-proxy.grok.comOAuth routingReasoningEncryptedContent)<env>Test plan
responses_body_includes_prompt_cache_key_and_store_falsesoft_trim_tool_output_*,prune_stale_tool_outputs_clears_oldest_and_keeps_recentgrok-composer-2.5-fastsession — confirm usage % rises slower than before for similar workskilltool using names from system<available_skills>