← Back to Pull requests

fix(step): keep diagnostics from every started job when another job fails #1642

Closed
unknown closed this pull request without merging on Oct 04, 2026 01:33 UTC
View on GitHub
unknown unknown commented on Oct 03, 2026 23:59 UTC
Author

<!-- entire-trail-link-start -->
https://entire.io/gh/jdx/hk/trails/218
<!-- entire-trail-link-end -->

Problem

When a step fans out into several jobs (a workspace_indicator step, or a batched step) and one job's check fails, the step's other jobs were aborted wherever they happened to be. A job aborted after its command finished but before it recorded its output left no diagnostics, so --sarif, --format json and MCP results were incomplete after a failure, and which jobs were missing depended on timing.

This also hit --no-fail-fast, which should report everything. run_all_jobs returned on the first failing job regardless of that setting and dropped its JoinSet, aborting the sibling jobs.

Example: two workspaces, api fails at once, web takes 0.3s and then reports [W1], both with diagnostic_format = "gcc":

$ hk check --all --no-fail-fast --sarif out.sarif
$ jq '[.runs[0].results[].ruleId]' out.sarif
before: ["A1"]
after:  ["A1", "W1"]

Change

run_all_jobs now waits for every job task (join_jobs in src/step/execution.rs) instead of returning on the first error:

  • --no-fail-fast, or a failure allowed by allow_failure: siblings run to completion and record their diagnostics.

  • Fail-fast: on the first failure hk cancels the running commands at once (the same marking and cancellation the step group already did, now shared as abort_running_steps), then waits for the siblings to return. Commands are still killed immediately; a sibling whose command had already finished records its diagnostics before it exits. A 10s grace period aborts any job that still has not returned, so a stuck job cannot hang the run. Ctrl-C gets the same 10s bound (without being treated as a failure), and a job waiting on mise env stops when the run is cancelled. A user's Ctrl-C always ends the step as cancelled (exit 1, command was cancelled, as before this PR), even if no job had started a command yet: the cancel token decides, not the jobs' results. A step waiting on a dependency stops waiting when the run is cancelled, and a cancelled step always wakes its dependents, so nothing hangs.
  • The returned error is still the first one, except that a not-allowed error (for example a job that could not start) replaces an earlier allowed command failure and also triggers fail-fast cancellation, so it is no longer hidden. Under fail-fast the step group ignores cancellation errors from siblings once a failure has aborted them, so the original failure is always the one reported. Exit codes and output are otherwise unchanged apart from the recovered diagnostics. Errors from siblings that were cancelled are only logged at debug level.

    I chose this over per-job cancel hooks or recording in an abort path: a dropped task cannot run code, and awaiting the tasks reuses the existing cancellation token with a small change.

    Limits

  • Under fail-fast, a sibling whose command is still running when the first failure arrives is killed, and ensembler discards the output of a cancelled command, so its diagnostics are not recorded. Which jobs have already finished when the first failure lands is still a race: with two workspaces that fail immediately, 21 of 30 local runs had both diagnostics under --fail-fast (30 of 30 under --no-fail-fast). Follow-up: keep the partial output of a cancelled command (needs an ensembler change).

  • A different step that is mid-recording when fail-fast stops the group is still dropped by the step group's JoinSet. Draining it would hang steps waiting on a failed dependency, so it needs separate handling. Follow-up.
  • Validation

  • New bats tests in test/diagnostics.bats (each with HK_LIBGIT2=1 and 0): --no-fail-fast SARIF and JSON keep both jobs' diagnostics (fail on main, deterministic: A1 only), and fail-fast kills a 30s sibling in under 15s while keeping the failing job's diagnostics.

  • New unit tests for join_jobs (waits after a failure, cancel then drain, grace-period abort, all-success).

  • test/diagnostics.bats: 18/18 ok (plan 1..18). 16 other bats files touching fail-fast, depends, allow_failure, batching, junit and staging: all ok. 30 repeated runs of the new tests: 30/30.

  • cargo test step:: passes locally (165) and on the Windows CI box (150); cargo fmt --check and cargo clippy --all-targets -- -D warnings are clean.

  • Not run: the full bats suite and builtins_tests.bats.
  • 🤖 Generated with Claude Code

    AI-assisted — Tool: Claude Code; model: anthropic/claude-sonnet-5-5; version: unavailable.

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Changes core parallel job joining, fail-fast abort, and Ctrl-C handling in the step runner; behavior is heavily tested but affects when hooks exit, what error is reported, and diagnostic completeness.

    > Overview

    Fixes incomplete diagnostics when one parallel job fails by awaiting every job task instead of dropping the JoinSet on the first error, so siblings that already finished a check can still record SARIF/JSON output. With --no-fail-fast (or allow_failure), siblings run to completion; with fail-fast, running commands are cancelled immediately, siblings get a short grace window to return, then stuck tasks are aborted.

    > Tightens cancellation vs fail-fast semantics: is_cancellation, a fail_fast_aborted flag, settle_joined_jobs, and shared abort_running_steps keep user Ctrl-C distinct from a step-driven abort (correct exit/message, ignore sibling cancellation noise after fail-fast). Dependency waits and dependent wakeups respect cancel; mise env uses kill_on_drop and stops when the run is cancelled.

    > Tests: new unit coverage for join_jobs and settlement logic; bats for multi-job diagnostics, fail-fast timing/reporting, and Ctrl-C/mise/dependency cases.

    > <sup>Reviewed by Cursor Bugbot for commit fe8e02f1350989d69b967296cfe5c62ad63202fb. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

    Bug Fixes
    Fail-fast runs now stop sibling jobs after a failure while preserving diagnostics from the job that failed.
    Cancellation is handled more consistently: Ctrl-C stops running commands, dependency waits, and stalled environment resolution, while the original failure remains visible when one occurred first.
    Allowed failures continue to permit dependent steps when the run was not interrupted by Ctrl-C.
    * Diagnostic reports now retain results from jobs that finish when fail-fast is disabled.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 94m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1642"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%
    Repository