Skip to content

fix(bayn): preserve bar evidence and enforce replay completeness - #14593

Merged
gregkonush merged 5 commits into
mainfrom
codex/bayn-replay-correctness-20260917
Sep 18, 2026
Merged

gregkonush merged 5 commits into
mainfrom
codex/bayn-replay-correctness-20260917

Conversation

@gregkonush

@gregkonush gregkonush commented Sep 18, 2026

Copy link
Copy Markdown
Member

Summary

  • Preserve the first identical bar publication as timing evidence while selecting the latest raw revision and its exact rolling feature. Saved live and simulated cuts bind both deliveries and reproduce their source coordinates, content and arrival times.
  • Give corrected bars a separate publication window. Quotes retain their existing age limit. An explicit policy marker preserves legacy snapshot reconstruction and archive timing rules.
  • Support close-only MARKET/DAY sells and fractional liquidation in replay. Reconstruct requests, fills and fees after restart. Fail the simulation when a fresh arrival quote cannot supply the entire market close, and prevent acceptance after broker delivery failures.
  • Count unavailable required decision observations separately from successful no-trade and expected lifecycle waits. Missing benchmark evidence now produces missing-decision-data and INCOMPLETE even with flat, exact accounting.

Related Issues

None. These changes address four independently reproduced correctness defects in the Bayn follow-up audit.

Testing

  • Regression commit 3da7138658: 5 failures reproduced before the fixes, with 39 other focused tests passing.
  • bun run --filter @proompteng/bayn test: 1,274 passed, 101 integration/environment cases skipped, 0 failed.
  • bun run --filter @proompteng/bayn test:postgres: 68 passed against isolated PostgreSQL 17.11.
  • With isolated PostgreSQL and TigerBeetle: bun test src/intraday-replay/runtime.integration.test.ts src/intraday-replay/durable-broker.integration.test.ts: 10 passed. Includes production fallback MARKET/DAY liquidation with exact accounting, native missing-benchmark/no-trade controls, fractional fill accounting and client restart. Coverage controls exercise a bounded native decision interval, not a full economic study.
  • bun test src/intraday-replay/restart.integration.test.ts: 1 passed in the required disposable bayn_test database. The first attempt used another _test database and was correctly rejected by the test's environment guard.
  • Final review added a separately reproduced fractional-account guard: enabled accounts can close fractional inventory; disabled accounts reject before order creation. All 45 broker tests and both durable accounting cases passed after the fix.
  • bun test services/bayn/src/market-data/streaming/bar-publication.test.ts: 10 passed, including live and simulated reconstruction, legacy cuts, changed late data, feature mismatch, publication tampering and stale/future data.
  • bun run --filter @proompteng/bayn tsc, lint, lint:oxlint, lint:oxlint:type, and build: passed. Bun 1.4.0 and pinned Node 24.11.1 were used. nix develop was unavailable because the local Nix daemon was stopped; the pinned Node binary was available in the Nix store.

Breaking Changes

No database migration. New cuts include a versioned bar-publication policy and optional publication witnesses; this version still reproduces legacy cuts. Older binaries cannot interpret the new evidence fields.

The replay market-close model requires enough fresh displayed liquidity for a complete fill. It fails explicitly for an unsupported DAY remainder instead of estimating later fills. This change does not qualify a strategy's profitability or change trading authority, quote-size units, or strategy thresholds.

Checklist

  • Testing section documents the exact validation performed.
  • Screenshots and Breaking Changes sections are handled appropriately.
  • Documentation, release notes, and follow-ups are updated or tracked.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-18T06:30:54.877231Z 35bf18d PR opened
ℹ️ 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: 35bf18d780

ℹ️ 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 thread services/bayn/src/intraday-replay/broker.ts
@gregkonush
gregkonush merged commit 2c23759 into main Sep 18, 2026
16 of 18 checks passed
@gregkonush
gregkonush deleted the codex/bayn-replay-correctness-20260917 branch September 18, 2026 06:37
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.

1 participant