Skip to content

fix(bots): apply edited standing instructions on the next turn - #275

Merged
nixuuu merged 1 commit into
devfrom
fix/bot-instructions-refresh
Nov 6, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/bot-instructions-refresh

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026

Copy link
Copy Markdown
Member

Change

Changing a bot's standing instructions now starts its next turn in a fresh hidden harness session, with the current instructions, the existing Canopy conversation history and the latest stored handoff note. The user keeps the same bot and chat. Clearing instructions works too; an already-running turn keeps its original snapshot.

Cause and provider behavior

The UI saves BotConfiguration.instructions through UpdateBot into bots.configuration in Postgres. The gateway reads that configuration for each new turn and sends the current instructions in its durable RunBotTurn command. The missing boundary was the worker's persisted session.json fingerprint: it included model, tools and isolation version, but omitted standing instructions and name. Restarting an app, gateway or worker kept selecting that same provider session.

Provider Existing instruction/resume path Fix
Claude The official Agent SDK receives systemPrompt, including with resume; the saved session retains earlier conversation context. Start with a new sessionId after relevant settings change, supplying the current system prompt and gateway history.
Codex The official app-server receives baseInstructions on both thread/start and thread/resume; resume restores the old thread context. Use thread/start after a change rather than relying on an override to replace all earlier instruction context.
Grok The official CLI receives the curated agent profile and current prompt; ACP session/load restores its session. Use session/new with the current profile and rebuilt history after a change.

This confirms the missing invalidation and provider input paths. It does not claim that every CLI version ignores instruction overrides on resume; the fix deliberately avoids that dependency. Rebuilt prompts explicitly give current standing instructions precedence over conflicting historical instructions/preferences.

Scope and compatibility

  • Add RunBotTurn.configuration_key = 11: a stable SHA-256 of name, standing instructions and approval policy, excluding per-turn time/hops/context. The worker includes this key and effort alongside the existing model/tool fingerprint. Name, persona, policy, effort, model and connector catalog edits therefore refresh the hidden session. Appearance-only/no-op saves resume normally.
  • Provider/instance session namespaces and Runs on routing remain unchanged. Device/library skills and plugins stay excluded from bots. Connector grant changes keep their existing tool-fingerprint invalidation and gateway authorization.
  • Reuse the existing budgeted history rebuild and persisted handoff note. Do not delete transcripts, notes, routines, reminders or watches, replay historical tools, or add summarization calls. The full visible transcript remains in Postgres; oversized rebuilds retain the existing history budget. Provider-private reasoning is not transferred.
  • Additive protobuf only; generated code included. WORKER_LINK_PROTOCOL remains 1, frozen UpdateService unchanged, no DB migration. Older workers ignore the new field and keep existing behavior; upgrade workers to get the fix. New workers safely handle old gateway commands by fingerprinting the full instructions, which may cause more frequent session rebuilds.

Verification

Gateway/worker regression coverage uses real Postgres, WorkerLink, WorkerHost and the official Claude SDK with controlled provider CLI fixtures. All three providers cover resumed sessions, editing/clearing instructions, worker and gateway restarts, an edit during an active turn, unchanged saves, appearance, name, policy, effort/model changes, preserved chat history and a durable handoff note. Fixtures read the actual SDK initialization system prompt, app-server baseInstructions, or Grok profile; their answers derive from those instructions. Legacy session fingerprints and commands without the additive field are covered by the harness isolation test.

  • bun install — passed, lockfile unchanged.
  • bun run gen:check, bun run typecheck, bun run lint, bun run format:check — passed.
  • bun run check:tmp — 1,490 passed, 158 skipped, 0 failed across 265 files; temp cleanup passed. All nine new refresh regression cases passed in this full run.
  • bun run --filter @canopy/web build — passed.

Paid/live inference and manual UI/browser checks were not run. No UI code or copy changed; the shared UI API is covered through gateway integration. Polish bot documentation is updated.

Fixes: #97

@nixuuu
nixuuu merged commit d15905a into dev Nov 6, 2026
9 checks passed
@nixuuu
nixuuu deleted the fix/bot-instructions-refresh branch November 6, 2026 11:57
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.

1 participant