Skip to content

fix(outbound): a delivery mirrored into another session is silently dropped - #134083

Merged
roboclaw-bot merged 1 commit into
openclaw:mainfrom
edenfunf:fix/outbound-mirror-writer-fence
Sep 1, 2026
Merged

roboclaw-bot merged 1 commit into
openclaw:mainfrom
edenfunf:fix/outbound-mirror-writer-fence

Conversation

@edenfunf

Copy link
Copy Markdown
Contributor

Closes #132766

What Problem This Solves

A message the user has already received can be missing from the transcript of the session it was delivered into. When a run in one session delivers an outbound payload addressed to another session, the mirror that records it in the receiving session's transcript is refused, the refusal is logged at warn after the channel send has already succeeded, and it is never retried. The user sees the message; the receiving session never learns it happened, and every later turn in that session answers from a history that is missing it.

Nothing surfaces this. There is no error, no retry, and no counter — the reporter of #132766 found it only by auditing mirror counts against their gateway journal, where it had been happening for four days across five session keys and three agents, on one channel for 8 of 8 deliveries.

The same drop sits on five delivery paths, not one: the generic outbound mirror, the plugin-handled send mirror, the source-reply mirror, and both of the gateway's internal source-reply persistence points.

Why This Change Was Made

Each of those paths asked for the current writer claim without saying which session it was about to write into, so it inherited whichever run happened to be executing. When that run belonged to a different session, the transcript guards correctly refused a claim that did not describe the target — which is why the symptom is a session rebound refusal rather than a corrupted write.

Every one of the five now names the session it writes into. Naming it is only half the repair: the ownership test compares full targets, and a delivery mirror holds a session key but not that session's store path, so a key-only request could not be answered at all and would have been refused even when the run did own the session. The fence lookup now has its own ownership test that compares session keys when the caller cannot form a target and defers to the existing target comparison whenever it can. The shared contextMatches used by the initial-writer inheritance and the commit assertion is untouched, so those two paths keep their exact semantics.

Boundaries. A same-session mirror still inherits the run's fence — the guard is scoped, not removed. The unscoped lookup still returns the ambient claim and is kept for the one caller that legitimately asks "which run is writing right now" rather than "may I write into this session". The issue's secondary ask — making the four session rebound emit sites distinguishable in the log — is not addressed here; it is a change to a shared refusal string on a much hotter path and stands on its own.

User Impact

A message delivered into another session is now recorded in that session's transcript instead of being silently dropped, so the receiving session answers from the history the user actually sees. Sessions that were quietly desynchronised stop drifting further apart. Nothing changes for a delivery into the running session's own transcript, and nothing changes about when a channel send succeeds or fails.

Evidence

Behavior addressed: an outbound payload mirrored into a session other than the delivering run's own is refused as session rebound, logged at warn after a successful send, and lost permanently.

Real environment tested: a real temporary state directory with the real SQLite session store, the real exported mirrorDeliveredPayloads, and the real appendAssistantMessageToSessionTranscript guards that issue the refusal. Only the channel send is absent; the defect is entirely in the mirror that runs after it. Node v24.18.0 on Windows 11.

Exact steps or command run after this patch: create two real sessions in one store, give the delivering session an active writer run the way a live turn does, leave the receiving session unowned (the ordinary state of a session that is not mid-turn), then mirror one payload into each from inside the delivering run's transcript-write context.

Evidence after fix:

$ node --import ./scripts/tsx.mjs ./outbound-mirror-writer-fence-proof.mts
store: ...\.openclaw\agents\main\sessions\sessions.json
cross-session mirror  agent:main:discord:channel:receiving: 0 -> 2 transcript event(s)
same-session mirror   agent:main:discord:channel:delivering: 0 -> 2 transcript event(s)
PASS: the mirror into the other session landed in its transcript
PASS: the mirror into the delivering run's own session still lands

Observed result after fix: the cross-session mirror lands, and the same-session mirror is unchanged — the fence is scoped, not dropped. No warn line is emitted.

Before evidence: the identical script against the same commit with src/config/sessions/transcript-write-context.ts and src/infra/outbound/deliver-transcript.ts reverted to origin/main:

[outbound/deliver] failed to mirror outbound delivery into session transcript; channel send already succeeded: session rebound for sessionKey: agent:main:discord:channel:receiving
store: ...\.openclaw\agents\main\sessions\sessions.json
cross-session mirror  agent:main:discord:channel:receiving: 0 -> 0 transcript event(s)
same-session mirror   agent:main:discord:channel:delivering: 0 -> 2 transcript event(s)
FAIL: the mirror into the other session was dropped (session rebound)
PASS: the mirror into the delivering run's own session still lands

That warn line is the reporter's production line, verbatim down to the format. The same-session control passes on both sides, so the difference is the cross-session case alone.

Additional review: the unit tests fail without the fix. Reverting only src/infra/outbound/deliver-transcript.ts to origin/main and rerunning src/infra/outbound/deliver-transcript.writer-fence.test.ts fails with expected { agentId: 'wolf', …(8) } to not have property "expectedWriterRunId" / Received "run-running" — the delivering run's claim, on a mirror into another session. Restoring the fix returns 3/3. src/config/sessions/transcript-write-context.test.ts adds four cases that pin both halves and the unchanged target path, and its ten pre-existing cases still pass (14/14).

Checks run on the exact head: tsgo -p tsconfig.core.json with no diagnostics; the sharded core test-type lane, which caught a TS2493 in the new test file on its first run — fixed by giving the mock its parameter type rather than adding a cast, which also let an existing assertion be deleted; lint:core; oxfmt --check on all seven touched files; check:assertion-safety --base origin/main and check:max-lines-ratchet --base origin/main, both OK; check:import-cycles, 0 cycles.

What was not tested: no live gateway drove a real cross-session announce or handoff; the proof drives the same exported mirror entry point directly. The channel send itself is not exercised, which is deliberate — the send already succeeds in the reported failure.

Proof limitations or environment constraints: this host has three suites that fail before this change and fail identically with src/config/sessions/transcript-write-context.ts, src/gateway/internal-source-reply-persistence.ts, src/infra/outbound/deliver-transcript.ts, src/infra/outbound/outbound-send-service.ts and src/infra/outbound/source-reply-mirror.ts reverted to origin/main, so they are pre-existing here and not caused by this change: src/plugin-sdk/session-transcript-runtime.test.ts (21 failures, all EPERM ... syscall: 'rm' while removing a temp directory in afterEach; identical 21 failed / 3 passed on both sides), src/config/sessions/transcript.test.ts (suite-level EPERM in the same cleanup shape, so all 65 tests are skipped and none actually runs), and one 120s timeout in src/agents/tools/sessions.test.ts (sessions_send gating > keeps an exact-incarnation send synchronous to its scoped lifecycle grant, 120074ms on this branch versus 120064ms on reverted source). Everything else in the touched and neighbouring set passes.

@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Aug 31, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 31, 2026
@clawsweeper

clawsweeper Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 7:58 AM ET / 11:58 UTC.

ClawSweeper review

What this changes

The PR scopes transcript writer fences to the session receiving each outbound mirror so cross-session deliveries are recorded instead of being rejected as rebound writes.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: this is a source-proven P1 repair for silent transcript-state loss, and current main still has the unscoped fence reads. The patch scopes the sender’s writer claim to the destination session without weakening the full-target commit guard.

Priority: P1
Reviewed head: c5e55d8bf5d471fd77ba15a3a553bd2d67e010e9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-consistent repair with credible real-store before/after proof and targeted regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed production owner is the outbound transcript mirror, exercised directly against a real temporary SQLite session store and real append guards in the supplied before/after terminal trace; it shows the destination transcript receiving the cross-session event after the fix while the same-session control remains unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the outbound transcript mirror, exercised directly against a real temporary SQLite session store and real append guards in the supplied before/after terminal trace; it shows the destination transcript receiving the cross-session event after the fix while the same-session control remains unchanged.
Evidence reviewed 7 items Current-main failure path: Fetched main still takes the ambient fence with no target at each reviewed mirror path; the transcript append rejects a mismatched lifecycle or writer ID as session-rebound.
Owner-boundary repair: The new predicate uses key equality only for callers that cannot construct a full target, while callers with a target or file retain the existing full-target comparison.
Production caller and callee: The generic delivery invokes the mirror after send completion, and the append owner rejects only supplied stale or foreign fence values; withholding a foreign fence therefore preserves the destination write rather than bypassing a target check.
Findings None None.
Security None None.

How this fits together

Outbound delivery sends a payload through a channel and then records it in the destination session transcript. Writer fences protect active session writes, so a mirror must not pass a sending run’s fence to a different destination session.

flowchart LR
  A[Agent run] --> B[Outbound delivery]
  B --> C[Channel send]
  B --> D[Transcript mirror]
  D --> E[Destination session]
  E --> F[Writer fence check]
  F --> G[Transcript event]
Loading

Before merge

  • Resolve merge risk (P1) - The bug fix is production net +39 lines; retain the separate key-only ownership predicate because reusing the full-target comparator would change commit-boundary semantics.
  • Complete next step (P2) - The open PR already contains the focused repair; await ordinary exact-head CI and maintainer merge handling rather than opening a parallel fix lane.
Agent review details

Security

None.

PR surface

Source +39, Tests +176. Total +215 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 46 7 +39
Tests 2 176 0 +176
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 222 7 +215

Review metrics

Metric Value Why it matters
Production versus test LOC production +46/-7 (net +39); tests +176/-0 The production increase is the scoped ownership predicate and five call-site corrections; the full-target comparator cannot be reused for key-only mirrors without changing commit-guard behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #132766
Summary: This PR explicitly addresses the canonical report’s same ambient-writer-fence failure and supplies the corresponding repair.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the destination-key-scoped fence lookup after exact-head checks complete; it preserves same-session fencing and prevents foreign-session fence inheritance without adding another delivery path.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the destination-key-scoped fence lookup after exact-head checks complete; it preserves same-session fencing and prevents foreign-session fence inheritance without adding another delivery path.

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

Yes. The supplied real-store before/after trace reproduces the cross-session drop, and fetched main retains the same unscoped lookup and session-rebound guard path.

Is this the best way to solve the issue?

Yes. The repair corrects the fence lookup at the ownership boundary while retaining strict full-target matching where callers can express a target.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 43e9a3d81776.

Labels

Label changes:

  • add P1: A successfully delivered cross-session message can be silently absent from the receiving session history, causing subsequent agent context drift.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the outbound transcript mirror, exercised directly against a real temporary SQLite session store and real append guards in the supplied before/after terminal trace; it shows the destination transcript receiving the cross-session event after the fix while the same-session control remains unchanged.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the outbound transcript mirror, exercised directly against a real temporary SQLite session store and real append guards in the supplied before/after terminal trace; it shows the destination transcript receiving the cross-session event after the fix while the same-session control remains unchanged.

Label justifications:

  • P1: A successfully delivered cross-session message can be silently absent from the receiving session history, causing subsequent agent context drift.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production owner is the outbound transcript mirror, exercised directly against a real temporary SQLite session store and real append guards in the supplied before/after terminal trace; it shows the destination transcript receiving the cross-session event after the fix while the same-session control remains unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the outbound transcript mirror, exercised directly against a real temporary SQLite session store and real append guards in the supplied before/after terminal trace; it shows the destination transcript receiving the cross-session event after the fix while the same-session control remains unchanged.

Evidence

What I checked:

  • Current-main failure path: Fetched main still takes the ambient fence with no target at each reviewed mirror path; the transcript append rejects a mismatched lifecycle or writer ID as session-rebound. (src/infra/outbound/deliver-transcript.ts:43, 43e9a3d81776)
  • Owner-boundary repair: The new predicate uses key equality only for callers that cannot construct a full target, while callers with a target or file retain the existing full-target comparison. (src/config/sessions/transcript-write-context.ts:101, c5e55d8bf5d4)
  • Production caller and callee: The generic delivery invokes the mirror after send completion, and the append owner rejects only supplied stale or foreign fence values; withholding a foreign fence therefore preserves the destination write rather than bypassing a target check. (src/infra/outbound/deliver-core.ts:538, c5e55d8bf5d4)
  • Focused regression coverage: The added mirror test asserts that a same-session mirror retains its fence while a cross-session mirror receives neither fence field; the context tests also pin key-only and full-target behavior. (src/infra/outbound/deliver-transcript.writer-fence.test.ts:72, c5e55d8bf5d4)
  • Real behavior evidence: The supplied PR-body terminal trace exercises the production exported mirror with a real temporary SQLite session store before and after the repair, showing the cross-session transcript event changes from 0 to 2 while the same-session control remains 2. (c5e55d8bf5d4)
  • Feature-history routing: Local history identifies the admitted-run transcript fence work as a prior session-area change; partial history prevented verification of an exact introducing source hunk, so this is routing evidence only. (src/config/sessions/transcript-write-context.ts:51, c9b346e216a6)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

…into

Co-authored-by: VACInc <3279061+VACInc@users.noreply.github.com>
@roboclaw-bot
roboclaw-bot force-pushed the fix/outbound-mirror-writer-fence branch from c5e55d8 to 1f34a7c Compare September 1, 2026 01:49
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Maintainer adoption verification for 1f34a7c3ecc1d1bf6d10fd49df90019dd5624f9a:

  • Rewrote only commit metadata to add Co-authored-by: VACInc <3279061+VACInc@users.noreply.github.com>; git diff c5e55d8bf5d471fd77ba15a3a553bd2d67e010e9..1f34a7c3ecc1d1bf6d10fd49df90019dd5624f9a is empty and git range-diff shows only that trailer.
  • GitHub parses both edenfunf and VACInc as commit authors.
  • Exact-head CI: 243 successful, 40 skipped, 1 neutral, 0 pending, 0 failed.
  • Local non-executing checks: git diff --check origin/main...HEAD; exact source-byte comparison against the previously reviewed head.
  • Latest ClawSweeper review has no findings and sufficient real-store proof. No re-review was requested because this head changes attribution only, not source or behavior.

VACInc assignment is verified on this PR, canonical issue #132766, and predecessor issue #125885. PR #132852 is the incomplete duplicate; #134498 is a separate post-send rebound race with its own durable-recovery product decision.

No merge or automerge action was taken.

@roboclaw-bot
roboclaw-bot merged commit ef6fe66 into openclaw:main Sep 1, 2026
284 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 1, 2026
…into (openclaw#134083)

Co-authored-by: VACInc <3279061+VACInc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

3 participants