Skip to content

Multi-line tool-error payloads leak past the focused-query filter and bias the memory judge toward safety facts #824

Closed

Description

@maxivillus

Summary

focus_query_text (crates/jcode-base/src/memory_prompt.rs) strips tool noise by
dropping lines that start with [Tool error: / [Tool:, but tool-error
payloads are multi-line and only the first line carries that prefix. Subsequent
lines of the error message pass through into the focused query, the retrieval
context, and the LLM judge. Sandbox command-safety rejections in particular —
"This command was not run...", "cannot be confirmed", "is irreversible", "could
not be identified statically" — are lexically close to safety/governance memory
facts, so they shift the judge's votes away from the actual topic.

Impact

Verified in an ACP task (NTL-486): the agent's tool calls tripped the sandbox on
protected commands; the multi-line [Tool error: ...] blocks reached the judge,
which then injected 5 safety-related facts instead of the token-related fact the
task actually asked about. The throttle had fired and the pool was large (30/22
candidates) — the loss was caused by the noisy judge input, not by retrieval
coverage. Any host whose tasks run under restrictive tool policies (read-only
review, sandboxed containers, blocked globs/recursive deletes) hits this
constantly.

Root cause

format_content_block_for_relevance wraps an error payload in a single block:

ContentBlock::ToolResult { content, is_error, .. } => {
    if is_error.unwrap_or(false) {
        Some(format!(
            "[Tool error: {}]",
            truncate_chars(content.trim(), MEMORY_CONTEXT_MAX_BLOCK_CHARS / 4)
        ))
    } else {
        None
    }
}

The payload keeps its internal newlines, so focus_query_text, which iterates
line-by-line, drops only the first line:

if trimmed.is_empty()
    || trimmed.starts_with("[Tool:")
    || trimmed.starts_with("[Tool error:")
    || ...
{
    continue;
}

The remainder — e.g. - target contains a glob, so the exact set of affected files is not known before execution (target: /sys/...) or - targets a protected system or home path that must never be destroyed (target: a user home dir) — is treated as
session prose and kept in the focused query.

Proposed change (implemented and verified locally)

Drop command-safety block errors by content, not only by the [Tool error:
prefix:

if trimmed.is_empty()
    || trimmed.starts_with("[Tool:")
    || trimmed.starts_with("[Tool error:")
    || trimmed.starts_with("[Result:")
    || trimmed.starts_with("[Image]")
    || trimmed.starts_with("[OpenAI native compaction]")
    // Multi-line error payloads only carry the prefix on the first line; drop the
    // sandbox-block markers wherever they appear so safety wording cannot steer
    // retrieval or the judge toward safety facts.
    || trimmed.contains("This command was not run")
    || trimmed.contains("cannot be confirmed")
    || trimmed.contains("is irreversible")
    || trimmed.contains("could not be identified statically")
    || trimmed.contains("could not be identified")
{
    continue;
}

A more general fix would track "inside a [Tool error: block" state across lines
(like the existing <system-reminder> handling) instead of a marker list; the
marker list above is the minimal, backward-compatible version.

Environment

  • jcode v0.68.0, Linux x86_64, DeepSeek provider, local all-MiniLM-L6-v2 embeddings.
  • ACP protocolVersion 1, host: Multica daemon; 2-vote consensus judge
    (memory_rerank_votes = 2).
  • Verified locally: with the content filter, the judge no longer sees sandbox
    wording and votes on the actual topic.

Activity

  1. added
    bug
    triage: reproducible
    autonomous: likely
    on Aug 7, 2026
  2. 1jehuang commented on Aug 8, 2026

    @1jehuang
    Owner

    Fixed on agent/triage-2026-08-07 in commit 9d75bf606. Tool-error blocks are structurally normalized so multiline payloads cannot leak into focused memory queries, while later user prose remains intact. All 45 focused memory tests pass.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  3. added
    triage: fixed-pending-release
    on Aug 8, 2026
  4. 1jehuang commented on Aug 8, 2026

    @1jehuang
    Owner

    The validated fix is now available for review in #841 on a clean branch based on the public default branch.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  5. added a commit that references this issue on Aug 8, 2026
    35e9e4b
  6. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  7. added 5 commits that reference this issue on Aug 30, 2026
    058d7d4
    23bbc44
    0960775
    de72a5b
    d8b6bab
  8. added a commit that references this issue on Sep 18, 2026
    b7b5977
  9. added a commit that references this issue on Oct 9, 2026
    e2e161b
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

    autonomous: likelybugtriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions