feat: add metadata and state filtering to GET /instances#103
Merged
Conversation
Add query parameters to the list instances endpoint so callers can filter by instance state and/or user-defined metadata key-value pairs: GET /instances?state=Running&metadata[team]=backend&metadata[env]=staging Uses OpenAPI deepObject style for the metadata parameter, which oapi-codegen deserializes into map[string]string automatically. Multiple metadata entries are ANDed -- an instance must match all specified key-value pairs. Adds ListInstancesFilter type with a Matches() method, updates the Manager interface to accept *ListInstancesFilter, and wires it through the API handler. Co-authored-by: Cursor <cursoragent@cursor.com>
✱ Stainless preview buildsThis PR will update the
|
sjmiller609
approved these changes
Feb 17, 2026
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.
Summary
stateandmetadataquery parameters toGET /instancesso callers can filter the list by instance state and/or user-defined metadata key-value pairsdeepObjectstyle for the metadata parameter (?metadata[team]=backend&metadata[env]=staging), which oapi-codegen deserializes intomap[string]stringautomaticallyExample:
Changes
openapi.yaml: Addedstate(enum) andmetadata(deepObject) query params toGET /instanceslib/oapi/oapi.go: Regenerated from updated speclib/instances/types.go: AddedListInstancesFiltertype withMatches()methodlib/instances/manager.go: UpdatedManagerinterface and implementation to accept*ListInstancesFiltercmd/api/api/instances.go: Handler converts OAPI params → domain filterlib/instances/filter_test.go: 19 test cases covering filter matching and end-to-end filtered listing with on-disk metadataTest plan
TestListInstancesFilter_Matches— 13 cases covering nil/empty filter, state, metadata, and combinationsTestListInstancesFilter_Matches_NilMetadata— instance with no metadata vs metadata filterTestListInstances_WithFilter— 6 sub-tests exercising the fullListInstancespath with on-disk metadata files (no KVM required)TestStorageOperations,TestStateTransitions, builds mock, etc.)Made with Cursor
Note
Medium Risk
Touches the
ListInstancesinterface and OpenAPI-generated bindings, so downstream callers/tests must be updated and subtle query-binding/filtering bugs could change which instances are returned.Overview
Adds optional filtering to
GET /instancesvia newstateandmetadataquery parameters (metadata uses OpenAPIdeepObjectsyntax and all criteria are ANDed).Plumbs the filter through the API handler into the domain layer by introducing
instances.ListInstancesFilter(withMatches) and updatinginstances.Manager.ListInstancesto accept a filter; updates call sites/tests and regenerates the OpenAPI client/server bindings + spec. Includes new unit and on-disk integration tests for filter behavior.Written by Cursor Bugbot for commit 84f3ae5. This will update automatically on new commits. Configure here.