fix(state): Gracefully handle stale service entries in state database#302
fix(state): Gracefully handle stale service entries in state database#302hubertdeng123 merged 6 commits intomainfrom
Conversation
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧Release
🤖 This preview updates automatically when you update the PR. |
When a service is removed from disk but its entry persists in the SQLite state database, commands that iterate over active services (down, reset, toggle) crash with an unhandled ServiceNotFoundError. This handles the error at all 5 vulnerable call sites by skipping stale entries and cleaning them up from all state tables. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77475f7 to
f4aff7b
Compare
…validate=True) Move the stale service detection and cleanup from individual try/except blocks at each call site into the get_active_service_names helper. Call sites now pass validate=True to get a pre-filtered set, eliminating the need for repetitive error handling at each iteration point. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The `get_non_shared_remote_dependencies` function calls `get_active_service_names(validate=True)` via its own module-level import, so tests must mock both `devservices.commands.down` and `devservices.utils.dependencies` import locations. Also fixes lint import ordering and formatting. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove unused `state = State()` in status.py (F841) left over from refactoring to `get_active_service_names()`. Revert ruff formatting in test_dependencies.py that conflicted with black. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@claude address my comment |
hubertdeng123
left a comment
There was a problem hiding this comment.
This should fixe the issue when working on feature branches with services with devservices configs, then switching back to default branches. Let's give it a shot, thanks for your PR
Yeah It's somewhat similar to what happened to me. I was adding a service for a new util and then decided to just make it a CLI for now and ended up with broken env for all projects :/ |
Summary
down,reset,toggle) crash with an unhandledServiceNotFoundErrorState.remove_stale_service_entry()to clean up entries from all state tables (started_services,starting_services,service_runtime)get_active_service_names()helper inservices.pyto replace repeated 3-line boilerplate across 8 call sitesvalidate=Trueto verify each service still exists on disk, removing stale entries automatically — used at all 5 iteration sites that callfind_matching_serviceTest plan
get_active_service_names(validate=True)verifying stale entries are removed🤖 Generated with Claude Code