@@ -54,6 +54,7 @@ const (
5454// PR represents a pull request with metadata. 
5555type  PR  struct  {
5656	UpdatedAt          time.Time 
57+ 	CreatedAt          time.Time 
5758	TurnDataAppliedAt  time.Time 
5859	FirstBlockedAt     time.Time  // When this PR was first detected as blocked 
5960	Title              string 
@@ -63,6 +64,7 @@ type PR struct {
6364	ActionReason       string 
6465	ActionKind         string  // The kind of action expected (review, merge, fix_tests, etc.) 
6566	TestState          string  // Test state from Turn API: "running", "passing", "failing", etc. 
67+ 	WorkflowState      string  // Workflow state from Turn API: "running_tests", "waiting_for_review", etc. 
6668	Number             int 
6769	IsDraft            bool 
6870	IsBlocked          bool 
@@ -863,21 +865,42 @@ func (app *App) tryAutoOpenPR(ctx context.Context, pr *PR, autoBrowserEnabled bo
863865		return 
864866	}
865867
868+ 	// Only auto-open if the PR is actually blocked or needs review 
869+ 	// This ensures we have a valid NextAction before opening 
870+ 	if  ! pr .IsBlocked  &&  ! pr .NeedsReview  {
871+ 		slog .Debug ("[BROWSER] Skipping auto-open for non-blocked PR" ,
872+ 			"repo" , pr .Repository , "number" , pr .Number ,
873+ 			"is_blocked" , pr .IsBlocked , "needs_review" , pr .NeedsReview )
874+ 		return 
875+ 	}
876+ 
866877	if  app .browserRateLimiter .CanOpen (startTime , pr .URL ) {
867878		slog .Info ("[BROWSER] Auto-opening newly blocked PR" ,
868- 			"repo" , pr .Repository , "number" , pr .Number , "url" , pr .URL )
879+ 			"repo" , pr .Repository ,
880+ 			"number" , pr .Number ,
881+ 			"url" , pr .URL ,
882+ 			"workflow_state" , pr .WorkflowState ,
883+ 			"test_state" , pr .TestState ,
884+ 			"is_draft" , pr .IsDraft ,
885+ 			"age_since_creation" , time .Since (pr .CreatedAt ).Round (time .Second ),
886+ 			"age_since_update" , time .Since (pr .UpdatedAt ).Round (time .Second ))
869887		// Use strict validation for auto-opened URLs 
870888		// Validate against strict GitHub PR URL pattern for auto-opening 
871889		if  err  :=  validateGitHubPRURL (pr .URL ); err  !=  nil  {
872890			slog .Warn ("Auto-open strict validation failed" , "url" , sanitizeForLog (pr .URL ), "error" , err )
873891			return 
874892		}
875- 		if  err  :=  openURL (ctx , pr .URL ); err  !=  nil  {
893+ 		// Use ActionKind as the goose parameter value, or "next_action" if not set 
894+ 		gooseParam  :=  pr .ActionKind 
895+ 		if  gooseParam  ==  ""  {
896+ 			gooseParam  =  "next_action" 
897+ 		}
898+ 		if  err  :=  openURL (ctx , pr .URL , gooseParam ); err  !=  nil  {
876899			slog .Error ("[BROWSER] Failed to auto-open PR" , "url" , pr .URL , "error" , err )
877900		} else  {
878901			app .browserRateLimiter .RecordOpen (pr .URL )
879902			slog .Info ("[BROWSER] Successfully opened PR in browser" ,
880- 				"repo" , pr .Repository , "number" , pr .Number , "action" , pr .ActionKind )
903+ 				"repo" , pr .Repository , "number" , pr .Number , "action" , pr .ActionKind ,  "goose_param" ,  gooseParam )
881904		}
882905	}
883906}
0 commit comments