Repository navigation
feat: finish client-side idempotency gaps from #568 - #604
Merged
Merged
Conversation
Finishes the remaining #568 work left open after #590: typed errors are now surfaced on TaskResult, `replay_ttl_seconds` is exposed on the client with fail-closed semantics, `useIdempotencyKey()` validates BYOK input up front, and idempotency keys are redacted from debug logs by default. - TaskResult.errorInstance: IdempotencyConflictError / IdempotencyExpiredError attached automatically when the seller returns those codes. The SDK pulls the sent idempotency_key from task state — the server intentionally omits it from error bodies (it's a read-oracle). - adcpErrorToTypedError helper lets callers that already hold an AdcpErrorInfo type-narrow it themselves. - getIdempotencyReplayTtlSeconds() on SingleAgentClient / AgentClient reads adcp.idempotency.replay_ttl_seconds from cached capabilities. Throws on v3 sellers that omit the (required) declaration rather than defaulting to 24h, which would mislead retry-sensitive flows. - useIdempotencyKey(key) validates against IDEMPOTENCY_KEY_PATTERN up front. - redactIdempotencyKey / redactIdempotencyKeyInArgs truncate keys to 8 chars in MCP and A2A debug logs. ADCP_LOG_IDEMPOTENCY_KEYS=1 opts into full logging for local debugging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Format-only change to satisfy the Code Quality CI job. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Security (security-reviewer): - Redact idempotency_key in Activity.payload.params — this is the observability hook buyers typically pipe into Datadog/Sentry, so the key was leaving the process in the clear. - Tighten useIdempotencyKey() invalid-key preview from 32 chars to 8 to match the redactIdempotencyKey() policy — near-valid 16-char keys were flowing verbatim into exception messages. - Make idempotencyKey non-enumerable on IdempotencyConflictError / IdempotencyExpiredError so console.log(err) and JSON.stringify don't leak the key (parameter properties are enumerable by default in TS; explicit Object.defineProperty fixes it). DX (dx-expert): - Teach docs/llms.txt the errorInstance instanceof pattern, the getIdempotencyReplayTtlSeconds() fail-closed behaviour, and the useIdempotencyKey() BYOK helper — previously only mentioned in the changeset. - Add an Idempotency section to README with the four-line happy path. Code quality (code-reviewer): - Add tests for redactIdempotencyKeyInArgs covering the referential- equality contract the A2A rebuild-only-when-changed logic depends on, plus JSON-serialization leak tests for the non-enumerable key fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
docs/llms.txt is generated by scripts/generate-agent-docs.ts — editing the output directly lost on CI regenerate. Move the errorInstance instanceof, useIdempotencyKey, and getIdempotencyReplayTtlSeconds sections into the generator so they survive regeneration. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Apr 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the remaining acceptance criteria from #568 that were left open after PR #590. Four concrete additions, all additive / non-breaking.
TaskResult. When the seller returnsIDEMPOTENCY_CONFLICT/IDEMPOTENCY_EXPIRED, the result now carries anerrorInstancepopulated with the correspondingADCPErrorsubclass. Callers who want `if (result.errorInstance instanceof IdempotencyConflictError)` get it without switching on code strings. The SDK pulls the sent `idempotency_key` from tracked task state — the server intentionally omits it from error bodies (read-oracle).Plus `adcpErrorToTypedError(adcpError, key)` exported for callers that already hold an `AdcpErrorInfo` and want to type-narrow themselves.
Public API additions
```ts
import {
adcpErrorToTypedError,
useIdempotencyKey,
redactIdempotencyKey,
type IdempotencyCapabilities,
} from '@adcp/client';
const ttl = await client.getIdempotencyReplayTtlSeconds(); // throws on non-compliant v3
```
Not a breaking change
`TaskResult.errorInstance` is additive — existing code switching on `adcpError.code` still works. The new method only throws when callers explicitly ask for it against a non-compliant seller.
Test plan
🤖 Generated with Claude Code