Skip to content

O7: ledger supplies last_heartbeat from previous committed record #13

Done

Description

@Pigbibi

Follow-up from the Astra review of #9 (P1-1, decision (b)). Must land in SH-2 part 4 (ledger, scheduler, replay).

Current state (part 2, #9)

When session inputs carry no last_heartbeat, build_fuse_validated_inputs() defaults it to as_of and sets heartbeat_source="adapter_self". That is the job's own self-attested heartbeat, not independent liveness evidence, so a stalled chain cannot trip O7.

Today no caller (ledger.py build_record_body, scheduler, cloudrun_job, demo) supplies last_heartbeat or scheduled_interval.

Required change (part 4)

  • The ledger passes the previous committed record's decision_timestamp_utc as last_heartbeat (heartbeat_source="previous_committed_record").
  • scheduled_interval is the expected spacing between consecutive trading-session decisions, derived from the pinned calendar rather than a fixed 60s.
  • Bootstrap rule: a first-ever run with no previous committed record (genesis, sequence == 0) follows an explicit, documented rule with heartbeat_source="genesis_bootstrap". It must not fall back silently to as_of.
  • Replay reproduces the same heartbeat inputs from the chain.

Tests

  • A stale previous record, more than 2 scheduled intervals old, trips O7.
  • Genesis with no previous record is handled by the documented bootstrap rule and is labelled as such.
  • A normal next-session run with a fresh previous record leaves O7 NORMAL.
  • The full suite and python -m shadow.sh2_acceptance stay green.

Activity

  1. Pigbibi commented on Nov 26, 2026

    @Pigbibi
    ContributorAuthor

    Scope addition, decided in the #9 review: L0 two-pass in part 4.

    The ledger currently evaluates FUSE rows first (evaluate_non_stub_tiers) and sizes afterwards (compute_session_sizing). As a result, L0 sees only the pre-sizing exposure as proposed_exposure.

    Part 4 should:

    1. Size the targets.
    2. Re-evaluate L0 against the actual proposed exposure from those targets.
    3. Block the session if the proposal exceeds max_loss_cap.

    Tests:

    • A flat book with a large proposed buy above the cap must trip L0.
    • A proposal within the cap stays NORMAL.

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions