Replace pickers with composable Store backends - #273
Open
bruno-f-cruz wants to merge 11 commits into
Open
Conversation
Retires clabe.pickers in favour of a Store protocol (resolve/list/write/scoped) with a Kind descriptor binding a record name to its pydantic model. - clabe.ui gains ambient passthroughs for every Frontend method, so stores and builders no longer thread a frontend. Output methods no-op headless; prompts raise NoFrontendError. - clabe.stores: Kind, Store, StoreBase, CompositeStore, LocalFileStore (with a Layout reproducing today's config-library tree), DataverseStore, MemoryStore. - SessionBuilder keeps the one interactive job with no database behind it, and drops the makedirs side effect from session construction. - ByAnimalModifier moves to clabe.modifiers and reads/writes through a Store.
MemoryStore appends rather than replacing, as Dataverse does: a fake that can only ever hold one record per kind and scope cannot stand in for a store with several candidates, and rebinding its record list broke scoped views sharing the same data.
Examples declare their record kinds once in _mocks.py and use the ambient prompts, which is the pattern the refactor is for. The mkdocs nav is the output of docs/build.py, so it also picks up sections that had drifted out of the committed file (web, aind_apps, logging, runnable, aind_validators). CI regenerates it before deploying either way.
bruno-f-cruz
force-pushed
the
feat-stores
branch
from
September 8, 2026 15:50
1b10c9c to
6321d3d
Compare
msal is a Windows-only dependency of that extra, so eagerly importing the Dataverse backend from stores/__init__.py broke every import of clabe.stores on Linux. Dataverse becomes a public submodule imported explicitly, matching how data_transfer exports robocopy but not aind_watchdog.
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.
Retires
clabe.pickersin favour of a composableStore— a four-method interface over the databases that hold rigs, task logic, trainer state and per-animal reconfigurations.Implements the Pickers to Stores plan. Clean break — no deprecation shims. A companion PR against
Aind.Experiment.VrForagingfollows.Why
DefaultBehaviorPickerfused data access, user prompting,Sessionconstruction and recency caching into one object, andDataversePickersubclassed it purely to swap one record — trainer state — for a different backend. That inheritance is the defect; composition was what was wanted.What lands
clabe.ui— ambient frontend. Module-level passthroughs for everyFrontendmethod, finishing the patternnotify()already started. Output methods (notify,header,activity) no-op headless; prompts raiseNoFrontendErrorrather than hanging on a rig. Addsuse_frontend()as a context-manager form ofset_current_frontendfor tests.clabe.storesKind[T]from_rig/from_task/from_session/from_trainer_statefix the canonical names; the bare constructor snake-cases the model name for custom records.Storeresolve(interactive) ·list(headless) ·write·scopedStoreBaseCompositeStoreLocalFileStoreLayout.DataverseStoreclabe.stores.dataverseand is not re-exported fromclabe.stores, becausemsalis a Windows-only dependency of theaind-servicesextra — the same convention asdata_transfer.aind_watchdog.MemoryStoreSessionBuilder(clabe/session.py) keeps the one genuinely interactive job with no database behind it. It holds no hidden state, so recovery flows narrow a store explicitly instead of pokingpicker._session.ByAnimalModifiermoves toclabe.modifiersand reads/writes through aStore, so it stops reaching intopicker.subject_dir.Call-site accounting
picker.pick_rig(Model)store.resolve(VR_RIG)picker.pick_task(Model)store.resolve(VR_TASK)picker.pick_trainer_state(Model)store.resolve(SUGGESTION)picker.push_new_suggestion(ts)store.write(SUGGESTION, ts)picker.dump_model(rig)store.write(VR_RIG, rig)picker.pick_session(Session)SessionBuilder(launcher).build()picker.subject_dirstore.scoped(subject=...)Hard constraint honoured
DefaultLayoutreproduces the existing tree on\allen\aind\scratch\AindBehavior.db\...byte-for-byte:Rig/<COMPUTERNAME>/*.json,Task/*.json,Subjects/<subject>/{task,trainer_state}.json. No migration. The library-wide vs subject-specific task lookup — a nested try/while inpick_task— is now an ordered scope chain: subject folder first, then the shared library.Deviations from the plan, and why
ConfiergeStoreis not in this PR.ConfiergeServiceonly exists on the unmergedfeat-add-ficus-adapterbranch. The adapter slots in with no base-class change once that lands.SessionBuilder.subject_sourcedropped. The plan marked it an extension point with no caller; there is no sensibleKindfor a bare subject string. Add it when something needs it.store.resolve(ManipulatorPosition)wraps the model inKind(...)internally. The naming trap (Kind(AindVrForagingRig)→"aind_vr_foraging_rig", not"rig") is documented onKind.resolvenow floats recently-chosen options to the top of one list. The picker'suse_cacheflag is gone — ordering never changes what is selectable.Kind.from_trainer_state's validator (reject stageless, warn off-curriculum), so both backends get them from one place.Open
writereturnsNone. Revisit if a caller needs the written id.LocalFileStore.resolveoffers the pick list only; no file-browse escape hatch yet.