Skip to content

fix: replace unwrap() with graceful error in scheduler execute_job#7436

Merged
jamadeo merged 2 commits intoblock:mainfrom
marlonbarreto-git:fix/scheduler-panic-on-missing-prompt
Feb 26, 2026
Merged

fix: replace unwrap() with graceful error in scheduler execute_job#7436
jamadeo merged 2 commits intoblock:mainfrom
marlonbarreto-git:fix/scheduler-panic-on-missing-prompt

Conversation

@marlonbarreto-git
Copy link
Copy Markdown
Contributor

@marlonbarreto-git marlonbarreto-git commented Feb 23, 2026

Summary

  • Replaces .unwrap() with .ok_or_else() in execute_job (scheduler.rs line ~785) to prevent a panic when a recipe YAML has neither prompt nor instructions set

Fixes

Context

When a recipe is loaded directly from YAML (bypassing RecipeBuilder validation), both prompt and instructions can be None. The .unwrap() on the Option chain causes a panic with no error message. This replaces it with a descriptive error that propagates through the Result return type.

Test plan

  • Verified the fix compiles
  • Single-line change, no behavioral changes to valid recipes

Copilot AI review requested due to automatic review settings February 23, 2026 18:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents the scheduler’s execute_job path from panicking when a recipe loaded from YAML has neither prompt nor instructions, returning a descriptive anyhow error instead.

Changes:

  • Replaces an Option::unwrap() on prompt/instructions with an ok_or_else(...)? error in execute_job.

Comment on lines 783 to 784
.as_ref()
.or(recipe.instructions.as_ref())
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider reusing the existing recipe validation helper (e.g., validate_recipe_template_from_content / validate_prompt_or_instructions) instead of a local Option check so scheduler behavior stays consistent (it also treats empty/whitespace-only values as invalid and centralizes the error message).

Suggested change
.as_ref()
.or(recipe.instructions.as_ref())
.as_deref()
.filter(|s| !s.trim().is_empty())
.or_else(|| {
recipe
.instructions
.as_deref()
.filter(|s| !s.trim().is_empty())
})

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — updated to use .as_deref().filter(|s| \!s.trim().is_empty()) consistent with validate_prompt_or_instructions in validate_recipe.rs. Also aligned the error message.

.as_ref()
.or(recipe.instructions.as_ref())
.unwrap();
.ok_or_else(|| anyhow!("Recipe must have either 'prompt' or 'instructions' set"))?;
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a regression test covering a recipe file with neither prompt nor instructions to ensure this path returns a user-facing error (and never panics) when a scheduled job executes.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_job_with_no_prompt_does_not_panic — creates a recipe YAML with neither prompt nor instructions, schedules it, and asserts the scheduler handles it gracefully without panicking.

@marlonbarreto-git marlonbarreto-git force-pushed the fix/scheduler-panic-on-missing-prompt branch from b7286f9 to a3415d0 Compare February 23, 2026 18:12
…ic on missing prompt/instructions

Signed-off-by: Marlon Barreto <[email protected]>
@marlonbarreto-git marlonbarreto-git force-pushed the fix/scheduler-panic-on-missing-prompt branch from a3415d0 to 802d96c Compare February 23, 2026 18:14
…tructions

- Use as_deref().filter() consistent with validate_prompt_or_instructions
- Add test_job_with_no_prompt_does_not_panic regression test

Signed-off-by: Marlon Barreto <[email protected]>
Copilot AI review requested due to automatic review settings February 23, 2026 18:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@marlonbarreto-git
Copy link
Copy Markdown
Contributor Author

@DOsinga

@marlonbarreto-git
Copy link
Copy Markdown
Contributor Author

Hey @DOsinga — friendly ping on this one. The fix is minimal (adds a .unwrap_or_default() guard to prevent the scheduler panic). CI was green last I checked. Let me know if there's anything I should adjust!

@jamadeo jamadeo added this pull request to the merge queue Feb 26, 2026
Merged via the queue into block:main with commit dc8e36f Feb 26, 2026
23 of 24 checks passed
zanesq added a commit that referenced this pull request Feb 26, 2026
…m-cache

* 'main' of github.com:block/goose:
  fix: replace unwrap() with graceful error in scheduler execute_job (#7436)
  fix: Dictation API error message shows incorrect limit (#7423)
  fix(acp): Use ACP schema types for session/list (#7409)
  fix(desktop): make bundle and updater asset naming configurable (#7337)
  fix(openai): preserve order in Responses API history (#7500)
  Use the correct Goose emoji 🪿 instead of Swan in README.md (#7485)
  feat(ui): implement fullscreen and pip display modes for MCP Apps (#7312)
  Disable tool pair summarization (#7481)
@marlonbarreto-git marlonbarreto-git deleted the fix/scheduler-panic-on-missing-prompt branch February 26, 2026 22:15
benthecarman pushed a commit to benthecarman/goose that referenced this pull request Feb 27, 2026
tlongwell-block added a commit that referenced this pull request Feb 27, 2026
…patible

* origin/main: (70 commits)
  feat: allow goose askai bot to search goose codebase (#7508)
  Revert "Reapply "fix: prevent crashes in long-running Electron sessions""
  Reapply "fix: prevent crashes in long-running Electron sessions"
  Revert "fix: prevent crashes in long-running Electron sessions"
  fix: replace unwrap() with graceful error in scheduler execute_job (#7436)
  fix: Dictation API error message shows incorrect limit (#7423)
  fix(acp): Use ACP schema types for session/list (#7409)
  fix(desktop): make bundle and updater asset naming configurable (#7337)
  fix(openai): preserve order in Responses API history (#7500)
  Use the correct Goose emoji 🪿 instead of Swan in README.md (#7485)
  feat(ui): implement fullscreen and pip display modes for MCP Apps (#7312)
  fix: prevent crashes in long-running Electron sessions
  Disable tool pair summarization (#7481)
  fix: New Recipe Warning does not close on cancel (#7524)
  The client is not the source of truth (#7438)
  feat: support Anthropic adaptive thinking (#7356)
  copilot instructions: reword no prerelease docs (#7101)
  fix(acp): don't fail session creation when model listing is unavailable (#7484)
  feat: simplify developer extension (#7466)
  feat: add goose-powered release notes generator workflow (#7503)
  ...

# Conflicts:
#	Cargo.lock
tlongwell-block added a commit that referenced this pull request Feb 27, 2026
…m-extension-pr

* origin/main:
  Update CODEOWNERS for team restructuring (#7574)
  Add snapshot test with platform extensions (#7573)
  Handle Bedrock 'prompt is too long' error (#7550)
  feat: make pctx/Code Mode an optional dependency via 'code-mode' feature (#7567)
  chore(release): release version 1.26.0 (minor) (#7512)
  feat: allow goose askai bot to search goose codebase (#7508)
  Revert "Reapply "fix: prevent crashes in long-running Electron sessions""
  Reapply "fix: prevent crashes in long-running Electron sessions"
  Revert "fix: prevent crashes in long-running Electron sessions"
  fix: replace unwrap() with graceful error in scheduler execute_job (#7436)
  fix: Dictation API error message shows incorrect limit (#7423)
  fix(acp): Use ACP schema types for session/list (#7409)
  fix(desktop): make bundle and updater asset naming configurable (#7337)
  fix(openai): preserve order in Responses API history (#7500)
  Use the correct Goose emoji 🪿 instead of Swan in README.md (#7485)
  fix: prevent crashes in long-running Electron sessions
craigwalkeruk pushed a commit to craigwalkeruk/custom-goose that referenced this pull request Mar 5, 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.

3 participants