Skip to content

Queued inbound message processed against stale session state — agent contradicts its own reply seconds later (2026.6.10) #103287

Closed

Description

@boatworkco

Version: 2026.6.10 (aa69b12), macOS 26.5.1, imessage channel, dmScope per-channel-peer.

Summary: When message B arrives while a long turn for message A is still running in the same DM session, B's turn can compile its context BEFORE A's completed turn is committed to the session transcript. The agent then replies to B with no knowledge of A's turn — in our case flatly contradicting the reply it delivered 5 seconds earlier.

Timeline (from the session's trajectory.jsonl; relative times):

  • t+0.0s — turn A starts (session.started → context.compiled → prompt.submitted). Long agentic turn (~3.2 min, large context ~96k tokens, multiple tool calls).
  • t+105s — message B arrives mid-turn; queued.
  • t+193.9s — turn A: model.completed (t+193.92 session.ended). Its reply is delivered: "[work] done, file sent."
  • t+194.35s — turn B: session.started; context.compiled at t+194.36 — 425 ms after turn A ended — and turn B's compiled context is missing turn A's entire exchange (its reply says the message that started turn A "never came through" and cites state from hours earlier).
  • t+198.5s — turn B's contradictory reply is delivered to the same human, 5s after turn A's.

Supporting signals: turn B's compiled input was far smaller than the live session (~<50k vs ~96k); no compaction events occurred in this window (all compactions that day were hours earlier), so this looks like queue-release racing the transcript write-back rather than compaction.

Expected: a queued message's turn must never compile against session state older than the last delivered assistant message — i.e., release the queue on transcript-commit, not on model-completion (or have context.compiled block on the pending append).

Impact: user-facing self-contradiction — worst-case trust damage for assistant products. Happy to provide sanitized trajectory excerpts.

Reported from a production fleet running OpenClaw on Mac minis; happy to test a patch.

Activity

  1. added
    P1High-priority user-facing bug, regression, or broken workflow.
    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.
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    on Jul 10, 2026
  2. clawsweeper commented on Jul 10, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 10, 2026, 5:50 AM ET / 09:50 UTC.

    Summary
    Keep open. The report gives a precise production ordering failure on v2026.6.10, while current main has no focused regression or fix provenance proving that the prior assistant transcript is visible before the next queued turn compiles context; the supplied related issues have distinct stall, restart, or admission failure modes.

    Reproducibility: no. not yet on current main. The production timeline is strong and identifies a narrow concurrency window, but no current-main test or live run has reproduced the missing prior-turn transcript after queued admission.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.
    • Include redacted logs or terminal output.

    Next step
    The report is concrete and the shared-core boundary is bounded enough for one focused repair attempt, beginning with a deterministic regression.

    Review details

    Best possible solution:

    Make existing reply-operation completion await all canonical session-event and transcript writes required by the next turn, then add a regression that delays turn A's final append while turn B is queued.

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

    No, not yet on current main. The production timeline is strong and identifies a narrow concurrency window, but no current-main test or live run has reproduced the missing prior-turn transcript after queued admission.

    Is this the best way to solve the issue?

    No, not exactly as phrased: releasing from a separate transcript-commit signal could create competing completion sources. The narrowest maintainable fix is to make the existing reply-operation/session-owner completion boundary include the required transcript finalization.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • There is no deterministic current-main reproduction yet, and broad session/runtime changes after v2026.6.10 could have altered the window without establishing a traceable fix.
    • Changing the drain boundary without focused coverage could regress steering, final delivery, abort cleanup, or follow-up lifecycle behavior.

    Codex review notes: model internal, reasoning high; reviewed against 7fe004d85251.

    Label changes

    Label changes:

    • add P1: The production race caused the assistant to contradict a reply delivered five seconds earlier in the same direct-message session.
    • add impact:session-state: The queued turn compiled against session state that omitted the immediately preceding completed exchange.
    • add issue-rating: 🦐 gold shrimp: Current issue advisory state selects this label.
    • add clawsweeper:needs-info: Current issue advisory state selects this label.

    Label justifications:

    • P1: The production race caused the assistant to contradict a reply delivered five seconds earlier in the same direct-message session.
    • impact:session-state: The queued turn compiled against session state that omitted the immediately preceding completed exchange.
    Evidence reviewed

    Acceptance criteria:

    • pnpm test src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts
    • pnpm test src/auto-reply/reply/queue.in-flight.test.ts
    • pnpm test src/agents/embedded-agent-runner/run/attempt.session-lock.test.ts
    • pnpm test src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.ts
    • pnpm check:changed -- src/auto-reply/reply/agent-runner.ts src/auto-reply/reply/reply-run-registry.ts src/auto-reply/reply/queue/drain.ts src/agents/embedded-agent-runner/run/attempt.ts

    What I checked:

    • Detailed production timeline: The report identifies a 425 ms window between turn A ending and turn B compiling context, with turn B omitting A's complete exchange despite no compaction in the interval.
    • Existing queue-admission contract: Current main keeps the follow-up queue dormant while an active reply operation exists and schedules draining through an after-clear callback. (src/auto-reply/reply/agent-runner.ts:148, 7fe004d85251)
    • Reported build already had the basic gate: The exact v2026.6.10 commit already deferred follow-up drain until reply-operation clear, so the observed race is narrower than a missing queue gate and likely lies in what clear considers finalized. (src/auto-reply/reply/agent-runner.ts:138, aa69b12d0086)
    • Current completion ordering: Current finalization registers the after-clear drain and then completes the reply operation, making reply-operation completion the decisive admission boundary for queued work. (src/auto-reply/reply/agent-runner.ts:2804, 7fe004d85251)
    • Adjacent transcript ordering work: Embedded-runner history contains a flush-before-afterTurn repair, but its focused test covers context-engine lifecycle ordering rather than queued next-turn context compilation after a delayed final append. (src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.ts:2288, 7ac8b48a08bf)
    • No canonical duplicate established: The supplied related reports concern restart loss, maintenance or compaction stalls, and a stranded active-reply marker; none describes a queued turn starting successfully but reading a transcript that omits the preceding turn.

    Likely related people:

    • steipete: Authored the clear-before-drain and centralized follow-up lifecycle commits that define when queued turns are admitted after an active reply. (role: introduced follow-up drain lifecycle; confidence: high; commits: a9817a5f97bd, 0909df1a4f3d; files: src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/reply-run-registry.ts)
    • sandieman2: Authored the merged repair for final-reply delivery when a queued follow-up claims the session, directly adjacent to this lifecycle boundary. (role: recent queue/session contributor; confidence: high; commits: c67dc59b02b0; files: src/auto-reply/reply/agent-runner.ts, src/auto-reply/reply/queue/drain.ts)
    • jalehman: Authored the refactor routing auto-reply sessions through the shared session seam used by the affected queue and embedded-runner paths. (role: session seam contributor; confidence: medium; commits: 127e174c9e4d; files: src/auto-reply/reply/queue/drain.ts, src/agents/embedded-agent-runner/run/attempt.ts)
    • IWhatsskill: Authored the transcript flush-before-afterTurn repair and focused ordering test in the embedded runner. (role: transcript finalization contributor; confidence: medium; commits: 7ac8b48a08bf; files: src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.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. openclaw-barnacle commented on Jul 25, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  4. steipete commented on Jul 27, 2026

    @steipete
    Contributor

    Thanks for the detailed production timeline; the queue-release/old-context race reported against 2026.6.10 is addressed on current main (e57549c).

    Current production behavior:

    • src/auto-reply/reply/dispatch-from-config.lifecycle.ts waits for tracked turn-lifecycle work and final reply delivery, then releases the reply operation with completeWithAfterClearBarrier; queued follow-ups cannot overtake the preceding turn.
    • src/auto-reply/reply/reply-turn-admission.ts waits for that per-session follow-up admission barrier and rechecks the authoritative session identity.
    • src/auto-reply/reply/followup-runner.ts reloads the persisted session after admission instead of compiling from the stale enqueue-time snapshot.

    The exact ordering is protected by src/auto-reply/reply/dispatch-from-config.reply-dispatch.test.ts (clears the reply lane but defers follow-up admission until final delivery settles) and src/auto-reply/reply/reply-turn-admission.test.ts (keeps an already-waiting follow-up behind the delivery barrier). The steering sibling is covered by src/auto-reply/reply/agent-runner.runreplyagent.e2e.test.ts (waits for transcript commit and keeps a rejected adoption finalizer irrevocably adopted).

    Landed dispatch-lifecycle implementation: 668e5e8096ad
    Landed queue/session-state reload: 2c31af136429
    Landed final-delivery ordering regression: c67dc59b02b0
    Landed transcript-commit regression: f79e8859855b

    Closing as completed based on the current canonical source and focused checked-in regression evidence for the reported stale queued-turn ordering.

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

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.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