Skip to content

feat(replication): epoch fencing and manual promotion (ADR 0002) - #7

Open
ChromaBeast wants to merge 8 commits into
mainfrom
claude/gifted-swirles-5904ad
Open

ChromaBeast wants to merge 8 commits into
mainfrom
claude/gifted-swirles-5904ad

Conversation

@ChromaBeast

Copy link
Copy Markdown
Owner

What

ADR 0002 plus the first safe slice of manual promotion.

  • ADR: docs/adr/0002-replication-membership-and-manual-promotion.md covers membership, epochs, fencing, promotion preconditions, client discovery, failure cases, what automatic election would still need, and open owner decisions.
  • Epoch and role persisted in cluster-state.json; epoch carried in StreamWAL, records, Ack and the new Fence RPC (not yet in WAL frames).
  • Followers reject a stale-epoch leader; a leader steps down on a higher epoch; the read-only check now runs inside the engine write batch so the fence is exact.
  • POST /api/replication/promote (admin-only, audited as replication.promote). Fences the old leader, waits for its final LSN, then promotes. If the leader is unreachable it refuses unless acceptDataLoss is set.
  • Studio: Promote action, disabled with a stated reason unless the node is caught up.
  • Gap plan Replication row updated.

Reviewer notes

  • Promotion is manual. There is no automatic election and this is not high availability.
  • This branch is stacked on claude/figma-ui-comparison-4d2e45 (Phases 0-2), so the diff against main includes those commits. The promotion work is the last two commits.
  • api/proto/*.pb.go regenerated with buf (no protoc here).
  • Promote runs on the replica's own Studio; Add replica is still a command.
  • Not exercised in a browser; Studio is covered by type check and bun test.
  • Verified: go build ./... && go vet ./... && go test ./... -race, bun test.

- Sidebar: 232px width, 10px item padding and gap, panel background,
  solid active item in dark mode.
- Add StatCard/StatGrid and use them for summary tiles on Overview,
  Indexes and Backups, all fed by real engine values.
- API Keys: four role cards on top, explanation note below the list.
- Settings: left sub-menu (General, Storage, Networking, Security,
  Limits); card definitions moved to settings/SettingsCards.tsx.
- Logs: Time/Level/Event header row and Export CSV (toLogCsv, tested).
- docs: add studio-figma-gap-plan.md with the phased plan for the
  Figma features the engine does not back yet.
Server:
- metrics: in-memory History ring and RequestMetrics.Total; the web
  server samples gauges every 10s for 24h and serves them at
  GET /api/metrics/history (admin only, window capped at 24h).
- auth: TokenStore tracks last use in memory only, so authenticating
  never writes to the engine; List reports last_used_at.
- logbuf: entries carry a source derived from the message text;
  /api/logs accepts source=.

Studio:
- Keys: Last used column.
- Logs: Source column, source and time-range filters, source in the
  text and CSV exports.
- Metrics: Live / 1h / 24h range picker backed by the server history.
- Overview: requests-per-second chart for the last hour.
- docs: record the Phase 1 differences in studio-figma-gap-plan.md.
- audit: append-only, hash-chained audit.log in the data directory.
  Records sign-ins, key and record changes, user deletes, checkpoints,
  settings changes and backup actions; never values or secrets. The
  server refuses to start if the existing chain is broken. Served at
  GET /api/audit and shown on a new Audit tab on the Logs page.
- runtimecfg: WAL checkpoint threshold, sign-in rate limit and backup
  schedule can be changed live at /api/settings/runtime, are validated,
  saved to runtime-settings.json (overriding the flags on restart) and
  audited. Engine and rate limiter gain runtime setters.
- backup: create, verify, list and download (tar) backups of a running
  node, with an optional schedule and retention. Built on
  Engine.CreateSnapshot, so reads and writes pause for the copy. Bundles
  match beastctl's format; a test proves beastctl verify and restore
  accept them. Restore stays an offline beastctl step.
- Studio: Backups table with Back up now, Verify, Download and a copy
  restore command; editable settings cards; Audit tab.
- docs: record Phase 2 in studio-figma-gap-plan.md.
Persisted epoch and role, epoch carried in replication RPCs, Fence RPC,
stale-epoch rejection by followers, leader step-down on a higher epoch,
admin promote endpoint with audit entry, and a Studio Promote action
gated on the node being caught up. Promotion is manual; no automatic
election and not high availability.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T20:42:15.568285Z
We couldn’t complete this review. Comment @codex review to try again.
9277c1d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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.

1 participant