Repository navigation
fix(server): say once that a lost data directory needs a restart - #321
Merged
Merged
Conversation
lexfrei
marked this pull request as ready for review
November 16, 2026 09:13
Contributor
Author
|
@kvaps this one is ready for review. #320 is merged, so I rebased it onto main. A running process that lost its data directory now logs one ERROR saying a restart is required, reports degraded health without exposing the path, and stops writing, also when a second process took over the lock. Opus reviewed the current commit twice with no findings, and CI is green. |
lexfrei
force-pushed
the
fix/gitstore-lost-store-signal
branch
3 times, most recently
from
November 16, 2026 09:36
45c2398 to
b110f70
Compare
8000
A clone removed under a running process is refused with ErrStoreLost, but the sync loop kept retrying it and logging the same warning every tick, and both health endpoints still said ok. The operator had no clear signal that only a restart recovers. Worse, the data-directory lock lives inside the directory it guards. Removing the directory removes the claim: a second serve or mcp starts, makes a fresh lock file, clones into the same path, and the first process sees a HEAD again and writes into the newcomer's clone. A lock file that is no longer the file this process holds, or gone, is now the same condition as a clone without HEAD. gitstore.Repo gains an optional store guard that CheckStore consults, and the server wires the lock into it, so commit, fetch and deepen refuse, including writes that bypass the write queue. The push and the repack do not pass through CheckStore and check before they start; the sync tick checks before it looks at any board. A stat that fails without proving the loss (EACCES) is not treated as one. On Windows the lock is held without sharing, so the directory cannot be removed while held and the check is off. The first hit logs one ERROR naming the domain or the lock file and "restart required", the state is kept until restart, the tick stops warning, and /api/healthz and the mcp daemon's /healthz report degraded with storeLost carrying a fixed reason. Both answer without a login, so the reason names no path; the path is in the ERROR line. The latched state is part of every repository's guard: the sync stops for every domain of the board, so a write to a surviving domain is refused too instead of sitting unpushed until the restart. A write that arrives while the state holds is refused at the request door, before the cache takes it: a 2xx that the drain later rolls back tells the caller, and an MCP agent above all, that a change was kept when it was not. /api/v1 answers 503 with the new storeLost problem code, and an MCP tool call returns a tool error with the same reason. The MCP refusal covers reads as well: an agent sees no banner, and the board it would read no longer syncs. Both health endpoints answer 503 in this state, with the same body. It is the one degraded state a restart cures, and a liveness probe acts on the status code; an unpushed backlog stays 200, since restarting would not make the remote accept the push. aeman service status still reads the 503 body. The process does not exit: a probe restarts a pod, and a process without a supervisor keeps explaining why it refuses instead of vanishing. The board's banner read any degraded health as "saved locally but not pushed". With storeLost it now says the data directory is lost and that changes are refused until a restart. Assisted-by: LLM Signed-off-by: Aleksei Sviridkin <f@lex.la>
lexfrei
force-pushed
the
fix/gitstore-lost-store-signal
branch
from
November 16, 2026 22:27
b110f70 to
cf19835
Compare
Signed-off-by: Andrei Kvapil <kvapss@gmail.com> # Conflicts: # docs/api.md # docs/design/behavior-matrix.md # pkg/gitstore/lostclone_test.go
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a running process loses its data directory, it now says once that it needs a restart, refuses every write at the door, and answers 503 on its health endpoints so a probe can restart it. It also stops writing into a directory another process may own.
Before this, the operator got no clear signal. The sync loop logged the same warning every 15s until restart, and
/api/healthzstill said ok. Now the first check that finds the condition logs one ERROR naming the domain and "restart required", and the state is kept until restart. The sync tick is skipped with no warning, and pushes, commits, maintenance and deepening are refused.Writes are refused before they are applied. A write under
/api/v1gets 503 with a new problem code,storeLost, and an MCP tool call gets a tool error with the same reason. Before, the write was accepted with a 2xx and rolled back later in the drain, so an MCP agent was told "ok" for a change that was lost. The MCP refusal covers read tools too: an agent sees no banner, and the board it would read no longer syncs. REST reads keep working, so the board stays readable in the browser./api/healthzand the/healthzof theaeman mcp --listendaemon answerdegradedwith astoreLostfield, and with HTTP 503. A restart is the only cure for this state, and a liveness probe acts on the status code. An unpushed backlog stays 200, since restarting would not make the remote accept the push.aeman service statusreads the 503 body, so it reports the daemon as degraded rather than silent. Both endpoints answer without a login, so the reason names no path; the path is in the ERROR line.The process does not exit on its own. The Helm chart's liveness probe reads
/api/healthzand restarts the pod. A process without a supervisor keeps explaining why it refuses instead of vanishing. The trade-off is the unitaeman service installwrites: it restarts only a process that exits, so a daemon in this state is restarted by hand.docs/api.mdsays so.The board's banner used to read any
degradedas "saved locally but not pushed", which was false here. WithstoreLostit now says the data directory is lost and changes are refused until a restart.On a board of several repositories this covers every domain. The sync stops for all of them, so a write to a surviving domain would otherwise sit unpushed until the restart. A commit made before the state latched is pushed after the restart.
The second problem is a race around the lock. The data-directory lock lives inside the directory it guards, so removing the directory removes the claim. A second
serveormcpcan then start, make a fresh lock file, clone into the same path and take the lock. The 8000 first process sees a HEAD again and writes into the newcomer's clone, and a test reproduces exactly that. The holder now compares the file it holds with the file at<data>/lock(os.SameFile). A different file, no file, or a data path that is now a file counts as a lost directory. A stat that fails without proving it (EACCES) does not.On Windows the check is off. The lock file is opened without sharing, so the directory cannot be removed while the lock is held. That follows from the share-mode-0 open in
datalock_windows.goand was not run on Windows. Renaming the data directory away while the lock is held is not covered. The lock stays inside the data directory, because that directory may be a mount root.Every commit, fetch and deepen refuses through one place. The check sits in
gitstore.Repo.CheckStorebehind a new optionalSetStoreGuard, which also covers writes that skip the queue (team create, synchronous delete, ghost sweep). Push and repack do not go throughCheckStore, so they check before they start. The sync tick checks before it looks at any board, so a daemon no client has used yet still notices. It costs a fewstatcalls.Rows G90 and G91 are in the behavior matrix.
docs/api.mddocumentsstoreLost, the 503 answers, the MCP tool error and the limit of the lock, andapi/openapi.yamlnames the new problem code.Testing:
go test ./...passes,go test -racepasses oninternal/server,pkg/gitstoreandcmd/aeman,golangci-lintreports nothing, and inweb/npm run typecheckandnpm testpass. Each new test failed before its fix, and removing each guard makes a named test fail.Follow-ups, not in this PR:
/api/healthz, so in this state the pod leaves the Service endpoints at once and the new banner is rarely seen on a Helm install before liveness restarts the pod. A separate readiness path is a chart change of its own.docs/design/git-backend.mdstill says a secondserveormcpon the same directory is refused at start. That was already untrue before this PR: removing the directory with its lock file lets a second process start. It needs one sentence pointing at G91.gitSync.storeLoststats the lock file twice per check, once directly and once through each repository's guard. This is harmless but redundant.--sync-interval 0writes are still refused, but the ERROR line appears only when health, maintenance or a request first checks the store.TestALostDomainStopsWritesToTheOtherschecks only that the head did not move. It could also assert that the refused write's error says "restart required".--datathe clones live in the user cache directory, and a cache cleaner that removes the lock file now stops the process until restart. That is the intended answer to a lost claim, but the docs could recommend an explicit--datafor a long-running service.