Skip to content

Stop forcing zero stale grace on mainnet so prior-tip shares are credited, not rejected - #225

Merged
kiwidream merged 5 commits into
2.x.xfrom
RobertClarke/stale-check
Sep 4, 2026
Merged

kiwidream merged 5 commits into
2.x.xfrom
RobertClarke/stale-check

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Verifies how PRISM classifies prior-tip shares and lifts the one production pin that turned them into miner-facing rejects.

What was verified (no behavior bug found in the classification itself):

  • A share on the just-replaced tip is credited with credit_policy=stale-grace when the window is open: acknowledged true to the miner, ledgered, counted in qbit_prism_grace_credited_shares_total, and never block-submitted. The window stays open until the connection receives new-tip work and for PRISM_STRATUM_STALE_GRACE_SECONDS after that delivery; eligibility is exactly one tip back.
  • With the window at zero, the same share is rejected with Stratum error 21 (stale-job / unknown-job, because the buried job context expires immediately).
  • Every reject is sent as {"result": null, "error": [code, message, {"reason_id": ...}]}. Miner firmware counts any pool-side error as a reject; "stale" on the miner side is only ever derived client-side. The only way the pool avoids a reject is to accept the share, which is what stale grace does.

The issue: the production gate (coordinator startup, scripts/check-env.sh, scripts/prism-self-check.py) forced PRISM_STRATUM_STALE_GRACE_SECONDS=0 on mainnet. So on mainnet every in-flight prior-tip share became an error-21 reject at each ~75 s block. That was introduced in #19 citing audit-bundle v1.1 verifier compatibility; this release's verifier still selects and accepts the v1.1 logical schema (audit_bundle_schema_for_shares, AUDIT_BUNDLE_SCHEMA_V1_1 in crates/qbit-prism/src/lib.rs).

The change (narrow, no hot-path code touched):

  • Remove the mainnet-only zero pin from the three gates. Mainnet now follows the same bounded-grace rule as every other production chain (default 3 s; 0 remains a valid explicit choice).
  • Validate the exported value with the coordinator's own env_nonnegative_float() semantics in both the doctor and the self-check, so a value that passes validation cannot then crash the coordinator at startup. The self-check previously parsed with int(), which rejected a valid fractional window such as 0.5.
  • Flip the production-gate tests and env fixtures to the bounded default, and align the synthetic mainnet compose fixture.
  • Update the docs and the .env.example comment that described the pin, and note that reward windows containing a credited share publish the logical qbit.prism.audit-bundle.v1.1 schema.

Operator note: external mirrors or verifiers that only understand qbit.prism.audit-bundle.v1 must be on a release that accepts v1.1 before a mainnet pool runs with the default window. The in-repo verifier already does.

Rebase onto 2.x.x

This branch was authored against main and rebased onto 2.x.x, which had diverged by 60 commits. Three things moved on this release line and the change was re-landed accordingly:

  • validate_prism_production_gate() now lives in lab/prism/coordinator_config.py (with an environ= keyword) rather than lab/prism/prism_coordinator.py.
  • Its regression test now lives in tests/test_prism_coordinator_config.py rather than tests/test_prism_coordinator_vardiff.py.
  • The tip-classification docstring now lives in lab/prism/tip_refresh.py.

The one main-only commit the branch had picked up — "Gate PRISM Postgres test containers on the real server" (#134), already merged to main — is not part of this change and was dropped.

Review follow-ups

An independent review of the rebase raised four items, all addressed in the final commit:

  • docs/prism-ledger-ops.md still told auditors to upgrade "before operators enable stale-grace crediting", contradicting the deployment guidance in the same document now that the window is on by default.
  • Validating stale grace with python3 made the interpreter a hard prerequisite for every prism-lane doctor run; production already required it, but lab bring-up did not. The hard failure is kept in production and the check is skipped with a doctor notice otherwise.
  • The production env fixtures still pinned the retired zero, so every full-environment production test proved the old contract.
  • The mainnet positive test asserted only that the old error message was gone, while its non-zero exit came from unrelated missing inputs. It now runs a complete mainnet production environment and asserts a clean exit for 3, 0.5, and an explicit 0.

Validation

  • python3 -m unittest tests.test_check_env_production_gate tests.test_prism_self_check tests.test_prism_coordinator_config tests.test_mainnet_compose_contract tests.test_prism_compose_profile (286 tests)
  • python3 -m unittest discover -s tests -p 'test_*.py' (3173 tests; the only failures are the five test_prism_job_builder.ShareWindowSpoolTests cases that need os.splice, which macOS lacks and CI covers on Linux)
  • git ls-files '*.sh' | xargs shellcheck -x and bash -n clean
  • python3 -m compileall -q docker lab tests examples scripts clean

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-04T16:22:19.179090Z 400a6f5 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: 87b8230a99

ℹ️ 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 scripts/check-env.sh Resolved

@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: bf7855eeb3

ℹ️ 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 scripts/prism-self-check.py Resolved

@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: d508744b32

ℹ️ 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 scripts/check-env.sh Resolved
@kiwidream
kiwidream changed the base branch from main to 2.x.x September 4, 2026 15:24
kiwidream and others added 5 commits September 4, 2026 11:38
…ited, not rejected

The production gate pinned PRISM_STRATUM_STALE_GRACE_SECONDS=0 on mainnet
(coordinator startup, scripts/check-env.sh, scripts/prism-self-check.py).
With a zero window every in-flight share on the just-replaced tip is
rejected with Stratum error 21 (stale-job / unknown-job) at each block,
and miner firmware counts any pool-side error as a reject: "stale" on the
miner side is only ever derived client-side, so the only way the pool
avoids a reject is to accept the share. That is exactly what the
stale-grace credit policy does (ack, ledger with credit_policy=stale-grace,
never block-submit), and the classification logic itself was verified
against the existing tip-flip tests.

Mainnet now follows the same bounded-grace rule as every other production
chain (default 3 s; an explicit 0 remains valid). The pin was added in #19
citing audit-bundle v1.1 verifier compatibility; this release's verifier
accepts v1.1, and the docs now say to keep external mirrors and verifiers
on a release that does too. No hot-path code changes.

On this release line the coordinator-side gate lives in
lab/prism/coordinator_config.py rather than lab/prism/prism_coordinator.py,
and its regression test lives in tests/test_prism_coordinator_config.py.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…g the check

Restore the ENV_ preservation for PRISM_STRATUM_STALE_GRACE_SECONDS so the
doctor validates the value Compose will hand the coordinator rather than
the .env.example default, and replace the removed mainnet-only equality
check with a lane-level non-negative numeric check that runs in every mode.
Without this, an exported value such as "not-a-number" passed the doctor
and then crashed the coordinator at startup in env_nonnegative_float().

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K8uGJEY2npTQuJPwS9Qg6M
…ntics

The coordinator accepts any finite non-negative float for
PRISM_STRATUM_STALE_GRACE_SECONDS and check-env now validates the same
shape, but the self-check still parsed the value with int(), so a valid
fractional window such as 0.5 failed `make prism-self-check`. Parse a
finite non-negative decimal instead.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K8uGJEY2npTQuJPwS9Qg6M
…octor and self-check

A hand-written regex cannot match env_nonnegative_float(): it rejected
valid runtime syntax such as 1e-1, .5 and 3., and accepted an integer
large enough to overflow to infinity at startup. Both check-env.sh and
prism-self-check.py now convert with float() and require a finite,
non-negative result, exactly as the coordinator does.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01K8uGJEY2npTQuJPwS9Qg6M
…innet coverage

Four follow-ups from reviewing the rebase against this release line.

Docs: the ledger-ops share-accounting paragraph still told auditors to
upgrade "before operators enable stale-grace crediting", which contradicts
the deployment paragraph in the same document now that the window is on by
default. It also, along with two other lines, named the v1.1 bundle schema
without saying it is the logical schema; the on-disk body is the v2
container carrying logical_audit_bundle_schema once share segmentation is
on. Both are now stated precisely.

check-env: validating stale grace with python3 made the interpreter a hard
prerequisite for every prism-lane doctor run. Production already required
it for the difficulty validation, but lab bring-up did not, and README
lists Python 3 only for the unit-test helpers. Keep the hard failure in
production and skip the check with a doctor notice otherwise, with a test
covering both branches over a python3-free PATH.

Tests: the production environment fixtures still pinned the retired zero, so
every full-environment production test proved the old contract, and the
mainnet positive test asserted only that the old message was gone while its
non-zero exit came from unrelated missing inputs. The fixtures now carry the
bounded default, and the mainnet test runs a complete production environment
and asserts a clean exit for 3, 0.5, and an explicit 0.
@kiwidream
kiwidream force-pushed the RobertClarke/stale-check branch from 94f27b5 to 400a6f5 Compare September 4, 2026 16:18
@kiwidream
kiwidream merged commit c3ca8bb into 2.x.x Sep 4, 2026
11 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/stale-check branch November 3, 2026 20:47
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