Repository navigation
fix(agent): keep the system prompt byte-stable across agent-mode switches (Shift+Tab) - #1135
Conversation
|
@infer can you finalise the work on this PR? prepare it for a review. use /ponytail:ponytail /go /go-concurrency Update the PR title and body. |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll skills loaded and followed. Everything is committed, pushed, and the PR is updated. Let me close out the todos: All done - the PR is finalized, committed, pushed, and ready for review. What I didDiagnosed and fixed the failing Validated the whole change against the issue's acceptance criteria, then completed the missing pieces (docs):
Check results (mirroring CI):
PR housekeeping: retitled to Deliberately skipped (per the issue's open questions, called out in the PR body): the residual native-tools-array cache miss in plan mode (option 1a accepted) and the compact short-form guidance on repeated flips (open question 5) - both are follow-up material, not blockers. Model: Tokens: 5,141,891 in · 26,200 out · 5,168,091 total (56 requests) Tool calls: 69 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
gofmt the INFER_PROMPTS_AGENT_MODE_ADJUSTMENT_* entries in cmd/runtime/config.go and the struct padding in config/prompts.go; the CI prepare go fmt check flagged both.
…instructions Update configuration-reference.md and plan-mode.md for the #1134 rename (agent.system_prompt_plan/_auto to agent.mode_adjustment_plan/_auto) with the deprecation and precedence notes, the byte-stable system prompt guarantee, and the reminders.enabled false behavior (mode-specific instructions are not delivered when reminders are off).
|
@infer remove backward compatibility deprecation notes! no backward compatibility needed. use /ponytail:ponytail YAGNI |
|
Model: Todos
Pull Request✅ Infer Result: SuccessDone. All backward-compatibility and deprecation machinery for the mode-adjustment rename is gone - pushed as What was removed (commit
|
The rename of agent.system_prompt_plan/_auto to agent.mode_adjustment_plan/_auto is unreleased, so no compatibility layer is needed (YAGNI). Removes the UnmarshalYAML legacy-key decoding, the deprecated INFER_PROMPTS_AGENT_SYSTEM_PROMPT_PLAN/_AUTO env aliases with their warnings, and the legacy-alias tests; the renamed YAML keys and env vars are now the only way to configure mode adjustments. Docs no longer advertise the deprecated names, and the dead-env warning now points INFER_AGENT_SYSTEM_PROMPT_PLAN at the renamed var.
…ve prompt cache Plan mode advertised only 8 tool schemas, so a mid-session standard/plan switch changed the request's tools array and invalidated the provider's cached prefix despite the byte-stable system prompt from #1134. All mid-session modes now advertise the full tool list; plan-mode restrictions are enforced at execution time (recoverable error, mirroring the bash allow-list), plan-only tools are rejected outside plan mode, and doomed calls skip the approval prompt. ReadOnly subagents keep their filtered list. The status-bar tool count now reflects what is actually sent.
…ore mode adjustment keys
|
🎉 This PR is included in version 0.186.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #1134
Summary
Mode switches mid-conversation (Shift+Tab in chat, or accepting a plan) no longer swap the system prompt sent as
message[0]. Previously the agent rebuiltmessage[0]from the live mode (agent.system_prompt_planin plan mode,agent.system_prompt_autoin auto-accept), changing the conversation prefix and invalidating provider prompt/KV caches, so the whole conversation was re-processed at uncached rates. The mode-change<system-reminder>user message is now the single, cache-preserving carrier of mode-specific instructions, enriched with everything the old per-mode prompts carried.What changed
internal/agent/agent_utils.go: removedgetSystemPromptForMode();message[0]is always assembled fromagent.system_promptand is byte-stable across turns AND across mode switches.buildToolsInfo()(AVAILABLE TOOLS) andbuildBashAllowInfo()(BASH ALLOW-LIST) moved from the static prompt into the per-request volatile tail, so the live mode's tool roster still updates on the next turn without touchingmessage[0].config/reminders.go: the built-inon_mode_changeguidance now carries the full per-mode behavior the old prompts held - the plan workflow (clarify first,AskUserQuestionfor discrete choices,RequestPlanApprovalonly when complete), the required plan Markdown sections, the plan/auto tool-set deltas consistent withllm_tool_service.ListToolsForMode, the auto-accept destructive-action policy, and the standard per-call approval note. Users override per-key via the reminder'sguidancemap inreminders.yaml.ReminderQuery.ModeGuidance(internal/agent/domain/hooks.go) plusmodeGuidanceOverrides(): prompts.yaml per-mode adjustments (agent.mode_adjustment_plan/agent.mode_adjustment_auto) layer onto the reminder when set. Precedence: user-editedreminders.yamlguidance beats prompts.yaml adjustment beats built-in default.config/prompts.go:agent.system_prompt_plan/_autorenamed toagent.mode_adjustment_plan/agent.mode_adjustment_auto(YAML keysmode_adjustment_plan/mode_adjustment_auto). They ship empty and are no longer backfilled - the built-in texts live in the reminder guidance. No backward compatibility (YAGNI): the old YAML keys and env aliases are simply gone; only the renamedINFER_PROMPTS_AGENT_MODE_ADJUSTMENT_PLAN/_AUTOenv vars load.docs/configuration-reference.mdanddocs/plan-mode.mdupdated (rename and precedence notes, the byte-stability guarantee,infer debug agent system_promptnow listing the tools and bash-allow-list sections under the volatile tail).reminders.enabled: falsebehavior is documented explicitly: the mode-change reminder is the sole carrier of mode instructions, so with reminders disabled the per-mode instructions are not delivered (documented trade-off, per the issue's open question 3).Deliberately kept (per the issue's open questions)
toolsarray still shrinks in plan mode, so providers that fold tools into the cache prefix still see a residual miss on a mode flip (open question 1a). System-prompt stability is the main win; enforcing plan-mode read-only at execution time instead of via the tool list is a possible follow-up.Tests
TestAgentServiceImpl_BuildSystemPromptByteStableAcrossModeSwitchpinsmessage[0]byte-identity across standard/plan/auto-accept even with mode adjustments configured (the acceptance-criteria regression test).config/reminders_mode_change_test.go; the legacy-alias tests were removed together with the aliases.cmd/runtimecovers the renamedINFER_PROMPTS_AGENT_MODE_ADJUSTMENT_PLAN/_AUTOenv vars loading into the mode-adjustment slots.Verification
go vet -tags purego ./...,golangci-lint run --build-tags purego,markdownlint, andgo test -race -tags purego ./...all pass.cmd/runtime/config_pointer_env_test.go(pointer defaults tests) also fail onmainat00f2061in this runner environment; they are unrelated to this change.