Optional resident serve mode for warm backlog reads (addresses #13) - #18
Closed
dan-huminology wants to merge 1 commit into
Closed
Optional resident serve mode for warm backlog reads (addresses #13)#18dan-huminology wants to merge 1 commit into
dan-huminology wants to merge 1 commit into
Conversation
Introduce Session with in-memory graph, Unix-socket proxy in the CLI, ergo serve, reload-on-mismatch, and --no-server one-shot fallback. No JSONL schema changes; existing tests pass.
This was referenced Aug 30, 2026
Owner
|
I appreciate the PR, but I came up with a solution that gives us about a 10x speedup for many operations, without changing the operating model of ergo. Closing this for now, but please lmk if the new approach works for you. |
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.
Summary
This PR adds an opt-in resident command server for operators who keep full
backlog.jsonlhistory and hit read latency as the log grows (#13).Default behavior is unchanged: every command still works one-shot with no server running. When an operator starts
ergo serveagainst a repo, subsequent CLI invocations proxy over a per-repo Unix socket and reuse a warm in-memoryGraphinstead of callinginspectEventLogon every command.--no-server— forces today's one-shot path even when a socket is live--no-server, crash mid-append) trigger a reload before the next requestProblem
Each CLI invocation opens the repository and scans the full log. On a busy project that grows to tens of MB,
listcosts on the order of 0.6 s user CPU per call (#13 remeasure comment: 26 MB, 0.62–0.66 s on ergo 6.0.1). Parallel watchers and agents multiply that cost. Prune shrinks the file but discards audit history.The missing piece is not a new store — it is a process that keeps the derived
Graphand applies incremental updates.Approach
Session— holdsRepository,*Graph,eventLogRead, journal, and a file fingerprint. Mutations use warmupdateLoaded/updateLoadedWithJournal(same validation and append asUpdate, withoutloadWithReadon the hot path).ergo serve— one process per.ergodirectory; listens on.ergo/ergo.sock, writes.ergo/ergo.pid. One mutex serializes mutations.CLI proxy — proxied commands dial the socket, send a length-prefixed JSON envelope (
method,dir,payload, optionalstdinfor body), and print the response. Missing socket or dial failure falls back to the existing one-shot path.Body on the wire — body bytes travel in
stdinwith a small metadata struct;[]byteis not JSON-marshaled on the wire.Commands that never proxy:
init,serve,version,quickstart,where,info, help.Out of scope
Operator UX
servelogs each request to stderr (method, latency, client pid/ppid/argv).Performance
Measured 2026-08-30 on ergo
resident-server, live backlog 6.8 MB / 10,195 lines. Five consecutive/usr/bin/timeruns, stdout discarded, warmserverunning.list --jsonlist --readyshow <id>Proxied CLI user CPU is near zero because the scan runs in
serve, not in each short-lived client. The win is faster end-to-end return (~15× onlist --jsonfor this file size) and eliminating repeated full-file reads from frequent callers.Unit test:
OpenSession+ twoListcalls → injectedinspectEventscounter stays at 1.Tests
go test ./...List; out-of-band reload; warm claiminternal/ergo/session_test.gointernal/ergo/protocol_test.goservefails when socket livecmd/ergo/serve_roundtrip_test.goExisting
cmd/ergointegration tests pass with no socket present.Reviewer notes
Applicationmethods are thin wrappers:OpenSession→Sessionmethod →Closeplan*extracts share mutation logic between coldUpdatehelpers and warmSessioncompact/prunerun the cold path, thenSession.reload()dirmust match the directory the server openedTest plan
go test ./...--no-server)list,show,claim,bodymatch one-shot outputserveon same.ergoexits non-zero— Dan's AI Helper