Conversation
…ecedence Put thread background first, latest user instruction last, and add an explicit instruction-precedence block. Wrap per-compaction and per-message items with metadata attributes so they read as individual references instead of one flat blob. Split compaction summaries into active-asks / superseded-or-completed-asks / facts buckets so stale or completed asks stop reading as currently active. Rationale and citations in #221. Co-Authored-By: Devin <devin@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Shrink JSDocs on buildUserTurnText and buildConversationContext to the intent only, drop the redundant <thread-background> preamble (the precedence block already covers it), fold the single-use attr helpers into buildConversationContext, and collapse single-line section pushes. No behavior change. Co-Authored-By: Devin <devin@cognition.ai>
…er block Keep <latest-user-instruction> as the final block of the user turn so the model sees the active ask last, and move <instruction-precedence> to the top of the wrapper so the reconciliation rules frame the context that follows. Each marker (<thread-background>, <session-context>, <turn-context>, <latest-user-instruction>, and the <thread-compactions>/<thread-transcript> blocks inside background) now opens with a one-line purpose statement so the role of every block is self-describing. Co-Authored-By: Claude sonnet-4.5 <devin-ai-integration[bot]@users.noreply.github.com>
Tag names are the system markers; they do not need an explanatory sentence inside each block. Remove the <instruction-precedence> wrapper and the descriptor lines from <thread-background>, <session-context>, <turn-context>, <latest-user-instruction>, <thread-compactions>, and <thread-transcript>. Behavior-relevant structure (ordering, per-compaction/per-message metadata, priority="highest" on the latest instruction) is preserved. Co-Authored-By: Claude sonnet-4.5 <devin-ai-integration[bot]@users.noreply.github.com>
…ion> The 'user' qualifier is implicit in the turn context and 'current' is more direct than 'latest'. Attribute (priority="highest") and placement (final block of the wrapper) are unchanged. Co-Authored-By: Claude sonnet-4.5 <devin-ai-integration[bot]@users.noreply.github.com>
specs/testing/unit-spec.md:47 bans unit tests that assert exact or substring prompt prose on prompt builders. Keep only the pure-logic branch cases (raw pass-through, empty-conversation undefined) and defer structural XML validation to integration or eval coverage. Co-Authored-By: Claude sonnet-4.5 <devin-ai-integration[bot]@users.noreply.github.com>
The local escapeAttr only handled double quotes, so author names and slack_ts values containing &, <, or > would produce malformed XML attributes. Swap to the shared escapeXml utility from @/chat/xml, which covers all five XML special characters. Co-Authored-By: Claude sonnet-4.5 <devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reshapes the user-turn prompt wrapper and thread-background rendering so Claude Sonnet and GPT-5 treat the current instruction as authoritative and prior thread context as read-only reference material. Addresses the failure mode tracked in #221 and
getsentry/junior-prod#35, where Junior drifts onto a narrowed-but-superseded ask from earlier in a thread.Changes in
packages/junior/src/chat/respond-helpers.ts(buildUserTurnText):<thread-background>,<session-context>,<turn-context>,<current-instruction priority="highest">—<current-instruction>is always the final block, matching Anthropic's long-context guidance to place the active query last.<current-message>/<thread-conversation-context>wrappers.Changes in
packages/junior/src/chat/services/conversation-memory.ts:buildConversationContextwraps each compaction in<compaction index=… covered_messages=… created_at=…>and each transcript entry in<message index=… ts=… role=… author=… slack_ts=…>, so each prior item is an individually addressable reference instead of a flat blob.summarizeConversationChunkprompt now produces three fixed sections —<active-asks>,<superseded-or-completed-asks>,<facts>— so stale or already-acted-on asks stop reading as live constraints after compaction.Rationale and authoritative prior art (Anthropic long-context guide, OpenAI GPT-5 prompting guide, OpenAI Model Spec chain-of-command) are cited in #221.
Review & Testing Checklist for Human
buildUserTurnTextoutput shape against a real thread turn (e.g. local dev or an eval snapshot) and confirm the final tag emitted is</current-instruction>and<thread-background>precedes it.Notes
<thread-transcript>/<thread-compactions>marker names; routing fixtures intests/unit/routing/subscribed-decision.test.tsstill reference them.summary: string) is unchanged — only the prompt that generates it is updated.tests/unit/services/turn-checkpoint.test.ts > reuses the latest stored transcript…reproduces onmain(requiresREDIS_URL) and is unrelated to this PR.executedflag in<message>wrappers.Link to Devin session: https://app.devin.ai/sessions/f46faf27a4354f7dab95abd8dfc50211
Requested by: @dcramer