Skip to content

fix(agent-stream): batch contiguous tool argument fragments - #4006

Merged
kev1n77 merged 1 commit into
openBitFun:mainfrom
kev1n77:codex/fix-4005-params-partial-journal
Nov 19, 2026
Merged

kev1n77 merged 1 commit into
openBitFun:mainfrom
kev1n77:codex/fix-4005-params-partial-journal

Conversation

@kev1n77

@kev1n77 kev1n77 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4005

  • Publish the first tool-argument fragment immediately. Batch only adjacent ordinary ParamsPartial deltas for the same tool call within a stream attempt, using a 16 ms window and a 4 KiB buffer limit.
  • Flush pending deltas before tool, text, reasoning, or snapshot boundaries, and before stream completion, cancellation, or errors. Keep provider idle deadlines independent of batch flushes.
  • Use the existing payload, cursor allocation, and JSONL format. Crash recovery reads the batches already published and journaled.

Type and Areas

Bug fix in the shared Rust agent-stream crate.

Motivation / Impact

The runtime journal was serializing a full record for every small argument fragment. In the original isolated macOS Desktop reproduction, the same 33,224 bytes of ExecCommand arguments now produce 349 ParamsPartial records and a 177,239-byte journal. The baseline was 33,224 records and 13,645,695 bytes, a 98.7% size reduction. Reassembled arguments matched the single-fragment control byte for byte, and the tool completed successfully.

Verification

  • cargo test --locked -p openbitfun-agent-stream — 86 passed, including tool interleaving, argument snapshots, byte and idle-time flushes, and cancellation ordering.
  • cargo test --locked -p openbitfun-ai-adapters --test ai_stream_contracts stream_processor_openai — 12 passed.
  • cargo test --locked -p openbitfun-agent-runtime --no-default-features --features agent-runtime --lib session_event_journal — 18 passed.
  • cargo build --locked -p openbitfun-desktop --bin openbitfun-desktop — passed on macOS.
  • Isolated macOS Desktop with the original loopback model fixture — volume comparison passed. Interrupting parameter delivery closed the model stream and retained the written arguments for recovery. Reloading the WebView and requesting backfill from cursor 19 replayed 22 contiguous events through cursor 41. After a host SIGKILL and restart, the snapshot recovered all 3,687 journaled parameter bytes at cursor 41. An incremental request for the old host stream returned snapshotRequired.

Reviewer Notes

AI-assisted. Testing level was full for the local Desktop reproduction and focused Rust suites. Native Desktop evidence was collected on an isolated build with the same stream patch. Live Peer Device, SSH workspaces, Remote Connect, and Detached Dispatch were outside the test scope.

Checklist

  • The PR contains only the scoped stream fix and its regression tests.
  • Relevant verification and coverage limits are recorded above.

@kev1n77
kev1n77 merged commit 76bc00e into openBitFun:main Nov 19, 2026
13 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.

[Bug]: Runtime event journal bloats when tool arguments arrive in small fragments

1 participant