Skip to content

[Bug]: Reused tool-call IDs collide during terminal settlement and close streams without run_finished #1093

Closed

Description

@aptend

Existing issue check

  • Searched for stream closed before run_finished and tool/collision reports; no matching report found.

Version and environment

Astra 0.2.12, commit 92324dce9a34fd012dc2fc71f3680acfa2d5ef8e, Linux x86_64, Server + remote CLI Edge. Server and CLI were built from the same revision. The affected session used Kimi-K3 through an OpenAI-compatible provider.

Actual behavior

A long session repeatedly ends with:

[contract_violation] stream closed before run_finished

The latest three affected runs failed during terminal persistence. Model requests preceding settlement succeeded; the stream error does not indicate that no task work was executed.

In the most recently inspected run, durable tool_call events contained 34 calls but only 22 distinct call IDs. In particular, bash:83 appeared five times with five different argument hashes:

Run event index Call ID SHA-256 of arguments, shortened
26 bash:83 7d424f543a41
77 bash:83 100a106170af
84 bash:83 644a7cb5e77b
106 bash:83 4fb1380cc516
143 bash:83 72f87f8f53f0

Other repeated IDs included bash:82, bash:84, read_file:85, and read_file:86. These are observations of the runtime's recorded calls; the investigation has not isolated whether ID reuse originates in provider output, adaptation, or replay.

Evidence and failure sequence

On 2026-10-20 at approximately 18:08:28 UTC+8, the Server logged:

normal completion downgraded before durable commit because tool ledger is incomplete
attempted=22 terminal=22 unresolved=0 expected=34 consistent=false

This was followed by multiple:

agent event identity collision recorded without applying derived effects
source=runtime_trace_event

At 18:08:29 UTC+8:

failed to persist atomic streaming canonical terminal settlement
required canonical event trace:tool_call_rejected:63b95398b7a87ec0482a40fb was rejected; terminal settlement aborted

Computing the current trace ID from this run ID and bash:83 reproduces the conflicting suffix 63b95398b7a87ec0482a40fb.

The client then receives the generic missing-terminal stream failure. Several seconds later the durable run acquires a recovery-generated run_error and failed run_finished with error_code=crash_recovery and error="recovered from crash". The Server process remains healthy; these recovery events should not be interpreted as evidence of a process crash.

The same terminal-settlement rejection was observed in two preceding runs at approximately 17:06 and 17:57 UTC+8.

Code evidence

All links are pinned to the deployed revision:

  1. tool_trace_call_id returns record.tool_call_id unchanged when present. Its fallback includes a round/index, but that fallback is not used for these calls.
  2. build_tool_trace_events constructs start and terminal event IDs from [run_id, call_id]. Distinct calls sharing an ID within one run therefore receive identical trace event IDs despite differing arguments/rounds.
  3. Atomic terminal persistence rejects the conflicting canonical evidence and rolls back the settlement transaction.
  4. Streaming lifecycle error handling disables publication of the stream terminal when settlement fails.
  5. HTTP stream fallback consequently synthesizes stream closed before run_finished, hiding the actionable collision error from the client.

Expected behavior

  • Distinct admitted tool invocations must have distinct lifecycle event identities even when their display/provider call IDs repeat across rounds.
  • Replaying the same canonical invocation must retain stable identity and remain idempotent.
  • Tool accounting must not collapse distinct invocations merely because their provider/display IDs match.
  • A failed terminal transaction must preserve the actual persistence error in a typed client-visible outcome without falsely claiming successful durable completion.

Reproduction and regression coverage

The live failure is confirmed; a minimal deterministic reproduction has not yet been run. Suggested fixture:

  1. Use a mock provider to return the same tool-call ID in successive rounds with different arguments and independently admitted invocation identities.
  2. Execute/settle those calls and finish the run.
  3. Assert distinct canonical start/terminal events and correct invocation counts.
  4. Replay the exact same invocation and assert no duplicate effects.
  5. Inject an event identity conflict and verify the stream exposes the specific settlement failure while durable recovery remains consistent.

ToolCallRecord already carries an optional invocation_identity; investigate using the existing canonical invocation contract consistently for trace IDs and accounting rather than inventing another independent identity scheme.

No credentials, private endpoints, raw tool arguments, or proprietary task contents are included in this report.

Activity

  1. added
    kind/bug
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions