DSH plugin reference cancel: no publish, even after storage
Cancellation does not mean "stop as fast as possible"; it means "do not publish even if the result is already computed". DSH plugin guarantees that storage completing after a cancel still will not put context into the message. Without a signal from the host, that guarantee does not exist.
DeepSeek Harness: The user stopped, but context still appeared
First check whether the signal reached prepare. (source) Scene:
User clicks stop
Host resets UI state but never aborts the request
prepare keeps running, storage completes, context publishes
The next message carries referenced content
From the user's view, it kept running after stopping; in the chain, cancellation stopped at the UI layer.
Diagnose by logging the error branch: look for SESSION_REFERENCE_CANCELLED. If it never appears, cancellation never arrived.
DeepSeek Harness: Where the cancellation boundary sits
On one prepare call, not globally. (source) Rules:
prepare(agent, content, references, signal)takes an optional signal;- When passed, it is the cancellation boundary for this turn;
- Cancellation affects this preparation only, not other messages;
- Without a signal, prepare never guesses that the user might want to stop.
The fourth point means cancellation is a host responsibility, not a service default.
DeepSeek Harness: Storage completion vs cancellation
Two orders; both must end in "do not publish". (source) Comparison:
| Order | Storage | Cancellation | Result |
|---|---|---|---|
| 1 | Completes first | Arrives later | Not published |
| 2 | Completes later | Arrives first | Not published |
The second is the hard case: when cancellation arrives, data is still being written, but finished data is still unusable.
The official wording is direct: cancellation prevents publication, including when storage completes after cancellation.
Implementation-wise this requires checking cancellation again before publishing, not only at the entry.
DeepSeek Harness: Which error code to return
Return SESSION_REFERENCE_CANCELLED; never an empty context. (source) Three reasons:
- An empty context means "no referenced content", which is a different meaning;
- The code lets callers distinguish a user stop from an empty reference set;
- Logs can measure cancellation frequency and inform UX work.
Swallow the cancellation and return success, and the user sees context appear on the next message.
The reverse is also wrong: returning CANCELLED for every failure hides real problems. Use the code that matches the cause.
DeepSeek Harness: Four host actions after cancel
Four things, in order. (source) Steps:
- Stop writing this preparation's result into the message;
- Keep the user's selected references but mark them "not applied";
- Do not retry automatically unless the user sends again;
- Record the cancellation reason to separate manual stops from timeouts.
The second is easy to miss: after cancelling, a resend should not require reselecting everything.
The fourth is useful product data: frequent cancellations may mean preparation is slow, not that users are fickle.
One timing detail remains: check the signal again before publishing. Check only at entry and storage can finish after the cancel, letting context slip into the message anyway.
DeepSeek Harness: Testing the race
Two race cases plus a control. Steps:
- Cancel right after preparation finishes and confirm no context is published;
- Cancel mid-preparation, delay storage so it completes after cancel, and confirm no context is published;
- Pass no signal and confirm normal publication as a control.
Case 2 needs artificial storage delay; otherwise it is hard to trigger.
Case 3 proves the test harness is not cancelling by accident.
Three passes mean cancellation is checked both at the entry and before publication.
After cancellation comes the security boundary. Read why DSH plugin marks referenced context untrusted; for error mapping, read the seven DSH plugin reference error codes; for the wider picture, read how DSH plugin implements session references.
Sources: DeepSeek Harness reference - Session references, session-reference/src/index.ts
FAQ
Most likely the signal never reached DSH plugin prepare. DSH plugin publishes nothing after cancellation, but only if the host actually passes a signal and aborts it; cancelling UI state alone does not stop the request.
DSH plugin returns SESSION_REFERENCE_CANCELLED when cancellation happens. Returning an empty context instead blurs user cancellation with an empty reference set and hides the event from logs.
The DSH plugin guarantee is about publication, not about undoing work. Even if storage completes after the cancel, the context must not be published.
DSH plugin file reference cancellation stops discovery, while session reference cancellation blocks publication of prepared context. They share the signal shape but act at different stages.
Related Terms
- signal
- The optional signal on prepare marks the cancellation boundary for one turn.— DeepSeek Harness reference - Session references
- SESSION_REFERENCE_CANCELLED
- SESSION_REFERENCE_CANCELLED is the stable error code returned when a session reference call is cancelled.— DeepSeek Harness reference - Session references
- publication
- Publication is the step that places prepared context into the message; cancellation blocks it regardless of storage timing.— session-reference/src/index.ts
- race window
- The race window is the interval between starting preparation and publishing, during which a cancellation may arrive.— DeepSeek Harness reference - Session references
Sources
- DeepSeek Harness reference - Session references· deepseek-ai
- session-reference/src/index.ts· deepseek-ai