Skip to content

fix: debug_assert against recording IngressStatus::Unknown - #11015

Merged
mraszyk merged 2 commits into
masterfrom
mraszyk/forbid-unknown-ingress-status
Aug 5, 2026
Merged

mraszyk merged 2 commits into
masterfrom
mraszyk/forbid-unknown-ingress-status

Conversation

@mraszyk

@mraszyk mraszyk commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

IngressStatus::Unknown stands for the absence of an ingress history entry, so it must never be recorded as the status of a message. Hence, this PR adds a debug_assert for preventing IngressStatus::Unknown to be inserted into the ingress history.

Two test fixtures did record one:

  • test_traverse_ingress_history covered the canonical state encoding of Unknown, which is unreachable for the same reason. Drop the entry along with the corresponding expected traversal.

  • valid_transitions() listed Unknown both as an origin and as a target status. Represent the origin as an Option<IngressStatus>, where None stands for "no ingress history entry" (which is what Unknown means), and drop it from the targets. test_invalid_transitions (testing all but valid_transitions()) thus now covers Unknown as an invalid target from every origin, including from an empty ingress history.

Note. The IngressStatus::is_valid_state_transition() checks done by the callers of IngressHistoryState::insert() only catch this if an entry already exists, as any transition away from Unknown (i.e. from "no entry") is allowed. This PR doesn't tighten the validation as it could crash a subnet in production (unlike debug_assert).

`IngressStatus::Unknown` stands for the absence of an ingress history entry, so
it must never be recorded as the status of a message. The
`IngressStatus::is_valid_state_transition()` checks done by the callers of
`IngressHistoryState::insert()` only catch this if an entry already exists, as
any transition away from `Unknown` (i.e. from "no entry") is allowed. Assert it
at the bottom of the stack instead, where the entry is actually recorded.

Three test fixtures did record one:

* `test_traverse_ingress_history` covered the canonical state encoding of
  `Unknown`, which is unreachable for the same reason. Drop the entry along with
  the corresponding expected traversal.

* `valid_transitions()` listed `Unknown` both as an origin and as a target
  status. Represent the origin as an `Option<IngressStatus>`, where `None`
  stands for "no ingress history entry" (which is what `Unknown` means), and
  drop it from the targets. `test_invalid_transitions` thus still covers
  `Unknown` as an invalid target from every origin, including from an empty
  ingress history, which is exactly what the `debug_assert` catches.

* the `test_backward_compatibility` state fixture recorded five of them. Record
  the five ingress states that actually can be recorded instead, which also
  covers the `reply` and `Completed(Reject)` canonical encodings that the
  fixture was missing. The partial state hashes change accordingly: the fixture
  changed, the hashing did not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a defensive debug_assert! to prevent recording IngressStatus::Unknown (which semantically represents “no ingress history entry”), and updates test fixtures to stop encoding/expecting Unknown as a persisted status.

Changes:

  • Add debug_assert! in IngressHistoryState::insert() to catch attempts to record IngressStatus::Unknown.
  • Update multiple tests/fixtures to avoid persisting Unknown and to model “no entry” as None where appropriate.
  • Refresh backward-compatibility fixture ingress states and update expected partial state hashes accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rs/state_manager/src/tree_hash.rs Updates the backward-compatibility state fixture ingress statuses and expected partial state hashes.
rs/replicated_state/src/metadata_state/tests.rs Adds a regression test for inserting Unknown and removes Unknown from an existing fixture’s status list.
rs/replicated_state/src/metadata_state.rs Adds a debug_assert! preventing IngressStatus::Unknown from being recorded.
rs/execution_environment/tests/history.rs Reworks transition fixtures/tests to treat “no entry” as None and make Unknown invalid as a target.
rs/canonical_state/src/traversal.rs Removes an unreachable traversal fixture/expectation for encoding Unknown in canonical state traversal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rs/replicated_state/src/metadata_state/tests.rs
@mraszyk
mraszyk marked this pull request as ready for review August 4, 2026 08:40
@mraszyk
mraszyk requested a review from a team as a code owner August 4, 2026 08:40
@zeropath-ai

zeropath-ai Bot commented Aug 4, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to 2bcaef2.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► rs/canonical_state/src/traversal.rs
    Modify tests to remove direct ingress status with Unknown and adjust event sequence
► rs/execution_environment/tests/history.rs
    Update valid_transitions representation and test logic to use Option for origin state and adjust transition expectations
► rs/replicated_state/src/metadata_state.rs
    Add debug_assert to prevent recording IngressStatus::Unknown
► rs/replicated_state/src/metadata_state/tests.rs
    Add test asserting panic on inserting Unknown status into ingress history

Comment thread rs/state_manager/src/tree_hash.rs Outdated
@mraszyk
mraszyk added this pull request to the merge queue Aug 5, 2026
Merged via the queue into master with commit 1855fcd Aug 5, 2026
42 checks passed
@mraszyk
mraszyk deleted the mraszyk/forbid-unknown-ingress-status branch August 5, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants