SIGN IN SIGN UP

Reduce Antigravity request amplification for large payloads

A single 8 MiB inlineData request allocated about 480 MB end to end. The
Gemini-to-Antigravity translator was responsible for the largest share:

- The entry point converted the payload between string and []byte, so the
  whole request was copied before any rewrite happened.
- The contents array was rebuilt part by part even when every role was already
  valid and no function name needed rewriting.
- The envelope was built by splicing the payload into the template first and
  then setting the model, which copied the payload a second time.
- fixCLIToolResponse took and returned a string, so even its no-op path copied
  the request twice.

Keep the payload as []byte throughout, pre-scan for roles and function names
before deciding to rebuild, fill the small envelope before splicing the payload
in once, and switch fixCLIToolResponse to []byte with a fast path that returns
the input unchanged.

Benchmarked on an 8 MiB inlineData request: 84.0 MB/op to 16.8 MB/op and
44.9 ms/op to 39.3 ms/op. Outputs were compared byte for byte against the
previous implementation across 5166 generated and hand-built requests.
S
sususu committed
b7a441522a904270afcb41761c81b8682884406c
Parent: ea8882b
Committed by sususu98 <33882693+sususu98@users.noreply.github.com> on 8/8/2026, 4:40:57 PM