Skip to content

fix: give one next action when a confirmation token is rejected - #253

Merged
bardesss merged 2 commits into
mainfrom
fix/confirm-rejection-one-instruction
Sep 14, 2026
Merged

bardesss merged 2 commits into
mainfrom
fix/confirm-rejection-one-instruction

Conversation

@bardesss

Copy link
Copy Markdown
Owner

Problem

Raised during the review of #249 and left out of it, since #249 was already doing one thing well.

When a presented token is rejected for expired, mismatch or malformed, the handler issues a fresh one and returns it. The text it returns reads:

Not applied — the confirmation token was rejected (malformed). That is not a confirmation token issued by this server. Call this tool again without confirm to preview the operation and use the token it returns verbatim. A fresh token for this exact operation: v1.….

Two different next actions in one paragraph. check.remedy is right for a failure that hands nothing back — used throws, and it is the one rejection that deliberately does not reissue — but every failure that reaches this branch has just minted a token, named one sentence later. A caller that follows the remedy throws away a good token and spends another preview.

Before #249 the trailing sentence pointed at confirm_token, which a text-only client could not see, so the remedy was the only reachable instruction and the conflict was latent. Making the token visible surfaced it.

Fix

check.remedy comes out of the text and stays in confirm_error, so the diagnosis is still there for anything that reads the structured half. The text gives one instruction, worded the way the plain preview words it:

Not applied — the confirmation token was rejected (malformed). Do not resend the rejected one. To apply this, call delete_media again with the same arguments plus confirm set to v1.….

The word order is load-bearing

My first attempt put the warning after the token (set to \v1.…` — not the token that was just rejected`). A probe caught that this breaks the thing both this and #249 exist for. Clipping the token out of the sentence four plausible ways:

                       before          after
last backticked span   applied         applied
with its backticks     applied         applied
last whitespace word   FAILED          applied
after "set to "        FAILED          applied

unwrap() from #250 strips punctuation, not a trailing clause. #249's preview text already ended with the token, which is why it survived all four. Ending the rejection the same way is what makes the two paths behave alike, so there is now a test pinning that invariant for both rather than a convention nobody wrote down.

All eight combinations (two texts, four clips) apply, with apply() firing once each.

Tests

test/writeTool.test.ts, both written before the change and watched to fail:

  • the rejection text carries one next action, not two: it names the fresh token and no longer says "without confirm", while confirm_error still does
  • both the preview and the rejection end with the token itself

The three gates

> arr-mcp@1.26.5 lint
> eslint .

> arr-mcp@1.26.5 typecheck
> tsc --noEmit

 Test Files  103 passed (103)
      Tests  2683 passed (2683)

What was exercised

Harness tests, plus the before-and-after clipping measurement above against the real registerWriteTool and ConfirmTokens. Not run against a live stack. The change is two template strings and the removal of one interpolation; no response field changes, so it is a fix:.

🤖 Generated with Claude Code

bardesss and others added 2 commits September 14, 2026 16:29
The rejection text interpolated check.remedy, which says to call the tool
again *without* `confirm`. That is right for a failure that hands nothing
back, and wrong here: every rejection that reaches this branch has just
issued a fresh token, named in the very next sentence. A caller that
follows the remedy discards a usable token and spends another preview.

The remedy stays in `confirm_error` as the diagnosis. The text now gives
the single next action, worded the way the plain preview words it.

The token also moves to the end of the sentence, which is the property
that makes it liftable. A reader clipping the trailing word or the final
backticked span gets the token; prose after it defeats both, and unwrap()
strips punctuation, not a clause. Measured across both texts and four
clipping strategies, all eight now apply; with the warning after the
token, two of four failed on the rejection path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bardesss
bardesss merged commit c581462 into main Sep 14, 2026
2 checks passed
@bardesss
bardesss deleted the fix/confirm-rejection-one-instruction branch September 14, 2026 14:36
bardesss added a commit that referenced this pull request Nov 6, 2026
The rejection text interpolated check.remedy, which says to call the tool
again *without* `confirm`. That is right for a failure that hands nothing
back, and wrong here: every rejection that reaches this branch has just
issued a fresh token, named in the very next sentence. A caller that
follows the remedy discards a usable token and spends another preview.

The remedy stays in `confirm_error` as the diagnosis. The text now gives
the single next action, worded the way the plain preview words it.

The token also moves to the end of the sentence, which is the property
that makes it liftable. A reader clipping the trailing word or the final
backticked span gets the token; prose after it defeats both, and unwrap()
strips punctuation, not a clause. Measured across both texts and four
clipping strategies, all eight now apply; with the warning after the
token, two of four failed on the rejection path.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant