Skip to content

MC-2 follow-ups: refuse reference cycles and duplicate keys, no name guess for described tables, guide() description, v10 golden (#631) - #632

Merged
guijacquemet merged 3 commits into
mainfrom
claude/mc631-followups
Nov 12, 2026
Merged

guijacquemet merged 3 commits into
mainfrom
claude/mc631-followups

Conversation

@guijacquemet

@guijacquemet guijacquemet commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #631. These are the follow-ups to MC-2 (#630, merged 60cb7c4). The block's rules come from MorphoFeature's design note docs/restart/designs/coverage-experiment-block-2026-11-12.md (branch claude/restart-doc). Nothing is inferred from a folder name.

Owner questions (each with my recommendation first)

  1. Marker of the new scan finding (item 3). I used ✅: "Controls: the tables carry condition_id (a described run), so no control is guessed from the condition names; …". Recommend keeping ✅. Nothing is wrong with the data, and scan.setup() still refuses until a control is declared. The alternative is ⚠️, as MC-2's "No control is defaulted" finding uses. ⚠️ would turn the scan title of every described table scanned without its coverage.json from ✅ to ⚠️.
  2. Other name-based proposals for described tables. Two kinds remain. The scan's reagent_groups (names like siX#1/siX#2). The guided "several controls" path: members by name stem, a parent when a name extends another (VEC_SiNC under VEC), and treatment keys. This PR suppresses only the control guess: the scan's control_guess, and the guided session's proposed_controls, which is the same guess. Recommend suppressing the rest too whenever the tables carry condition_id, in a follow-up. Design note §4.2 already forbids reagent groups from names once a run is described.
  3. The "Several conditions are compared (N): add a 'target' column" suggestion now appears on described tables scanned without a description, because no control is known. Recommend that for condition_id tables it point to the description's target suggestions rather than a target column.
  4. Saved answers gain "targets": null in every guided session. Older files still load because the field defaults to None. Recommend no ANSWERS_VERSION bump.

What changes

  1. Reference cycles (A→B→A, and longer) are refused as experiment_block_malformed, and the message names the cycle (experiment.references form a cycle (VEC -> VEC_SiCol6a1 -> VEC_SiNC -> VEC)). Chains that end at a root, as in v10, are accepted. Code: _described_shape._refuse_cycles.
  2. Duplicate JSON keys. read_coverage now parses with an object_pairs_hook. A key named twice in one object, anywhere in coverage.json, is refused as experiment_block_malformed and never read last-wins.
  3. No name-based control guess when the tables carry condition_id. This holds with or without coverage.json. The column is read where named_by_id reads it: the FOV table, or the observation table when there is no FOV table.
    • The scan adds the finding above, ending "…or must be declared by their ID (control={'condition': ...})".
    • The control question has no suggestion.
    • scan.setup() without a control says "declare the control by its condition_id, or give the scan the experiment description".
    • The guided session proposes no control by name either (proposed_controls).
    • With a description, the description's control is listed first. On main it was first only when it happened to be the name guess.
  4. guide(description=...).
    • When the description gives a default control, the control questions are skipped. The session prints "The controls come from the experiment description (description …), so they are not asked", followed by the tests (chains as chains).
    • The positive-control question still runs, among the conditions that are not a control.
    • The target suggestions are shown as written. The user is asked "Group the reagents of one target with them?" with three options: use them as suggested / edit them / leave them unconfirmed (not used), the default. Enter never confirms.
    • Confirmed targets go into the answers (Answers.targets) and from there into Setup(targets=...).
    • Answers saved with a description are not reused without it ("what differs: the experiment description").
    • For an export without the block (experiment_block_missing), the session asks for a control until one is declared, instead of crashing later in Setup.
    • The new code is in the private module workflows/_guided_described.py.
  5. Golden v10 (tests/morphofeature_exports/v10, a reference chain) was made with make_exports.py.
    • Environment: MorphoFeature main d33c6284e4a860eff08cbdfcc098c8069e963234 (recorded in provenance.json), preprocessing 0.5.1, CellPatcher 0.4.0, normalization 0.4.0, numpy 2.5.4, pandas 3.1.1, Python 3.13.18.
    • Re-running the script re-made v03/v27/v30/v33 byte-identical.
    • Two runs of v10 are byte-identical.
    • NAMES now includes v10.

Bug found on the way: described_setup(experiment, **fields) clashed with Setup's own experiment field (the correction families). As a result, scan.setup(..., experiment=...) on a described scan raised TypeError, and every guided Answers.setup does exactly that. The first parameter is now positional-only. Regression test: test_a_described_scan_takes_the_setups_own_experiment_field.

Regression tests (tests/test_described_followups.py)

I ran the new file against main's src, with the v10 folder copied in: 19 failed, 6 passed.

Item Tests that fail on main
1 test_references_that_form_a_cycle_are_refused ×3 (2-cycle, 3-cycle, a second chain's 2-cycle)
2 test_a_key_named_twice_is_refused ×3 (in references, in experiment, top-level schema_version)
3 test_without_the_coverage_json_no_control_is_guessed_by_name ×3, test_condition_id_in_the_observation_table_alone_is_a_described_table, test_the_scan_lists_the_descriptions_control_first
4 the seven test_guide_* tests. On main guide has no description parameter.
5 Without the folder (main), test_every_fixture_has_an_export and test_the_v10_golden_is_the_chain_of_its_description fail
bug test_a_described_scan_takes_the_setups_own_experiment_field

These 6 pass on main and stay as guards: chain accepted, goldens have no duplicate keys, declared control gets no finding, blockless + description, v10 golden (folder copied in), and one more.

I updated three existing assertions that encoded the old behaviour:

  • test_described.py: the blockless scan's guess is now None.
  • test_morphofeature_exports.py v33: the conditions are ["DrugA", "ctrl"] with no guess, and the image table's ctrl row comes second.
  • The default-control test now runs on the four single-control fixtures, since v10 is a chain.

Before/after on v03/v27/v30/v33 (main 60cb7c4 vs this branch)

Byte-identical for all four fixtures:

  • read_coverage repr;
  • DescribedExperiment.summary();
  • scan_design(..., description=...).summary();
  • the full report text of described_setup;
  • the Setup repr from the described scan.

Changed, by design (item 3): scan_design(objects, fovs) without a description, on tables that carry condition_id. Exactly, for v33:

-  Conditions: ctrl (named like a control; not declared) and DrugA.
+  Conditions: DrugA and ctrl.
   (layout table: the ctrl row moves below DrugA)
+  ✅ Controls: the tables carry condition_id (a described run), so no control is guessed from the
+     condition names; the controls come from the experiment description (scan_design(...,
+     description=read_experiment(coverage_json, fovs))) or must be declared by their ID
+     (control={'condition': ...}).
+  - Several conditions are compared (2): add a 'target' column naming what each acts on, if some
+    should have the same effect; the report then says whether they agree.
-  3. Which condition is the negative control? Suggested: ctrl. Options: ctrl and DrugA.
+  3. Which condition is the negative control? Options: DrugA and ctrl.

The other three fixtures change the same way:

  • v03/v30: CTRL (named like a control; not declared) becomes CTRL. v03 also says rep1 and rep2: CTRL where it said the control only, because the repeat lines no longer know a control.
  • v27: the target suggestion's count changes from "3 besides the control" to "4".
  • All three: the same ✅ finding, and no "Suggested: CTRL".

These changes are intended. Without the description, the only way to call CTRL/ctrl a control was to read it as a name. #631 item 3 and design note §3.4/§4.2 forbid that once a run is described. The target suggestion is owner question 3.

Guided session without a description (item 3 again): all four still guess no control. The control default becomes "no control", so the positive-control question is not offered, and the tests line reads "No control is declared…". In v03, the gate no longer proposes "several controls" from CTRL's name. The saved answers gain "targets": null (owner question 4).

Guided session with a description (new): no control question. The tests come from the description. For v27, the suggestions SRC: DrugA and DrugC / src: DrugB are asked with "leave them unconfirmed" as the default.

Gate (on 7eb5caf, Python 3.13.18; venv inside the work folder)

  • pytest -n 0 tests/test_guards.py tests/test_function_guards.py tests/test_function_tools.py: 102 passed, 1 warning.
  • python tools/audit.py --check-against origin/main: baselines only tightened against origin/main.
  • python -m ruff check src tests data: All checks passed. python -m ruff format --check src tests data: 534 files already formatted.
  • Whole suite, pytest -n 3 -rs: 4647 passed, 2 skipped, 6 xfailed (16 min 56 s). Both skips are tests/test_morphobricks_constants.py:21: "morphobricks-preprocessing is not installed (MorphoCoverage does not depend on it, D-g)".
  • CI on 7eb5caf: check success, spec-pin success.
  • I did not run the reference check (data/reference). No committed dataset carries condition_id (grep of data/), so item 3 cannot change any of their outputs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc

…guess for described tables, guide() description, v10 golden (#631)

- The experiment block's references must not form a cycle (A -> B -> A, or longer):
  refused as experiment_block_malformed, naming the cycle.
- read_coverage parses coverage.json with an object_pairs_hook: a key named twice in one
  JSON object is refused as experiment_block_malformed, never read last-wins.
- Tables that carry condition_id get no control guessed from the names, with or without
  their coverage.json; the scan says the controls come from the description or are
  declared by ID, and the guided session proposes no control by name either. With a
  description, its control is listed first (it was first only when it was also the name
  guess).
- guide(description=...): the control questions are skipped when the description gives
  the controls; its target suggestions are shown and the user confirms, edits or leaves
  them (Enter leaves them). An export without the block is asked until a control is
  declared. The confirmed targets are saved with the answers; answers saved with a
  description are not reused without it.
- described_setup takes its description positionally only, so Setup's own experiment
  field (the correction families) reaches the Setup (it raised a TypeError from a
  described scan).
- Golden export of Spec fixture v10 (a reference chain), from MorphoFeature main d33c628
  with preprocessing 0.5.1, CellPatcher 0.4.0, normalization 0.4.0; the other four
  re-made byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
The control order moves to _conditions and the described-table lookup to _described;
behaviour unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G3qp9AxjpGPw9xfWAUJNqc
)

- Owner question 3 (2026-11-12): for tables that carry condition_id, the scan's
  "Several conditions are compared" suggestion points to the experiment
  description's target suggestions (or a grouping declared by condition ID),
  not to a 'target' column. Undescribed tables keep the 'target' column hint.
- _refuse_cycles walks each condition once (conditions already known to reach
  a root are not walked again), so a deep chain no longer costs O(n^3): a
  3000-condition chain took ~35 s, now well under 1 s, with the same
  acceptance and the same cycle messages.
- Regression tests: test_a_described_table_is_pointed_to_the_descriptions_targets,
  test_a_deep_chain_is_read_and_a_long_cycle_named (also a chain running into
  a cycle names only the cycle).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WX6rdMV1r5jUPUR94kxV5a

Copy link
Copy Markdown
Contributor Author

Independent review: approve, with one fix commit (6381376)

Owner answers (2026-11-12): all four recommendations accepted.

What I checked

  • Refusals happen at parse time, before any analysis. I checked each case below; every one is refused as experiment_block_malformed with an actionable message:

    • self-reference;
    • a missing reference;
    • a reference that differs from a condition ID only by case or whitespace;
    • a reference that is an int or a list;
    • a missing references entry;
    • 2-, 3-, 50-, 400- and 1500-long cycles;
    • a duplicate key, given verbatim or through a \u escape.
  • Case variants. A key that differs only by case or whitespace is a distinct JSON key, so it is not refused as a duplicate. It is refused instead as "not a key of experiment.conditions" wherever it is used as a reference. Two condition IDs that differ only by case (VEC and vec) are accepted. This follows the design note: "no trimming, no case change", and v27 keeps SRC and src apart on purpose.

  • No name guess with condition_id. The only two name-based control guessers are _scan_names.control_guess and _guided_controls._CONTROL_PART. Both are now gated on by_id, and that covers:

    • the scan;
    • ask_gate;
    • ask_control;
    • proposed_controls.

    live.py and retrospective contain no other guess. The notebook declares its control explicitly, and its guide() goes through the gated scan. Two name-based proposals remain: stems, parents and keys in the several-controls path, and reagent_groups. Both are tracked in Described tables (condition_id): stop the remaining name-based proposals (scan reagent_groups, guided several-controls stems, parents and treatment keys) #633.

  • Positional-only described_setup. No caller passes experiment= by keyword: I checked this repo, its notebooks and docs, and MorphoFeature.

  • Golden v10. I regenerated all five goldens independently with make_exports.py, in a fresh venv at MorphoFeature d33c628 with preprocessing 0.5.1, CellPatcher 0.4.0, normalization 0.4.0, numpy 2.5.4, pandas 3.1.1 and Python 3.13.18. v03, v10, v27, v30 and v33 all came out byte-identical to the committed files, provenance.json included. The older goldens are not touched by the diff.

Fix commit 6381376

  1. Q3. On tables that carry condition_id, the scan's "Several conditions are compared" suggestion now points to the description's target suggestions, or to Setup(targets={condition_id: target}), and no longer to a 'target' column. Two cases:

    • a description that suggests no target says so;
    • undescribed tables are unchanged.

    Regression test: test_a_described_table_is_pointed_to_the_descriptions_targets. It fails on 7eb5caf.

  2. _refuse_cycles walks each condition once. Before, it re-walked every chain from every condition, which is O(n³). A 3000-condition chain took about 35 s in the test, against about 0.5 s now. Acceptance and the cycle messages are unchanged. Regression test: test_a_deep_chain_is_read_and_a_long_cycle_named. It also checks that a chain running into a cycle names only the cycle.

  3. docs/common/data_format.md is updated, and function_index.jsonl is regenerated.

Gate on 6381376

  • Local, fresh venv, Python 3.13.18: 4649 passed, 2 skipped, 6 xfailed. Both skips are test_morphobricks_constants.py:21: preprocessing is not installed.
  • The ruff check and format check are clean.
  • tools/audit.py --check-against origin/main: baselines only tightened.
  • CI check and spec-pin both pass. Note that CI check runs only the guard tests and the audit, not the whole suite.

Minor note, not blocking. Take a description that has a block but no references, where the user answers "no control". The saved answers then read "Control: the experiment description's references". That is true, since there are none, but it reads less plainly than "none".

🤖 Generated with Claude Code


Generated by Claude Code

@guijacquemet
guijacquemet merged commit 5cdccf6 into main Nov 12, 2026
2 checks passed
@guijacquemet
guijacquemet deleted the claude/mc631-followups branch November 12, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants