Skip to content

model: record every provider call in one stage ledger for cache cost latency and convergence budgets #930

Open

Description

@EffortlessSteven

Parent

#840 — useful reviewer and trustworthy CI evidence gate.

Related work: #865 stage-aware convergence reserve, #868 calibration/economics.

Verified gap

model_stages.json is currently reconstructed from model-lane receipts plus follow-up results. It is not the authoritative lifecycle of every provider call, and reporter/re-distillation/continuation activity can be omitted or ambiguously classified. The current global max_model_calls budget also treats primary investigation, retries, refutation, reconsideration, and final synthesis as one undifferentiated pool.

The product needs the model equivalent of TaskLedger before provider/cache economics or protected final-lead capacity can be trusted.

Outcome

Introduce one append-only ModelStageLedger / call lifecycle for every model/provider invocation:

planned
→ queued
→ provider_wait/backpressure
→ running
→ terminal

Each call records at least:

RevisionIdentity
call_id
programme/lane
stage = routing | primary | challenge | proof_arbitration |
        receipt_reconsideration | final_lead | retry | fallback
provider / model / endpoint / service tier
queue_ms / request_ms / ttft_ms? / generation_ms?
fresh_input / cache_write / cache_read / output / reasoning? tokens
prefix/cache identity
retry/fallback provenance
terminal status / HTTP class
price basis + estimated direct cost when available

Stage budgeting and #868 calibration derive from this ledger rather than from inferred lane/file presence.

Scope

  • Emit lifecycle events around every existing provider call path, including preflight, primary specialists, proof planner, refuter/challenge, reporter, reporter re-distillation, lane continuation/reconsideration, retries, and fallbacks.
  • Preserve provider-specific cache/token fields but normalize them into one additive receipt surface.
  • Record unavailable metrics as absent, not zero.
  • Compute stage-aware call consumption from explicit stage identity.
  • Make the ledger work with model-off and missing price tables.
  • Keep prompt contents/secrets out of telemetry; persist digests/section identities rather than raw private context where possible.
  • Allow review: reserve model calls for challenge, proof reconsideration, and one authoritative final judgment #865 to protect final-lead/reconsideration/retry reserves from primary fanout.

Acceptance

  • Every network model call in a run maps to exactly one model-stage lifecycle.
  • Reporter, re-distillation, continuation, retry and fallback calls cannot disappear from cost/time accounting.
  • Queue/backpressure time is distinct from provider request duration.
  • Cache read/write/fresh token classes remain separate.
  • A missing provider metric does not serialize as a misleading zero.
  • Primary calls cannot spend a protected final-lead reserve once review: reserve model calls for challenge, proof reconsideration, and one authoritative final judgment #865 consumes this ledger.
  • Model-off produces an empty/explicit no-model ledger without breaking run accounting.
  • Same recorded calls replay to the same stage/cost summary.
  • Raw prompts and credentials are absent from aggregate telemetry.

Proof

  • Full call-path fixture covering primary, retry, fallback, challenge, reporter, continuation and final lead.
  • Backpressure/timeout/missing-token-usage/missing-price fixtures.
  • Cache hit/write/read accounting fixture.
  • Model-off fixture.
  • Forged/missing-call verifier negatives.
  • Full provider/model orchestration/calibration/CLI/workspace/fmt/Clippy/policy/exact-head gate.

Non-goals

Dependency/order

Depends on #923. Land before #865 becomes authoritative and before #868 becomes a promotion/learning input.

Rollback

Keep the stage ledger in shadow while retaining current call scheduling. Do not let inferred model_stages.json remain the long-term authority.

Activity

  1. EffortlessSteven commented on Aug 24, 2026

    @EffortlessSteven
    MemberAuthor

    PR-sized decomposition — #945 C5.1–C5.3

    1. C5.1 pure ModelStageLedger — call/stage lifecycle, revision binding, stage taxonomy, optional metrics and deterministic replay.
    2. C5.2 production instrumentation — preflight, primary, planner, challenge, reporter, redistillation, continuation/reconsideration, retry/fallback and final-lead call paths.
    3. C5.3 projections/verifier — queue/provider/cache/token/TTFT/throughput/cost summaries, missing-metric semantics and forged/missing-call negatives.

    No model-selection policy in this train. #865 consumes stage budgets; #868/#938 consume the measured projections.

  2. EffortlessSteven commented on Aug 24, 2026

    @EffortlessSteven
    MemberAuthor

    Concrete PR decomposition

    #1009 pure ModelStageLedger lifecycle/stage taxonomy
    → #1010 instrument every provider call path
    → #1011 derive cache/token/latency/throughput/cost/critical-path projections
    

    No inferred lane/file presence remains authoritative. Reporter, redistillation, continuation, reconsideration, retry/fallback and final lead must all be ledgered. Missing provider metrics remain absent, not zero; raw prompts/secrets stay out.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions