Skip to content

fix(session): edge-trigger build-switch reminder instead of scanning full session history - #38067

Closed
Duo-Huang wants to merge 1 commit into
anomalyco:devfrom
Duo-Huang:fix/reminders-edge-trigger-custom-agents
Closed

Duo-Huang wants to merge 1 commit into
anomalyco:devfrom
Duo-Huang:fix/reminders-edge-trigger-custom-agents

Conversation

@Duo-Huang

@Duo-Huang Duo-Huang commented Jul 21, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #38066

Type of change

  • Bug fix

What does this PR do?

SessionReminders.apply (packages/opencode/src/session/reminders.ts) decides whether to inject the "operational mode has changed from plan to build" reminder using:

const wasPlan = input.messages.some((msg) => msg.info.role === "assistant" && msg.info.agent === "plan")

This checks "has this session ever contained a plan-agent message" (scanning the full uncompacted history), not "was the immediately preceding turn plan". With only the built-in plan/build toggle this rarely matters, but opencode supports custom primary agents (docs/agents). Once a third primary agent is used between plan and build, wasPlan stays true from the old plan message and the reminder both mislabels the transition and can re-fire on every subsequent build turn.

Fix: use findLast to check only the immediately preceding assistant message's agent, matching the pattern already used a few lines below in the experimentalPlanMode branch.

How did you verify your code works?

Manually reproduced against a real session: switched plan -> custom read-only agent (several turns) -> build. Confirmed the stale "from plan to build" banner still fires on unpatched code, and with this one-line logic change it correctly reflects the immediately preceding agent instead. Did not run the full monorepo test suite in my environment; there's no existing test file for reminders.ts to extend, happy to add one if pointed at a similar fixture.

Screenshots / recordings

N/A, not a UI change.

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. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

…r build-switch reminder

SessionReminders.apply's legacy (!experimentalPlanMode) branch used
`messages.some(msg => msg.info.agent === "plan")` to decide whether to
inject the BUILD_SWITCH reminder. This checks whether the session has
EVER contained a plan-agent message, not whether the immediately
preceding turn was plan.

With only the built-in plan/build toggle these are nearly equivalent in
common usage, but opencode explicitly supports custom primary agents
(https://opencode.ai/docs/agents). Once a third primary agent is in
rotation (e.g. a custom read-only "ask"-style agent), `.some()` keeps
matching build turns for the rest of the (uncompacted) session history
-- even many turns after leaving plan, with an unrelated agent in
between -- producing a reminder that falsely claims "changed from plan
to build" when the actual previous turn was something else entirely.
Repeated firing of the same reminder also risks training the model to
discount what's meant to be a high-signal system message.

Fix by checking only the immediately preceding assistant message's
agent, mirroring the findLast-based pattern the experimentalPlanMode
branch a few lines below already uses.

Observed in production against a live session with a custom read-only
'ask' primary agent: Ask -> build transition incorrectly reproduced the
stale 'changed from plan to build' banner from several turns earlier.
@Duo-Huang
Duo-Huang force-pushed the fix/reminders-edge-trigger-custom-agents branch from 78c3fbb to 5007223 Compare August 13, 2026 02:20
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SessionReminders: build-switch banner mislabels/repeats when a custom primary agent (e.g. read-only 'ask') is used between plan and build

1 participant