Skip to content

perf(sync): coordinate startup across processes - #50

Merged
pablontiv merged 15 commits into
mainfrom
pablontiv/issue-46-startup-sync
Aug 21, 2026
Merged

perf(sync): coordinate startup across processes#50
pablontiv merged 15 commits into
mainfrom
pablontiv/issue-46-startup-sync

Conversation

@pablontiv

Copy link
Copy Markdown
Owner

What

  • replace quadratic startup tagging concatenation with an incremental accumulator
  • coordinate startup sync across processes with a persistent 0600 advisory lock
  • allow compatible snapshot/config followers to continue immediately while mutations wait up to five seconds
  • make snapshot query preparation read-only and non-migrating
  • add unit, subprocess, crash-recovery, race, and Windows cross-compile coverage
  • document the owner/follower contract and package inventory

Why

Concurrent Backscroll invocations independently repeated expensive startup work and could contend on SQLite. Large sessions also triggered O(n²) string concatenation during tagging, causing commands to exceed 120 seconds and consume excessive transient memory.

Closes #46.

How

  • added tagging.Accumulator to classify each message without constructing a session-sized string
  • added internal/startuplock using github.com/gofrs/flock v0.13.0, keyed by the canonical database path
  • classified all operational commands as snapshot reads, metadata reads, or mutations
  • centralized owner/follower coordination in the root startup policy
  • retained mutation leases through handlers, including recover post-install sync
  • routed busy snapshot followers through compatible OpenReadOnly WAL inspection and emitted freshness warnings only on stderr
  • added deterministic process barriers proving single-flight ownership, timeout behavior, and crash recovery

Design: docs/superpowers/specs/2026-08-21-startup-sync-coordination-design.md
ADR: docs/adr/0003-coordinar-sync-entre-procesos.md

Verification

  • rootline validate docs/adr/0003-coordinar-sync-entre-procesos.md --strict
  • just check
  • go test -race ./...
  • just test
  • just ci — aggregate coverage 86.5%
  • repeated subprocess/process-death tests (-count=5)
  • GOOS=windows GOARCH=amd64 go test -c ./internal/startuplock
  • accumulator benchmark scales linearly from 128 to 512 records at ~2.28 MB/s

Checklist

  • Tests pass (just test)
  • Code is clean (just check)
  • Snapshots updated if needed (N/A — no snapshot suite)
  • Changes are documented if user-facing

@pablontiv
pablontiv merged commit c72366a into main Aug 21, 2026
6 checks passed
@pablontiv
pablontiv deleted the pablontiv/issue-46-startup-sync branch August 21, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup sync has quadratic session-text aggregation and can stall commands

1 participant