8.5 KiB
084 — Replace server status with server cleanup for revision-mismatch processes
Summary
This plan updates the CLI server command set by removing server status and adding server cleanup.
server cleanup will terminate discovered db-worker-node processes that are both:
- owned by
:cli - revision-mismatched with the current CLI revision
The implementation will reuse current logseq-cli and db-worker-node lifecycle primitives:
- server discovery from lock files (
logseq.cli.server/list-servers) - revision metadata persisted in locks by db-worker-node (
:revision) - shutdown/kill paths already used by server stop/restart flows
Requested behavior changes
- Remove
logseq server status --graph <name>. - Add
logseq server cleanup. server cleanupkills only discovered:cli-owned server processes whereserver revision != current CLI revision.
Current baseline
servercommand entries are defined insrc/main/logseq/cli/command/server.cljsand currently includelist/status/start/stop/restart.- CLI parse/build/execute routing is centralized in
src/main/logseq/cli/commands.cljs. - Running server discovery already includes revision in
src/main/logseq/cli/server.cljs(list-serversreturns:revision). - Revision mismatch semantics already exist and use exact string comparison (
compute-revision-mismatches). - db-worker-node writes revision into lock metadata in
src/main/frontend/worker/db_worker_node_lock.cljs; legacy locks may have missing revision.
Product decisions (locked)
-
server statusis removed, not deprecated.- No alias.
- Parsing
server statusshould fail as unknown command after removal.
-
Mismatch rule remains exact string comparison.
- If
cli-revision != server-revision, it is a mismatch. nil/missing server revision is treated as mismatch.
- If
-
Cleanup scope is discovered servers in current data-dir.
- Source of truth is lock-file-backed discovery from
list-servers. - We do not add global OS-wide process scanning for all possible data dirs.
- Source of truth is lock-file-backed discovery from
-
Cleanup ownership scope is
:clionly.- Cleanup targets only servers where
:owner-sourceis:cli. - Mismatched servers owned by
:electron(or other owners) are reported but not terminated.
- Cleanup targets only servers where
-
Termination strategy is graceful-first for eligible targets.
- Attempt graceful shutdown first.
- Fallback to process kill if needed.
CLI contract for server cleanup
Command surface
- New command:
logseq server cleanup - No
--graphrequired. - Works with existing global options (
--data-dir,--config,--output, etc.).
Result shape (proposed)
Return structured data for stable JSON/EDN automation:
:cli-revision:checked(count of discovered servers):mismatched(count):eligible(count of mismatched servers with:owner-source :cli):skipped-owner(mismatched servers not owned by:cli):killed(servers/pids successfully terminated):failed(servers/pids that could not be terminated)
Human output should summarize counts and list failed targets if any.
Implementation design
1) Remove server status wiring
- Remove
server statusentry fromcommand/server.cljs. - Remove
:server-statusbranches in:- parse-time graph-required validation set
- build-action dispatch
- execute dispatch
- Remove status-specific formatter branch/tests.
2) Add server cleanup command entry and action
In command/server.cljs:
- Add entry
['server' 'cleanup']with description and example. - Add
build-actionbranch for:server-cleanup(no repo requirement). - Add executor
execute-cleanup.
In commands.cljs:
- Route
:server-cleanupin build-action and execute. - Ensure graph-required command set excludes cleanup.
3) Add cleanup orchestration in logseq.cli.server
Introduce a new function (e.g. cleanup-revision-mismatched-servers!) that:
- resolves CLI revision (
logseq.cli.version/revision, passed from command layer) - calls
list-servers - computes mismatches using existing exact compare helper
- partitions mismatches into eligible (
:owner-source :cli) vs skipped-owner targets - terminates each eligible mismatched server process
- removes stale locks when PID no longer exists
- returns structured result data
Implementation should reuse existing stop/shutdown logic where possible to avoid duplicate lifecycle behavior.
4) Ownership-aware termination behavior
Cleanup must not bypass ownership rules globally; it should only target mismatched servers owned by :cli.
Recommended approach:
- Filter mismatch targets to
:owner-source :clibefore termination. - Reuse existing stop/shutdown flow for eligible targets.
- Keep existing owner-aware behavior unchanged for
stop/restart. - Report non-CLI mismatched servers in
:skipped-ownerfor visibility.
5) Formatting and docs
- Add human formatting branch for
:server-cleanupinformat.cljs. - Remove obsolete
:server-statushuman formatting and associated tests. - Update CLI docs and examples in
docs/cli/logseq-cli.md.
File scope (expected)
src/main/logseq/cli/command/server.cljssrc/main/logseq/cli/commands.cljssrc/main/logseq/cli/server.cljssrc/main/logseq/cli/format.cljssrc/main/logseq/cli/command/core.cljs(if help grouping text needs update)src/test/logseq/cli/commands_test.cljssrc/test/logseq/cli/command/server_test.cljssrc/test/logseq/cli/server_test.cljssrc/test/logseq/cli/format_test.cljscli-e2e/spec/non_sync_inventory.edncli-e2e/spec/non_sync_cases.edndocs/cli/logseq-cli.md
TDD execution plan
- Add failing parse/build tests for removing
server statusand addingserver cleanup. - Add failing command execute tests for cleanup action wiring.
- Add failing server lifecycle tests for mismatch selection and termination behavior.
- Add failing formatter tests for new human cleanup output and remove status output expectations.
- Implement command and server orchestration changes.
- Update docs and cli-e2e inventory/cases.
- Run focused tests, then full lint+test.
Testing plan
Unit tests
-
commands_test.cljsserver statusbecomes unknown command.server cleanupparses/builds/dispatches.- cleanup does not require
--graph.
-
command/server_test.cljs- cleanup execute returns structured summary.
- mismatch semantics remain exact compare.
-
server_test.cljs- cleanup kills only mismatched revision servers with
:owner-source :cli. - mismatched servers owned by non-CLI owners are reported in
:skipped-ownerand remain untouched. - matching revision servers are untouched.
- missing revision is treated as mismatch.
- failures are reported in
:failed.
- cleanup kills only mismatched revision servers with
-
format_test.cljs- human cleanup output includes counts and failure lines.
- status formatting tests removed/replaced.
CLI E2E
- Remove
server statuscoverage case. - Add
server cleanupcoverage case (at least smoke path with zero or controlled mismatches). - Update non-sync inventory command list under
:server.
Verification commands
bb dev:test -v logseq.cli.commands-test
bb dev:test -v logseq.cli.command.server-test
bb dev:test -v logseq.cli.server-test
bb dev:test -v logseq.cli.format-test
bb -f cli-e2e/bb.edn test --skip-build
bb dev:lint-and-test
Risks and mitigations
-
Risk: Ownership metadata may be missing/legacy (
:unknown) and reduce cleanup coverage.- Mitigation: keep cleanup intentionally strict (
:clionly) and report skipped-owner targets explicitly for operator follow-up.
- Mitigation: keep cleanup intentionally strict (
-
Risk: Legacy locks without revision cause aggressive cleanup.
- Mitigation: keep behavior intentional and documented (
missing revision = mismatch).
- Mitigation: keep behavior intentional and documented (
-
Risk: Duplicate stop logic divergence.
- Mitigation: reuse existing stop/shutdown flow for
:cli-owned targets and keep ownership filtering in one cleanup helper.
- Mitigation: reuse existing stop/shutdown flow for
Acceptance criteria
logseq server status ...is no longer available.logseq server cleanupexists and executes without--graph.- Cleanup terminates only discovered mismatch servers with
:owner-source :cli(server revision != CLI revision). - Mismatched servers with non-CLI ownership are not terminated and are reported as
:skipped-owner. - Matching-revision servers are not terminated.
- Structured JSON/EDN output reports
checked/mismatched/eligible/skipped-owner/killed/failedsummaries. - Human output is clear and actionable.
- Unit tests and relevant cli-e2e coverage are updated and passing.