Skip to content

Session context silently lost between consecutive turns with z.ai provider (GLM gateway) #76665

Description

@Nelsoncongbao

Summary

Session conversation history is silently dropped between consecutive user messages when using zai/glm-5.1 (z.ai-style provider). The first user message and its assistant reply disappear from the session file when the second user message arrives, causing the agent to lose all context.

Environment

  • OpenClaw: 2026.5.2 (8b2a6e5)
  • Channel: Feishu (via @larksuite/openclaw-lark)
  • Default model: zai/glm-5.1
  • OS: macOS 26.3.1 (arm64)
  • Node: v24.14.1

Reproduction

  1. Start a fresh DM session (Feishu channel, zai/glm-5.1 default model)
  2. Send a text message → agent replies correctly with full context
  3. Send a second message (e.g., attach a docx file) → agent sees ONLY the second message; the first exchange is gone from context

Evidence from session store

First backup (61318122-...jsonl.bak-97174-1777807809142, 7 lines):

[0] session
[1] model_change → qiniu/claude-opus-4-7
[2] thinking_level_change
[4] user: "小宇宙前面两天你帮我做的临时论文…"  ← FIRST MESSAGE (intact)
[5] custom: System inbound metadata
[6] assistant: "聪聪先把最后一版论文发我…"     ← FIRST REPLY (intact)

Second backup (61318122-...jsonl.bak-97174-1777807887760, created ~78s later after docx upload):

[0] session
[1] model_change → qiniu/claude-opus-4-7
[2] thinking_level_change
[3] custom (system prompt)
[4] user: [media attached: ...docx]             ← ONLY docx, first message GONE
[5] custom: [media attached: ...docx]
[6] assistant: "聪聪发了个 docx 文件,但没说要干啥"  ← Agent lost context

Between the two backups (78 seconds apart), the session file was rewritten: the first user message + assistant reply were silently removed. The model_change entry (line 1) was preserved, suggesting the session metadata survived but conversation history did not.

Configuration

{
  "agents": {
    "defaults": {
      "model": { "primary": "zai/glm-5.1" },
      "contextPruning": {
        "mode": "cache-ttl",
        "ttl": "5m",
        "keepLastAssistants": 3,
        "minPrunableToolChars": 30000,
        "hardClear": { "enabled": true }
      }
    }
  },
  "session": {
    "dmScope": "per-channel-peer",
    "maintenance": { "mode": "enforce", "maxEntries": 50, "pruneAfter": "2h" },
    "reset": { "mode": "idle", "idleMinutes": 999999 }
  }
}

The session.reset.idleMinutes: 999999 rules out idle reset as the cause (78s gap is nowhere near the threshold). pruneAfter: 2h also does not explain losing context within seconds.

Related

Impact

  • Agent becomes context-blind mid-conversation, requiring user to re-explain everything
  • No error is raised — the loss is silent
  • Happens reliably on the second user message in a fresh session

Expected Behavior

Session history should accumulate across turns. Prior messages should never be silently dropped without explicit user action (e.g., /new) or configured reset/cleanup thresholds being met.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:message-lossChannel message delivery can be lost, duplicated, or misrouted.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions