Skip to content

fix(runtime): stop counting insignificant tool-argument whitespace as stream activity - #4888

Draft
jsiu93 wants to merge 1 commit into
apache:mainfrom
jsiu93:fix/bound-tool-input-stream
Draft

fix(runtime): stop counting insignificant tool-argument whitespace as stream activity#4888
jsiu93 wants to merge 1 commit into
apache:mainfrom
jsiu93:fix/bound-tool-input-stream

Conversation

@jsiu93

@jsiu93 jsiu93 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Insignificant JSON whitespace in tool-argument deltas no longer counts as stream activity; the existing idle watchdog and its recovery handle the stall.

Track string and escape state independently for each tool-call ID. Spaces, tabs, carriage returns, and line feeds outside JSON strings leave the activity clock unchanged. Whitespace inside strings remains activity, including across escaped quotes and split deltas. Other stream parts retain their existing behavior.

The criterion follows JSON syntax. The existing 120-second idle timeout, recovery policy, strict settings, and tool schemas remain unchanged. This patch adds no threshold or content heuristic.

Refs #4861

Verification

  • Red against the original implementation: 6 tests, 2 passed and 4 failed. Thirty insignificant whitespace deltas incorrectly produced 33 activity callbacks where 3 were expected.
  • Final targeted green: 8 tests passed, 0 failed, including the existing stream-activity test. Coverage includes provider-executed tools, string whitespace, escaped quotes and backslashes split across deltas, interleaved IDs, ID reuse, non-JSON whitespace, and unchanged text/reasoning activity.
  • Complete @maka/runtime test:dist: 3,268 tests, 3,255 passed, 13 skipped, 0 failed.
  • Full repository build, format, lint, and typecheck passed.
  • Live patched TUI, Auto mode, gpt-6-astra, captured relay traffic: a Bash argument loop emitted 4,129 argument bytes. Its last meaningful delta arrived at 5.015 seconds; Maka closed the HTTP stream at 125.025 seconds, 120.010 seconds later. On unpatched main a comparable loop lasted about 902 seconds.
  • The TUI showed Retrying in 2s (2/2), then Retrying (2/2). The retry completed pwd. Canonical accounting records attempt 0 as aborted with missing usage and attempt 1 as completed with reported usage under the same logical call ID. Provider code and retryable fields remain absent on the aborted attempt, following the existing watchdog accounting path.

Security

The change lets the existing watchdog cancel a provider stream that only appends insignificant JSON whitespace. Permission checks, sandbox boundaries, and execution authority remain unchanged. The existing single idle-recovery allowance and observable-output safety gates still govern replay.

AI use

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

Tool(s) and scope: OpenAI Codex-family model via pi implemented the patch, tests, and this description; human-reviewed.

Checklist

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

Does this PR entail a change in behavior?

  • Yes, described under Summary above
  • No

Open questions for maintainers

Should whitespace-only text or reasoning deltas eventually share this activity definition? This draft preserves their current behavior because whitespace in those streams can carry presentation meaning; tool-argument JSON supplies an explicit syntax-level distinction.

… stream activity

Track JSON string and escape state independently for each streaming tool call.
Keep whitespace inside string literals active across split and escaped deltas.
Let the existing idle watchdog cancel whitespace stalls and apply its recovery.
Cover interleaved calls and preserve text and reasoning stream behavior.
Refs apache#4861

Generated-by: pi (gpt-6-astra)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant