Repository navigation
Description
Problem
Three J5 daemons take their start point from a table nothing writes any more, so two of them replay the entire event history on every server start. On j5/main today, a restart can retire a live Captain's Crews and archive their seats, even though the Captain is still live.
CrewSeatFinishNotifier.ts (~436) and CrewLaunchReporter.ts (~414) start their stream with:
SELECT COALESCE(MAX(sequence), 0) AS sequence FROM orchestration_v2_eventsThe upstream sync (#256, 2026-09-23) brought in upstream's ApplicationEventSource migration. It copies V2 events into orchestration_events (application_event_version = 2), and the event store has written only there since then. streamStoredEventsFrom → EventSinkV2.stream → OrchestrationEventStore reads orchestration_events. Nothing writes orchestration_v2_events outside migrations, so the query returns 0. The stream then starts at sequence 0 and replays everything.
Live install (read-only count): orchestration_v2_events holds 0 rows; orchestration_events holds 124,139 V2 rows, up to sequence 151,945.
SilenceDetector.ts (~634) has the same query, but it only uses it to seed its durable cursor the first time.
What it does
The Captain archive cascade rides the finish notifier's stream, so every historical Captain thread.archived or thread.deleted event is handled again at boot.
Reproduced by Astra on unchanged j5/main (1ff729bc0d), on an isolated copy of real data:
- The server booted at 15:46:19 with a live Captain and 2 live Crews.
- At 15:46:41–42, a replay of an old archive event for that Captain retired both Crews ("Trio" archived 15:46:41.871, "PartialRegression" 15:46:42.246) and archived all 4 seats.
- The Captain stayed live (
archived_atNULL).
The replay also reprocesses old seat finishes and launch reports. Old finish notices showed up in Captain threads after a restart.
#315 raises the stakes further: its cascade also acts on thread.unarchived, thread.settled, and thread.unsettled. Once it merges, the replay would also settle, unsettle, and restore Crews from history.
Fix
Take the high-water mark from the table the stream actually reads. The simplest way is the event store's own latestSequence(), so J5 doesn't hard-code a table name again. Otherwise use SELECT COALESCE(MAX(sequence), 0) FROM orchestration_events WHERE application_event_version = 2 in all three places.
Add a test that boots the notifier with existing V2 events and asserts that nothing before the high-water mark reaches handleStoredEvent.
Found by the Crews review panel (Claude Opus 5.5 + Astra) while re-verifying #292/#313/#300/#315.
Activity