Repository navigation
Description
Parent epic: #929
Phase: 2 (follow-up to #1141 / PR #1454)
Depends on: nothing
Blocks: nothing
Problem
LocalFileBinding.release() does not fully deregister the adapter, so its
qualified_name stays claimed for the backend's lifetime and no later binding can
register under it.
release() calls AdapterMixin.unload_peft_adapter, which removes the entry from
LocalHFBackend._loaded_adapters — but nothing removes it from _added_adapters,
the registered set that add_adapter populates and that add_adapter itself
checks for duplicates. There is no inverse verb for add_adapter on the mixin, so
the binding has nothing to call.
Observed, with a fake backend reproducing LocalHFBackend.add_adapter's guards:
after prepare : backend set = True | _added_adapters = ['answerability_lora']
after release : backend = None | _staged_backend = None | _added_adapters STILL = ['answerability_lora']
re-prepare without bind_backend -> RuntimeError: requires bind_backend() to be called first
re-prepare after bind_backend -> RuntimeError: Backend refused to register 'answerability_lora'
Two consequences:
- The name is burned. A different
LocalFileBindingfor the same capability
can never be registered on that backend after the first one is released, even
though the first is fully torn down from the model's point of view. release()overstates itself. Its docstring said "releases all resources"
and feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1141's acceptance criterion says "release()cleanly unregisters". Neither
was accurate. PR feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1454 corrects the docstring to say exactly what is and is not
released, and points here.
The actual question: should re-registration be supported at all?
This issue is a question first, not an agreed fix. The merged WeightsBinding
contract (mellea/backends/adapters/_core.py, from #1134) says:
release()— terminal; releases all resources. The binding is not reusable
afterrelease().
If "terminal" is meant strictly, then a released binding never being revivable is
correct, and the only defects are the wording and the confusing error. But
#1141's own text says the opposite — "prepare once per session (or explicit
release()+prepare() cycle)" — which the merged ABC forbids. That contradiction
has been flagged on #1141 and needs settling here.
So, in order:
- Decide the contract. Is a binding reusable after
release()? The ABC says
no; feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1141 said yes. One of them is wrong. - Only then decide the mechanism. If bindings stay terminal, the fix may be
nothing more than what PR feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1454 already did (accurate docstring, clearer error)
plus a decision about whether a fresh binding should be able to claim a
released name — which is the case that actually bites. - If a released name must become re-claimable,
add_adapterneeds an inverse.
That is a change to the mixin verb contract, which feat(backends): EmbeddedBinding implements apply_activation (Granite Switch path); remove render_controls + set_request_adapter (Epic #929 Phase 2) #1142 and add support for granite-switch / embedded adapters on our huggingface backend #1018 also build
on, so it should not be done incidentally.
Why it matters for #1465
#1465 routes intrinsic generation through adapter_scope. If that work ends up
preparing a binding per call rather than once per session, it hits this
immediately — the second call cannot register. Worth resolving before #1465 picks a
lifetime for its bindings, even if the resolution is "terminal is correct, prepare
once".
Scope
- Settle whether
WeightsBinding.release()is strictly terminal, and reconcile the
ABC docstring with feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1141's text so they no longer contradict. - Decide whether a released
qualified_nameshould become re-claimable by a fresh
binding, and if so add the inverse ofadd_adapterto the mixin contract. - Whatever is decided, cover it with a test: either that re-registration after
release works, or that it fails with a clear, accurate error.
Not in scope
Changing unload_peft_adapter's own semantics — it correctly manages the loaded
set. The gap is the absent registered-set counterpart.
References
- PR feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1454 — added
release(), corrected its docstring and the misleading
"Backend refused to register" message to point here - feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1141 — acceptance criterion "
release()cleanly unregisters"; its
"release()+prepare()cycle" line contradicts the merged ABC - Found while verifying a third-party review of PR feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) + from_catalog() (Epic #929 Phase 2) #1454
Activity
fix(backends): address review findings on release(), phase hooks and …
planetf1 commentedon Aug 11, 2026
Additional findings, from finishing PR #1454
Four things a future implementer will want, none of which were in the original write-up.
1. The leak is visible through the public API, not just internal state
LocalHFBackend.list_adapters()isreturn list(self._added_adapters.keys()). Sincerelease()never clears_added_adapters, a released adapter is still reported bylist_adapters()— indefinitely. So this is not merely internal bookkeeping drift;it is the documented public accessor giving an answer that contradicts "released".
Note
list_adapters()'s current contract is deliberate and correct as written — itsdocstring says "all adapters that have been registered via
add_adapter, whether ornot they have also been loaded", and #1140 changed it to read
_added_adaptersprecisely so
LocalHFBackendandOpenAIBackendagreed. So the fix is not "makelist_adaptersignore released adapters"; it is deciding whetherrelease()shouldderegister at all. If it should,
list_adapters()follows for free.2. The behaviour is already pinned by a test — treat that as the tripwire
test/backends/test_adapters/test_local_file_e2e.py(end of the lifecycle test)already encodes it, with a comment:
That assertion deliberately reaches for
_loaded_adaptersbecauselist_adapters()would fail. So the limitation was understood during implementation;what was missing was it being reflected in
release()'s docstring and #1141'sacceptance criterion (both now corrected).
Useful consequence: any change to this contract must update that test and delete that
comment, which makes the decision impossible to make silently. Worth keeping as the
canary rather than loosening it.
3.
release()also retains the object, not just the nameadd_adapterdoesself._added_adapters[adapter.qualified_name] = adapter— a strongreference to the binding. So after
release()the backend still holds the bindingalive for its own lifetime. Minor next to the name collision, but it is the other half
of why "releases all resources" was inaccurate, and it matters for a long-lived backend
cycling through many adapters.
4. Which bindings the contract question actually touches
Scoping the blast radius, so this does not get treated as wider than it is:
LocalFileBindingEmbeddedBindingprepare/activate/deactivate/releasemethods added toEmbeddedBinding"ServerMediatedBindingNotImplementedErrorstubsSo in practice: #1465 needs the answer, a future 3.1 will inherit it, and #1142 is
unaffected.
5. The ABC already sanctions documenting a deviation
WeightsBinding's docstring says: "Concrete implementations are expected to documentany deviations from this contract (e.g. servers that prepare-and-activate atomically)."
PR #1454 did exactly that, so the current state is contract-conformant rather than a
violation. The open question is narrower than "fix the bug": should this deviation
persist, or should
release()become a true inverse ofadd_adapter? If the answeris "persist", this issue closes with no code change beyond what #1454 already shipped.
fix(backends): address review findings on release(), phase hooks and …
feat(backends): LocalFileBinding implements verbs (PEFT/aLoRA path) +…
fix(backends): close review gaps in remove_adapter()'s inverse-verb c…
fix(backends): address review findings on the adapter registry lifecycle
fix(backends): release() deregisters via a new remove_adapter() inver…