You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(idempotency): is_wrapped() misses @store.wrap under any outer decorator, so boot validation rejects a wired platform #1295
On 8.0.0, is_wrapped(fn) returns True only when fn itself is the closure that IdempotencyStore.wrap returned (adcp/server/idempotency/store.py:89-99). Put any decorator on top of @store.wrap, even one that uses functools.wraps and keeps __wrapped__ pointing at the wrapped function, and is_wrapped returns False. The boot validator then rejects the platform, because it advertises idempotency.supported=True but appears to have no wrapped method. The validator runs in create_adcp_server_from_platform (decisioning/serve.py:475-479), and again per request for scoped capabilities in PlatformHandler.get_adcp_capabilities (decisioning/handler.py:1886-1894).
is_wrapped(outer): False
is_wrapped(outer.__wrapped__): True
validator: AdcpError INVALID_REQUEST | AdcpError[INVALID_REQUEST / terminal]: capabilities.adcp.idempotency.supported=True is dec
The comment at store.py:367-373 explains why the check doesn't call inspect.unwrap(): that returns the innermost handler, which is not in the set. That reasoning holds for unwrap-then-check. It does not rule out checking each link of the __wrapped__ chain.
Why an adopter hits this
Outer decorators on handlers are common: error translation, metrics, tracing, auth. Embedded Sales Agent wraps every idempotent method in translate_idempotency_conflict (core/idempotency.py), which maps IdempotencyConflictError to a wire IDEMPOTENCY_CONFLICT with recovery="correctable". Without a workaround, the platform fails boot validation.
ESA's workaround imports the private registry and adds its outer function to it (_WRAPPED_FUNCTIONS.add(_wrapper), core/idempotency.py ~line 112). It guards the import with except (ImportError, AttributeError) in case the SDK renames it. The other option, _adcp_idempotency_external = True, turns the check off for the whole platform, which defeats its purpose.
Ask
Either option keeps the existing spoof resistance, because membership is still granted only by IdempotencyStore.wrap:
Have is_wrapped walk the __wrapped__ chain with a bounded depth, and return True if any link is in _WRAPPED_FUNCTIONS.
Add a public mark_wrapped(outer, inner) (or IdempotencyStore.register_outer(outer, inner)) that registers outer only if inner is already registered.
Classification: Bug Bucket(s): middleware (label not found in repo — flagged in run summary) Status: ready-to-implement Milestone: (omitted — no version target named)
What the experts said:
code-reviewer: Fix is correct and non-breaking; missing test for @outer @store.wrap scenario is a blocker that must ship with the fix; docstring needs functools.wraps contract note; update the store.py:367–373 comment to describe the per-step chain-walk vs. inspect.unwrap().
security-reviewer: Safe to ship._WRAPPED_FUNCTIONS is still only written by IdempotencyStore.wrap — the chain-walk changes what is_wrapped accepts as evidence, not what gets registered. Spoof via manual __wrapped__ assignment is no worse than the existing _adcp_idempotency_external escape hatch. Update the maintainer comment at store.py:367–373 so it doesn't mislead future maintainers into reverting the fix.
My take: The root cause is clear and both experts converge on Option 1 (walk the __wrapped__ chain, check each link). Option 2 (mark_wrapped public API) has the same spoofing surface with worse adopter ergonomics, and the existing _adcp_idempotency_external escape hatch already covers fully external dedup. This is a non-breaking bug fix that should land before ESA's private-registry workaround spreads further.
Implementation scope:
src/adcp/server/idempotency/store.py — is_wrapped() (lines 89–99): Replace the direct membership check with a bounded __wrapped__ chain-walk (depth cap of ~16 to guard against pathological cycles). Check each link; return True as soon as any link is in _WRAPPED_FUNCTIONS. __func__ resolution applies only to the outermost call (mid-chain links are always raw functions via functools.wraps). Add a # guard against pathological __wrapped__ cycles comment on the depth cap.
src/adcp/server/idempotency/store.py — comment block at lines 367–373: Replace the "Do NOT change to inspect.unwrap()-then-check" language with a note explaining that per-step chain-walk is the correct idiom and why it differs from full unwrapping (full unwrap reaches the original handler, which is not in the set).
src/adcp/server/idempotency/store.py — is_wrapped() docstring: Add a line stating that outer decorators must use functools.wraps (or otherwise set __wrapped__) for the chain-walk to reach the registered wrapper. An outer decorator that omits functools.wraps will still fail validation — this is expected and should be mentioned in the error message path.
tests/test_validate_idempotency_wiring.py — TestIsWrapped: Add a test: apply a @functools.wraps-using outer decorator on top of @store.wrap and assert is_wrapped(outer) returns True. Also assert the two-deep case (@outer1 @outer2 @store.wrap) works. Verify is_wrapped still returns False for an outer decorator that does NOT use functools.wraps.
Required checks before PR:pytest tests/test_validate_idempotency_wiring.py, mypy src/adcp/server/idempotency/, ruff check ..
Non-breaking rationale:is_wrapped only gains True returns where it previously returned False (false negatives). No public API signature changes. Existing wrapped functions are found on the first iteration with no behavior change.
Activity
bokelley commentedon Oct 2, 2026
Triage
Classification: Bug
Bucket(s): middleware (label not found in repo — flagged in run summary)
Status: ready-to-implement
Milestone: (omitted — no version target named)
What the experts said:
@outer @store.wrapscenario is a blocker that must ship with the fix; docstring needsfunctools.wrapscontract note; update the store.py:367–373 comment to describe the per-step chain-walk vs.inspect.unwrap()._WRAPPED_FUNCTIONSis still only written byIdempotencyStore.wrap— the chain-walk changes whatis_wrappedaccepts as evidence, not what gets registered. Spoof via manual__wrapped__assignment is no worse than the existing_adcp_idempotency_externalescape hatch. Update the maintainer comment at store.py:367–373 so it doesn't mislead future maintainers into reverting the fix.My take: The root cause is clear and both experts converge on Option 1 (walk the
__wrapped__chain, check each link). Option 2 (mark_wrappedpublic API) has the same spoofing surface with worse adopter ergonomics, and the existing_adcp_idempotency_externalescape hatch already covers fully external dedup. This is a non-breaking bug fix that should land before ESA's private-registry workaround spreads further.Implementation scope:
src/adcp/server/idempotency/store.py—is_wrapped()(lines 89–99): Replace the direct membership check with a bounded__wrapped__chain-walk (depth cap of ~16 to guard against pathological cycles). Check each link; returnTrueas soon as any link is in_WRAPPED_FUNCTIONS.__func__resolution applies only to the outermost call (mid-chain links are always raw functions viafunctools.wraps). Add a# guard against pathological __wrapped__ cyclescomment on the depth cap.src/adcp/server/idempotency/store.py— comment block at lines 367–373: Replace the "Do NOT change toinspect.unwrap()-then-check" language with a note explaining that per-step chain-walk is the correct idiom and why it differs from full unwrapping (full unwrap reaches the original handler, which is not in the set).src/adcp/server/idempotency/store.py—is_wrapped()docstring: Add a line stating that outer decorators must usefunctools.wraps(or otherwise set__wrapped__) for the chain-walk to reach the registered wrapper. An outer decorator that omitsfunctools.wrapswill still fail validation — this is expected and should be mentioned in the error message path.tests/test_validate_idempotency_wiring.py—TestIsWrapped: Add a test: apply a@functools.wraps-using outer decorator on top of@store.wrapand assertis_wrapped(outer)returnsTrue. Also assert the two-deep case (@outer1 @outer2 @store.wrap) works. Verifyis_wrappedstill returnsFalsefor an outer decorator that does NOT usefunctools.wraps.pytest tests/test_validate_idempotency_wiring.py,mypy src/adcp/server/idempotency/,ruff check ..is_wrappedonly gains True returns where it previously returned False (false negatives). No public API signature changes. Existing wrapped functions are found on the first iteration with no behavior change.Triaged by Claude Code. Session: https://claude.ai/code/session_01MFKwWqzacWU1RJCGobp5GT
Generated by Claude Code