Skip to content

fix(directsdk): stream tool calls as Claude writes them - #360

Merged
alt-glitch merged 11 commits into
sid/ddsdk-setupfrom
sid/ddsdk-tool-streaming
Nov 15, 2026
Merged

alt-glitch merged 11 commits into
sid/ddsdk-setupfrom
sid/ddsdk-tool-streaming

Conversation

@alt-glitch

@alt-glitch alt-glitch commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Merges after #357; stacked on it.

Tool calls now reach Hermes as Claude writes them, so a long write_file shows "Preparing write_file…" instead of a bare spinner, and a broken or cut-off tool call is retried instead of failing the turn. Closes #164, #221, #326, #327, #328, #341.

Before

On #357's head, the relay held each tool call until Claude finished writing it:

  • A large write_file showed only the thinking spinner until the whole call was written: 30 s for a 1,500-word file.
  • A call whose streamed arguments were invalid JSON, or cut off at max_tokens, was dropped. Claude Code then failed the turn with error_max_turns, and each retry failed the same way.
flowchart LR
  M[Claude writes a tool call] --> H[relay holds it until complete]
  H --> S[Hermes shows a spinner]
  H -->|arguments do not parse| D[call dropped, turn fails]
Loading

After

The relay passes each tool call on as Claude streams it:

  • Hermes sees the tool name as soon as Claude starts the call, then the arguments as they are written.
  • A call whose arguments do not parse comes back with finish length and its raw arguments. Hermes never runs a call from a length reply; it retries.
  • After invalid JSON, that conversation's next requests ask the API to buffer and validate tool input. A cut-off call keeps streaming.
flowchart LR
  M[Claude writes a tool call] --> P[name, then argument deltas, as written]
  P --> U[Hermes shows Preparing write_file]
  P -->|arguments do not parse| L[finish length, never run, retried]
Loading

What the user sees

Situation Before (#357 head) After
A long write_file call the thinking spinner until the call is written (30 s for 1,500 words) "Preparing write_file…" from the moment the call starts
Invalid JSON in a tool call (#221) the turn fails; every retry fails the same way the call is not run; the next request answers
A tool call cut at max_tokens (#164) Native request failed: error_max_turns the call is not run; Hermes retries with more room
A refusal the reason, no request id one log line with model, request id and category; the refusal text ends with (request_id=req_...) for Anthropic's false-positive form (#341)
response_format: json_object on an auxiliary call (#327) ValueError on every call dropped by core before the request
A request refused before Claude Code starts (#328) retried as an unknown error not retried; fallback allowed
A tool id from another provider (terminal:42) sent to Anthropic unchanged and rejected a stable toolu_hermes_<hash> id, paired with its result
Claude names a tool mcp__<tool> core repairs it and logs a line per call mapped to the offered tool
Before (15 s into a long write_file call) After (15 s into a long write_file call)
Before After

The interactive CLI on the same prompt. The after row reads "wriie_file" because the capture's tmux counts the width of the ✍️ emoji differently from the CLI; in a terminal it reads "write_file".

Not in this PR

  • Telling core the native output cap, so a length retry does not shrink max_tokens: no plugin seam yet.
  • The burst of text after a tool result (P#33): it comes from the API, not the plugin; tracked there.

Live verification

Check Before (#357 head) After (this head)
Interactive hermes -p <scratch>, "write a 1,500-word guide in one write_file call", real Claude Code 2.1.319, Sonnet 5.5 30 s of "deliberating..." with no tool row, then the edit "Preparing write_file…" from 9 s until the edit at 53 s
Offline evals on Claude Code 2.1.319 and the CI pin 2.1.292 pass pass; invalid streamed JSON answers finish length with 1 upstream request; a refusal answers content_filter with 1 upstream request
Cache wire eval, 25 requests Claude Code's environment message changed between requests 1 and 2 (the stable-context tests fail with this fix reverted) the same on every request

Both shots are the same moment, 15 s after the prompt was sent. The two runs wrote files of different length (37.7 s and 53.5 s turns), so only the 15 s frame is a like-for-like comparison.

Cherry-picked with authorship: #21 (@efron), #342 (@mwe-ai), #336 (@kanederkson, the relevant commit), #171 (@salch-cred, the _fast_eligible hunk and its tests). Superseded: #256, #338 (both turned eager streaming off, which brought back multi-second silent gaps).

Follow-ups

  • A core seam for the native output cap.

Next PR

#361 (one Claude Code process per Hermes agent) is stacked on this branch and moves here when this merges.

@alt-glitch

Copy link
Copy Markdown
Contributor Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

RetriggerTREX TREX

Tested 2 flows, found no issues.

What we tested

  • Pass · Prepare a streamed file in Hermes · View ↗
  • Pass · Recover a broken tool call in Hermes · View ↗

@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No blocking defect was established; the two earlier maintainability and test-coverage comments remain non-blocking follow-ups.

Findings

  1. P2 Tool state has several owners ▶
  2. P2 Refusal tests stop too early ▶
Fix with agent prompt
### Issue 1
claude-subscription-directsdk/directsdk.py:1170-1176
The new tool state is split between `Capture.arguments`/`unparsed_calls`, `_ToolStream.raw`/`slots`, and overlapping `calls`, `parsed_calls`, and `unparsed` lists here. Finalization then reaches into `tool_stream.slots` to reconcile them. Changing tool-input rules now requires matching changes across these representations.

This violates the repository requirement to keep feature logic behind a dedicated abstraction rather than scatter special cases. Consolidate these rules before merging. Use one ordered per-tool model with raw input, parsed input, and streamed position. Derive final calls, replay data, and remaining deltas from it. Keep the two input streams separate, but share their tool-state rules.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 2
claude-subscription-directsdk/tests/test_directsdk_tool_stream.py:136-140
This test checks that the plugin emits parseable arguments and `content_filter`, but `len(bodies) == 1` only counts the single `Client.create` call. Hermes decides whether to retry after assembling those chunks, so this test can pass without protecting that behavior.

Feed the actual chunks through the existing `_hermes_stream_response` and `_hermes_reply` helpers. Check that Hermes drops the tool and shows the refusal. Include malformed eager input too: `_json_suffix` returns `None` for `{"path": /tmp/a.txt}`, so that case follows a different path from a cut-off valid string.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

This PR sends tool names and arguments to Hermes as Claude writes them.

  • Claude tool calls reach Hermes as their names and arguments arrive.
  • Anthropic receives valid tool IDs for calls from other providers.
  • Requests this plugin cannot serve can stop retrying or use another provider.
  • Claude refusal messages can include the request ID support needs.
  • Wrapped Claude date reminders stay in the relay’s stable request context.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Claude starts a tool call] --> B[Send its name to Hermes]
  B --> C[Send argument fragments]
  C --> D{How did the reply end?}
  D -->|Valid call| E[Finish tool_calls]
  D -->|Broken arguments| F[Finish length]
  D -->|Refusal| G[Finish content_filter]
  F --> H[Invalid JSON disables eager input next time]
Loading

Reviews (4) · Last reviewed commit: "Merge f2b97192c9bacf55987ebad0dafed74d3b..." · Reviewed by Greptile

Comment on lines +1170 to +1176
parsed_calls = list(calls)
# A call whose arguments did not parse (cut at max_tokens, or invalid streamed JSON) reaches Hermes with
# its raw arguments and finish length: Hermes never runs a call from a length reply, it re-sends the
# request with a larger output cap (#164, #221). A refused call stays out (below).
unparsed = [] if refused or not admission.used else admission.capture.unparsed_calls
for call_id, native_name, raw in unparsed:
calls.append({'id': call_id, 'type': 'function', 'function': {'name': offered_tool_name(native_name or '', hermes_names)[1], 'arguments': raw}})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tool state has several owners

The new tool state is split between Capture.arguments/unparsed_calls, _ToolStream.raw/slots, and overlapping calls, parsed_calls, and unparsed lists here. Finalization then reaches into tool_stream.slots to reconcile them. Changing tool-input rules now requires matching changes across these representations.

This violates the repository requirement to keep feature logic behind a dedicated abstraction rather than scatter special cases. Consolidate these rules before merging. Use one ordered per-tool model with raw input, parsed input, and streamed position. Derive final calls, replay data, and remaining deltas from it. Keep the two input streams separate, but share their tool-state rules.

Context Used: Perform a deep code quality audit of the current branch's changes. Rethink how to structure / implement the changes to meaningfully improve code quality without impacting behavior. Work to improve abstractions, modularity, reduce Spaghetti code, impr... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: claude-subscription-directsdk/directsdk.py
Line: 1170-1176

Comment:
**Tool state has several owners**

The new tool state is split between `Capture.arguments`/`unparsed_calls`, `_ToolStream.raw`/`slots`, and overlapping `calls`, `parsed_calls`, and `unparsed` lists here. Finalization then reaches into `tool_stream.slots` to reconcile them. Changing tool-input rules now requires matching changes across these representations.

This violates the repository requirement to keep feature logic behind a dedicated abstraction rather than scatter special cases. Consolidate these rules before merging. Use one ordered per-tool model with raw input, parsed input, and streamed position. Derive final calls, replay data, and remaining deltas from it. Keep the two input streams separate, but share their tool-state rules.

**Context Used:** Perform a deep code quality audit of the current branch's changes. Rethink how to structure / implement the changes to meaningfully improve code quality without impacting behavior. Work to improve abstractions, modularity, reduce Spaghetti code, impr... ([source](https://app.greptile.com/custom-context?memory=instruction-0))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +143 to +147
with upstream(tmp_path, reply(['{"path": "/tm'], 'refusal', details)) as (client, bodies):
chunks = list(client.create(**REQUEST, stream=True))
arguments = ''.join(d.function.arguments or '' for d in tool_deltas(chunks))
assert json.loads(arguments) == {'path': '/tm'}
assert chunks[-1].choices[0].finish_reason == 'content_filter' and len(bodies) == 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Refusal tests stop too early

This test checks that the plugin emits parseable arguments and content_filter, but len(bodies) == 1 only counts the single Client.create call. Hermes decides whether to retry after assembling those chunks, so this test can pass without protecting that behavior.

Feed the actual chunks through the existing _hermes_stream_response and _hermes_reply helpers. Check that Hermes drops the tool and shows the refusal. Include malformed eager input too: _json_suffix returns None for {"path": /tmp/a.txt}, so that case follows a different path from a cut-off valid string.

Prompt To Fix With AI
This is a comment left during a code review.
Path: claude-subscription-directsdk/tests/test_directsdk_tool_stream.py
Line: 143-147

Comment:
**Refusal tests stop too early**

This test checks that the plugin emits parseable arguments and `content_filter`, but `len(bodies) == 1` only counts the single `Client.create` call. Hermes decides whether to retry after assembling those chunks, so this test can pass without protecting that behavior.

Feed the actual chunks through the existing `_hermes_stream_response` and `_hermes_reply` helpers. Check that Hermes drops the tool and shows the refusal. Include malformed eager input too: `_json_suffix` returns `None` for `{"path": /tmp/a.txt}`, so that case follows a different path from a cut-off valid string.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

alt-glitch and others added 8 commits November 10, 2026 04:11
…message

Claude Code 2.1.292 and 2.1.319 send today's date as
"<system-reminder>\nToday's date is ...\n</system-reminder>", but _DATE_LINE
only matched the bare 2.1.299 text. The date-move branch never fired, so the
environment message (messages[1]) carried the date on the opening request and
lost it from request 2 on, leaving a trailing role:system date row. That is
the residual of #38: an edit of an early message before the turn's thinking.

The regex now accepts the optional wrapper. The unit fixtures use the wire
text, and the cache eval asserts messages[1] reads the same on every request
of a fresh conversation (red on the base: "native environment message changed
after the opening request"; green on 2.1.319 and 2.1.292).
Salvaged from P#21 (cherry-pick of f4faf14, rebased onto main: the import hunk conflicted because main already imports hashlib). Closes P#21.
…egment) to the offered tool

Native Claude Code sometimes names a tool mcp__<tool>, dropping only the server segment of
mcp__hermes__<tool>. directsdk handled the full prefix and the bare name (#62) but not this form,
so core's _repair_tool_call fixed it and logged "Auto-repaired tool name" on every such call
(cosmetic, no failures). Map it back to the offered name in the tool_use loop, which also keeps
the replayed history on the offered name.

Test: test_server_segment_slip_maps_to_the_tool_and_replays_with_the_offered_name (fails without the fix).

Merged from P#342 as is (cherry-pick of b05ffb8). Closes P#342.
… not retried (#327 #328)

Salvaged from P#336 (kanederkson, ebcff9c only; its advanced-delegation and
mcp-serve commits are unrelated and stay out).

unsupported_response_formats before the first auxiliary request. The plugin
refuses schema-less json_object, so declare it. Set by attribute after
construction, as supports_streaming is: a constructor kwarg fails on a host
that predates the field (requires_hermes >= 0.21.4).

said failure_retryable True. Every pre-spawn refusal in directsdk.py now
raises RequestRejected (a ValueError, so existing callers are unchanged), and
the profile hook maps it, by class name, to format_error with retryable False
and should_fallback True, so a different fallback provider still gets its
try. A plain ValueError from anywhere else keeps core's own verdict, unlike
P#336's blanket ValueError/TypeError match.

Tests red on the base: the refusal verdict and the auxiliary drop.
Closes P#336, #327, #328.
…th on the per-call path

Native keeps a call whose streamed arguments are not valid JSON and answers it locally with a parse error, so --max-turns 1 ends the turn with error_max_turns and exit code 1. The relay drops the unparsable call at message_stop, so the answer carried no calls and the boundary judged the turn a failure: the step raised RuntimeError Native request failed: error_max_turns instead of returning the text it already had.

Treat a turn whose calls were all dropped (admission.capture.unparsed) like a turn with calls at the error_max_turns boundary, also in _fast_eligible. The answer reaches Hermes with finish length and no tool calls, as 55c1b45 described for the relay path (#164).

Salvaged from P#171 (cherry-pick of e15ee45; its CHANGELOG hunk conflicted and is dropped, the next commit writes the entry). The next commit changes the outcome: the cut call reaches Hermes with its raw arguments instead of being dropped.
…ken one (#164 #221 #326)

One root cause behind three reports. The relay dropped a tool call whose
streamed arguments did not parse, and the plugin sent no tool-call delta
before the final chunk.

- A cut (max_tokens) or invalid call now reaches Hermes with its raw
  arguments and finish length. Core never runs a call from a length reply;
  it re-sends the request. Finish tool_calls would be unsafe: core repairs
  and runs an unclosed argument. Previously #221 failed the turn after 3
  attempts (error_max_turns) and a mixed reply silently lost the bad call.
- eager_input_streaming stays on by default (turning it off regressed the
  #156 stall fix: a 6 s zero-event gap live). After an invalid (not cut)
  reply, that conversation's next requests buffer tool input so the API
  validates it, the same knob core's Anthropic transport turns on.
- The tool call header (id, name) streams at content_block_start and each
  argument fragment streams as a chat-completions tool_calls delta, so
  Hermes shows "Preparing <tool>" at once. A refusal mid-call gets a closing
  suffix that makes the streamed arguments parse, so core's accumulator
  keeps content_filter (one request) instead of turning it into a
  truncation it retries (the triage prototype measured 5 requests).
- One name mapping (offered_tool_name) serves the header stream and the
  final calls, so P#342's server-segment slip applies to both.

P#171's fast-path clause and tests are kept from the previous commit; its
tests now assert the cut call reaches Hermes with raw arguments.

Through core's real turn loop (e2e_221.py, real CLI, fake upstream):
invalid JSON done in 2.6 s (was: failed after 3 attempts, 11.98 s); cut
done in 2.6 s with no error; unclosed done; refusal mid-call and after a
parsed call both end content_policy_blocked after 1 request, 0 tools run.
Tests red on the base: tests/test_directsdk_tool_stream.py (5). Admission
eval gains a bad_tool mode.

Not done here: reporting native's output cap through get_max_tokens. It
would put max_tokens on every request (CLAUDE_CODE_EXTRA_BODY and
CLAUDE_CODE_MAX_OUTPUT_TOKENS), and core's boost would then ask for 2x the
model cap on a chat_completions route, where _model_output_limit is None.
No clean seam; left as a core follow-up.

Closes #164, #221, #326. Supersedes P#256 (eager off by default, adds a
non-secret env var, does not fix the cut) and P#338 (removes eager
streaming, bundles 4 unrelated commits).
… in message.refusal (#341)

An upstream refusal left no trace: the request id appeared in no log, so a
user could not ask Anthropic support about it. Each refusal now logs one
WARNING with model, request_id and stop_details.category, and
message['refusal'] ends with (request_id=req_...). The id passes the same
bounded req_ check ClaudeAPIError already applies, now one helper.

Core still prefers preamble content over provider_data['refusal'] when text
came first (agent/turn_truncation.py handle_content_policy_refusal); that is
a core follow-up. The log line covers that case meanwhile.

Test red on the base: test_refusal_names_its_request_id_in_the_log_and_the_message.
Closes #341.
Merges the invalid-JSON and cut-at-max-tokens cases, which drive the
same path (the call is returned with finish length, never run, and the
next request picks how the API streams the arguments), into one
parametrized test. Drops the exhaustive _json_suffix prefix test: the
refusal-mid-call test already proves the streamed arguments of a cut
call parse. Each fix commit's code, reverted alone, still fails a kept
test.
@alt-glitch
alt-glitch force-pushed the sid/ddsdk-tool-streaming branch from 192abf9 to 68f030a Compare November 9, 2026 22:57
@alt-glitch alt-glitch changed the title claude-subscription-directsdk: tool calls stream as written; a broken tool call no longer fails the turn fix(directsdk): stream tool calls as Claude writes them Nov 9, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor Author

@greptileai review

@unsupportedpastels unsupportedpastels left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PR #360 fix(directsdk): stream tool calls as Claude writes them @ 68f030a8

Verdict: 🟡 Changes requested. The normal tool-streaming and malformed-input recovery paths work, but a refusal after streamed tool input no longer reliably reaches Hermes as a terminal refusal. There is one integration issue to address without turning streaming off.

Direction: This follows #164, #221, #326, #327, #328 and #341: expose tool preparation, recover broken calls without executing them, declare already-unsupported JSON-object mode, avoid deterministic retries, and retain refusal diagnostics. The four salvaged contributions retain their authorship. The refusal behavior requested in #326 is not yet preserved through core's stream assembly; see M1.

Critical Major Minor CI
0 1 0 — none

Checked:

  • Compared the complete 12-file delta against #357 at a8b0fa89; traced provider registration → Client.create → request validation/history → relay capture → native stream events → final chunks → Hermes' actual _StreamingCall._call_chat_completions and response normalizer. Also read the plugin's AGENTS, README, CHANGELOG and repository contribution rules.
  • Linux/Python 3.14: full head suite 5 failed, 576 passed, 9 subtests passed; #357 suite 5 failed, 557 passed, 9 subtests passed. All five failures are inherited, not findings here. The four refusal-helper failures need main's #370 test-stub update; the other failure is the Linux no_uid simulation under the stripped test environment and passes with USER restored.
  • All seven changed test files: 103 passed, RUNNER_RC=0. Copied only those tests onto #357: 23 failed, 80 passed; the failures exercise date folding, names, ID normalization, broken calls, streaming and diagnostics. The pre-start rejection test's missing exception class is not, by itself, behavioral proof.
  • Default eager streaming stays on; complete tools and no-argument tools still return one call in one upstream request. Broken nonrefused arguments and truncated arguments finish length; only invalid, nontruncated JSON disables eager input on the next request. Foreign IDs stay paired, valid IDs and signed replay stay intact, and offered-name mapping preserves the original tool name. Existing async, cancellation, workspace, credential-isolation and proxy/CA tests ran in the full suite.
  • Both offline native evals passed on Claude Code 2.1.292, including the 25-request cache-wire check. A paced real-native positive control emitted the tool header at 1.111 s, before the final chunk at 2.311 s, with argument fragments assembled exactly once; the fix retains the same three tool deltas. Eleven isolated production mutations each made a PR test fail. Two concurrent fixture calls completed independently; eight threads inserting 1,000 conversation flags retained the configured 256 entries.
  • Trial merge with current main 8b5b6296: the only textual conflict is the inherited plugin version choice, already present for #357. Keeping 0.4.0 gives 1 failed, 584 passed, 9 subtests passed; only the same no_uid harness case remains. No tests workflow ran at this stacked head; the CI cell does not represent the local suite.

Not checked: Live model inference, the private timing/cache/billing receipts or the two screenshot claims, Claude Code 2.1.319, and Windows/macOS execution. No platform-specific finding is inferred from Linux results.

Security: Checked the changed native-control-protocol and history inputs against the plugin's credential/host-execution promises and Hermes SECURITY.md §§2.2–2.6: argument injection, profile credential scoping, child environment, loopback routing, temp-directory/symlink handling and process cleanup. No new security-boundary issue found; M1 is a refusal/retry correctness issue, not containment against an adversarial model.

Thanks @alt-glitch! Keeping eager streaming enabled while handling malformed input separately is worth preserving.


Critical — none


Major

M1: A refusal after streamed tool input loses its explanation, or becomes a retryable truncation · directsdk.py / core stream assembly

  • Where: tool fragments emitted before completion, suffix-only refusal finalization, and the test that stops before Hermes assembly.

  • Problem: When native has already streamed a tool header and argument bytes before a no-text refusal, clearing the final response object's calls cannot retract the earlier deltas. Hermes assembles those deltas rather than adopting chunk._response. With the repairable prefix {"path":"/tm, the tool remains in the assembled message, suppressing promotion of message.refusal into displayed content. With malformed eager input {"path": /tmp/a.txt}, _json_suffix cannot repair it, and core changes content_filter to length. The latter enters truncation recovery instead of the terminal refusal path. #357 returned neither call and preserved the reason. This confirms and extends @greptile-apps' “Refusal tests stop too early” observation.

  • Evidence: Real Claude Code 2.1.292, a paced loopback SSE peer with named events, and Hermes' actual stream driver; no model inference or real login. Each row is a separate request. TREE selects the reviewed checkout; CLAUDE selects the pinned executable.

    $ python -I real_driver.py "$TREE" --claude "$CLAUDE" --check
    {"raw": "{\"path\":\"/tm", "finish": "content_filter", "tools": 1, "content": null, "requests": 1}
    {"raw": "{\"path\": /tmp/a.txt}", "finish": "length", "tools": 1, "content": null, "requests": 1}
    REFUSAL_FAILURES=2
    PROBE_RC=1
    

    The identical probe on #357 reports content_filter, zero tools and Flagged for both rows. With the companion fix below, both report content_filter, zero tools and Flagged (request_id=req_fixture01); REFUSAL_FAILURES=0, exit 0. This demonstrates the wrong finish/reason, not an actual repeated paid request or tool execution.

  • Fix: I'd suggest pairing this with a core change that discards accumulated tool fragments on a provider-confirmed content_filter before argument repair and refusal promotion, then requiring a core version containing that change. A three-line companion fix was verified on a disposable core copy; all 103 PR changed-file tests remain green without edits. Add a regression that feeds the real streamed chunks into core for both prefixes above; checking only the last chunk and one Client.create misses the problem.

    Verified companion core change
    --- a/agent/chat_completion_helpers.py
    +++ b/agent/chat_completion_helpers.py
    @@
    +        # A terminal provider refusal invalidates every tool fragment already streamed.
    +        if finish_reason == "content_filter":
    +            tool_calls_acc = {}
             mock_tool_calls, has_truncated_tool_args = self._assemble_tool_calls(tool_calls_acc, finish_reason)
  • Feature check: Ordinary complete tools and no-argument tools still complete in the default streaming configuration at #357, head and fix; malformed nonrefused calls still finish length at head/fix. The fix does not disable tool headers, argument streaming, signed replay or eager input, and all 103 changed-file tests pass with it.


Minor — none

Good

  • Foreign-ID normalization reserves already-valid identifiers first and rewrites calls/results together without altering source history or payload strings.
  • Broken JSON retains its raw arguments and changes the next request's eager-input policy only when the upstream stop was not max_tokens.
  • Refusal request IDs are bounded and validated before entering diagnostics, rather than logging arbitrary header contents.

@greptile-apps

greptile-apps Bot commented Nov 10, 2026

Copy link
Copy Markdown

M1 is valid. close_refused() can append a suffix when the streamed arguments are repairable, but it cannot retract tool-call fragments already emitted. For malformed arguments, it may append nothing; in both cases Hermes can still assemble the earlier tool call, so the refusal is not reliably terminal. The existing refusal test checks the plugin's chunks, not core's assembled response. Keep eager streaming enabled, but clear accumulated tool calls in core on content_filter before assembly/promotion, and add a regression that feeds these streamed chunks through Hermes for both prefixes.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@alt-glitch

Copy link
Copy Markdown
Contributor Author

@greptileai review

@greptile-apps

This comment has been minimized.

@alt-glitch

Copy link
Copy Markdown
Contributor Author

@greptileai review

@alt-glitch
alt-glitch merged commit 64c98c6 into main Nov 15, 2026
65 of 66 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment