Skip to content

Long-running tool results can poison persisted session context #87651

Closed

Description

@ooiuuii

Summary

In OpenClaw 2026.5.26, long-running tools can persist many individually sub-cap toolResult entries into a session. The aggregate persisted tool output can later make even very short follow-up messages exceed the model context window.

This is not specific to one command or provider. The concrete report came from a Telegram direct session with a long-running process task, but the underlying issue is a general persisted-history/tool-output budget problem.

Real environment

  • Version observed: OpenClaw 2026.5.26
  • Surface: Telegram direct conversation
  • Runtime shape: Windows-side OpenClaw bot/session running a long process task
  • Model context: large-context model, but session history still became poisoned by aggregate persisted tool output

User-visible symptom

After a long-running process task produced repeated tool output, normal short Telegram messages failed repeatedly:

Your input exceeds the context window of this model. Please adjust your input and try again.

This happened even for short follow-up messages such as:

1

So the problem was not the current user input length; the previous persisted session history had grown too large.

Evidence from session inspection

The affected direct session contained many repeated persisted messages like:

role: toolResult
toolName: process
content: text chunks, many around ~30k chars each

Each individual chunk could be under an existing per-result cap, but the active branch accumulated enough of them that later prompts replayed too much tool output.

Raw screenshots/logs are intentionally not attached here because they include private Telegram/session details. The relevant error text and persisted-message shape are quoted above in redacted form.

Expected behavior

Persisted session history should not allow repeated tool outputs to grow without an aggregate budget. A long-running tool should not poison future turns such that unrelated short user messages fail context assembly.

Related fix

A proposed fix is in:

The PR keeps the existing per-tool-result cap, and adds an aggregate persisted toolResult budget for the active branch so repeated sub-cap outputs are rewritten/truncated before later user turns can replay them all.

Activity

  1. ooiuuii commented on May 28, 2026

    @ooiuuii
    ContributorAuthor

    Proposed fix PR: #87639

  2. clawsweeper commented on May 28, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed May 28, 2026, 9:38 AM ET / 13:38 UTC.

    Summary
    Keep open. Current main still lacks aggregate persistence enforcement in the session tool-result guard, and the issue is paired with the open fix PR at #87639.

    Reproducibility: yes. source-level. Append several sub-cap toolResult messages through the guarded SessionManager path and inspect the active branch aggregate; current main caps individual results but does not bound the aggregate at persistence time.

    Next step
    An open linked PR already implements the candidate fix, so a separate repair lane would duplicate current review work.

    Review details

    Best possible solution:

    Review and land the linked PR, or an equivalent narrow fix, so persisted toolResult history has both per-result and aggregate active-branch budgets with regression coverage.

    Do we have a high-confidence way to reproduce the issue?

    Yes, source-level. Append several sub-cap toolResult messages through the guarded SessionManager path and inspect the active branch aggregate; current main caps individual results but does not bound the aggregate at persistence time.

    Is this the best way to solve the issue?

    Yes. The linked PR's direction is narrow: keep the existing per-result cap, enforce an aggregate active-branch budget after tool results are persisted, and add focused session-guard coverage.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The linked fix rewrites persisted session branch entries, so PR review should check session-state compatibility and transcript update behavior before merge.
    • No live Telegram repro was run in this read-only sweep; confidence comes from source inspection plus the provided redacted real-session evidence.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against 76ebc149567b.

    Label changes

    Label justifications:

    • P2: This is a normal-priority persisted-session bug with real user impact but a narrow linked fix path.
    • impact:session-state: The failure is caused by accumulated persisted session history poisoning later context assembly.
    Evidence reviewed

    What I checked:

    Likely related people:

    • Peter Steinberger: Git history points to the original session tool-result guard and live tool-result cap work in this area. (role: feature-history owner; confidence: high; commits: f5d5661adfec, 5586b3fd19cd; files: src/agents/session-tool-result-guard.ts, src/agents/session-tool-result-guard.test.ts)
    • ooiuuii: Authored the linked open PR and supplied the real-session evidence tying repeated process tool results to context overflow. (role: related fix author and reporter; confidence: high; commits: 8930882a21cd; files: src/agents/session-tool-result-guard.ts, src/agents/session-tool-result-guard.test.ts, src/agents/embedded-agent-runner/tool-result-truncation.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  3. added
    P2Normal backlog priority with limited blast radius.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    on May 28, 2026
  4. openclaw-clownfish commented on Jun 15, 2026

    @openclaw-clownfish
    Contributor

    Thanks @ooiuuii for the detailed report and source repro. I am closing this because the fix landed in #87639: #87639. That PR bounds aggregate persisted tool results so long-running tool output cannot keep poisoning later session context, which is the failure tracked here at #87651.

    Clownfish is keeping the canonical fix path on the merged PR, and the report/source context here remains part of the attribution for that work. If this still reproduces on current main, or if there is a different path that #87639 did not cover, please reply and we can reopen or split a follow-up.

  5. locked as resolved and limited conversation to collaborators on Jun 25, 2026
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

    P2Normal backlog priority with limited blast radius.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions