Repository navigation
corral mcp: open the findings store read-only, per call, so concurrent sessions can start - #521
Merged
Merged
Conversation
…cond agent session's server can start. `corral mcp` is a read-only findings server that every Claude Code session spawns, but it opened the local DuckDB store with criticscore.Open: read-write, with CREATE TABLE and migrations, held for the server's whole life. DuckDB allows one read-write process per file, so the first session's server held an exclusive lock and every later session's server died at startup with "IO Error: Could not set lock ... Conflicting lock is held" (observed 2026-11-12). The same held handle kept `certify --local` from recording findings for as long as any agent session stayed open. criticscore.OpenReadOnly opens an existing store with access_mode=read_only and runs no DDL; a missing local file returns ErrNoStore without creating anything. `corral mcp` now opens through it for each tool call and closes before returning, so readers share the file and an idle server holds no lock at all. A missing store reads as zero findings and is not created (the old path created the state directory and an empty store at start). The DuckDB limit is not removed, only narrowed, and both tests and comments say so: a read-only open cannot share with a concurrent read-write process in either direction, so a tool call made while `certify --local` writes the store fails, now with an error that says why. A test executes that limit so a DuckDB upgrade that lifts it shows up as a failing test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…meone running corral mcp in more than one agent session, including the write that still blocks a read, because the fix changes start-up behaviour and had no entry. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defect, as observed (2026-11-12)
corral mcpis a read-only findings server, registered globally, so every Claude Code session spawns one. It opened the local DuckDB findings store withcriticscore.Open: read-write, withCREATE TABLEand migrations, and it kept that handle open for the life of the server. DuckDB allows one read-write process per file. The first session's server therefore held an exclusive lock, and every later session's server failed at startup:The same held handle also stopped
certify --localfrom recording findings for as long as any agent session stayed open.Fix
criticscore.OpenReadOnly(dsn)opens an existing store with DuckDB'saccess_mode=read_only. It runs no DDL and no migrations. It pings at open, so a lock conflict shows up there and not on the first query. If the local file is missing it returnscriticscore.ErrNoStoreand does not create the file. Anmd:DSN passes through with only the access mode added.corral mcpnow servesstoreFindings{path}. That reader opens the store read-only for each tool call and closes it before returning, so an idle server holds no lock at all. The path comes fromstatedir.Path, notPathForWrite, because a reader should not create a directory.certify --localfor the whole agent session. Opening per call costs one open for each tool call, and an agent makes only a handful.list_audit_findingswithtotal: 0, answersget_audit_findingwith the existing "no finding" error, and creates neither the file nor its directory.case "mcp":path andmcp_findings.go, and criticscore is the only open.The DuckDB limit, stated honestly
Read-only opens share the file with each other across processes. They do not share with a concurrent read-write process. A tool call made while
certify --local(orcorral criticscore confirm|refute) is writing the store fails. It now fails with an error that names the cause and says to retry, not with DuckDB's lock text alone. The limit is written inOpenReadOnly's doc comment, and a test executes it (TestOpenReadOnlyStillBlockedByAConcurrentWriter). If a DuckDB upgrade lifts the limit, that test fails, and the comment should then change.A side effect: because no migration runs, a store last written by an older corral is read at its own schema. A query that names a newer column fails with DuckDB's error and does not migrate a file the reader was never meant to change. Any
certify --localbrings the store forward. This is documented onOpenReadOnly.Tests (competing session in a SEPARATE process)
DuckDB's lock is per process, so the competing session runs in a separate process: the test binary re-execs itself as the holder, the same shape as statedir's
TestHelperHoldDuckDB. These tests use the real opener against real DuckDB files, with no mocks.internal/criticscore: two read-only opens across processes both succeed and read the data. Read-only is still blocked by a writer in another process. A missing store returnsErrNoStoreand is not created.cmd/corral(storeFindings, the reader the server actually serves):total: 0through a real in-memory MCP client, and neither the file nor its directory is created.RED (the reader stub used
criticscore.Open, andOpenReadOnlywas stubbed toOpen), which reproduces the production error exactly:GREEN after the fix: all pass.
I also ran a smoke test against the real binary, using a temporary state dir over stdio JSON-RPC. With no store,
list_audit_findingsreturned zero findings and the state dir was not created. With a seeded store, server A was held alive while server B started, and both returned the finding.Gates
go build ./...: okgo vet ./...: okgofmt -l ./cmd ./internal: prints nothinggo test ./... -count=1: green, 102 packages ok, 0 failuresbash scripts/check-licensing.sh: OKbash scripts/gen-cli-docs.sh --check: OK.mcp -htext is unchanged.bash scripts/check-security.sh: gofmt and gosec pass. govulncheck FAILS on GO-2026-6859, a Go 1.26.10 stdlibnet/httpissue fixed in 1.26.11. It has nothing to do with this change, and a separate PR bumps Go.busyWriterreturns an error and does not print.🤖 Generated with Claude Code