Skip to content

[Bug]: Preserve Harness request context and native tool-call history #3737

Closed

Description

@Buktal

Problem

On 2.1.0-SNAPSHOT at db0b67eb8e2d8ca89a6b59691cca51e3032d26a1, several request-boundary paths lose information or misrepresent its source:

Trigger Current behavior Expected behavior
A user message contains an image and an @path reference Expanding the reference rebuilds the message as text and drops the image Retain the original blocks and metadata, then append a bounded file preview
A background notification arrives before reasoning The inbox is consumed and history is updated, but the current model-input snapshot can miss the notification; a notification can also be appended to assistant speech Deliver a separate, identified context message to both the next request and durable history
Plan mode changes before the model call The implemented refresh hook is excluded from middleware scheduling Refresh the active system policy at the real model boundary
A tool's arguments are truncated or malformed Invalid arguments can become {} and reach the handler; a valid object followed by malformed text can pass lenient validation Reject the incomplete call and return an error with its original ID; retain executable siblings
Anthropic history contains multiple thinking blocks or parallel tools Thinking signatures/boundaries can be lost, and parallel calls are rewritten as serial exchanges Preserve native block order, signatures, and the assistant-call/user-result batch

Two small prompt changes support the same goal: use the existing slim skill-catalog view while retaining loadable IDs, and ask compaction to retain still-active user constraints, corrections, acceptance criteria, and authorization wording.

Reproduction evidence

Offline probes against the baseline reproduce the behavior without provider credentials:

  • Text plus image plus @./README.md: content blocks 2 -> 1, images 1 -> 0.
  • A queued notification followed by a direct final answer: one model request, zero notifications in that request, one notification in stored history, an empty inbox. This reproduces with and without Harness request preparation.
  • Plan-to-build transition: stale PLAN system guidance alongside BUILD runtime state.
  • A length response with incomplete raw arguments invokes a local counter tool once with {}. The regression expectation is zero handler invocations and a matched error result.
  • Follow-up checks cover A1 -> B -> A2 notification order, two thinking signatures in one response, an empty tool-call start at output cutoff, and a blank line 1001 followed by nonblank line 1002.

Delivery plan

One tracking issue, four review units:

  • #3738 — Request context: preserve file-attachment blocks and deliver ordered inbox notifications to the next request.
  • #3739 — Core tool integrity: retain stop reasons, validate the whole JSON object, and pair rejected calls with errors.
  • #3740 (draft, depends on fix(core): reject incomplete and malformed tool-call arguments #3739) — Anthropic replay: retain native signatures and block boundaries and preserve parallel tool batches. Depends on core tool integrity.
  • #3741 — Runtime prompts: refresh Plan policy, select the slim skill catalog, and preserve active constraints in the compaction prompt.

Each PR references this issue. Close the tracking issue after all four units merge.

Acceptance

  • Existing text/images/message metadata survive attachment expansion; closing delimiters are neutralized, and line/character limits are explicit, including blank omitted-line boundaries.
  • The next model request and history each receive the same notifications once, in inbox order, with original IDs and sources; automated events do not imply user approval.
  • Entering/exiting Plan mode through real ReAct scheduling updates the prepared request.
  • Malformed calls never enter the handler or permission gate. Error results and lifecycle events retain the call ID; complete calls in the same batch remain executable.
  • Native Anthropic stream and nonstream responses survive accumulation and the next request with each thinking signature paired to its own block. Text middleware transformations remain effective.
  • Skill IDs/loading paths and explicit full-metadata opt-in remain available. Summary wording distinguishes current constraints from withdrawn decisions.

Evidence and scope

The design was checked against both ZCode 3c5b227649371507ddc4eb46ac5133afe6db1cab and DeepSeek Harness 86a402200d95fecef4529d969836f1fe13c6cb0d: source-labelled context, file-reference/read-more wording, native reasoning metadata, block-aligned replay, output-limit handling, slim skill discovery, and compaction extraction rules. Their policies differ: DeepSeek stops before tool execution on max-tokens; ZCode's malformed-JSON-to-empty-object fallback is a counterexample rather than the behavior to copy. ASJ retains complete sibling calls and reports invalid ones through its existing tool-result path.

Related: #2648 (output truncation), #2841 (malformed-argument diagnostics), #2791 (async waiting). This work addresses execution integrity and request delivery; retaining raw malformed arguments, changing task-state polling, and redesigning large-output recovery remain outside this issue. Workspace-rule discovery belongs to #3722/#3723; this series does not duplicate it. Earlier input-layout/compaction work is tracked in #3690.

Validation uses local fake models and tools. It establishes message/protocol behavior; task success, provider cache hits, or token savings have not been measured with real-model A/B evaluation.

Validation

All four isolated review snapshots pass their targeted tests and Spotless checks: 22, 60, 85, and 51 tests respectively, no failures/errors; the Anthropic snapshot has one existing skip. The complete series applied to upstream 07c5f3078d682da30f29e96b6d76f68242cbc2e1 passes mvn -B -T1C clean verify: 11,340 tests, 0 failures, 0 errors, 242 skipped, across 75 Maven test-module summaries.

Matching EN/ZH context documentation is included. The unchanged documentation content passed the prior documentation test/validation runs. The broken-links checker has a baseline failure with identical diagnostics in an isolated HEAD comparison; this series does not claim that repository-wide checker is green.

Activity

  1. juruoO-o commented on Nov 12, 2026

    @juruoO-o
    Collaborator

    Closing as delivered by #3738, #3739 and #3741 (all merged), which together cover this parent request: preserving attachments and inbox context, rejecting incomplete/malformed tool-call arguments, and refreshing plan guidance and context prompts. Reopen if part of the request is still unaddressed.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions