1jehuang / 1jehuang/jcode

[Feature/Bug] Add native turn-scoped deduplication for identical tool calls

Open
#1,029 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autonomous: no bug enhancement priority: high recurring-theme triage: needs-decision
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:

  1. Expose a stable turn/step identifier to pre_tool, or provide a built-in deduplication policy.
  2. Define whether an exact duplicate in one batch is collapsed to one execution with shared results or rejected with a structured error.
  3. Do not deduplicate calls with different canonical inputs, changed state, or an explicit retry path.
  4. Preserve correct tool-result mapping when a batch contains duplicates and when calls run concurrently.
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.