Skip to content

fix(chat): Preserve the active request through handoff - #1938

Merged
dcramer merged 15 commits into
mainfrom
test/handoff-current-instruction
Sep 26, 2026
Merged

dcramer merged 15 commits into
mainfrom
test/handoff-current-instruction

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

Summary

Handoff discarded the authored request and used a generated summary as the new instruction. Old PR-maintenance rules could replace the current task and cause the agent to stop without doing the work.

  • Retain the latest authored instruction and its provenance before the handoff summary.
  • Escape generated summaries inside an evidence-only thread-context block. Copied instruction tags must not create a new active request.
  • Keep open-plan state and the runtime-owned completed-handoff fact outside that evidence block. The completed fact prevents repeated model switches.
  • Persist fresh input with instruction provenance.

Regression evidence

The reduced live eval reproduced task abandonment before the fix at 046f8be04: the agent called handoff, received a summary saying “No known code work remains,” then replied about old work without editing the cleanup fixture. It ended normally, not by timeout. The explicit-request control passed.

Before-fix CI evidence

The unchanged live pair passed after the fix at 69158bb64: both requests called handoff, completed cleanup, and delivered replies.

After-fix CI evidence

The reduced eval reproduces task abandonment, not production’s exact silent ending. The production trace showed the resumed agent returning [[NO_REPLY]]. Successful live runs do not establish a zero recurrence rate.

Validation

After cleanup at fa6feea9a:

  • 27 focused Junior component tests passed.
  • The eval harness transcript component test passed.
  • Core and eval typechecks passed.
  • Core lint, dependency checks, file-length, test-architecture, formatting, and ast-grep checks passed.

Before cleanup, all 726 component tests passed. Cleanup removed the research diary and temporary diagnostic dumps, simplified a test assertion, and shortened comments. Live eval inputs and outcome assertions are unchanged. No new live eval run was needed for that cleanup.

The cited integration shard remains red on two unrelated assertions: a delivery case omitted reportProgress, and event discovery made two searches where its assertion expected one. Both eval files are unchanged, and neither failing session used handoff. Those assertions were not changed or bypassed.

via David Cramer.

--

View Junior Session [Sentry]

@vercel

vercel Bot commented Sep 25, 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 26, 2026 1:29am UTC

Request Review

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

3 screenshot changes — 3 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Detail · Desktop
Conversation Detail · Desktop
Changed
Conversation Event Log · Desktop
Conversation Event Log · Desktop
Changed
System Cache Missing · Desktop
System Cache Missing · Desktop
Changed

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

Test whether missing prior tool results make the old coding task appear unfinished. Keep the paired requests, models, and completion assertions unchanged.

Co-Authored-By: David Cramer <[email protected]>
@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

The fixed standard destination became a no-op when routing selected standard. Keep the task and history unchanged and request the other configured profile.

Co-Authored-By: David Cramer <[email protected]>
@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

Replace contradictory prior write and PR claims with the requested edit and a verified Node check. Keep the live cleanup requests and assertions unchanged.

Co-Authored-By: David Cramer <[email protected]>
@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

Keep the latest committed instruction with its provenance before the handoff summary, as active compaction does. Treat the summary as context rather than a replacement instruction. Mark fresh input explicitly so actorless local runs retain it too.\n\nThe existing regression fails without the fix. All 726 component tests, typecheck, and lint pass. Keep the live reproduction unchanged for the CI control.

Co-Authored-By: David Cramer <[email protected]>
@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

The unchanged live control repeated handoff because summaries marked the switch unconfirmed. Summarization runs before the tool result. Keep the committed target in continuation context so the next model can see that the switch completed. Leave the eval input and assertions unchanged.

Co-Authored-By: David Cramer <[email protected]>
@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

Escape generated summary text in the existing thread-context block for handoff and both compaction paths. Keep authored instructions, open plan state, and completed handoff facts separate.

Extend the existing retention regression with copied instruction tags. It fails before this change and passes after it. All 726 component tests, typecheck, lint, dependency, file-length, and test-architecture checks pass.

Co-Authored-By: David Cramer <[email protected]>
@sentry-evals

sentry-evals Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

@dcramer
dcramer marked this pull request as ready for review September 26, 2026 01:25
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Sep 26, 2026
Keep the runtime rule beside the code. Remove the experiment diary and temporary eval event dumps. Simplify the instruction-retention assertion without changing live inputs or outcome checks.

Co-Authored-By: David Cramer <[email protected]>
@sentry-junior sentry-junior Bot changed the title test(chat): Cover lost requests after model handoff fix(chat): Preserve the active request through handoff Sep 26, 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 fa6feea. Configure here.

@dcramer
dcramer merged commit 69bdeda into main Sep 26, 2026
46 of 47 checks passed
@dcramer
dcramer deleted the test/handoff-current-instruction branch September 26, 2026 01:38
@sentry-evals

sentry-evals Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

In progress

junior-behavioral

Run Status
Base Pending
Head (CI run) Complete

@sentry-evals

sentry-evals Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

In progress

junior-integration

Run Status
Base Pending
Head (CI run) Complete

dcramer added a commit that referenced this pull request Oct 3, 2026
Moves the handoff continuity evals to the agent test fixture from #2001.
They are the first eval files in a suite, as proposed in the issue
comment on suites with shared setup.

A suite is a Vitest project for one directory. The `coding` project runs
`evals/integration/coding/`. It points the fixture at
`agent-options.ts`, whose default export is the `createApp()` options of
every test in the suite: the GitHub and memory plugins. It also adds the
coding skills with `SKILL_DIRS`, the same host setting production reads.
Tests call `run()` with no `agent()` call. `agent(options)` replaces the
suite defaults key by key.

```ts
test(`finishes the cleanup after handoff: ${label}`, async ({ run }) => {
  await insertMemory({ content: "Deslop means cleaning the entire changeset: ...", kind: "procedure" });
  const conversation = await run(mention(`Switch to the other configured profile first. ${instruction}`), {
    history: handoffHistory(),
  });
  // a completed handoff, then an editFile that removes the class and the factory
});
```

**Fixture changes**

- `insertMemory({ content, kind })` writes a memory about a Slack person
through the memory plugin store. The old case stored a conversation
memory, but a test cannot know a Conversation id before `run()`. A
memory about the person is recalled in every later Conversation of that
person.
- `reply(text, { toolHistory })` now takes `{ name, arguments, result }`
items. The loader builds the model messages. Before, tests built Pi
messages with `fauxAssistantMessage`, which the test rules forbid.
- The history loader now matches two details of real Slack turns. An
input that addresses Junior and has no reply stores the `[[NO_REPLY]]`
assistant message, as a real turn that stays silent does. Slack text
goes through the same markdown conversion as Slack ingress, so `[task]`
reaches the model as `\[task]`. The loader comparison test adds a real
Slack turn without a reply. A plain thread message that does not address
Junior still loads without an answer.
- A `handoff` event now completes the tool call that triggered it. A
handoff replaces agent history, so the reporting API never gives that
call a tool result, and the call stayed `running`. The dashboard already
shows the handoff event in place of the call. Without this change, both
cases failed on runs where the agent handed off and made the correct
edit.

**Fidelity to #1938**

This case is the live reproducer from #1938: after a handoff, the
summary said no code work remained, and the agent replied about old work
without the edit. The model must see the same history as before. The old
harness stored an assistant `[[NO_REPLY]]` after each maintenance task,
and the first version of this move dropped those messages. The loader
fix above restores them. Memory recall was checked on a real turn: the
inserted memory appears in the turn's recall context. In the terse case,
the standard model hands off one time, and the handoff model makes the
edit from the summary. In the explicit-request control, the router can
start on the handoff model. That model then obeys "switch to the other
profile", and the standard model hands back. The assertion looks for an
edit after the first handoff, as before.

**Review focus**

- `vitest.evals.integration.config.ts`: the projects do not extend the
root config. The root config owns the global setup, so the egress tunnel
and the Postgres template start one time. Vitest gives what the root
setup provides to every project. The CI shard command and the result
file do not change.
- Each `coding` test logs
`plugin.session.completed_task_schedule.failed`. After a turn, the
memory plugin sends its extraction task to the Vercel queue, and the
fixture cannot replace that queue yet. This case does not need
extraction. #2001 now tracks a `createApp()` plugin task queue option,
which must land before the memory evals move.

Refs #2001

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
dcramer added a commit that referenced this pull request Oct 7, 2026
…2055)

Integration evals failed in 26 of the last 60 workflow runs, and five
cases caused almost all of the failures. Four of them showed a product
gap. The fifth tested its contract in a slow way. This change fixes each
cause, so the evals are a stable base for the rest of #2001.

| Flaky case | Cause | Change |
| --- | --- | --- |
| Repo-wide event automation | Core stored `resourceType: "issue"` with
the identifier `getsentry/junior`. Nothing checked that an identifier
fits its resource type. | A resource type can declare its identifier
shape. Core rejects a mismatch. |
| "What events are available" | Event type search needed every query
word to match. "GitHub events" returned nothing, so the agent searched
again. | One matching term is enough. More matching terms rank first. |
| Event automation with system credentials | Guardian compared the
automation's `credentialMode` with the credential fact of the current
action, then asked the user to confirm what they had requested. | One
sentence in the Guardian policy, and a Guardian eval case. |
| Reminder that names the requester | "Use a Slack mention" was only
text in a tool description. The agent stored "Remind Test User", which
notifies nobody. | The create and update tools reject an instruction
that names the requester without their mention. |
| Handoff continuity | A normal turn took 50 to 75 seconds, and the idle
budget is 60. | The eval is one short case with no sandbox work. |

## Event identifier shapes

`events.resourceTypes[].identifier` is a new optional field of the
plugin event contract: `{ format, pattern }`. GitHub declares it for all
five resource types. Watches, event automation tools, and dashboard
edits use the same check. Event type search returns the format.

The agent now gets this error and corrects the call:

```
Identifier "getsentry/junior" does not fit resourceType "issue" in namespace "github". Expected format: "owner/repo#number". If the identifier is correct, use one of these resourceType values: "repository".
```

A resource type without a declared shape accepts any identifier, as
before. Linear has the same ambiguity between `issue` and `team` and
does not declare a shape yet.

## Requester mention

This is a behavior change. An instruction that contains the requester's
display name must also contain `<@U…>`. The check covers only the
requester, because that is the one name core can map to a user ID. An
update is checked only when it changes the instruction.

## Handoff eval

The old eval made the agent do a full code cleanup after the handoff.
Most of the time went to sandbox work that the contract does not need,
and the explicit-request variant passed before #1938, so it protected
nothing.

The new case keeps the same history and the forced profile switch. The
request is a term that only memory defines: give a review verdict as a
reaction. The eval asserts a completed `handoff` and then an
`addReaction`.

| | Result |
| --- | --- |
| With the #1938 fix | 8 of 8 passed, 32 to 40 seconds |
| Retained instruction removed from `compactContextForHandoff` | 3 of 8
passed. Four failures showed the original symptom: the agent said the
old work was done and gave no verdict. |

The summary sometimes carries the request by itself, so the eval does
not fail every time without the fix. #1938 recorded the same limit.

## Evidence

Each case was sampled in one run after its fix:

| Case | CI failures before (of about 27 runs) | After |
| --- | --- | --- |
| Repo-wide event automation | 7 | 8 of 8. Four runs sent `issue` first,
got the error, and corrected to `repository`. |
| "What events are available" | 3 | 6 of 6 |
| System credentials | 3 | 30 of 30 isolated Guardian reviews (25 of 30
before), 8 of 8 end to end |
| Requester mention | 5 | 10 of 10 |
| Handoff continuity | 8 | 8 of 8 |

## Also in this change

`conversation-turn-work.test.ts` polled 5 seconds for a title that comes
from a live model call, and it failed once on `main`. It now awaits the
title work that the worker gives to `waitUntil`.

## Not fixed

- Two cases failed one time each: the agent added a title to a
reschedule that the user did not request, and one judge score in
scheduler credentials. They are too rare to verify a fix.
- `watched-message-behavior.test.ts` failed one CI run on an error after
teardown. It has no teardown and belongs to the passive routing group of
#2001.

Refs #2001

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

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

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant