Skip to content

Reset the rich progress bar between executions of the same driver - #1824

Open
dhananjay6561 wants to merge 2 commits into
apache:mainfrom
dhananjay6561:fix-rich-progress-bar-reuse
Open

dhananjay6561 wants to merge 2 commits into
apache:mainfrom
dhananjay6561:fix-rich-progress-bar-reuse

Conversation

@dhananjay6561

Copy link
Copy Markdown

h_rich.RichProgressBar only works for the first execution of a driver. The adapter lives on the driver, and every run_before_graph_execution adds another task to the same rich Progress while all the advancing still goes to task_ids[0]. So when you build a driver once and call execute a few times (the usual pattern), the first bar keeps counting past its total and every later run adds a bar that stays at 0%:

from hamilton import ad_hoc_utils, driver
from hamilton.plugins import h_rich

def a(x: int) -> int: return x
def b(a: int) -> int: return a

pb = h_rich.RichProgressBar()
dr = driver.Builder().with_modules(ad_hoc_utils.create_temporary_module(a, b)).with_adapters(pb).build()
for _ in range(3):
    dr.execute(["b"], inputs={"x": 1})
print([(t.completed, t.total) for t in pb._progress.tasks])
# main:  [(6, 2), (0, 2), (0, 2)]  and the terminal shows a stale 100% bar plus 0% bars
# fixed: [(2, 2)]

The same happens with dynamic execution: on the second run the "Running" bar goes to 8/4 and the new one stays empty.

Changes

  • run_before_graph_execution removes the previous run's tasks and resets _task_based before adding the new bar, so each execution starts from a clean progress bar.
  • Added tests/plugins/test_h_rich.py (there were no tests for this adapter yet): one for a single run reaching its total, one for a reused driver.

How I tested this

  • test_progress_bar_starts_fresh_on_each_execution fails on main (two tasks instead of one) and passes with the change.
  • pytest tests/plugins/test_h_rich.py tests/plugins/test_h_tqdm.py (5 passed).
  • Ran the snippet above, and a Parallelizable/Collect DAG executed twice with the setup from the class docstring: each run now shows only its own bars with correct counts.
  • ruff format --check and ruff check (0.16.9) on the touched files.

Notes

rich comes in through typer in the test group, but the test module uses pytest.importorskip("rich") so it skips cleanly if it isn't installed.

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 07:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@dhananjay6561

Copy link
Copy Markdown
Author

Hi @skrawcz @jernejfrank, a small one for the rich progress bar. Reusing a driver kept stacking empty bars and over-counting the first one, so this clears the previous run's bars at the start of each execution. Added the first tests for that adapter too. Thanks for taking a look!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants