Skip to content

reviewer: bound preparation time and expose progress - #849

Open
jameshilliard wants to merge 5 commits into
sashiko-dev:mainfrom
jameshilliard:fix/review-preparation-timeouts
Open

jameshilliard wants to merge 5 commits into
sashiko-dev:mainfrom
jameshilliard:fix/review-preparation-timeouts

Conversation

@jameshilliard

@jameshilliard jameshilliard commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bound daemon review preparation and expose its progress so a stalled baseline lookup, fetch, checkout, or patch application cannot hold a review slot indefinitely without indicating what it is doing.

The existing AI review timeout starts after preparation. This adds a separate preparation budget without changing AI timeout/retry behavior, baseline ordering, or prerequisite precedence. It is a safeguard against unbounded preparation, not a claim to identify the cause of a particular production hang.

Changes

  • Add review.preparation_timeout_seconds (default: 1800) and review.preparation_max_retries (default: 3 additional attempts, matching the AI retry default). Retry timeouts with fresh worktrees and bounded backoff; do not retry ordinary application failures through this mechanism.
  • Retain worktree ownership across cancellation and give cleanup its own 120-second budget, pausing the preparation deadline during cleanup. Stop retries if cleanup fails or times out, and still attempt worktree unregistration when directory deletion fails.
  • Cancel Git hooks and transports along with daemon preparation commands, drain input/output concurrently, and handle child exit without leaving pipe-holding descendants behind. Preserve foreground process groups for interactive Git callers.
  • Let shared remote configuration, reference, and timestamp writers finish with their locks held after cancellation. Cleanup waits only for the interrupted attempt's own writes. Own post-fetch HEAD initialization through timestamp publication so a retry cannot skip unfinished setup when reusing local refs. Preserve selective refspecs and the upstream policy of reusing existing local remote refs. On shutdown, signal these Git writers with SIGTERM so their lockfile-cleanup handlers can run. Treat baseline database errors as preparation failures rather than failed patch application.
  • Query the symbolic remote HEAD before requesting branch advertisements. Bound query duration, stdout/stderr capture, and parsed record counts; preserve ref names as bytes so non-UTF-8 names do not discard or corrupt a valid HEAD. Keep network discovery outside configuration locks.
  • Persist claim-fenced preparation stages, attempt counters, timestamps, backoff, and timeout history in the existing baseline logs. Publish the application stage once per baseline, not once per patch. Add a separate Review preparation panel above baseline details in the web UI, and keep polling through queued states, reruns, and late baseline/status publication without rebuilding an unchanged view.
  • Generate new public preparation diagnostics only from fixed labels and numeric metadata, without exposing subprocess output or local paths. Preserve existing baseline log entries and require no database migration or new API endpoint.
  • Keep the design document in a separate commit and document the configuration in the root settings, operator guide, and a focused example. Keep the existing CI setup; no UI test suite or Node.js action is added.

Exhausted preparation timeouts and cleanup failures finish as Failed with a specific preparation reason. An ordinary unsuccessful baseline search retains Failed To Apply. Cancellation or a replacement claim prevents further attempts and stale progress/status updates.

Validation

  • make check-pr RANGE=origin/main..HEAD: formatting, Clippy across all three feature profiles, sign-offs, and 1,843 passing Rust tests (2 ignored).
  • Verified the Git process and worktree-cleanup commits independently with make check-pr in a throwaway clone.
  • Repeated the Git process tests 10 times and the preparation tests 5 times.
  • Synthetic regression coverage includes successful fresh-worktree retries, retry exhaustion, zero retries, ordinary application failure, killed descendants, pipe deadlocks and early stdin closure, scoped process groups, output limits, shared-writer cancellation and shutdown lockfile cleanup, cancellation during remote URL/refspec reconfiguration and post-fetch HEAD initialization, custom remote HEAD discovery and non-UTF-8 refs, cleanup deadlines/errors, cancellation and supersession, baseline persistence failure, fixed public diagnostics, configuration validation, and one progress update per multi-patch application.
  • Manually checked UI polling through queued states, stale readiness on reruns, readiness before metadata publication, unchanged metadata, and terminal status. No UI test files are committed.

No production patch samples or diagnostic artifacts are included in the commits.

@sashiko-bot

sashiko-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

Sashiko review

Commit 5/5 — 0eb2ba80 reviewer: add bounded preparation attempts

  • [MEDIUM] src/reviewer.rs: Reviewer::prepare_baseline_attempts() calls
    preparation.stage(PreparationStage::ApplyingPatches) inside the per-patch
    loop on every patch instead of once before the loop. Because
    Preparation::stage() in src/reviewer/preparation.rs unconditionally resets
    stage_started_at and writes baseline_logs to SQLite, an N-patch series runs
    N redundant database writes per baseline candidate and resets the Stage
    started and Stage elapsed fields in renderPreparationProgress() after every
    patch. Move the stage transition out of the loop, or make
    Preparation::stage() a no-op when the stage has not changed.

Full review and stage logs on sashiko.sashiko.dev

@jameshilliard
jameshilliard force-pushed the fix/review-preparation-timeouts branch from 0eb2ba8 to 5d8e5eb Compare November 9, 2026 05:35
@jameshilliard

Copy link
Copy Markdown
Contributor Author

Moved the ApplyingPatches transition before the patch loop in 5d8e5ebc. It now runs once per baseline candidate, only when target patches will actually be applied, so the stage start time remains stable and the loop no longer writes redundant progress updates.

Added a Rust regression test that applies a two-patch series, records baseline-log writes through a SQLite trigger, and verifies exactly one running applying_patches update. make check-pr RANGE=origin/main..HEAD passes with 1,749 Rust tests passing and 2 ignored.

The existing commits were amended. The UI test suite and its Node.js CI step were also removed; the web UI functionality is retained.

@sashiko-bot

sashiko-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

Sashiko review — v2

✓ No issues found across 5 commits.

Full review log on sashiko.sashiko.dev

Define a separate preparation deadline and retry budget, retained
worktree ownership for cancellation, and structured public progress.
Keep AI execution and ordinary baseline selection behavior unchanged.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Separate allocation from registration and checkout so a caller can keep
the worktree outside a cancellable operation and explicitly remove it.
Keep the existing constructor responsible for cleanup on errors.

Test cancellation while waiting for the worktree lock, cleanup after an
invalid revision, and successful population of a fresh checkout.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Reuse the CLI process-group guard for scoped daemon preparation
commands. Kill hooks and transports when their owning future is
cancelled. Keep interactive commands in the foreground group so
terminal credentials and Ctrl-C continue to work normally.

Drain stdout and stderr while feeding patches to git am to avoid a
full-pipe deadlock. Observe exit without reaping the leader, terminate
remaining descendants, then reap it without signalling a reusable PID.
Keep the existing CLI shutdown registry.

Test concurrent input and output, inherited and isolated process groups,
helpers waiting for parent exit, descendant cancellation, and registry
cleanup with synthetic commands.

Fixes: b03f297 ("Implement sandboxed git worktree and apply patch operations")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Return directory removal and blocking-task errors instead of logging
and discarding them. Still attempt metadata removal when directory
deletion fails, while preserving the original error. Metadata pruning
must not report successful cleanup while checkout files remain.

Keep managed ownership until metadata removal finishes, and separate
directory deletion so cleanup-lock tests can synchronize with it.
Cover managed worktrees and unregistered allocations with a filesystem
error reproducible without permission assumptions. Check registrations
as well as the returned error.

Fixes: 104fc7f ("git_ops, prompts: offload GitWorktree TempDir cleanup to blocking pool")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
Bound daemon baseline and prerequisite preparation before AI execution.
Default to a 30-minute deadline and three fresh-worktree retries,
matching the AI retry count while keeping its budget independent. Retry
only timeouts, and stop if bounded cleanup cannot finish safely.

Retain worktree ownership across cancellation and pause the attempt
deadline during separately bounded cleanup. Shield shared remote config,
ref, and timestamp writes with owned locks. Join only the attempt's own
writers before retrying. Use SIGTERM for shared writers on shutdown so
Git can clean its lockfiles. Query remote HEAD outside config locks,
bound its output, and tolerate unrelated non-UTF-8 refs. Retain
ownership through post-fetch HEAD initialization so retries can reuse
local refs without skipping unfinished setup. Treat baseline database
errors as preparation failures, not failed patch application.

Publish typed preparation stages, attempt counters, timing, and timeout
history through claim-fenced baseline logs. Show progress in the web UI
using fixed public labels without interpolating subprocess diagnostics.
Publish the application stage once per baseline rather than per patch,
preserving its start time without redundant database writes. Continue
polling while queued or in review, including through reruns and late
baseline metadata publication. Preserve legacy baseline entries and
ordinary application failures.

Cover successful retries, exhaustion, cleanup failure, cancellation,
supersession, persistence failure, settings, multi-patch progress, and
shared-writer ownership with synthetic fixtures and controlled timeouts.
Document the new configuration and keep the existing CI setup.

Fixes: db16ef0 ("refactor: move baseline/model/prompts to patchset level and log baseline detection")
Fixes: 04bd858 ("baseline: add branch patterns for selective remote refspec fetching")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
@jameshilliard
jameshilliard force-pushed the fix/review-preparation-timeouts branch from 5d8e5eb to ffa8b34 Compare November 9, 2026 19:16
@sashiko-bot

sashiko-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown

Sashiko review — v3

✓ No issues found across 5 commits.

Full review log on sashiko.sashiko.dev

@jameshilliard

Copy link
Copy Markdown
Contributor Author

This should fix stuck reviews like these, hard to tell for sure this was the cause without access to the sashiko server but this change will also show more precisely where the reviewer failed at a minimum even if it doesn't fully fix the underlying issue:
https://sashiko.dev/#/patchset/20261108-submit-intel-nand-probe-disable-v1-v1-1-eb0471429e09%40gmail.com
https://sashiko.dev/#/patchset/20261108-submit-tegra-nand-irq-teardown-v1-v1-1-2c570ad4a22c%40gmail.com
https://sashiko.dev/#/patchset/20261108-submit-qcom-nand-child-probe-errors-v1-v2-0-4a8704cbf7b4%40gmail.com

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.

1 participant