Repository navigation
fix(matrix): spawns from Gateway chat.send turns break thread bindings until restart - #177372
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesRetain Matrix’s owning plugin runtime so Gateway-originated subagent spawns can persist thread bindings. Example: A Gateway chat.send turn requests sessions_spawn with thread:true and mode:"session" in an existing Matrix room session.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a current Matrix binding failure with a small, owner-local change; no actionable correctness or security findings remain. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway agent turns call the shared binding service, which delegates to Matrix’s account manager to persist bindings in SQLite and route Matrix threads to child sessions. flowchart LR
A[Gateway chat.send] --> B[Agent sessions_spawn]
B --> C[Session binding service]
C --> D[Matrix binding manager]
D --> E[Owning plugin runtime]
E --> F[SQLite worker]
D --> G[Matrix thread]
Technical reviewBest possible solution: Use the manager’s startup runtime for every binding-storage operation while preserving existing worker serialization and lifecycle checks. Do we have a high-confidence way to reproduce the issue? The supplied differential built-Gateway run reproduces the failure twice on frozen main, and current-main source retains the same caller-dependent lookup; this review executed no target code. Is this the best way to solve the issue? This is the smallest complete repair: bind storage access to the existing Matrix manager’s runtime rather than changing shared adapter semantics or introducing another state owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b18521eecc6d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +10, Tests +215. Total +225 across 2 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 29, 2026, 6:52 AM ET / 10:52 UTC (Revision 2). |
|
I ran the spawn and follow-up scenario on head The records below select fields from projected artifacts. Times are UTC. Credentials, endpoints, process identities, upstream identifiers and the CLI idempotency value are omitted. Run timelineCLI receipt and actual spawnThe shipped {"params":{"sessionKey":"agent:main:matrix:channel:!room:localhost",
"message":"Use sessions_spawn exactly once with runtime=subagent, task=\"Reply MATRIX-CHILD-OK\", thread=true, mode=session, label=proof-core. Report the actual tool result.",
"deliver":true,"timeoutMs":90000},"response":{"status":"started"}}
{"name":"sessions_spawn","transport_tool":"dispatch_action",
"arguments":{"runtime":"subagent","task":"Reply MATRIX-CHILD-OK","thread":true,"mode":"session","label":"proof-core"},
"result":{"status":"accepted","childSessionKey":"agent:main:subagent:1685a51b-a137-4363-b10c-540b02a82311","mode":"session","modelApplied":true}}The inbound room-message spawn was also accepted and created the second binding. These are actual calls and results, not prompt instructions treated as execution. Binding and retained childBoth retained records matched before stop, after kill and after fresh startup before traffic. Selected fields of the original binding follow. {"conversationId":"$root-2","parentConversationId":"!room:localhost",
"targetKind":"subagent","targetSessionKey":"agent:main:subagent:1685a51b-a137-4363-b10c-540b02a82311",
"label":"proof-core","boundBy":"system","boundAt":1793098068673,
"lastActivityAt":1793098068673,"idleTimeoutMs":86400000,"maxAgeMs":0}The other root was Selected event fields show the incoming message and delivered reply under the same root. {"at":"2026-10-27T10:49:35.676Z","kind":"enqueue","event_id":"$fixture-7",
"m.relates_to":{"rel_type":"m.thread","event_id":"$root-2","m.in_reply_to":{"event_id":"$root-2"}}}
{"at":"2026-10-27T10:49:39.049Z","kind":"send","event_id":"$root-8",
"m.relates_to":{"rel_type":"m.thread","event_id":"$root-2","m.in_reply_to":{"event_id":"$root-2"}},
"markers":["MATRIX-FOLLOWUP-OK"]}The final answer matched exactly and added one provider request. Counted attempts and usage estimatesAll 27 requests returned HTTP 200. Input totals include cached and cache-write tokens.
These estimates use the run's assumed per-million rates of $0.20 uncached input, $0.02 cached input, $0.25 cache writes and $1.20 output. Cached and write tokens are subtracted before charging uncached input. I have not verified these as published prices. The first attempt's request 11 has no usage, so its cost is unknown. Billing is unsettled. The first observer missed a spawn nested in This is head only. The earlier base failure used a mock model. The forced restart proves persistence, not graceful exit. Config watching fell back to polling in the sandbox, so there was no hot reload. |
Differential built Gateway + local Synapse proofCandidate: Both sources were staged from those Git archives and built with Node 24.22.1 inside secretless Docker. Each normal built Gateway loaded the bundled Matrix plugin. Matrix traffic went to a real, task-owned Synapse homeserver ( A deterministic local OpenAI-compatible provider supplied tokens to the real agent runtime. It used the advertised Observed user path
Synapse accepted a top-level “session active” banner on both failed main attempts, but the native spawn results report failed persistence. A returned child ID alone is therefore not treated as a successful binding. Child chat.send, persistence and negative controlsFor subsequent operator Synapse recorded these actual follow-up deliveries: Then the candidate Gateway was stopped and restarted with the same state. A local Matrix user sent an ordinary follow-up into root #1, with no Gateway origin override. That input appeared in the original child #1 history as An unbound-session Graceful shutdown evidenceAll four final Gateway processes received SIGTERM and were awaited until their actual process exit, each with code Only final completed turns and real spawn-tool result objects are counted here. Earlier fixture preparation failures and a rejected broad collector oracle are retained privately and excluded from this differential proof. No unit tests were added or run in this repair pass. Simplification pass: retain the existing owner runtime and all existing worker/reconciliation/retirement checks. Production +11/-1 (net +10), tests +215/-0; this worker changes neither. The contributor's separate provider supplement remains attributed head-only evidence, not this before/after or shutdown receipt. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in a1c3e81. Thanks @MarMarLabs. Sessions spawned into Matrix threads now keep their thread binding. |
…s until restart (openclaw#177372) fix(matrix): keep the Matrix thread binding for sessions spawned through chat.send When chat.send spawned a child session in a Matrix room, the plugin read its runtime before the binding was ready, so the Matrix thread binding wasn't stored. Replies didn't reach the thread, and later messages in it didn't reach the child. The binding is now taken from the runtime captured at spawn time. Evidence: built Gateway with the bundled Matrix plugin against a real local Synapse. On main the binding wasn't stored (twice); with this change two spawned sessions were bound and delivered native threaded replies (twice). After a graceful Gateway restart, a normal inbound message in the thread reached the original child and got a threaded reply. Unbound-session controls sent nothing to Matrix. Details: openclaw#177372 (comment). Thanks @MarMarLabs. Co-authored-by: Ayaan Zaidi <[email protected]>
Related: #175379.
What Problem This Solves
Fixes: a thread-bound subagent spawn requested through Gateway
chat.sendfails to persist its Matrix binding and can leave the account's binding manager unusable until restart.User Impact
Users can create persistent Matrix thread-bound children through Gateway-originated turns, receive their replies in the intended Matrix thread, and continue that same child after a Gateway restart. Ordinary inbound replies and unbound-session delivery remain unchanged.
Why This Change Was Made
The Matrix binding manager now retains its owning plugin runtime when it starts instead of looking up a runtime from whichever caller later invokes a storage callback. Initial loading, persistence, reconciliation and activity writes use that same owner. Existing worker serialization, registry-retirement and manager-authority checks remain intact; there is no new storage format, configuration or public API.
Evidence
Built Gateway + real local Synapse differential proof, native Matrix events, controls and actual process-exit receipts.
c8a27378eecac4f7cb82110f682ca0284d0493a9: two independent spawns return the native Matrix persistence/reconciliation error, including after a graceful Gateway restart.ca70b506831a951154279cb3a1301aa3ad98b142: two spawns are accepted on the same account, and Synapse records both automatic child replies and subsequent operator sends in their respective native Matrix threads.Contributor: @MarMarLabs. The separate contributor provider supplement is attributed head-only evidence, distinct from the differential and graceful-exit run above.
Merge Danger
Two-way code change with no schema migration: existing-format bindings remain readable after a revert, and already-created child sessions/bindings are not automatically removed. A bad runtime capture could disrupt Matrix binding persistence or lifecycle cleanup; other channel adapters and the core binding service are unchanged.