Skip to content

CON-215: generatePosts fails soft on a past date instead of aborting the turn - #113

Merged
grsmv merged 2 commits into
mainfrom
fix/con-215-generate-posts-past-date
Aug 15, 2026
Merged

CON-215: generatePosts fails soft on a past date instead of aborting the turn#113
grsmv merged 2 commits into
mainfrom
fix/con-215-generate-posts-past-date

Conversation

@grsmv

@grsmv grsmv commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Problem

Picking a past publish date made the Campaign Assistant crash with a raw red error instead of recovering:

model call failed: tool "generatePosts" failed: error calling tool generatePosts:
2026-07-28 is in the past — choose 2026-07-29 (today) or a later date

Root cause: generatePosts returned a Go error for a past window (resolveWindow). Per the genkit tool-loop semantics established in CON-213, a tool returning a Go error aborts the entire Generate turn — it never reaches the model to be relayed — so it bubbled up through run.go as model call failed: ….

A contributing factor is visible in the bug screenshots: the request was "review the brief", yet the cheap RolePlanning (Haiku) planner mis-routed into generatePosts and ignored the prompt's existing past-date guard. A prompt-only guard therefore isn't enough — the tool itself must fail soft.

Fix

  • toolGeneratePosts now returns a zero-post GeneratePostsOutput carrying the reason as a warning for every user-correctable input — past/invalid window, non-target platform, unknown phase — via a new softGenerateFailure helper, instead of a turn-aborting Go error.
  • The soft path leaves generatedPostsResult unset, so run.go keeps the turn conversational (answered) and the model's reply carries the suggestion. The warning text already contains "choose or a later date", giving the model the material to suggest a valid alternative — exactly what the issue asks for.
  • Genuine system errors (engine unavailable, engine call failure) still propagate as errors.
  • Reinforced the prompt so the planner reliably treats a zero-post + warning result as a suggestion, not success.
  • Added TestGeneratePosts_SoftFailsUserInput covering all three soft paths (asserts no error, zero posts + warning, generation engine not invoked, no result recorded).

resolveWindow / resolvePhase / resolveTargetPlatforms are unchanged, so their existing unit tests stay green.

Behavior change

Input Before After
Past publish date 🔴 model call failed: … is in the past (turn aborts) Assistant replies: that date has passed — want today or a later date?
Non-target platform 🔴 model call failed: … is not one of this campaign's target platforms Assistant relays the reason and offers a targeted platform
Unknown phase 🔴 model call failed: unknown phase … Assistant relays the reason conversationally

Testing

  • go build ./...
  • go vet ./src/genkit/flows/campaign_assistant/
  • go test ./src/genkit/flows/campaign_assistant/ — all green, incl. the new test

Notes / follow-up

post_assistant's scheduling path has the same crash class — scheduleToolError returns ErrScheduledAtInPast as a Go error (post_assistant/tools.go:766). It's a separate flow and left out of this PR to keep it scoped to the reported generatePosts bug; happy to fold in as a follow-up.

Closes CON-215.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid post-generation inputs, including past publishing windows, unsupported platforms, and unknown campaign phases.
    • The assistant now provides warnings and suggests valid alternatives instead of reporting success or abruptly failing.
    • Invalid requests no longer trigger post generation or record generated-post results.

…e turn

A past (or otherwise invalid) publish window made the campaign assistant's
generatePosts tool return a Go error, which aborts the whole Generate turn
(CON-213) and surfaces to the user as a raw "model call failed: ... is in the
past". The cheap planner also occasionally mis-routes into generatePosts, so a
prompt-only guard isn't enough.

Return a zero-post GeneratePostsOutput with the reason as a warning for every
user-correctable input — past/invalid window, non-target platform, unknown
phase — via softGenerateFailure, leaving generatedPostsResult unset so the turn
stays conversational and the assistant suggests today or a later date. Genuine
system errors still propagate. Reinforce the prompt to relay a zero-post warning
as a suggestion, and add TestGeneratePosts_SoftFailsUserInput.
@linear-code

linear-code Bot commented Aug 14, 2026

Copy link
Copy Markdown

CON-215

@grsmv
grsmv deployed to testing August 14, 2026 13:04 — with GitHub Actions Active
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2885351d-4b9b-4c3f-a90b-195767c2942d

📥 Commits

Reviewing files that changed from the base of the PR and between f906eee and 6cd590a.

📒 Files selected for processing (3)
  • src/genkit/flows/campaign_assistant/prompts/campaign_assistant.tmpl
  • src/genkit/flows/campaign_assistant/tools.go
  • src/genkit/flows/campaign_assistant/tools_test.go

Walkthrough

generatePosts now handles user-correctable validation failures as zero-post warning results. The assistant prompt relays these warnings and suggests valid alternatives. Tests verify that generation does not start.

Changes

Campaign post generation

Layer / File(s) Summary
Soft-failure behavior
src/genkit/flows/campaign_assistant/tools.go, src/genkit/flows/campaign_assistant/prompts/campaign_assistant.tmpl
Invalid platforms, phases, and publish windows return zero-post results with warnings. The prompt requires the assistant to relay warnings and suggest valid alternatives.
Soft-failure validation coverage
src/genkit/flows/campaign_assistant/tools_test.go
Tests verify that invalid inputs skip generation, return warnings without Go errors, and leave generatedPostsResult unset.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 6cd59

This localized change makes user-correctable scheduling inputs conversational instead of aborting the assistant turn while preserving genuine system errors; no actionable merge-blocking risk remains beyond normal checks and review.

Possibly related PRs

  • ogen-app/ogen#68: Earlier generatePosts behavior that this change refines into conversational zero-post warnings.
  • ogen-app/ogen#72: Related generatePosts validation and prompt changes addressing exact post counts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: generatePosts now soft-fails on past dates instead of aborting the assistant turn.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/con-215-generate-posts-past-date

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@grsmv grsmv added the to test label Aug 14, 2026
@grsmv
grsmv deployed to testing August 14, 2026 13:08 — with GitHub Actions Active
@grsmv
grsmv deployed to testing August 14, 2026 13:10 — with GitHub Actions Active
@ogen-app ogen-app deleted a comment from coderabbitai Bot Aug 14, 2026
@ogen-app ogen-app deleted a comment from coderabbitai Bot Aug 14, 2026
@grsmv
grsmv deployed to testing August 14, 2026 16:11 — with GitHub Actions Active
@grsmv
grsmv deployed to testing August 14, 2026 16:15 — with GitHub Actions Active
@grsmv
grsmv deployed to testing August 14, 2026 16:17 — with GitHub Actions Active
@ogen-app ogen-app deleted a comment from coderabbitai Bot Aug 14, 2026
@grsmv

grsmv commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@grsmv
grsmv merged commit 433153f into main Aug 15, 2026
6 checks passed
@grsmv grsmv added the bug Something isn't working label Aug 15, 2026
@grsmv
grsmv deleted the fix/con-215-generate-posts-past-date branch August 15, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant