From 8507403b0f96667ccbab5ad7f83538600d5c0cc7 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 17 Apr 2026 14:41:22 +0200 Subject: [PATCH] Consume durable history from topic beginning Proof: npm test; node --test test/history-writer-static.test.mjs test/kafka-topics.test.mjs test/environment-status-history.test.mjs; node --check src/apps/history-writer.mjs. Assumptions: Durable history consumers are idempotent by event_id, so from-beginning subscription is safe when a topic has no committed group offset. Still fake: This protects durable event capture for repo-owned Kafka topics; it does not backfill events that were never published to Kafka. --- src/apps/history-writer.mjs | 2 +- test/history-writer-static.test.mjs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/history-writer-static.test.mjs diff --git a/src/apps/history-writer.mjs b/src/apps/history-writer.mjs index aa521d8..6d976aa 100644 --- a/src/apps/history-writer.mjs +++ b/src/apps/history-writer.mjs @@ -106,7 +106,7 @@ const intentRequestOutcomeTopics = new Set([ ]); for (const topic of topics) { - await consumer.subscribe({ topic, fromBeginning: false }); + await consumer.subscribe({ topic, fromBeginning: true }); } const state = { diff --git a/test/history-writer-static.test.mjs b/test/history-writer-static.test.mjs new file mode 100644 index 0000000..d749448 --- /dev/null +++ b/test/history-writer-static.test.mjs @@ -0,0 +1,10 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; + +const source = readFileSync(new URL('../src/apps/history-writer.mjs', import.meta.url), 'utf8'); + +test('history writer consumes from beginning so first events on newly-created topics are durable', () => { + assert.match(source, /consumer\.subscribe\(\{ topic, fromBeginning: true \}\)/); + assert.doesNotMatch(source, /consumer\.subscribe\(\{ topic, fromBeginning: false \}\)/); +});