Skip to content

feat(agent): unify Code Mode output budgeting, tail previews, and in-cell Read paging - #7125

Merged
M4n5ter merged 1 commit into
rust-previewfrom
feat/code-mode-output-budget
Nov 21, 2026
Merged

M4n5ter merged 1 commit into
rust-previewfrom
feat/code-mode-output-budget

Conversation

@M4n5ter

@M4n5ter M4n5ter commented Nov 21, 2026

Copy link
Copy Markdown
Member

Summary

Implements the unified Code Mode output budgeting, trailing preview, in-Cell workspace Read paging, and wait default timeout design finalized in #7108:

  • Single outer archive budget (no inner truncation or legacy compatibility branches):
    • Removed the inner clip() in plugins/agent/tools/src/cell/session.rs and froze the per-call display budget (effective_cell_display_chars: default 10,000 tokens / 40,000 UTF-16 chars, capped at 20,000 tokens / 80,000 chars, no lower clamp) onto ToolSuccess, ReturnedToolResult, and ExternalReturn::Output.
    • Unified pure-text (ArchivedPlaceholder) and mixed text+media (DurableToolProjection::Content) archiving across native replay, external-effect first delivery and redelivery, and imported replay under one display_budget_chars: usize model (MAX_PAGE_CHARS = 7,500 for ordinary tools; frozen Cell budget for exec/wait).
    • Added PageBudget::DisplayBody and single-pass cellStatus prefix capture so small or zero budgets (max_output_tokens: 0 / max_tokens: 0) never leak optional body text or fall back to full text, while still delivering mandatory cellStatus, resourceRef, and page.next (at=0).
  • Single-pass O(1) TailRing trailing preview & unified 40K async/recovery budget:
    • Added tailPreview (up to min(2,000, budget / 4) UTF-16 JSON-escaped units when budget >= 1,600) across pure-text and mixed text+media archives, preserving media order with one shared archive:<event-id> notice.
    • Preserved incremental prior_output on synchronous exec/wait interruptions without duplicating already-yielded output.
    • Unified asynchronous Cell notifications and RecoveredCell reports under a single shared 40,000-char JSON-escaped display budget (CellReportBody + bound_json_field_text) while preserving media parts in order.
  • Whole-Cell-lifetime Host OOM cap:
    • Updated CellContext (MAX_CELL_OUTPUT_BYTES = 16 MiB) to accumulate across the full Cell lifetime rather than resetting on take_output() / take_notifications(), accounting for per-item slot overhead and avoiding double-charging transferred external notifications.
  • In-Cell workspace Read paging & wait defaults:
    • Expanded ordinary in-Cell workspace text Read pages (including continuation pages) to 65,536 UTF-16 units (CELL_READ_PAGE_CHARS), keeping direct model Read and archive:/attachment:/session reads at 7,500.
    • Raised wait default yield_time_ms from 10_000 to 30_000 and placed yield_time_ms guidance on the line following the // @exec: / # @exec: pragma example so copied pragma lines parse cleanly.

Storage / Migration note

No database migration script is required: newly added fields (display_budget_chars, cell_status, tail_preview) use #[serde(default, skip_serializing_if = "Option::is_none")], and StoredToolResult::Inline(Box<ReturnedToolResult>) is #[serde(untagged)] (wire-identical). Existing SQLite rows deserialize cleanly and apply the unified default budget (7,500 chars).

Refs #7108

Verification

  • cargo fmt --check — pass
  • git diff origin/rust-preview --check — pass
  • cargo clippy --tests -p maka-code-runtime -p maka-js-runtime -p maka-python-runtime -p maka-agent-facts -p maka-agent-state -p maka-tools -p maka-agent-engine -p maka-session-import -p maka-files-native -p maka-agent-native -- -D warnings — pass (0 warnings)
  • cargo test -p maka-code-runtime -p maka-agent-facts -p maka-agent-state -p maka-tools -p maka-agent-engine -p maka-session-import -p maka-files-native — pass
  • cargo test -p maka-agent-native --lib code_mode_budget — pass (real V8 Host end-to-end acceptance covering budget tiers, tailPreview, mixed text+media order, zero-budget strict bounding, synchronous interruption incremental archive, in-Cell 65,536 workspace Read + continuations, native/external/imported parity, and async/recovery 40K JSON-escaped bounding)
  • cargo test -p maka-agent-native --lib compaction_cancels_background_request_when_main_finishes — pass
  • cargo test -p maka-schema — pass
  • Not run locally: maka-cli / desktop UI builds (no node_modules installed in the isolated worktree; verified via GitHub Actions CI).

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Google Antigravity authored the implementation, tests, and PR; Maka (codex/gpt-6.2-astra) performed multi-round design and code review.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

…cell Read paging

Implements the Code Mode output budgeting, tail preview, in-cell workspace
Read paging, and wait tuning design discussed in #7108:

- Collapse inner Cell clip() into a single outer archive budget frozen per
  return (default 10,000 tokens / 40,000 UTF-16 chars, max 20,000 tokens /
  80,000 chars, honoring small/zero budgets via PageBudget::DisplayBody and
  top-level cellStatus without leaking optional body text).
- Add single-pass O(1) TailRing trailing preview with exact JSON-escaped
  UTF-16 accounting across pure-text, mixed text+media (preserving media
  order with one shared event locator), and asynchronous Cell notifications
  / RecoveredCell reports (shared 40,000-char JSON-cost budget).
- Preserve incremental prior_output on synchronous exec/wait interruptions
  without duplicating previously yielded output.
- Enforce a whole-Cell-lifetime 16 MiB Host output cap (accounting for
  per-item slot overhead without double-charging transferred external
  notifications).
- Expand ordinary in-Cell workspace text Read pages (including continuations)
  to 65,536 UTF-16 units while keeping direct Read and archive/attachment/
  session reads at 7,500.
- Raise wait default yield_time_ms from 10s to 30s and clarify exec pragma
  guidance.

Refs #7108

Generated-by: Google Antigravity
@M4n5ter
M4n5ter merged commit 1599a73 into rust-preview Nov 21, 2026
6 of 8 checks passed
@M4n5ter
M4n5ter deleted the feat/code-mode-output-budget branch November 21, 2026 10:36
M4n5ter added a commit that referenced this pull request Nov 21, 2026
…re (#7135)

#7125 unified Code Mode output budgeting so external exec calls honor display_budget_chars (default 10,000 tokens / 40,000 UTF-16 chars) instead of always archiving at 7,500 chars. Because readArchivedResult() in external_codex_cli.mjs emitted 30,000 chars without setting max_output_tokens, exec returned inline output, JSON.parse threw a SyntaxError, and the worker exited without replying to session/prompt, causing antigravity_can_continue_after_host_restarts_during_a_prompt to hang until the 45s follow-up deadline.

Set max_output_tokens: 1000 with a 12,000-char payload so archive continuation is exercised deterministically regardless of default budget changes, surface non-JSON archive replies clearly, and fail pending ACP session/prompt requests immediately when the fixture aborts.

Refs #7125

Generated-by: Maka (Gemini)
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.

1 participant