DSH plugin normalization: what happens before prepare
"The referenced content was rewritten" almost always happens before prepare is called: a host folds normalization and cleanup into one step and processes bytes that should have been preserved. DSH plugin's boundary is simple: the host shapes input, prepare removes markers, and the snapshot preserves bytes.
DeepSeek Harness: Referenced content does not match the source
Look in host preprocessing first, not in the service. (source) A typical scene:
source: const x = 1 // two spaces
reference: const x = 1 // one space
If the host merged consecutive spaces before submit, the snapshot differs. The service did not rewrite anything; upstream did.
The test: hand the same content to prepare without host processing and compare. Identical results point at host processing; differences that persist point at the service.
DeepSeek Harness: Three processing stages
Three stages with separate owners; folding them together cancels each other out. (source) Comparison:
| Stage | Owner | What it does |
|---|---|---|
| Input normalization | Host | Converts editor content into readable blocks |
| Token removal | prepare | Deletes mention markers from the body |
| Snapshot preservation | prepare | Carries referenced content byte-for-byte |
Stage one produces content; stages two and three happen inside prepare.
Many teams move token removal into stage one, after which prepare cannot find the markers and loses the ability to tell body text from reference markers.
DeepSeek Harness: Three things hosts should normalize
Handle input shape only, never semantics. (source) Three items:
- Editor structure — turn rich text, lists, and code blocks into content blocks;
- Private markers — remove placeholders that exist only for UI display, but keep mention markers;
- Invalid control characters — clean characters that would break parsing.
Be careful with the third: remove only genuinely invalid characters, and do not treat tabs or newlines as dirt.
A useful standard: normalized content should match what the user sees, not the internal representation of a layout engine.
DeepSeek Harness: Three things hosts must not touch
All three are display polish and do not belong in the submit path. (source) Comparison:
| Action | Sounds reasonable | Actual problem |
|---|---|---|
| Merge consecutive spaces | Tidier content | Rewrites code and layout |
| Convert full-width to half-width | Uniform punctuation | Changes the user's text |
| Append missing periods | Complete sentences | Adds content from nothing |
What they share: the service cannot tell the original from the optimized result. Once written into a snapshot, the original cannot be restored.
If a product wants cleaner presentation, do it in the render layer rather than editing submitted content.
DeepSeek Harness: The boundary table
One boundary, three roles; follow the table. (source) Boundary:
| Content | Host | prepare |
|---|---|---|
| Mention markers | Keep | Remove |
| User body | Normalize into content blocks | Carry as-is |
| Referenced session content | Do not touch | Preserve by bytes |
This table settles most disputes: the host touches only its own input, and the service touches only markers and snapshots.
The telltale sign of a violation is string replacement over referenced content inside host code.
DeepSeek Harness: Testing the scope of differences
Four cases keep differences within the expected range. Steps:
- A message with consecutive spaces keeps the same count before and after referencing;
- A message with CRLF keeps its line endings;
- A message with full-width punctuation keeps that punctuation;
- A message with a mention loses the marker while the body stays complete.
Cases 1 and 2 target the most common "cleanup rewrites", and case 4 confirms token removal did not eat body text.
Four passes mean normalization affected input shape only.
If normalization fails, reject the submit rather than forcing the raw string into content and asking prepare to parse a reference it cannot recognize.
With the boundary clear, budgeting is next. Read the DSH plugin reference budget and 64 KiB fallback; to see which processing rewrites content, read DSH plugin byte preservation; for the wider picture, read how DSH plugin implements session references.
Sources: DeepSeek Harness reference - Session references, session-reference/src/index.ts
FAQ
Look at host preprocessing first in a DSH plugin reference. If a host merges spaces or normalizes line endings before submit, the snapshot differs even though DSH plugin never rewrote anything.
No, token removal is DSH plugin prepare's job. Deleting markers early means prepare cannot distinguish body text from reference markers and may treat the content differently.
No, that changes the user's original text and violates DSH plugin byte preservation. DSH plugin's byte preservation treats it as a rewrite, not cleanup, even if the result looks tidier.
Reject the submit in DSH plugin instead of passing the raw string into content. DSH plugin expects normalized readable blocks, and a host-side failure should not become a parsing problem downstream.
Related Terms
- input normalization
- Input normalization converts editor content into readable content blocks and is a host responsibility.— DeepSeek Harness reference - Session references
- token removal
- Token removal deletes host mention markers from the body during prepare.— session-reference/src/index.ts
- snapshot preservation
- Snapshot preservation carries referenced content byte-for-byte rather than by display needs.— DeepSeek Harness reference - Session references
- boundary table
- The boundary table assigns each kind of content to the host or to prepare to prevent overlapping edits.— DeepSeek Harness reference - Session references
Sources
- DeepSeek Harness reference - Session references· deepseek-ai
- session-reference/src/index.ts· deepseek-ai