Skip to content

fix(chat): preserve model history across Turns - #1848

Merged
dcramer merged 18 commits into
mainfrom
test/prompt-history-prefix-1844
Sep 11, 2026
Merged

dcramer merged 18 commits into
mainfrom
test/prompt-history-prefix-1844

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • store and replay the exact Pi message history across Turns
  • keep <runtime-turn-context> in model history while presentation projections can hide it
  • keep SQL Conversation events as the only model-history authority
  • stop new Redis Turn cursors from copying model context; retain read compatibility for old cursors
  • add a provider-neutral integration fixture and verify that the system prompt stays equal and the first model request stays an exact prefix of the second

Root cause

The Conversation history cutover removed <runtime-turn-context> before it wrote and replayed model history. The next Turn then inserted runtime context at the end of the prompt. This changed the cached prefix even when the context content did not change.

Normal history must be append-only. Compaction and handoff remain the only operations that can replace it. Presentation code can omit internal context without changing model history.

Verification

  • pnpm --filter @sentry/junior exec vitest run tests/integration/model-message-history.test.ts tests/component/task-execution/checkpoint.test.ts tests/unit/chat/pi/conversation-events.test.ts tests/component/runtime/agent-run-model-handoff.test.ts
  • pnpm --filter @sentry/junior typecheck
  • pnpm lint

Refs #1844.

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Sep 11, 2026 5:44pm UTC

Request Review

@dcramer
dcramer marked this pull request as ready for review September 11, 2026 17:16
@github-actions github-actions Bot added the risk: high PR risk score: high label Sep 11, 2026
@sentry-junior sentry-junior Bot changed the title test(chat): prove prompt history prefix churn fix(chat): preserve model history across Turns Sep 11, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e8b5aa2. Configure here.

@dcramer
dcramer merged commit 75c14ca into main Sep 11, 2026
40 checks passed
@dcramer
dcramer deleted the test/prompt-history-prefix-1844 branch September 11, 2026 17:52
dcramer added a commit that referenced this pull request Oct 15, 2026
In a Slack Conversation, a Turn that a person's Slack message did not
start got a shorter tool list. This covers event, automation, Agent
invocation (child result), and dashboard Turns. They dropped 11 tools:
`slackPublicSearch`, `addReaction`, the 4 event automation tools, and
the 5 scheduled automation tools. Explicit `/skill` Turns also dropped
`loadSkill`. The provider caches tools before the system prompt and
messages, so each change to the tool list wrote the whole Conversation
to the cache again.

**Change**

- `createTools` registers these tools from the Conversation's Slack
Location, not from the Source or Actor of the Turn. `loadSkill` is
always registered, and the `includeLoadSkill` option is gone.
- A tool can now be disabled for one Turn without leaving the tool list.
`disableTools(tools, reason)` sets `disabledReason`. The tool adapter
rejects calls to a disabled tool, direct or through `executeTool`,
before hooks, action review, and the executor. The Turn context lists
disabled tools in a `<disabled-tools>` block. The reason never goes into
a tool description or schema, so the tool list stays the same.
- The automation tools are disabled unless a person started the Turn
with a Slack message (`isSlackMessageTurn`). Scheduled automation tools
get the Slack Actor and Source only on those Turns. The existing checks
in the tools still reject other Turns, so a child agent result that
carries the person's Actor cannot create or change automations with that
person's credentials.
- `slackPublicSearch` is disabled without a Slack action token, and
`addReaction` without a message.
- `src/chat/README.md` documents the rule: tool registration depends on
the Conversation, not on one Turn.

**Why tests did not catch it**

- `model-message-history.test.ts` (#1848) only compared two web Turns
from the same origin.
- `tool-registration.test.ts` asserted the drift as expected behavior.

**Tests**

- `tool-registration.test.ts`: message, scheduled automation, event, and
Agent invocation Turns in one Slack Conversation get the same tool
names, descriptions, and schemas.
- `pi-tool-adapter.test.ts`: a disabled tool keeps the same tool list,
and direct and `executeTool` calls are rejected before the executor
runs.
- `slack-schedule-tools.test.ts`: an Agent invocation Turn with the
person's Slack Actor cannot create or delete automations, even when the
tools are called directly.
- `prompt.test.ts`: the Turn context lists disabled tools.

**Not in scope**

- Automation dispatch Conversations also change the system prompt, so a
stable tool list alone does not keep the cache there.
- Plugin tools cannot set `disabledReason` yet. No plugin tool changes
by Turn today.

Eval recordings will change, because more Turns now send these tools.

<!-- junior-request-attribution:start -->
via **David Cramer**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AC0B595QDZLL%3A1792042432.276599 -->

--

[View Junior
Session](https://junior-prod.sentry.dev/conversations/slack%3AC0B595QDZLL%3A1792042432.276599)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0B595QDZLL%3A1792042432.276599/?project=4510944073809921)

<!-- junior-session-footer:end -->

---------

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — bbec6ddc Deployed Sep 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant