-
Notifications
You must be signed in to change notification settings - Fork 39
docs: formalize locator refresh state contract #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+145
−12
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| # Locator Refresh State | ||
|
|
||
| Refresh requests run on a transient locator graph. The server configures that graph from a single configuration snapshot, runs discovery, and then syncs selected refresh-discovered state back into the long-lived shared locator graph only if that configuration generation is still current. | ||
|
|
||
| The `Locator::refresh_state()` classification is the contract for that boundary. It keeps configured inputs, self-hydrating caches, and correctness-critical discovery state distinct. | ||
|
|
||
| ## Classifications | ||
|
|
||
| | Classification | Meaning | Sync behavior | | ||
| | --- | --- | --- | | ||
| | `Stateless` | The locator keeps no mutable state that survives a request. | Nothing is copied back. | | ||
| | `ConfiguredOnly` | The locator stores configured inputs such as executable paths or workspace directories. | Refresh must use the transient locator's request snapshot and must not copy this state back. | | ||
| | `SelfHydratingCache` | The locator stores a cache that later requests can rebuild on demand. | Refresh may fill a transient cache, but correctness must not rely on syncing it. | | ||
| | `SyncedDiscoveryState` | The locator stores refresh-discovered state that later requests need for correctness or fidelity. | The locator must override `sync_refresh_state_from()` and copy only state appropriate for the `RefreshStateSyncScope`. | | ||
|
|
||
| ## Current Locator Inventory | ||
|
|
||
| | Locator | Mutable state | Classification | Notes | | ||
| | --- | --- | --- | --- | | ||
| | WindowsStore | Discovered Store environments | `SyncedDiscoveryState` | Full and matching global-kind refreshes replace the cache; workspace refreshes leave it alone. | | ||
| | WindowsRegistry | Discovered registry managers and environments | `SyncedDiscoveryState` | Full and matching global-kind refreshes replace the cache; workspace refreshes leave it alone. | | ||
| | WinPython | None | `Stateless` | Windows-only locator. | | ||
| | PyEnv | Manager and versions-directory cache | `SelfHydratingCache` | `find()` clears the cache, and `try_from()` can rebuild it from the environment. | | ||
| | Pixi | None | `Stateless` | Identification is derived from filesystem markers. | | ||
| | Conda | Environment, manager, and mamba-manager discovery caches; configured executable | `SyncedDiscoveryState` | Discovery caches are synced. The configured executable remains configuration state and is not copied from refresh locators. | | ||
| | Uv | Configured workspace directories; immutable uv install directory | `ConfiguredOnly` | Workspace directories come from the request configuration snapshot. | | ||
| | Poetry | Configured workspace directories and executable; discovered search result | `SyncedDiscoveryState` | Search results are synced or merged by scope. Configured inputs are not copied back. | | ||
| | PipEnv | Configured pipenv executable | `ConfiguredOnly` | The executable comes from the configuration snapshot. | | ||
| | VirtualEnvWrapper | Environment variables captured at construction | `Stateless` | No refresh-discovered mutable state. | | ||
| | Venv | None | `Stateless` | Identification is derived from `pyvenv.cfg` and filesystem layout. | | ||
| | VirtualEnv | None | `Stateless` | Identification is derived from virtualenv markers. | | ||
| | Homebrew | Environment variables captured at construction | `Stateless` | No refresh-discovered mutable state. | | ||
| | MacXCode | None | `Stateless` | macOS-only locator. | | ||
| | MacCommandLineTools | None | `Stateless` | macOS-only locator. | | ||
| | MacPythonOrg | None | `Stateless` | macOS-only locator. | | ||
| | LinuxGlobalPython | Reported executable cache | `SelfHydratingCache` | `try_from()` can repopulate the cache by scanning known global bin directories. | | ||
|
|
||
| ## Updating The Contract | ||
|
|
||
| When adding mutable state to a locator, classify it before relying on it across refreshes: | ||
|
|
||
| 1. If it is configured input, keep it under `ConfiguredOnly` and source it from `Configuration`. | ||
| 2. If it is only a performance cache, use `SelfHydratingCache` and make later requests able to rebuild it. | ||
| 3. If later requests need refresh-discovered state, use `SyncedDiscoveryState`, implement `sync_refresh_state_from()`, and cover full, workspace, and kind-filtered scopes with tests. | ||
|
|
||
| The locator graph has a regression test in `crates/pet/src/jsonrpc.rs` that pins the current classification of each locator created by `create_locators()`. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.