{"record":{"id":"1c2f2cb4c3206248","repo":"sipeed/picoclaw","slug":"singleton-check-failed-w","errorCode":null,"errorMessage":"singleton check failed: %w","messagePattern":"singleton check failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gateway/gateway.go","lineNumber":181,"sourceCode":"\t} else {\n\t\teffectiveLogLevel := config.EffectiveGatewayLogLevel(cfg)\n\t\tlogger.SetLevelFromString(effectiveLogLevel)\n\t\tlogger.Infof(\"Log level set to %q\", effectiveLogLevel)\n\t}\n\n\tbindPlan, listenResult, err := openGatewayListeners(cfg.Gateway.Host, cfg.Gateway.Port)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error opening gateway listeners: %w\", err)\n\t}\n\n\t// Enforce singleton: write PID file with generated token.\n\tpidData, err := pid.WritePidFile(homePath, bindPlan.ProbeHost, cfg.Gateway.Port)\n\tif err != nil {\n\t\tlogger.Warnf(\"write pid file failed: %v\", err)\n\t\tfor _, ln := range listenResult.Listeners {\n\t\t\t_ = ln.Close()\n\t\t}\n\t\treturn fmt.Errorf(\"singleton check failed: %w\", err)\n\t}\n\tdefer pid.RemovePidFile(homePath)\n\tcloseListeners := true\n\tdefer func() {\n\t\tif !closeListeners {\n\t\t\treturn\n\t\t}\n\t\tfor _, ln := range listenResult.Listeners {\n\t\t\t_ = ln.Close()\n\t\t}\n\t}()\n\n\tprovider, modelID, err := createStartupProvider(cfg, allowEmptyStartup)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error creating provider: %w\", err)\n\t}\n\n\tif modelID != \"\" {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/gateway/gateway.go#L163-L199","documentation":"Singleton enforcement in Run: pid.WritePidFile could not write the PID file with its generated token (another gateway instance already running, unwritable home dir). Listeners are closed and startup aborts so two gateways never share one port/home.","triggerScenarios":"Thrown at pkg/gateway/gateway.go:181 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check whether another gateway instance is already running (live or stale PID file in the home directory)","Stop the existing instance or remove a stale PID file","Verify the home directory is writable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","contentChangedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}