Skip to content

[Bug]: stripHallucinations deletes legitimate <dcp-*> blocks from tool output, silently truncating file reads #657

Closed

Description

@sexychina

Bug Description

stripHallucinationsFromString() is applied to every completed tool part's state.output as well as to text parts (dist/index.js, stripHallucinations()). Two of the regexes used there delete everything between a <dcp...> opener and a </dcp...> closer:

var DCP_PAIRED_TAG_REGEX = /<dcp[^>]*>[\s\S]*?<\/dcp[^>]*>/gi;
var DCP_UNPAIRED_TAG_REGEX = /<\/?dcp[^>]*>/gi;

Because this runs on tool output, any tool result that legitimately contains such a block is silently truncated before the model sees it. That includes reading this plugin's own source and prompt files, its docs, or any third-party file that happens to quote a reminder block. The model has no way to know that content was removed; it just sees a shorter string.

Concrete case: DCP's own default prompts (lib/prompts/turn-nudge.ts, iteration-nudge.ts, context-limit-nudge.ts, system.ts) are wrapped in the reminder tags. read on node_modules/@tarquinen/opencode-dcp/lib/prompts/turn-nudge.ts returns only lines 1 and 10 (the `export const ... = `` line and the closing backtick). Every line of actual instruction text is gone.

Expected Behavior

  • Tool output should not be rewritten. Either restrict stripHallucinations to text parts, or replace matched blocks with a visible marker (for example [dcp reminder removed]) instead of deleting their content, so the model can tell that something was elided.
  • If stripping tool parts has to stay, it should not delete content the model has not seen yet: it turns legitimate files into empty strings and makes pasted user content disappear (see below).

How to see it

  1. DCP 3.2.0, OpenCode V2, default settings, idFormat: xml.
  2. Write a file /tmp/t.txt containing AAA, a blank line, an opening <dcp-system-reminder> tag, the line HELLO-INSIDE, the matching closing tag, a blank line, and ZZZ.
  3. Ask the agent to cat /tmp/t.txt. The tool result delivered to the model is only AAA and ZZZ; HELLO-INSIDE and both tags are gone.
  4. Same with read on node_modules/@tarquinen/opencode-dcp/lib/prompts/turn-nudge.ts: only the first and last line come back.
  5. User messages take the same path: pasting a reminder block into the prompt arrives at the model as an empty message.

This is deterministic, unlike the intermittent cases in #642 / #632, which are about tags the model writes into its reply.

My guess (not confirmed)

stripHallucinations() was written for text the model produced — it also removes hallucinated mN</parameter> and <dcp-message-id>...</dcp-message-id> suffixes. Applying it to part.state.output extends a text-hygiene step to content the model never generated, so it can only produce false positives there.

Debug Context Logs

No DCP debug log captured; the reproduction above is deterministic and needs none. The stripped result is observable directly in the tool result the model receives.

DCP Version

3.2.0

Opencode Version

v2.0.29

Model

DeepSeek Flash (deepseek-flash)

Additional Context

  • Also observed: the unpaired-tag regex leaves stray characters behind when a suffix is stripped by INJECTED_MESSAGE_ID_SUFFIX_REGEX / HALLUCINATED_PARAMETER_SUFFIX_REGEX, which shows up as a lone " at the end of a reply. Separate from the deletion issue, but caused by the same function.
  • Workaround in use locally: none for tool output; there is no config switch to disable this pass, and autoUpdate means a local patch to dist/index.js would be overwritten.
  • Definition of done: reading a file that contains a <dcp-*> block returns that file's full contents.

Activity

  1. Tarquinen commented on Nov 16, 2026

    @Tarquinen
    Owner

    Fixed in #680 (merged into dev). It will ship in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions