ISSUE DESCRIPTION Removing a registered or subscribed service leaves stale local…
- User
ISSUE DESCRIPTION
Removing a registered or subscribed service leaves stale local metadata
After a successful unregister or unsubscribe operation, the corresponding provider or consumer URL must no longer participate in local metadata, service matching, or revision calculation. Removing one URL must preserve unrelated registrations. If the remote operation fails, local metadata must not be removed as though the operation succeeded.
Interface
Type: Function Name: RemoveService Path: metadata/metadata.go Input: registryId string, url *common.URL Output: (no return value) Description: Removes a provider service URL from the local metadata for the given registry. Use this during unregister flows to keep the in-memory application-level metadata consistent with the actual exported services.
Type: Function Name: RemoveSubscribeURL Path: metadata/metadata.go Input: registryId string, url *common.URL Output: (no return value) Description: Removes a subscribed service URL from the local metadata for the given registry. Use this during unsubscribe flows to ensure stale subscribed URLs are cleaned from the application-level metadata.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
- Assistant
I’ll first inspect the repository structure, metadata implementation, and unregister/unsubscribe call paths. Then I’ll identify the existing metadata synchronization behavior, implement removal only after successful remote operations, and run focused plus broader tests.
- Assistant
The metadata package currently only has add operations. The relevant service-discovery registry adds metadata after successful register/subscribe, so I’ll inspect its remove flows and the
MetadataInfodata model/revision logic to design exact URL removal that preserves unrelated entries. - Assistant
MetadataInfoalready exposes removal methods, but provider removal currently deletes the sharedServiceInfounconditionally and URL matching uses pointer identity. That can incorrectly remove service matching metadata when another registration has the same match key, and equivalent full URLs passed to unregister may not be the same pointer. I’ll inspect URL equality conventions and the complete service-discovery methods before changing behavior. - Assistant
URL comparison utilities intentionally ignore fields in some contexts, while the registry contract says unregister/unsubscribe is by full URL match. I’ll therefore use a stable full representation (
URL.String()) rather thanURLEqual, handle nil/missing registry entries as no-ops, and ensure providerServiceInfois retained/rebuilt when another exported URL shares its match key. I’ll also verify where unsubscribe can return early and what constitutes its remote mapping operation. - Assistant
The implementation plan is now concrete:
- Add the two requested package-level functions in
metadata/metadata.goas safe no-ops for nil URLs or unknown registries. - Strengthen
MetadataInforemoval to remove all full-URL-equal entries, while preserving/rebuildingServices[matchKey]from any unrelated remaining registration. - Invoke provider removal only after
UnRegisterServicereturns success. - Invoke subscription removal only after
serviceNameMapping.Removesucceeds. - Format and run metadata and service-discovery tests (including race checks if practical).
I’ll make these source-only changes without modifying tests.
- Add the two requested package-level functions in
- Assistant
The changes are in place and pass formatting/diff validation. I’ll now run focused tests for metadata internals and the service-discovery registry. These should expose regressions in removal semantics, mock expectations, and revision/customizer behavior.
- Assistant
The focused tests could not start because this environment has neither
GOMODCACHEnorGOPATHconfigured; this is infrastructure configuration rather than a code failure. I’ll set repository-external temporary Go cache paths for the test command and rerun without changing project files. - Assistant
Focused tests pass. I’ll now run a small temporary, repository-external reproduction that specifically checks the reported cases not covered by existing tests: removal via an equivalent cloned URL, preservation of unrelated provider/subscription URLs, and preservation of shared service matching metadata. I’ll also inspect mapping semantics to ensure the unregister/unsubscribe integration is attached to the correct successful operation.
- Assistant
The targeted reproduction passes, including clone-based full URL matching and shared match-key preservation. Mapping inspection confirms unsubscribe’s remote operation is
RemoveServiceAppMappingListener, so metadata removal correctly follows that success. Before finalizing, I’ll check all direct accesses to the global metadata map for consistency and run the broader registry test suite plus static analysis on changed packages. - Assistant
The broader registry suite and
go vetboth pass. Direct map access is confined to this metadata package (aside from same-package tests), so the new API is properly centralized. I’ll do a final diff review, check for accidental files, and run race-enabled tests on the two directly changed package areas to catch synchronization or URL-locking issues. - Assistant
Normal tests and vet pass. The race run found a pre-existing race in
TestServiceDiscoveryRegistryUnRegister_Concurrentitself: the test directly reads/writess.instanceswhile production code holds its mutex, so it is unrelated to these metadata changes; the metadata packages passed under-race.One final review identified an edge case worth tightening: removing a non-existent full URL with the same match key should be a true no-op rather than rebuilding the matching
ServiceInfo. I’ll make the helper report whether it actually removed an entry, then rerun focused tests before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.