chore(engine): rename correction-step counter for clarity#627
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 SummaryRenames the local counter
|
| Filename | Overview |
|---|---|
| packages/data-designer-engine/src/data_designer/engine/models/facade.py | Pure rename of local variable curr_num_correction_steps → parse_attempts in both generate and agenerate; no logic changes, no remaining references to the old name. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Start: parse_attempts=0, curr_num_restarts=0] --> B[Call LLM completion]
B --> C{Tool calls?}
C -- Yes --> D[Process tool calls\nupdate checkpoint] --> B
C -- No --> E[Append assistant message\nparse_attempts += 1]
E --> F{parser succeeds?}
F -- Yes --> G[Return output_obj]
F -- No: ParserException --> H{max_correction_steps == 0\nAND max_conversation_restarts == 0?}
H -- Yes --> I[Raise immediately]
H -- No --> J{parse_attempts <= max_correction_steps?}
J -- Yes --> K[Append user error message\nfor correction] --> B
J -- No --> L{curr_num_restarts < max_conversation_restarts?}
L -- Yes --> M[parse_attempts = 0\ncurr_num_restarts += 1\nRestore checkpoint] --> B
L -- No --> N[Raise GenerationValidationFailureError]
Reviews (1): Last reviewed commit: "chore(engine): rename correction-step co..." | 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.