Skip to content

feat(ledger): add SH-2 ledger integrity, scheduler, replay, and Cloud Run job (SH-2 4/5) - #15

Merged
Pigbibi merged 48 commits into
mainfrom
feat/sh2-part4-ledger-integrity
Nov 26, 2026
Merged

Pigbibi merged 48 commits into
mainfrom
feat/sh2-part4-ledger-integrity

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

AI assistance

  • Gemini (execution) + OpenAI Codex (gpt-6.2-astra, reasoning high, 2 local review rounds).

What changed

  • Add SH-2 ledger integrity, deterministic scheduler orchestration, bit-for-bit replay verification, Cloud Run Jobs entrypoint (src/shadow/cloudrun_job.py), and D1–D10 demonstration (demo/run_sh2_demo.py).
  • Implement Issue O7: ledger supplies last_heartbeat from previous committed record #13 (O7 calendar-derived scheduled_interval & last_heartbeat with genesis_bootstrap / previous_committed_record) and L0 two-pass re-evaluation using the frozen U-01 Step 6 post-trade joint exposure formula (compute_joint_exposure_for_quantities).
  • Add Cloud Run same-session idempotent retry with externally anchored pre-commit head, unconditional historical receipt/OTS/deadline checks even without Bitcoin headers, explicit persistent --data-dir/SHADOW_DATA_DIR requirement on Cloud Run & production, pre-commit .pending_evidence crash recovery, strict check_forward_clock_credit config lock precedence, nested fuse_inputs O7 consistency, and separate consecutive-appended vs verified clk01_credit reporting.
  • Keep all standing safety locks intact (config/production-scheduler.json: production_chain_locked: true, clk01_active: false, live: OFF, kelly: OFF, H: "0", B0: "50000").

How verified

  • Merged origin/main (SH-2 3/5) cleanly and ran full test suite after final edits: PYTHONPATH=src python3 -m unittest discover -s tests -> Ran 189 tests in 226.435s OK.
  • Completed 2 rounds of local codex review (gpt-6.2-astra, high), fixed all Round 1 & Round 2 P1s and trivial P2s, and logged remaining non-blocking P2s to SH-2 adapter/sizing hardening: P2 follow-ups from Astra review of #9 #12.

Why

Risk

Pigbibi and others added 30 commits November 25, 2026 23:47
Add VendoredFuseEvaluator, which re-verifies the vendored engine digests
before each evaluate() call, plus FUSE input translation, NO-NEW-RISK
clamping and per-tier sizing controls. Register fuse_adapter in the code
manifest, hash explicit scheduler config paths by their relative path,
and record the SH-2 entry gates. Part 2 of the SH-2 split of #7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Consume the csa22-v2 calendar to classify core RTH vs extended and
overnight windows, reject non-official-close and T+1 bars, resolve the
immediately preceding trading date, and bound decimal inputs. Add
http_limits with streaming byte caps and monotonic total deadlines for
market and OTS fetches. Part 3 of the SH-2 split of #7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Embed next_row_state_sha256 in record bodies, authenticate persisted
production history against an external trusted head and monotonic
anchor, and recover pending rejected state across multi-day rejections.
Wire FUSE into scheduler and replay, add the locked production config,
the Cloud Run job module, and the SH-2 demo used by the pipeline tests.
Part 4 of the SH-2 split of #7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Resolve o5_settled_cash before defaulting settled_cash to the bankroll,
keep a missing V7 session_time as missing instead of asserting a
regular session, and compile vendored source with dont_inherit=True so
legitimately compiled __pycache__ bytecode verifies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Default the canonical O5 session counters only when no alias carries
evidence, forward H so O9 can match authorized H change descriptors,
and stop substituting one_session_loss (a return fraction) for the
cumulative dollar loss L when re-tiering explicit FUSE payloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Stage N has no broker evidence in any mode, so absent broker_*
observations are substituted with modelled values and O3 is a model
self-reconciliation, not reconciliation evidence. Comment only; no
change to validated inputs or record hashes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Default session_order_count and session_turnover only when the key is
omitted; an explicitly null counter is unknown evidence and is passed
through as None so evaluate_O5() fails closed on turnover/order limits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Compare cached vendored bytecode by code-object equality instead of
marshal encoding, which differs between py_compile and compile() on
CPython 3.11/3.12, while still rejecting altered constants. Preserve an
explicitly null settled_cash or o5_settled_cash as unknown evidence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Validate every market record (including optional SPX) for eligibility,
calendar digest and effective session, apply corporate actions to V1
returns only when the ex-date is the decision session, pass explicit
null policy hashes and heartbeats through uncoerced, leave absent
settled cash unknown, pin the complete metadata digest set in code, and
execute only verified engine source bytes via a dedicated finder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Market records are now validated against the decision session, so the
ledger-integration and pipeline fixtures that build records by hand
carry the effective_session the feeder always sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Record heartbeat_source="adapter_self" when the adapter defaults the
O7 heartbeat to as_of, and "caller" when session inputs supply it, so a
self-attested heartbeat is never mistaken for liveness evidence. The
ledger-supplied heartbeat follows in part 4 (#13).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
SH-2 decisions are end-of-day, so every trading day, half days
included, maps to `open`; FuseControl's half_day_cutoff is a pre-trade
rule. Pin that the 2026-11-27 14:30 ET half-day decision maps to open
with O2 clear, and that late runs are the scheduler cutoff's job.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Pigbibi and others added 17 commits November 26, 2026 15:16
Apply the feeder's exact rate freshness rule, reject records retrieved
after the decision instant, reject the ineffective kill_switch_tripped
flag, fail closed on conflicting corporate actions and on caller closes
that disagree with the validated market close, and pass explicit nulls
(broker, cash, exposures, tolerance, proposal) through as missing.
Unknown tiers and missing high-water marks no longer fall back to
balanced or bankroll defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Ledger and pipeline fixtures that build market records by hand now
carry a T-1 SOFR effective date, a retrieval time before the decision
instant, and per-fund closes that match the fund payload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
The close-mismatch guard must compare values, not the strict sizing
parser (which rejects floats by design), so a float and a canonical
decimal string for the same close are treated as equal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Reject conflicting corporate actions before any successor state,
never let current_index_closes override a validated record, propagate
unknown held-position values into reconciliation and aggregates,
reject kill_switch_tripped on the effective payload at the evaluator
boundary, drop source records dated after the decision instant, and
compare timestamps as aware instants rather than strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Drop source records dated after the decision instant at the evaluator
boundary so nested fuse_inputs and direct payloads are covered, and
pass an unknown ledger quantity as share_count None (0 only for an
explicitly flat position) so O3/V2 cannot clear on an invented zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011iHeYdGvqQh5k2bkN5Eiuq
…-integrity

# Conflicts:
#	src/shadow/feeder.py
#	tests/test_feeder.py
#	tests/test_fuse_adapter.py
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 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-26T17:56:20.135085Z e6a5dc6 New commits
🔒 Security Review ✅ Completed 2026-11-26T17:58:39.073880Z e6a5dc6 New commits
ℹ️ 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: 0ffbdcab2e

ℹ️ 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 src/shadow/scheduler.py Resolved
Comment thread src/shadow/ledger.py Resolved
Comment thread src/shadow/ledger.py Resolved
@Pigbibi Pigbibi added the agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation label Nov 26, 2026
@Pigbibi Pigbibi added agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation and removed agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation labels Nov 26, 2026
@Pigbibi
Pigbibi merged commit 4cbbb34 into main Nov 26, 2026
13 of 15 checks passed
@Pigbibi
Pigbibi deleted the feat/sh2-part4-ledger-integrity branch November 26, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved An agent cleared this high-risk change on the current head; not an owner confirmation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

O7: ledger supplies last_heartbeat from previous committed record

1 participant