Plan mode leave reminder becomes the final user turn after a tool-driven agent switch, models refuse
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start with the reminder insertion logic in packages/core/src/plugin/plan.ts, especially the message placement shown in the issue, then inspect the related cases in plan.test.ts. Reproduce the trailing user reminder after a tool-driven switch and check how persisted reminders behave on retry. Done means the reminder stays in the correct order without leaving an empty user turn at the end, and the plan tests pass.
Written by the indexing model from the issue text.
Description
Description
When the agent switches away from plan partway through a turn, so the last message is an assistant or tool message rather than a user prompt, the opencode.plan context hook adds the "NO LONGER in Plan mode" reminder at the very end of the request:
// packages/core/src/plugin/plan.ts (dev ba06ff9e0b), lines 64-65
const at = event.messages.at(-1)?.role === "user" ? event.messages.length - 1 : event.messages.length
event.messages.splice(at, 0, Message.user(text))
The request then ends with a user turn that holds only a <system-reminder> and no instruction. gpt-5.3-codex replies "I'm sorry, but I cannot assist with that request." every time. The reminder is also persisted as a synthetic message, so it stays at the end on retries, and the session keeps refusing until the user types something.
This shows up with plan-approval plugins (Plannotator submit_plan): the tool result reads "Plan approved…", the plugin switches the agent to build, and the next request ends assistant(tool_call) > tool(result) > user(<leave reminder>). In my gateway logs, every refused request has this exact tail: 6 of 6 refusals on 2026-10-19.
Steps to reproduce
- Start a session in the
planagent. - Have a tool call switch the session to
build(for example, approve a plan in Plannotator). - Look at the next model request: its last message is a user message containing only the leave reminder. Seen with gpt-5.3-codex through an OpenAI-compatible Responses provider.
Proposed fix
If a switch reminder would be the last message and the message before it is not a user message, move the reminder to the start of the trailing assistant/tool run. The request then ends on the tool result, as a normal agent loop does, and the enter/leave order is kept. The same check also fixes reminders that were already persisted at the tail. Tests: two new cases fail before the fix and pass after it. All 15 tests in plan.test.ts pass, and tsc -b and prettier are clean. I have a patch ready and can open a PR if a maintainer is happy with this approach.
OpenCode version
2.0.32 (bug also present on dev ba06ff9e0b)
Plugins
@plannotator/opencode 0.28.23 (triggers it), plus local plugins
Operating System
macOS
- Dominant language
- TypeScript
- Stars
- 215k
- Forks
- 28.9k
- Avg merge
- 8h 27m
- Merged PRs (30d)
- 282
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from anomalyco/opencode
-
pending close triaging
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
anomalyco/opencode#57028 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
anomalyco/opencode#56891 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
anomalyco/opencode#56843 · 1 comment ·
Maintainers usually reply within 1 day
-
triaging
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
anomalyco/opencode#56765 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
anomalyco/opencode#56735 · 1 comment ·
Maintainers usually reply within 1 day
All issues in anomalyco/opencode
Similar issues
-
docs(api): openapi.yaml still documents gif-tools optimize colors as 2-256 instead of 2, 4, 16, 256Openarea: backend documentation priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
snapotter-hq/SnapOtter#2919 ·
Maintainers usually reply within 1 day
-
accepted :+1: bug db/redis
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
beekeeper-studio/beekeeper-studio#4882 · 1 comment ·
Maintainers usually reply within 1 day
-
ready-for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
konflux-ci/konflux-ui#1630 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
ahmedkhaleel2004/gitdiagram#233 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
simkimsia/netlify-axi#19 ·
Maintainers usually reply within 1 day