Make AddRoute idempotent (upsert instead of reject duplicates)
AddRoute now updates an existing route if one already exists for the same (listener, hostname) pair, instead of returning AlreadyExists. This makes repeated deploys idempotent — the MCP agent can register routes on every deploy without needing to remove them first. - DB: INSERT ... ON CONFLICT DO UPDATE (SQLite upsert) - In-memory: overwrite existing route unconditionally - gRPC: error code changed from AlreadyExists to Internal (for real DB errors) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -69,19 +69,15 @@ func (ls *ListenerState) Routes() map[string]RouteInfo {
|
||||
return m
|
||||
}
|
||||
|
||||
// AddRoute adds a route to the listener. Returns an error if the hostname
|
||||
// already exists.
|
||||
func (ls *ListenerState) AddRoute(hostname string, info RouteInfo) error {
|
||||
// AddRoute adds or updates a route on the listener. If a route for the
|
||||
// hostname already exists, it is replaced (upsert).
|
||||
func (ls *ListenerState) AddRoute(hostname string, info RouteInfo) {
|
||||
key := strings.ToLower(hostname)
|
||||
|
||||
ls.mu.Lock()
|
||||
defer ls.mu.Unlock()
|
||||
|
||||
if _, ok := ls.routes[key]; ok {
|
||||
return fmt.Errorf("route %q already exists", hostname)
|
||||
}
|
||||
ls.routes[key] = info
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveRoute removes a route from the listener. Returns an error if the
|
||||
|
||||
Reference in New Issue
Block a user