chore(engine): rename correction-step counter for clarity#627
Conversation
The local counter `curr_num_correction_steps` in `ModelFacade.generate` and `agenerate` was incremented before each parse attempt, so it actually counted parse attempts (initial + corrections), not corrections taken. The name suggested the latter, which made the surrounding `<= max_correction_steps` check read like a possible off-by-one even though the math worked out. Rename it to `parse_attempts` and add a short comment describing the semantics. Pure refactor: no behavior change. Closes #371
Greptile SummaryPure rename of a local counter from
|
| Filename | Overview |
|---|---|
| packages/data-designer-engine/src/data_designer/engine/models/facade.py | Local variable rename from curr_num_correction_steps to parse_attempts across all six usage sites in both generate and agenerate; no logic changes. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[LLM response received] --> B[parse_attempts += 1]
B --> C{parser succeeds?}
C -- yes --> D[return output]
C -- no --> E{max_correction_steps == 0\nAND max_conversation_restarts == 0?}
E -- yes --> F[raise immediately]
E -- no --> G{parse_attempts <= max_correction_steps?}
G -- yes --> H[append error as user message\nloop back to LLM]
G -- no --> I{curr_num_restarts < max_conversation_restarts?}
I -- yes --> J[parse_attempts = 0\ncurr_num_restarts += 1\nrestore restart checkpoint]
I -- no --> K[raise GenerationValidationError]
H --> A
J --> A
Reviews (2): Last reviewed commit: "Merge branch 'main' into fix/371-rename-..." | Re-trigger Greptile
PR #627 Review — chore(engine): rename correction-step counter for claritySummaryPure local-variable rename in FindingsCorrectness
Code quality & conventions
Risk / blast radius
Tests
Nits (optional, non-blocking)
VerdictApprove — merge as-is. Small, well-motivated, correctly-scoped cleanup. The rename closes the readability gap flagged in #371 without changing behavior, and the author chose the safer of the two possible fixes (rename vs. restructure) with clear reasoning. No issues found. |
Summary
Closes #371.
The local counter
curr_num_correction_stepsinModelFacade.generateandModelFacade.ageneratewas incremented before each parse attempt, so it actually counted parse attempts (initial + corrections), not corrections taken. The name suggested the latter, which made the surrounding<= max_correction_stepscheck read like a possible off-by-one even though the math worked out (withmax_correction_steps=1you get 1 initial + 1 correction = 2 attempts, which is the intended behavior).This PR:
curr_num_correction_steps→parse_attemptsin both the sync (generate) and async (agenerate) code paths.generatedescribing the semantics, and a back-reference comment inagenerate.max_correction_steps,max_conversation_restarts) and behavior unchanged. The error message text ("…despite N correction steps…") is also unchanged.I went with the rename rather than moving the increment into the
exceptblock, because moving the increment would change behavior whenmax_correction_steps == 0(no early-raise short-circuit reached) and would interact subtly with the restart-reset path. The rename captures the actual semantics without touching control flow.Test plan
make lint/ruff checkclean onfacade.pypytest packages/data-designer-engine/tests/engine/models/test_facade.py— 68 passedpytest packages/data-designer-engine/tests— 1975 passedtest_facade.py(e.g.total_callsfor(max_correction_steps, max_conversation_restarts)combinations) — still pass, confirming behavior is unchanged.