Skip to content

feat: opt-in request fingerprint cache for un-keyed retries - #13

Open
Shifat7 wants to merge 1 commit into
clutchpbcfo:mainfrom
Shifat7:pr-06-request-cache
Open

Shifat7 wants to merge 1 commit into
clutchpbcfo:mainfrom
Shifat7:pr-06-request-cache

Conversation

@Shifat7

@Shifat7 Shifat7 commented Aug 22, 2026

Copy link
Copy Markdown

What changed

Codex retries identical requests after local hiccups without an Idempotency-Key; each retry previously created another Hyperagent thread. Adds an opt-in cache of completed successful responses keyed by the existing canonical-body fingerprint (sha256):

  • src/config.mjs — lookupResponseCache / storeResponseCache behind a dedicated file lock; TTL pruning + oldest-first eviction; stored in private state dir (0600).
  • src/bridge.mjs — injectable cacheManager; un-keyed requests consult it before dispatch; hits replay locally with X-Response-Cache-Replayed: true and a sanitized response_cache_replayed gateway event; successful completions are stored only when no explicit key was used.

Config (all opt-in): enableResponseCache (false by default), responseCacheTtlMs (30 min), responseCacheMaxEntries (128).

Safety

  • Only completed successes cached — errors, cancellations, in-progress/indeterminate never.
  • Explicit Idempotency-Key always wins; its flows skip the cache entirely.
  • Off by default because silent replay changes semantics for un-keyed requests; enabling is an operator decision.

Why it saves credits

Duplicate retries stop creating duplicate Hyperagent threads.

Testing

npm test: 80 pass, 0 fail. New tests: store/replay exactness, TTL expiry + pruning, maxEntries eviction, no caching of failed dispatches, and Idempotency-Key precedence.

Store completed successful responses by sha256(canonical JSON body)
in the private state directory and replay identical un-keyed requests
locally until the TTL expires (bounded by maxEntries). Errors,
cancellations, and indeterminate dispatches are never stored; explicit
Idempotency-Key flows take precedence and skip the cache entirely.

Disabled by default: enableResponseCache must be explicitly true.
Replay is marked with X-Response-Cache-Replayed and a sanitized
gateway log event.
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