Question about `inspect_message` and `in_replicated_execution` behavior

Hi everyone,

I’ve been exploring the behavior of the in_replicated_execution method in the rust cdk and noticed something unexpected regarding its execution mode. Based on the IC interface spec, I was under the impression that inspect_message only runs on a single node and is not executed in replicated mode.

However, when I tested the ic_cdk::api::in_replicated_execution function within an inspect_message method, it appears to indicate that inspect_message is running in replicated execution mode. Here’s the code I used for testing:

#[ic_cdk::inspect_message]
fn inspect_message() {
    let in_replicated_execution = ic_cdk::api::in_replicated_execution();
    ic_cdk::println!(
        "Inspect message is in replicated execution: {}",
        in_replicated_execution
    );
    ic_cdk::api::call::accept_message();
}

#[ic_cdk::update]
fn update() {
    let in_replicated_execution = ic_cdk::api::in_replicated_execution();
    ic_cdk::println!(
        "Update is in replicated execution: {}",
        in_replicated_execution
    );
}

When I call dfx canister call backend update, the following logs are produced:

2025-01-17 22:10:07.393336193 UTC: [Canister a4tbr-q4aaa-aaaaa-qaafq-cai] Inspect message is in replicated execution: true
2025-01-17 22:10:07.634569429 UTC: [Canister a4tbr-q4aaa-aaaaa-qaafq-cai] Update is in replicated execution: true

This suggests that both the inspect_message and update methods are considered to be in replicated execution.

Am I misunderstanding something about how inspect_message is supposed to work? My expectation was that in_replicated_execution would return false for inspect_message, given that the spec mentions it is not executed in replicated mode.

Any clarification on this behavior would be greatly appreciated!

Thanks in advance! :blush:

2 Likes

If a canister exposes a query method called inspect_message then that method is used by the replica that proposes a block to determine if a message should be included in the block or not. It is this aspect that is outlined in the interface spec.

Query methods can also be executed in a replicated manner, e.g. when called via an ingress message or cross canister call.

I’m not sure I understand.

Looking at these points in the ic spec it seems that inspect message would never be run in replicated mode


1 Like

This is a bug, thanks for reporting. The system api incorrectly returns 1 in this case (although the message does run in non-replicated mode, i.e. on a single node only). We’ll fix it promptly.

4 Likes

Also can you explain this behavior? I am under the impression that canister_inspect_message is the Wasm export required to do ingress message inspection, and that it can only occur in non-replicated mode and is executed by a single node.

So what are you referring to here with exposing a query method called inspect_message? Are you saying the Wasm export would be canister_query inspect_message? I have never heard of this outside of this issue, where is this documented?

I can confirm that this is fixed in dfx 0.25.0, our tests in Azle are now passing correctly.

1 Like