G
YouTube TikTok Games
Skip to content

P0 Event History: off-WPF bounded batching, loss accounting and 50k benchmark - #167

Merged
masarray merged 2 commits into
masterfrom
feat/p0-event-history-async-hardening-20261111
Nov 11, 2026
Merged

masarray merged 2 commits into
masterfrom
feat/p0-event-history-async-hardening-20261111

Conversation

@masarray

Copy link
Copy Markdown
Owner

Goal

Harden the P0 numbered Event History delivered in #165/#166 for sustained IEC-101/104 event bursts without blocking the WPF Dispatcher on JSON serialization, SHA256 or file writes.

Design

  • One session-scoped bounded Channel writer (4,096 work items, 64-row batches). RecordEventHistory only assigns Event # and performs nonblocking TryEnqueue. Serializing/hashing/append happen on a single background worker.
  • JIT no DB dependencies. Existing events.bin + fixed-offset events.idx remain authoritative; a batch commits under one journal lock, and page reads verify SHA256 and sequence as before.
  • Explicit counters distinguish UI observed, indexed, pending and unindexed. Queue overflow or disk quota/error closes admission rather than manufacturing a hole in the original ordinal history. Existing indexed prefix remains readable.
  • Idempotent nonblocking cleanup on session reset/window close. Historical paging is performed off Dispatcher and retains pinned horizon.
  • Deduplicate exact matching original-frame Raw HEX from event-source and frame snapshot; original source identity/HEX restored unmodified on read.
  • Background status refresh throttled to about 350ms; no blocking Flush on WPF.

Regression and performance

  • 2,000 / 10,000 / 50,000 events with measured throughput and bytes, first/middle/last pages, original frame reconstruction.
  • Quota exhaustion, concurrent read/write, queue admission and pending accounting.
  • Full WPF 620-event smoke still requires a writer barrier before accepting indexed count.
  • Do not modify IEC-101 serial, Class 1/2 poll, FCB/ACD, GI or source routing, and keep P0 IEC-101: reconcile #136 and integrate shared per-link transaction/FCB core #145 separate.

Release gate

Draft until Windows CI, xUnit, CodeQL and full real-WPF acceptance are validated. Physical SICAM 1,200 bps FAT and true RTU FIFO completeness remain separate.

{
private sealed record Work(RelayEventRow? Row, TaskCompletionSource<bool>? Barrier);
private readonly Channel<Work> _channel;
private readonly EventHistoryJournal _journal;
Comment on lines +127 to +131
catch (Exception ex)
{
Fail("Event History writer failed: " + ex.Message);
activeBarrier?.TrySetException(new IOException(FailureReason, ex));
}
@masarray
masarray marked this pull request as ready for review November 11, 2026 13:23
@masarray
masarray merged commit 3fcfe73 into master Nov 11, 2026
8 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T13:25:22.050998Z 35857c1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35857c116d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 83 to +84
var indexed = _eventHistoryJournal?.Count ?? 0;
var pending = _eventHistoryWriter?.PendingCount ?? 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Publish history counters without taking the disk-writer lock

During sustained ingestion or slow temporary-disk writes, this footer still blocks the WPF Dispatcher: _eventHistoryJournal.Count and PendingCount both acquire the journal's _gate, while AppendBatch holds that same lock across hashing and file writes for an entire batch. The new periodic timer invokes this path even when the Events tab is inactive, so moving append operations to a worker does not isolate UI responsiveness from storage latency. Publish the committed count atomically, or provide a nonblocking status snapshot, rather than acquiring the I/O lock from WPF. This conflicts with the repository's PERF-01 bounded Dispatcher-work contract.

AGENTS.md reference: AGENTS.md:L31-L31

Useful? React with 👍 / 👎.

Comment on lines +65 to +67
Fail("Event History writer queue exceeded its bounded capacity; " +
"new rows are not indexed, and capture continues independently.");
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the new buffering and terminal-overflow policy

This introduces a 4,096-item asynchronous queue whose first overflow permanently closes history admission for the session, but the commit updates no documentation. Operators and maintainers need the output policy to distinguish pending rows from indexed rows, explain that later events remain unindexed after even a transient overflow, and describe reset/close cancellation of queued temporary history. AGENTS.md explicitly requires updating docs/OUTPUT_AND_PERFORMANCE_POLICY.md when buffering or retention behavior changes; add that update alongside this implementation.

AGENTS.md reference: AGENTS.md:L238-L238

Useful? React with 👍 / 👎.

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.

2 participants