Skip to content

feat(planning): granular step-level execution planning for Stage.META - #692

Merged
kstonekuan merged 3 commits into
Hebbian-Robotics:mainfrom
shobhitagnihotri69:feat/granular-step-planning-meta
Oct 6, 2026
Merged

kstonekuan merged 3 commits into
Hebbian-Robotics:mainfrom
shobhitagnihotri69:feat/granular-step-planning-meta

Conversation

@shobhitagnihotri69

@shobhitagnihotri69 shobhitagnihotri69 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor
  • Route outstanding checks per episode directly to SelectedRegisteredSteps
  • Treat episodes quarantined by settled critical checks as owing nothing in Stage.META
  • Group episodes by owed steps in batch and direct stage execution
  • Add tests for check addition, critical retuning, and batch grouping

Resolves #690

Summary

When new checks are registered or check versions/parameters are retuned, planning for Stage.META previously operated at a binary stage level: any unsettled check caused Stage.META to execute every check on every episode. Additionally, checks skipped downstream of a critical check quarantine never become settled in catalog history, which caused quarantined episodes to be continuously re-planned for Stage.META.

Per maintainer guidance in #690:

  • Route each episode's OutstandingStages.outstanding_steps into the existing step-selection machinery (SelectedRegisteredSteps), with no second filter inside _process_steps.
  • Episodes whose quarantine was produced by a settled critical check owe nothing more in Stage.META unless that critical check itself changes identity (retuning).
  • Airflow sub-DAGs and direct execution keep the same granularity: group episodes by the step subset they owe into batches (step_names_by_uri), carrying step_names into process_stage_batch.

Changes

  • src/hflow/stage_planning.py:
    • In plan_outstanding_stages, inspect episodes_latest for quarantine status (quarantined, quarantine_tags_json) and critical check identities.
    • If quarantined by a settled critical gate, mark the episode as owing nothing in Stage.META.
    • Record outstanding checks per episode in outstanding_steps.
    • In outstanding_stage_uris, support _stage_steps_by_uri to track steps owed per URI for the requested stage.
  • src/hflow/stage_execution.py:
    • In PlannedStageBatch, add step_names: NotRequired[list[str] | None].
    • In plan_stage_batches, accept step_names_by_uri to partition URIs by identical required step subsets before batching.
    • In run_stages_directly, partition URIs by owed step names and pass _registered_step_selection=SelectedRegisteredSteps(frozenset(steps)).
  • src/hflow/runtime/_templates.py:
    • In OUTSTANDING_PLAN_FILTER_TEMPLATE, collect stage_steps_by_uri and supply it to plan_stage_batches.
    • In process_batch, pass batch.get("step_names") to process_stage_batch(..., step_names=stage_step_names).
  • Tests:
    • tests/test_stage_planning.py: Added TestGranularStepPlanningForMeta testing that adding a check only reruns that check on already-settled episodes and skips quarantined episodes, and that retuning a critical check re-evaluates the quarantined episode.
    • tests/test_stage_execution.py: Added test_batch_lane_groups_by_step_names to verify batch planning partitions items by owed step subsets.

Verification

  • uv run ruff check & uv run ruff format --check passed cleanly (323 files formatted).
  • Targeted test suites (test_runtime_deploy.py, test_stage_execution.py, test_stage_planning.py) passed.
  • Full test suite passed: 2,477 passed, 49 skipped.

- Route outstanding checks per episode directly to SelectedRegisteredSteps
- Treat episodes quarantined by settled critical checks as owing nothing in Stage.META
- Group episodes by owed steps in batch and direct stage execution
- Add tests for check addition, critical retuning, and batch grouping

Closes Hebbian-Robotics#690
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds step-level batch grouping to stage execution planning.

The PR is not ready to merge: quarantined episodes can still miss diagnostic checks.

Findings

  1. P1 Quarantine blocks diagnostic checks ▶
  2. P2 Step groups multiply batches ▶
Summary

Stage.META now plans work per check, so adding or retuning a check does not rerun checks already settled. Direct runs and Airflow batches carry each episode’s owed checks into execution.

  • Stage.META runs only checks each episode still owes.
  • Stage runners group episodes by the checks each one owes.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Catalog outcomes] --> B[Outstanding steps per episode]
  B --> C[Group episodes by owed steps]
  C --> D[Direct stage run]
  C --> E[Scheduled batches]
Loading

Reviews (3) · Last reviewed commit: "refactor(planning): address review feedb..."

if missing:
outstanding_stages.add(stage)
outstanding_steps.extend(missing)
if not quarantined_by_settled_gate:

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.

P1 Quarantine blocks diagnostic checks

When a settled critical check has quarantined an episode, this gate removes every check that still owes work. That includes default diagnostic checks, which the runner allows to run after quarantine. A default check that failed or was added later never records its evidence. Keep those checks in the plan.

Knowledge Base Used: Stage planning and execution

Comment thread src/hflow/stage_execution.py Outdated
Comment on lines +255 to +265
for steps, group_uris in uris_by_steps.items():
group_item_sizes = {u: item_sizes[u] for u in group_uris}
group_batch_count = (
int(batch_count)
if batch_count is not None
else min(DEFAULT_BATCH_COUNT_LIMIT, len(group_item_sizes))
)
planned = plan_batches(
group_item_sizes,
batch_count=group_batch_count,
stagger_interval_s=DEFAULT_STAGGER_INTERVAL_S,

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.

P2 Step groups multiply batches

batch_count now applies to each owed-step group rather than the whole stage. With batch_count=1, three step groups create three worker tasks; the default limit of four can also be exceeded. This adds workers and stagger delay beyond what the caller requested. Divide the stage-wide batch allowance among the groups.

Knowledge Base Used: Stage planning and execution

@kstonekuan kstonekuan 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.

Thanks, the approach matches the spec and the quarantine rule is right. Three structural changes before I merge:

  • Template: step_names_by_uri=locals().get("stage_steps_by_uri") depends on whether the filter snippet was spliced in. Set stage_steps_by_uri = None at the top of plan() and pass it directly.
  • plan_stage_batches: the new branch copies the file-size lookup and bin-packing block. Size the URIs once in the existing path, then bin-pack each step group with the same code, so there is one sizing path and one stagger rule.
  • One owner for the per-stage step filter: run_stages_directly and outstanding_stage_uris both derive "outstanding steps for this stage" from plan.outstanding_steps and _registered_step_stages(). Put that in one helper in stage_planning.py and call it from both.

…ching

- Set stage_steps_by_uri = None at top of plan() template and pass directly
- Unify sizing and bin-packing in plan_stage_batches into single path and stagger rule
- Extract outstanding_steps_for_stage helper in stage_planning.py called by both planning and execution
@shobhitagnihotri69

Copy link
Copy Markdown
Contributor Author

Thanks for the review @kstonekuan,Addressed all three structural points:

  1. Template: Set stage_steps_by_uri = None at the top of plan() and passed it directly to plan_stage_batches.
  2. plan_stage_batches: Unified the URI sizing and bin-packing path so all URIs are sized once up front, and both single and multi-group cases share the exact same bin-packing logic and stagger rules.
  3. Single owner for per-stage step filtering: Extracted outstanding_steps_for_stage(plan, stage, stage_by_step_name) in src/hflow/stage_planning.py and called it from both outstanding_stage_uris and run_stages_directly.

@kstonekuan kstonekuan 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.

LGTM, thanks for the quick rework. Full suite passes merged onto main. Merging.

@kstonekuan
kstonekuan merged commit 1303bcc into Hebbian-Robotics:main Oct 6, 2026
3 checks passed
@shobhitagnihotri69

Copy link
Copy Markdown
Contributor Author

Thank you very much @kstonekuan for review and merging this pr , now I can solve one more bug

@kstonekuan kstonekuan mentioned this pull request Oct 8, 2026
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.

[Feature]: Granular step-level execution planning for Stage.META to skip already-settled checks

2 participants