Skip to content

Document that an adapter instance represents one resource - #1046

Open
serioushaircut wants to merge 1 commit into
Shopify:mainfrom
serioushaircut:docs-adapter-shared-object-thread-safety
Open

Document that an adapter instance represents one resource#1046
serioushaircut wants to merge 1 commit into
Shopify:mainfrom
serioushaircut:docs-adapter-shared-object-thread-safety

Conversation

@serioushaircut

@serioushaircut serioushaircut commented Aug 27, 2026

Copy link
Copy Markdown

Documents the contract behind #1045: an adapter instance represents one resource, and
access through the same instance is assumed good until that session ends.

Motivation:
Trust Battery is essentially doing it "wrong" - semian adapter is in a process wide singleton for entirety of core, instead of a "session-y" object, and we run into some weirdness. That spawned this clarification (and I follow up with Trust Battery to fix their use).

Wording follows @matthewd's review. The one genuine race in the same area — the
re-entrancy guard being stranded permanently — is #1047.

Co-authored-by: Claude Opus 5 noreply@anthropic.com
Orchestrated-by: ae noreply@shopify.com

@serioushaircut

Copy link
Copy Markdown
Author

Status nudge rather than a bump: this one is docs-only (README, no behaviour change) and backs the hazard reported in #1045, so it should be cheap to review.

Two things that may help whoever picks it up:

  • The reproduction in Semian::Adapter's re-entrancy guard silently disables the circuit when the adapter is mixed into a shared object #1045 needs no monkey-patching and runs against 0.28.2. It shows an already-open circuit being bypassed by a shared adapter instance, and the guard being stranded at true permanently.
  • If the preferred outcome is fixing the guard in the gem rather than documenting the requirement, I am happy to close this and send that patch instead. It changes behaviour for every user — circuits that never opened will start opening — which is why I did not lead with it.

🤖 AE · ✅ approved by @serioushaircut

@serioushaircut
serioushaircut force-pushed the docs-adapter-shared-object-thread-safety branch from 4b3c0ee to 0642d6f Compare August 31, 2026 08:38
@serioushaircut
serioushaircut force-pushed the docs-adapter-shared-object-thread-safety branch from 0642d6f to 144e8ed Compare August 31, 2026 08:43
@serioushaircut serioushaircut changed the title Document that Semian::Adapter must not be shared between threads Document that an adapter instance represents one resource Aug 31, 2026
Semian::Adapter's contract is that the object it is included in stands
for a single resource, and that once that resource is acquired, further
access through the same instance is part of the same session: nested
calls neither re-enter the circuit breaker nor take a second bulkhead
ticket, so a circuit that opens elsewhere cannot interrupt a session that
is already in flight and succeeding. Every adapter that ships with the
gem has that shape - the mixin goes into a connection object.

Nothing said so, and the failure is silent when the requirement is not
met: with the instance shared process-wide, calls from other threads are
treated as part of whatever session is in flight, so they are not
fast-failed when the circuit is open and their failures are not counted.

State the contract in Creating Adapters and in Thread Safety, and
suggest a per-unit-of-work session object as the adapterized wrapper
around a singleton, noting that circuit and bulkhead state is keyed by
semian_identifier in a process-wide registry, so short-lived adapter
instances still share one circuit.

Refs Shopify#1045

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Orchestrated-by: ae <noreply@shopify.com>
Assisted-By: devx/39c7b308-c333-4ffe-8cd7-f642a14a4b7c
@serioushaircut
serioushaircut force-pushed the docs-adapter-shared-object-thread-safety branch from 144e8ed to aa60a3d Compare August 31, 2026 09:12
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.

2 participants