[Feature/Bug] Add native turn-scoped deduplication for identical tool calls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Summary
Jcode should prevent an exact duplicate tool call from executing twice within one agent turn or tool batch. This is a safety feature for side-effecting tools and is distinct from provider retry replay.
Observed behavior
In an active v0.79.1 Linux x86_64 session, the agent/tool path emitted identical tool calls while performing a bounded verification. The calls had the same tool name and equivalent JSON input. Without a native turn-scoped guard, an exact duplicate can be accepted as another execution.
The risk is higher for non-idempotent tools such as file mutation, email, payment, deployment, or external API operations.
Distinction from existing issue
This is not a duplicate of #314. That issue identified provider retry/replay and was fixed in v0.31.0. This report is about exact duplicate calls emitted or accepted within the current turn/batch even when there is no provider stream replay.
Current workaround
The host can use the existing synchronous pre_tool hook to fingerprint:
(tool name, canonical JSON input)
A local policy can block only an exact repeat during a short burst window, while allowing different inputs, different tools, different sessions, and retries after the window. The workaround stores hashes only. It is necessarily approximate because the current hook contract exposes a session id but no turn id.
Requested behavior
Please consider a native, turn-aware guard at the tool dispatch boundary:
- Expose a stable turn/step identifier to
pre_tool, or provide a built-in deduplication policy. - Define whether an exact duplicate in one batch is collapsed to one execution with shared results or rejected with a structured error.
- Do not deduplicate calls with different canonical inputs, changed state, or an explicit retry path.
- Preserve correct tool-result mapping when a batch contains duplicates and when calls run concurrently.
- Add regression coverage for duplicate batch entries, side-effecting tools, provider retry/replay, and legitimate retries.
Expected result
Each exact (tool name, canonical input) should execute at most once within the selected turn/batch boundary unless the caller explicitly opts into a retry.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing synchronous pre_tool hook into the tool dispatch boundary; the issue does not name specific files or tests. Clarify the turn/batch identifier and duplicate policy, then add regression coverage for duplicate batch entries, side-effecting tools, provider replay, and legitimate retries. Done means exact calls execute at most once per selected boundary while preserving result mapping and explicit retries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- ai, cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100