Skip to content

feat(scarab): ledger-daemon PR-1 scaffold (Khepri-3 watchdog)#105

Draft
gHashTag wants to merge 1 commit into
mainfrom
feat/scarab-khepri-3-ledger-daemon
Draft

feat(scarab): ledger-daemon PR-1 scaffold (Khepri-3 watchdog)#105
gHashTag wants to merge 1 commit into
mainfrom
feat/scarab-khepri-3-ledger-daemon

Conversation

@gHashTag
Copy link
Copy Markdown
Owner

🪲 First building block of the Scarabaeus Engine (trios-railway#101).

This is PR-1 of 5 for Khepri-3. Scaffolds the crate with the tick loop, config, R7 audit emitter, and four DRY-RUN job stubs. Mutations land in PR-2..PR-5 (one per job).

Four jobs

Job Trigger Dry-run audit action Mutation lands in
1 workers.last_heartbeat > N s resurrect_candidate PR-2 Railway API redeploy
2 queue depth (pending+ready) autoscale_compute PR-3 service replicas patch
3 done rows with bpb < threshold leak_flag (writes last_error) already live
4 running rows older than N h zap_stuck (Khepri-2 requeue) already live

Jobs 3 and 4 are not dry-run — they write last_error and requeue respectively.

Verified locally

$ cargo build -p ledger-daemon
$ cargo test  -p ledger-daemon
$ cargo fmt   -p ledger-daemon

Refs

Anchor: phi^2 + phi^-2 = 3. NEVER STOP.

🪲 First building block of the Scarabaeus Engine (#101) — a single-replica
Railway service that ticks every 30 s and corrects course from above.

## What's in this scaffold (PR-1)

- Workspace member: `bin/ledger-daemon` with Cargo.toml + README.md.
- main.rs: tokio runtime, neon connect, tick loop with MissedTickBehavior::Skip,
  graceful Ctrl-C, four-job dispatch with no-fatal error collection.
- config.rs: env parsing (NEON_DATABASE_URL with TRIOS_NEON_DSN/DATABASE_URL
  fallback chain matching trios-trainer-igla::neon_writer), tick_secs,
  worker_dead_after_secs, leak_bpb_threshold, telegram, destructive_ok.
- audit.rs: R7 triplet emit helper writing to gardener_runs (action, lane,
  seed, before_bpb, after_bpb, decision JSONB).
- jobs.rs: four jobs as DRY-RUN scaffolds. Each runs the full SELECT and
  emits an audit row with `decision.dry_run=true` so we can verify
  decision quality from gardener_runs before wiring mutations.

## Four jobs

| Job | Trigger | Dry-run audit action | Mutation (PR-N) |
|---|---|---|---|
| 1 | workers.last_heartbeat > N s | `resurrect_candidate` | PR-2 Railway API redeploy |
| 2 | queue_depth (pending+ready) | `autoscale_compute` | PR-3 service replicas patch |
| 3 | done rows with bpb < threshold | `leak_flag` (writes last_error) | already live |
| 4 | running rows older than N h | `zap_stuck` (Khepri-2 requeue) | already live |

Jobs 3 and 4 are NOT dry-run — they write last_error and requeue
respectively. Jobs 1 and 2 are dry-run-only until PR-2 / PR-3.

## Verified locally

```
$ cargo build -p ledger-daemon       # clean
$ cargo test  -p ledger-daemon       # 0 passed (no unit tests yet, PR-2 adds)
$ cargo fmt   -p ledger-daemon       # clean
```

## Refs

- parent: trios-railway#101 🪲 Scarabaeus Engine umbrella
- depends-on: trios-railway#102 (Khepri-0 contract test)
- depends-on: trios-railway#103 (Khepri-1 LISTEN/NOTIFY)
- depends-on: trios-railway#104 (Khepri-2 retry/DLQ)

Anchor: phi^2 + phi^-2 = 3 — TRINITY — NEVER STOP.
gHashTag pushed a commit that referenced this pull request May 20, 2026
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