Skip to content

fix(opencode): handle session title generation failures with retry#35440

Open
1837620622 wants to merge 1 commit into
anomalyco:devfrom
1837620622:fix/session-auto-title-failure-handling
Open

fix(opencode): handle session title generation failures with retry#35440
1837620622 wants to merge 1 commit into
anomalyco:devfrom
1837620622:fix/session-auto-title-failure-handling

Conversation

@1837620622

@1837620622 1837620622 commented Jul 5, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #13710

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Session auto-naming (ensureTitle() in packages/opencode/src/session/prompt.ts) fails silently, leaving sessions with the default "New session - ..." title.

Root cause — three chained issues:

  1. Effect.orDie on the LLM stream — any API error during title generation kills the background fiber with no recovery.
  2. Unguarded model resolution — getSmallModel() or getModel() exceptions propagate as unhandled defects, silently killing the fiber.
  3. Effect.ignore at the call site — even surviving errors are silently discarded with zero logging.

Fixes:

  1. Effect.orDieEffect.catchAll with structured warning logging on the stream.
  2. Model resolution wrapped in Effect.fnUntraced + Effect.option — resolution failures return None and are gracefully skipped with a log entry.
  3. Effect.ignoreEffect.catchCause at the fork site so defects are logged.

Additional improvements:

  • Removed small: true — title generation now uses the conversation model (was silently failing when no small model variant was configured for the provider).
  • Added auto-retry: if the first LLM call produces no title, sleep 10s, re-check the title is still default (handles user rename), then retry with the full conversation.

All eight possible failure paths now produce a structured log entry, from model resolution through LLM call to DB persistence.

How did you verify your code works?

  • Verified all Effect APIs are used correctly (Effect.catchAll on streams, Effect.fnUntraced + Effect.option for model resolution, Effect.catchCause at fork site)
  • Confirmed Option, Cause, Stream, SessionV1 imports are already present in the file
  • Retry path correctly uses MessageV2.toModelMessagesEffect() to convert SessionV1.WithParts[] to ModelMessage[] before the LLM call
  • Retry checks Session.isDefaultTitle() before and after the delay to handle user renames
  • All error paths produce structured log output (verified by code review)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search results, I found several related PRs that address session title generation:

Potentially Related PRs

  1. PR feat(opencode): allow skipping session title generation via config #33148 - feat(opencode): allow skipping session title generation via config

    • Related to session title generation configuration; may be complementary to error handling improvements
  2. PR fix(session): don't let auto-title overwrite a title set mid-turn #32739 - fix(session): don't let auto-title overwrite a title set mid-turn

    • Addresses session title generation logic; related to the same feature area
  3. PR fix(provider): respect configured small_model and add opencode handling to smallOptions #31092 - fix(provider): respect configured small_model and add opencode handling to smallOptions

    • Related to model resolution and small model handling, which is part of the error path in this PR's fix

These are related to session title generation and the underlying infrastructure (model resolution, configuration), but none appear to be direct duplicates addressing the same silent error failure issue that PR #35440 targets.

@1837620622 1837620622 force-pushed the fix/session-auto-title-failure-handling branch from 7140b3f to a65c89d Compare July 5, 2026 16:12
@1837620622 1837620622 changed the title fix: session auto-title generation bails out silently on transient errors fix(opencode): handle session title generation failures with retry Jul 5, 2026
@1837620622 1837620622 force-pushed the fix/session-auto-title-failure-handling branch from a65c89d to 9230382 Compare July 5, 2026 16:18
Three fixes for ensureTitle():
1. Fix model resolution: wrap getSmallModel/getModel in Effect.option so
   resolution errors don't silently defect the fiber.
2. Fix LLM stream: replace Effect.orDie with Effect.catchAll so API errors
   produce a warning log instead of terminating the background fiber.
3. Fix call site: replace Effect.ignore with Effect.catchCause so unexpected
   defects are logged instead of silently swallowed.

Additionally:
- Remove small:true flag so title uses the current conversation model.
- Add retry path: if first LLM call produces no title, sleep 10 seconds
  then retry with full conversation history for better context.

Fixes anomalyco#13710
@1837620622 1837620622 force-pushed the fix/session-auto-title-failure-handling branch from 9230382 to ace8cff Compare July 5, 2026 16:49
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 5, 2026
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@1837620622

Copy link
Copy Markdown
Author

@maintainers This PR addresses the root cause of the intermittent auto-naming failure reported in #13710.

Summary of the approach:

The three bugs form a chain — any of them alone would cause silent failure. The fix addresses all three at their source:

  1. Model resolution now uses Effect.option so getSmallModel/getModel errors produce Option.None instead of a fiber-killing defect
  2. LLM stream uses Effect.catchAll so transient API errors are logged and produce empty output (which triggers the retry path)
  3. Call site uses Effect.catchCause so unexpected defects are logged

The retry path was added as a safety net: if the first attempt produces no title (regardless of the reason), wait 10 seconds for more conversation context, verify the title is still the default, and try again with the full history.

This is more robust than patching individual error causes because it handles:

  • Future API changes that introduce new error types
  • Provider-specific quirks (e.g., Copilot GPT-4o mini not supporting certain features)
  • Transient network/rate-limit failures
  • Any other unanticipated failure mode

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.

OpenCode Desktop Session Name is no longer written with AI at times

1 participant