JuliusBrussee/caveman · error
native runtime: socket already active
Error message
native runtime: socket already active
What it means
Before binding the Unix socket, ServeUnix probes an existing socket file with a 50ms dial. If another live process answers, it refuses to start rather than hijacking or double-binding; if the probe fails (stale socket from a crashed process), the file is removed and binding proceeds.
Solutions
- Stop the already-running runtime process that owns the socket, then restart.
- Use a distinct socket path (per-profile or per-session) to allow concurrent instances.
- If you own the socket and it is falsely 'active', kill the stale holder (lsof/ss on the path) and retry.
- Treat this error as expected in startup scripts: check for an existing healthy instance and attach to it instead of spawning a new one.
Example fix
// before
if err := nativeruntime.ServeUnix(ctx, sockPath, rt); err != nil { return err }
// after
if err := nativeruntime.ServeUnix(ctx, sockPath, rt); err != nil {
if strings.Contains(err.Error(), "socket already active") {
return nil // another runtime is serving; fine
}
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(sockPath); err == nil {
if c, derr := net.DialTimeout("unix", sockPath, 50*time.Millisecond); derr == nil {
c.Close()
return errors.New("runtime already serving")
}
} Try / catch
if err := nativeruntime.ServeUnix(ctx, path, rt); err != nil {
if strings.Contains(err.Error(), "socket already active") {
return nil // attach to existing instance
}
return err
} Prevention
- Use per-instance/per-profile socket paths
- Ensure supervisors stop old processes before restart
- Clean stale sockets only after a failed dial, like the library does
When it happens
Trigger: os.Stat(path) succeeds and net.DialTimeout("unix", path, 50*time.Millisecond) succeeds, i.e. a socket file exists at the runtime socket path and another process is actively listening on it.
Common situations: Starting a second instance of the coding agent while the first still runs; a supervisor restarting the service without stopping the old process; an unrelated process bound to the same default socket path.
Related errors
- native runtime: store is required
- native runtime: invalid decision id
- native runtime: invalid decision record
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/f4de5c3222262623.
Report an issue: GitHub.
Appendix: source
Thrown at proxy/internal/nativeruntime/server_unix.go:46
// ServeUnix exposes one-request-per-connection JSON over a user-only Unix
// socket. Runtime errors close or fail-open the individual call; they never stop
// the coding agent or the provider proxy.
func ServeUnix(ctx context.Context, path string, runtime *Runtime) error {
if runtime == nil || runtime.store == nil {
return errors.New("native runtime: store is required")
}
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
return fmt.Errorf("native runtime mkdir: %w", err)
}
if err := os.Chmod(filepath.Dir(path), 0o700); err != nil {
return fmt.Errorf("native runtime chmod dir: %w", err)
}
if _, err := os.Stat(path); err == nil {
conn, dialErr := net.DialTimeout("unix", path, 50*time.Millisecond)
if dialErr == nil {
_ = conn.Close()
return errors.New("native runtime: socket already active")
}
if err := os.Remove(path); err != nil {
return fmt.Errorf("native runtime remove stale socket: %w", err)
}
} else if !os.IsNotExist(err) {
return fmt.Errorf("native runtime inspect socket: %w", err)
}
listener, err := net.Listen("unix", path)
if err != nil {
return fmt.Errorf("native runtime listen: %w", err)
}
defer listener.Close()
defer os.Remove(path)
if err := os.Chmod(path, 0o600); err != nil {
return fmt.Errorf("native runtime chmod socket: %w", err)
}
go func() {
<-ctx.Done()View on GitHub (pinned to 3ee70a1026)