Commit 7f8f845
feat(chat): reorder harness markers and split compaction buckets (#222)
## 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`):
- Order (top → bottom): `<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.
- Drops legacy `<current-message>` / `<thread-conversation-context>`
wrappers.
- No explanatory prose inside markers — tag names carry the signal.
Changes in `packages/junior/src/chat/services/conversation-memory.ts`:
- `buildConversationContext` wraps 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.
- `summarizeConversationChunk` prompt 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
- [ ] Sanity-check the new `buildUserTurnText` output 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.
- [ ] Spot-check one compacted conversation in a real thread to confirm
the summarizer is producing the three-bucket XML (active / superseded /
facts) rather than a free-form paragraph. Because the summarizer is
model-generated, the prompt change only shapes output — run against the
production fast model to verify it complies.
- [ ] Decide whether this should be gated behind an eval sweep on both
Sonnet and GPT-5 gateway models before relying on the new marker shape
for production traffic. This PR does not add such an eval.
### Notes
- Intentionally preserved the `<thread-transcript>` /
`<thread-compactions>` marker names; routing fixtures in
`tests/unit/routing/subscribed-decision.test.ts` still reference them.
- No runtime behavior change beyond the emitted prompt text; no new
dependencies, no schema changes. Compaction storage format (`summary:
string`) is unchanged — only the prompt that generates it is updated.
- Pre-existing unit-test failure
`tests/unit/services/turn-checkpoint.test.ts > reuses the latest stored
transcript…` reproduces on `main` (requires `REDIS_URL`) and is
unrelated to this PR.
- Follow-up candidates (not in this PR): add an eval that exercises
narrow-then-broaden instruction drift across a compacted thread;
consider also marking the assistant's own prior tool calls with an
`executed` flag in `<message>` wrappers.
Link to Devin session:
https://app.devin.ai/sessions/f46faf27a4354f7dab95abd8dfc50211
Requested by: @dcramer
---------
Co-authored-by: devin-ai-integration[bot] <158243448+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin <devin@cognition.ai>
Co-authored-by: Devin <devin-ai-integration[bot]@users.noreply.github.com>1 parent 80673e4 commit 7f8f845
4 files changed
Lines changed: 73 additions & 33 deletions
File tree
- packages/junior
- src/chat
- services
- tests/unit
- misc
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
147 | 151 | | |
148 | 152 | | |
149 | 153 | | |
| |||
153 | 157 | | |
154 | 158 | | |
155 | 159 | | |
156 | | - | |
157 | | - | |
| 160 | + | |
| 161 | + | |
158 | 162 | | |
159 | | - | |
| 163 | + | |
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
172 | | - | |
173 | | - | |
| 171 | + | |
174 | 172 | | |
175 | | - | |
| 173 | + | |
| 174 | + | |
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | | - | |
| 178 | + | |
180 | 179 | | |
181 | | - | |
182 | 180 | | |
183 | | - | |
| 181 | + | |
184 | 182 | | |
| 183 | + | |
185 | 184 | | |
186 | 185 | | |
187 | 186 | | |
188 | | - | |
| 187 | + | |
189 | 188 | | |
190 | | - | |
191 | 189 | | |
192 | | - | |
| 190 | + | |
193 | 191 | | |
| 192 | + | |
194 | 193 | | |
195 | 194 | | |
196 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
197 | 202 | | |
198 | 203 | | |
199 | 204 | | |
| |||
Lines changed: 30 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
155 | 161 | | |
156 | 162 | | |
157 | 163 | | |
| |||
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
| 175 | + | |
169 | 176 | | |
170 | 177 | | |
171 | 178 | | |
172 | 179 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
179 | 183 | | |
180 | 184 | | |
181 | | - | |
182 | | - | |
| 185 | + | |
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
186 | | - | |
187 | | - | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
188 | 200 | | |
189 | 201 | | |
190 | 202 | | |
| |||
240 | 252 | | |
241 | 253 | | |
242 | 254 | | |
243 | | - | |
244 | | - | |
245 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
246 | 263 | | |
247 | 264 | | |
248 | 265 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
0 commit comments