Skip to content

doctor validate reports recipes in non-deterministic order #427

Closed

Description

@dubadub

cook doctor validate reports recipes in a different order on each run, so identical input produces non-identical output.

Cause

run_validate walks cooklang_find's RecipeTree, whose children are stored in a HashMap:

// cooklang-find-0.6.1/src/tree/model.rs:30
pub children: HashMap<String, RecipeTree>,

Rust's default HashMap hasher is seeded randomly per process, so iteration order differs between invocations. The walk emits each recipe's 📄 {path} header in whatever order it encounters them.

Impact

  • Output cannot be diffed between runs, so it is hard to tell whether a change to a recipe collection improved or worsened anything.
  • Anything comparing doctor validate output in CI is inherently flaky.
  • Repeated runs while fixing recipes shuffle the list, which is disorienting when working through a large collection.

Only visible with more than one recipe carrying errors or warnings, which is likely why it has gone unnoticed.

Suggested direction

Sort by path before reporting. Directory listing order is not a meaningful contract, and a stable order makes the output diffable.

Noticed while extracting doctor validate into a library crate. The extraction sorts by path — a library returning results in random order is worse than a CLI doing so — so this is fixed on that branch as a side effect. Filing separately because it is a pre-existing defect on main and worth recording independently of whether that branch lands.

Activity

  1. added
    help wanted
    on Aug 13, 2026
  2. dubadub commented on Aug 14, 2026

    @dubadub
    MemberAuthor

    Fixed on main by the cookcli-core extraction (#434), rather than by a change filed against this issue — the extraction sorts by path, since a library returning results in random order is worse than a CLI doing so.

    // crates/core/src/doctor.rs
    recipes.sort_by(|a, b| a.path.cmp(&b.path));

    Verified on three recipes carrying errors — five consecutive runs, identical each time:

    📄 r1.cook 📄 r2.cook 📄 r3.cook
    📄 r1.cook 📄 r2.cook 📄 r3.cook
    📄 r1.cook 📄 r2.cook 📄 r3.cook
    📄 r1.cook 📄 r2.cook 📄 r3.cook
    📄 r1.cook 📄 r2.cook 📄 r3.cook
    

    The order is by code point rather than alphabetical, so a capitalised name sorts before every lowercase one; that is pinned by a test and noted in the docs. Confirmed while clearing the help wanted backlog in #444; no change was needed.

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

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions