Fix app stream/timeline ordering desync and init lifecycle race (#73)

* fix(app): enforce canonical stream sequencing and init resolution

* refactor: extract timeline and stream reducers to pure functions
This commit is contained in:
Mohamed Boudra
2026-02-23 19:30:48 +07:00
committed by GitHub
parent 9b6f5e028c
commit a134132418
12 changed files with 1732 additions and 109 deletions
@@ -0,0 +1,38 @@
export type SessionTimelineSeqCursor =
| {
epoch: string;
endSeq: number;
}
| null
| undefined;
export type SessionTimelineSeqDecision =
| "accept"
| "drop_stale"
| "drop_epoch"
| "gap"
| "init";
export function classifySessionTimelineSeq({
cursor,
epoch,
seq,
}: {
cursor: SessionTimelineSeqCursor;
epoch: string;
seq: number;
}): SessionTimelineSeqDecision {
if (!cursor) {
return "init";
}
if (cursor.epoch !== epoch) {
return "drop_epoch";
}
if (seq <= cursor.endSeq) {
return "drop_stale";
}
if (seq === cursor.endSeq + 1) {
return "accept";
}
return "gap";
}