{"record":{"id":"26ddfaa89921130d","repo":"gastownhall/beads","slug":"acquire-connection-after-sql-mutation-w-w","errorCode":null,"errorMessage":"acquire connection after SQL mutation: %w: %w","messagePattern":"acquire connection after SQL mutation: %w: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/storage/dolt/store.go","lineNumber":3291,"sourceCode":"}\n\n// doltAddAndCommit stages the specified tables and commits on a pinned\n// connection. This prevents DOLT_COMMIT('-Am') from sweeping up stale\n// working set changes from concurrent operations (GH#2455). Every caller has\n// already committed its SQL mutation, so any publication failure here has an\n// indeterminate durable outcome and must not be replayed.\nfunc (s *DoltStore) doltAddAndCommit(ctx context.Context, tables []string, commitMsg string) error {\n\t// Batch/off auto-commit (bd-4wamg): leave the writes in the working set\n\t// for a later explicit commit point (bd dolt commit / CommitPending),\n\t// matching doltAddAndCommitInTx.\n\tif issueops.VersionCommitDeferred(ctx) {\n\t\treturn nil\n\t}\n\treturn s.withCircuitWrite(ctx, func(ctx context.Context) error {\n\t\tconn, err := s.db.Conn(ctx)\n\t\tif err != nil {\n\t\t\treturn s.recordDoltPublicationFailure(ctx,\n\t\t\t\tfmt.Errorf(\"acquire connection after SQL mutation: %w: %w\", err, ErrCommitIndeterminate))\n\t\t}\n\t\tdefer conn.Close()\n\n\t\tfor _, table := range tables {\n\t\t\tif err := schema.DrainCall(ctx, conn, \"CALL DOLT_ADD(?)\", table); err != nil {\n\t\t\t\treturn s.recordDoltPublicationFailure(ctx,\n\t\t\t\t\tfmt.Errorf(\"dolt add %s after SQL mutation: %w: %w\", table, err, ErrCommitIndeterminate))\n\t\t\t}\n\t\t}\n\n\t\t// Skip the commit when nothing was actually staged (idempotent no-op\n\t\t// write), so Dolt does not log a server-side \"nothing to commit\" warning\n\t\t// on every reconcile-cadence call. The guard tests the STAGED set rather\n\t\t// than the whole working set because this helper stages only a fixed\n\t\t// table list — an unrelated dirty table must not trigger an empty '-m'\n\t\t// commit. A guard-read failure is NOT a publication failure: nothing has\n\t\t// been committed and nothing is indeterminate, so plain error return.\n\t\tstaged, err := issueops.HasStagedChanges(ctx, conn)","sourceCodeStart":3273,"sourceCodeEnd":3309,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/dolt/store.go#L3273-L3309","documentation":"In commitWorkingSetAfterSQLCommit, acquiring a connection after a SQL mutation failed. Because a mutation already succeeded but the commit did not run, the error is wrapped with ErrCommitIndeterminate — the commit outcome is unknown and must not be blindly retried.","triggerScenarios":"The store attempts to dolt-add/commit tables after a raw SQL mutation (doltAddAndCommit path) and s.db.Conn(ctx) fails because the server became unreachable or the pool drained at exactly that moment.","commonSituations":"Dolt server crash or network drop between the SQL write and the publication commit; connection-pool exhaustion under heavy concurrent agent load.","solutions":["Treat the commit as indeterminate: run `bd dolt status` / `bd dolt log` to check whether the commit landed before retrying.","Restore Dolt server connectivity, then re-run the operation; the code path is idempotent for uncommitted staged changes.","If the commit did land, do nothing further; if not, re-trigger the operation to publish.","Check server logs for crash/restart at that timestamp."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check server reachability before mutations that require publication\nif err := s.db.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"skip mutation: publication path unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if errors.Is(err, ErrCommitIndeterminate) {\n    // verify with `bd dolt log` / `bd dolt status` whether the commit landed\n    // before re-triggering the operation\n}","preventionTips":["Never blind-retry operations wrapped with ErrCommitIndeterminate; check dolt log first.","Keep the Dolt server on stable infrastructure with health checks.","Avoid network partitions between bd and a server-mode Dolt.","Ensure connection pool headroom before write-heavy operations."],"tags":["dolt","connection","indeterminate-commit","database"],"backgroundTag":"commit-indeterminate","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}