{"record":{"id":"00533fe52fc755b9","repo":"gastownhall/beads","slug":"reading-issue-prefix-from-hosted-database-q-w","errorCode":null,"errorMessage":"reading issue_prefix from hosted database %q: %w","messagePattern":"reading issue_prefix from hosted database %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":103,"sourceCode":"// one exists, return \"\" — there is nothing to set, because init must not clobber\n// a prefix a shared database already carries. readErr is ignored here, exactly\n// as legacy init ignored it. Gateway: the prefix is server-provisioned, so an\n// existing value is adopted. A missing value is a provisioning-contract\n// violation — bd will not choose a prefix for a hosted database — but only when\n// the read genuinely succeeded and returned empty: a read error means we could\n// not consult the server, so it is surfaced as the transient failure it is\n// rather than misdiagnosed as an unprovisioned database.\n//\n// Whether the prefix may be WRITTEN is not decided here: that is the same\n// question as whether the substrate is unidentified, and issueops.Bootstrapper\n// answers it inside the transaction it writes in.\nfunc resolveInitIssuePrefix(gateway bool, existing, dbName, prefix string, readErr error) (value string, err error) {\n\tif existing != \"\" {\n\t\treturn \"\", nil\n\t}\n\tif gateway {\n\t\tif readErr != nil {\n\t\t\treturn \"\", fmt.Errorf(\n\t\t\t\t\"reading issue_prefix from hosted database %q: %w\", dbName, readErr)\n\t\t}\n\t\treturn \"\", fmt.Errorf(\n\t\t\t\"hosted database %q has no issue_prefix -- provisioning-contract violation; \"+\n\t\t\t\t\"bd will not choose one for a hosted database (re-provision server-side, then re-run init)\",\n\t\t\tdbName)\n\t}\n\treturn strings.ReplaceAll(prefix, \".\", \"_\"), nil\n}\n\n// resolveInitProjectID decides init's project identity by reconciling the local\n// metadata.json id (localID; \"\" when none is set yet) with the _project_id read\n// from the database (adoptedFromDB; \"\" when absent or not consulted). readErr is\n// the error, if any, from that read. changed reports whether the resolved id\n// differs from localID, so the caller can surface the reconciliation.\n//\n// Gateway: the hosted database's identity is server-authoritative, so an adopted\n// server id always wins and is reconciled onto local even when localID is already","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L85-L121","documentation":"In gateway (hosted) mode, the issue_prefix is provisioned server-side and init must read it from the hosted database. resolveInitIssuePrefix wraps the read error with the database name: a read failure is surfaced as transient rather than misdiagnosed as an unprovisioned database.","triggerScenarios":"`bd init` with a gateway-managed connection where the existing prefix is empty and the read of issue_prefix from the hosted DB returns an error (network failure, auth failure, server down, query error) — passed in as readErr.","commonSituations":"Flaky network to the hosted Dolt server; expired/invalid credentials; server maintenance or outage; DNS or proxy failures reaching the hosted endpoint.","solutions":["Retry `bd init` — the code treats this as a transient read failure, not a provisioning problem","Verify connectivity to the hosted server (ping/curl the endpoint, check `bd doctor`)","Check gateway credentials are valid and not expired","If it persists, contact the host/admin: the server may be down or your database misconfigured"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before init, confirm the hosted DB is reachable\n// e.g. curl or dolt sql against the gateway endpoint; or run `bd doctor`","typeGuard":null,"tryCatchPattern":"if _, err := resolveInitIssuePrefix(true, \"\", dbName, \"\", readErr); err != nil {\n    if readErr != nil { // transient read failure — retry with backoff\n        time.Sleep(time.Second)\n        return resolveInitIssuePrefix(true, \"\", dbName, \"\", readPrefixFromDB())\n    }\n    return err\n}","preventionTips":["Check network/VPN to the hosted server before running init","Keep gateway credentials fresh (re-auth before long sessions)","Run `bd doctor` to detect connectivity issues early","Distinguish transient read errors from the provisioning-violation error (805) before acting"],"tags":["network","gateway","hosted-database","issue-prefix","transient"],"backgroundTag":"hosted-db-read-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}