t8y2/dbx · error
agent is not connected
Error message
agent is not connected
What it means
The xugu agent's requireDB() guard returns this when s.db is nil — an RPC needing the database was issued with no live connection. It is the user-facing counterpart of validateConnection's 'not connected', phrased to make clear the agent (not the server) lacks the connection.
Source
Thrown at agents/drivers/xugu/main.go:1705
for _, item := range items {
item = strings.TrimSpace(item)
if item != "" {
result = append(result, item)
}
}
return result
}
return []string{raw}
}
func parsePort(value string) int {
port, _ := strconv.Atoi(value)
return port
}
func (s *server) requireDB() (*sql.DB, error) {
if s.db == nil {
return nil, errors.New("agent is not connected")
}
return s.db, nil
}
func (s *server) useDatabase(database string) error {
database = strings.TrimSpace(database)
if database == "" {
return nil
}
// Skip only when the live session is already on this database.
if s.currentDatabase != "" && strings.EqualFold(database, s.currentDatabase) {
return nil
}
// Fresh session still on connect-time DB: avoid a redundant USE.
if s.currentDatabase == "" {
if configured := configuredDatabaseName(s.params); configured != "" && strings.EqualFold(database, configured) {
s.currentDatabase = configured
return nilView on GitHub (pinned to c0390bff16)
Solutions
- Call connect before issuing any database RPCs
- Re-open the session and reconnect after an agent restart
- Handle this error by reconnecting transparently in the client driver wrapper
Example fix
// before
res, err := agent.Query(ctx, q)
// after
if _, err := agent.RequireDB(); err != nil { if err := agent.Connect(ctx, cp); err != nil { return err } }
res, err := agent.Query(ctx, q) Defensive patterns
Strategy: try-catch
Validate before calling
if s.db == nil { return errors.New("agent is not connected") } Type guard
func hasDB(s *server) bool { return s.db != nil } Try / catch
if _, err := agent.RequireDB(); err != nil {
if strings.Contains(err.Error(), "agent is not connected") {
if cerr := agent.Connect(ctx, cp); cerr != nil { return cerr }
}
} Prevention
- Serialize connect/disconnect against in-flight RPCs
- Auto-reconnect on this error in the client wrapper
- Detect agent restarts via session invalidation and reconnect
When it happens
Trigger: Any RPC routed through requireDB() (query, DDL, useDatabase, metadata) executed before connect or after the connection handle was cleared.
Common situations: Client assumed a persistent session after agent restart; disconnect raced a queued RPC; connection dropped server-side and the agent cleared its handle.
Related errors
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/188e7845c965a37a.
Report an issue: GitHub.