Skip to content

Conversation

@newhook
Copy link
Owner

@newhook newhook commented Jan 31, 2026

Summary

Replaces polling-based CI status checking with gh run watch for immediate notification when workflow runs complete. This reduces CI feedback latency from the poll interval (default 10 minutes) to immediate notification.

Before: Poll every 10 minutes, check if runs complete, fetch results
After: Watch runs directly with gh run watch, fetch results exactly once when done

Changes

New Components

  • WatchWorkflowRun task type (internal/db/scheduler.go): New scheduled task type for watching workflow runs
  • handler_watch_run.go (internal/control/): Handler that:
    • Runs gh run watch <run-id> --exit-status which blocks until completion
    • Schedules immediate PRFeedback task when run completes
    • Handles context cancellation gracefully (for work destruction)
    • Uses idempotency key (watch_run_<id>) to prevent duplicate watchers

Modified Components

  • handler_pr_feedback.go: After fetching PR status, spawns watchers for any in-progress or queued workflow runs
  • plane.go: Registers the new WatchWorkflowRun handler

Documentation & Tooling

  • CLAUDE.md: Added note about beads version alignment requirement
  • mise.toml and mise.tmpl: Pin beads to v0.49.2 for schema compatibility

How It Works

Detect in_progress/queued run (during PRFeedback)
    ↓
WatchWorkflowRun task exists for this run_id? → skip (idempotent)
    ↓
No → schedule WatchWorkflowRun task
    ↓
WatchWorkflowRun handler:
    gh run watch <run-id> --exit-status  // blocks until done
    ↓
    schedule PRFeedback task (immediate)
    ↓
PRFeedback handler:
    fetches logs, parses failures, creates beads

Issues Resolved

  • ac-7f7o: Instead of polling gh should we use gh run watch?
  • ac-7f7o.1: Add gh run watch for in-progress workflow runs
  • ac-7f7o.3: Add tests for WatchWorkflowRun handler

Testing

  • Added comprehensive test suite in handler_watch_run_test.go:
    • Missing metadata validation (run_id, repo)
    • Invalid run_id handling
    • Context cancellation (graceful shutdown)
    • Duplicate prevention via idempotency key
    • Multiple watchers for different run_ids
    • Handler registration verification

All tests passing:

=== RUN   TestHandleWatchWorkflowRunTask
--- PASS: TestHandleWatchWorkflowRunTask (0.32s)
=== RUN   TestScheduleWatchWorkflowRun  
--- PASS: TestScheduleWatchWorkflowRun (0.00s)
=== RUN   TestGetTaskHandlers_IncludesWatchWorkflowRun
--- PASS: TestGetTaskHandlers_IncludesWatchWorkflowRun (0.00s)

Notes

  • gh run watch replaces polling only for CI/workflow runs. Periodic polling is still needed for:
    • PR reviews and comments
    • Merge conflict detection
    • New runs triggered by subsequent pushes

🤖 Generated with Claude Code

Implement WatchWorkflowRun task type that uses `gh run watch` to block
until a workflow run completes, then immediately triggers a PRFeedback
task. This replaces polling for in-progress workflow runs.

Changes:
- Add TaskTypeWatchWorkflowRun to scheduler task types
- Create handler_watch_run.go with HandleWatchWorkflowRunTask handler
- Add ScheduleWatchWorkflowRun helper with idempotency key for dedup
- Modify handler_pr_feedback.go to spawn watchers for in-progress runs
- Register WatchWorkflowRun handler in ControlPlane.GetTaskHandlers
- Add comprehensive tests for the new handler

The flow: PRFeedback detects in-progress runs → schedules WatchWorkflowRun
tasks → watchers block on `gh run watch` → completion triggers PRFeedback
immediately. Uses run_id as idempotency key to prevent duplicate watchers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
newhook and others added 2 commits January 31, 2026 14:05
- Export ParsePRURL and add ExtractRepoFromPRURL helper function
- Add WatchWorkflowRun method to ClientInterface and Client
- Add GitHubClient field to ControlPlane for dependency injection
- Update handler_pr_feedback.go to use github.ExtractRepoFromPRURL
- Update handler_watch_run.go to use cp.GitHubClient.WatchWorkflowRun

This consolidates GitHub API operations in the github package for
better testability and consistency.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Changed spawnWorkflowWatchers from standalone function to ControlPlane method
- Use cp.GitHubClient.GetPRStatus() instead of creating new github.NewClient()
- Updated test to provide mock for GetPRStatus

This fixes the dependency injection pattern, making the code testable and consistent
with other ControlPlane methods.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@newhook newhook merged commit 49cafa5 into main Feb 1, 2026
3 checks passed
@newhook newhook deleted the feat/instead-of-polling-gh-should-we-use-gh-run-watch branch February 1, 2026 14:28
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