{"record":{"id":"cd3ff02243d51218","repo":"gastownhall/beads","slug":"reading-project-identity-project-id-from-hosted","errorCode":null,"errorMessage":"reading project identity (_project_id) from hosted database %q: %w","messagePattern":"reading project identity \\(_project_id\\) from hosted database %q: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":146,"sourceCode":"// MISMATCH. This CreateIfMissing skip is Gateway-only: a non-gateway\n// CreateIfMissing:true init against an already-existing database now DOES run\n// the verifier (GH#4637 Part A) and fails before reaching this reconciliation.\n// A missing server id is a provisioning-contract violation bd will not mint\n// over — even when a local id already exists — and a read error is surfaced as\n// the transient failure it is, so a flaky connection is not misdiagnosed as an\n// unprovisioned database.\n//\n// Non-gateway (legacy, unchanged): a non-empty localID is kept as-is (readErr\n// ignored, exactly as before); otherwise an adopted id wins (another rig already\n// chose it; minting a new one would break cross-project verification), else a\n// fresh identity is generated.\nfunc resolveInitProjectID(gateway bool, localID, adoptedFromDB, dbName string, readErr error) (value string, changed bool, err error) {\n\tif gateway {\n\t\tif adoptedFromDB != \"\" {\n\t\t\treturn adoptedFromDB, adoptedFromDB != localID, nil\n\t\t}\n\t\tif readErr != nil {\n\t\t\treturn \"\", false, fmt.Errorf(\n\t\t\t\t\"reading project identity (_project_id) from hosted database %q: %w\", dbName, readErr)\n\t\t}\n\t\treturn \"\", false, fmt.Errorf(\n\t\t\t\"hosted database %q has no provisioned project identity (_project_id) -- \"+\n\t\t\t\t\"provisioning-contract violation; bd will not mint an identity for a hosted database\",\n\t\t\tdbName)\n\t}\n\tif localID != \"\" {\n\t\treturn localID, false, nil\n\t}\n\tif adoptedFromDB != \"\" {\n\t\treturn adoptedFromDB, true, nil\n\t}\n\treturn configfile.GenerateProjectID(), true, nil\n}\n\n// shouldConsultInitProjectID reports whether init must read _project_id from the\n// database before resolving the local identity.","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L128-L164","documentation":"In gateway mode the project identity (_project_id) is server-authoritative. resolveInitProjectID wraps the read error with the database name: a failure reading _project_id is surfaced as a transient read problem, distinct from a missing identity, so a flaky connection isn't misdiagnosed as an unprovisioned database.","triggerScenarios":"`bd init` with a gateway connection (shouldConsultInitProjectID always consults in gateway mode) where adoptedFromDB is empty and the _project_id read returns an error (network, auth, server, query failure) — passed as readErr.","commonSituations":"Network blips to the hosted server; expired credentials; server outage/maintenance; proxy/DNS failures — same transient causes as the prefix read error (init.go:103).","solutions":["Retry `bd init` — this is treated as transient, not a provisioning violation","Check connectivity with `bd doctor` / curl the hosted endpoint","Validate gateway credentials and account status","Escalate to the host/admin if the server stays unreachable"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check hosted DB reachability before gateway init\nif err := pingHostedDB(dbName); err != nil {\n    return fmt.Errorf(\"hosted DB unreachable, fix connectivity before init: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := resolveInitProjectID(true, localID, \"\", dbName, readErr); err != nil {\n    if readErr != nil { // transient — back off and retry\n        time.Sleep(time.Second)\n        return resolveInitProjectID(true, localID, \"\", dbName, readProjectIDFromDB())\n    }\n    return err\n}","preventionTips":["Verify connectivity to the hosted server before init","Keep gateway credentials valid","Treat _project_id read errors as transient — don't mint local identities to work around them","Run `bd doctor` when in doubt"],"tags":["network","gateway","hosted-database","project-id","transient"],"backgroundTag":"hosted-db-read-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}