Skip to content

feat: wal durability - #27

Merged
notxorand merged 22 commits into
devfrom
wal-durability
Sep 5, 2026
Merged

notxorand merged 22 commits into
devfrom
wal-durability

Conversation

@notxorand

@notxorand notxorand commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

closes: #21

Greptile Summary

This PR introduces a custom write-ahead log and integrates durable source ingestion and cascade checkpoints into the inference runtime.

  • Adds eventual and strict WAL durability modes, recovery, batching, pending-work tracking, and LWW-backed fact reads.
  • Routes source mutations and rule-produced cascade outputs through durable checkpoints.
  • Restores HLC state from persisted timestamps and adds storage configuration to the CLI and supervisor.
  • Adds WAL and storage benchmarks plus persistence-focused tests.
  • The latest revision makes failed strict-write rollback conditional on the timestamp originally published, preventing it from replacing a newer intervening fact.

Confidence Score: 5/5

No new actionable issue was established by the changes since the previous review, so the PR appears safe to merge.

The latest change guards strict rollback with the originally published timestamp, preventing failed writes from replacing a newer fact. All eight earlier Greptile threads were manually resolved without explanatory replies and therefore do not remain in the merge-safety scoring set.

Important Files Changed

Filename Overview
src/wal.zig Implements WAL serialization, recovery, asynchronous grouped writes, durability modes, fact state, pending work, cascade checkpoints, and timestamp-guarded rollback.
src/storage.zig Delegates durable fact and pending-work operations to the custom WAL while retaining SQLite-backed module storage.
src/engine/context.zig Adds persistence access, cascade accumulation, rollback bookkeeping, and checkpoint management to execution contexts.
src/engine/loop.zig Drives inference from durable pending entries and commits cascade outputs together with the triggering acknowledgement.
src/engine/events.zig Persists mapped source facts before execution, restores the HLC from durable state, and coordinates connector shutdown with the run loop.
src/memory/lww.zig Adds independently owned rollback snapshots and complete ownership cleanup for values and causal-node strings.
src/wasm/host_abi/generic.zig Makes reads safe across lock release and integrates rule-produced writes with cascade rollback and checkpointing.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    S[Source event] --> P[Persist source mutation]
    P --> W[WAL batch checkpoint]
    W --> D[Durable pending entry]
    D --> I[Inference loop]
    I --> L[Update in-memory LWW cache]
    L --> C[Accumulate cascade outputs]
    C --> F[Flush cascade checkpoint]
    F --> A[Acknowledge source pending entry]
    F --> R[Recover facts and pending work after restart]
Loading

Reviews (5): Last reviewed commit: "fix: protect strict rollback state" | Re-trigger Greptile

+ integrate storage durability into runtime and CLI
+ add custom WAL recovery, batching, acknowledgements, and fsync modes
+ add SQLite and WAL performance benchmarks
+ update HLC initialization and ignore database artifacts
+ batch queued requests into one fsync
+ enforce record, field, queue, and mutation limits
+ mark terminal writer failures and reject pending work
+ distinguish torn tails from corrupt WAL records
expose durability as a build option and use it when opening storage,
with benchmarks reduced to a single inference iteration.
+ add queue capacity checks before publishing facts
+ defer eventual WAL cleanup until flush completion
+ expose queue fullness through DirtyQueue
Comment thread src/wal.zig
Comment thread src/wal.zig Outdated
Comment thread src/wasm/host_abi/generic.zig
Comment thread src/storage.zig
@codspeed

codspeed Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 14.58%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 3 untouched benchmarks
🆕 1 new benchmark

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ runtime.execution 7.4 s 8.6 s -14.58%
🆕 runtime.storage N/A 2.1 ms N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing wal-durability (5bc15e9) with dev (89658db)

Open in CodSpeed

Comment thread src/engine/events.zig
Comment thread src/memory/lww.zig
Comment thread src/wal.zig
Comment thread src/memory/lww.zig
@notxorand
notxorand merged commit 6c0a328 into dev Sep 5, 2026
4 of 5 checks passed
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.

feat: persistence for durability

1 participant