Skip to content

fix: avoid competing Gateway test boots and cold agent mutation imports - #208203

Merged
daniel-lxs merged 7 commits into
mainfrom
openclaw/postgres-cron-and-agents-list-346093
Nov 29, 2026
Merged

daniel-lxs merged 7 commits into
mainfrom
openclaw/postgres-cron-and-agents-list-346093

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Under CPU contention, the PostgreSQL cron graceful-stop case can exceed 90 seconds and the first authenticated agents.list request can exceed its 10-second WebSocket deadline. Both failures occurred on main. PG17 job · Roster job

User Impact

A first roster read loads its own handler and avoids importing agent creation, onboarding, avatar generation, and deletion. The RPC still requires operator.read and applies the same role and agent-visibility checks. The PostgreSQL change affects test scheduling.

Why This Change Was Made

The cron and Doctor tests each start real Gateway CLI processes. Running those two files in the existing serial, isolated CLI-process lane keeps their startup work from competing with each other. Matrix database portability keeps its existing lane. Both Gateway boots, both stops, the held receipt lock, and the restart assertions still run within the original 90-second cron case. Original lifecycle budget

The canonical method descriptor assigns agents.list to a dedicated lazy handler family. The first request still pays the cost of loading the roster code. The permission-read lint rule assigns the roster's six existing references to that module. Its per-file limit stays at six, and the mutation module has no allowance.

Evidence

The two original test files match main byte for byte. AWS comparisons used main d88223e2c350 and the runtime and routing tree at 1a7b10dc1f97. The only change from that tree to 9a569f1f0942 is the file path in the lint rule.

  • PG17, 1.25 CPUs. In the independent run, cron alone hit its 90-second deadline on main at 90.301 s. The PR passed cron in 60.849 s, and Doctor and Matrix passed on both revisions. A separate traced reproduction observed a successful receipt and a clean first-process exit before the second boot, with main at 90.418 s and the PR at 59.417 s. Moving only Doctor did not fix cron. Independent comparison · Traced main · PR replay · Doctor-only comparison
  • Bun, 0.65 CPU. The original AWS reproduction timed out at 10.002 s on main and passed all 17 cases on the PR. A diagnostic run measured 15.74 s for the first import of the shared handler family. The independent three-file replay passed 17/17 on both revisions. Its first authenticated roster request to a built Gateway, using only operator.read, took 530 ms on main and 297 ms on the PR. Each figure is one observation. Original main · PR replay · Independent comparison
  • Related coverage. The independent run passed 4/4 PG16 cron cases and 191/191 planner tests. Six related handler suites passed 140 cases with 17 skipped. Separate runs passed all four PG17 cron cases, the production build, protocol freshness, formatting, and the scheduling regression. Independent comparison · PG17 suite · Handler suites · Build · Scheduling regression
  • Permission-read guard. The boundary job on 1a7b10dc1f97 reported exactly the two imported identifiers and four calls in the moved handler. The existing exact-count regression checks that every listed allowance matches its actual use. Failing boundary job

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

🦞 Made with OpenClaw

roboclaw-bot and others added 3 commits November 29, 2026 09:14
Keep release discovery out of the PostgreSQL cron lifecycle fixture and load the real agents handler before timing fixture-publication RPCs. Keep both deadlines and all persistence and socket assertions.

Co-authored-by: daniel-lxs <[email protected]>
The timed case covers the row lock, both stops, the second cold boot and the durable post-restart assertions. Build the initial live Gateway in fixture setup and dispose it before the outer schema cleanup.

Co-authored-by: daniel-lxs <[email protected]>
Worked on by:
- @daniel-lxs

Co-authored-by: daniel-lxs <[email protected]>
OpenClaw-Publication: cf4cd4e2-346e-449c-8eef-19758a8b9062
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M labels Nov 29, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. clawsweeper:intake:bug Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 29, 2026
@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR separates agent roster reads from mutation imports and routes two PostgreSQL process tests through the existing serial CLI-process lane.

Example: The first authenticated agents.list request on a CPU-constrained Gateway.

  • Before: The request loads the shared agent mutation family; the reported reproduction exceeded its 10-second deadline.
  • After: The request loads the dedicated roster family while retaining operator.read and the existing visibility checks.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving repair with reported production-entry-point comparisons, retained regression coverage, and the previous blocker corrected; broad exact-head CI remains pending.
Proof confidence 🐚 platinum hermit (4/6) This maintainer-authored PR is exempt from contributor proof gating; its body reports PostgreSQL process recovery and a first authenticated roster request through a built Gateway, while linked CrabBox artifacts could not be inspected because of the environment allowlist.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Cold agent discovery and process-heavy PostgreSQL checks can time out under CPU contention.
Reason: The maintainer-authored direction addresses recorded failures with a focused extraction and existing scheduling machinery.

Merge readiness

✅ Ready for maintainer review

This PR remains useful and has no identified blocking defect; the prior permission-read bookkeeping finding is resolved, while broader CI is still running.

Reviewed head: 9a569f1f094241c6ec7e784769c3e7323beae48b

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway method descriptors select lazy RPC handler families, while the test planner assigns test files to execution lanes with different isolation and scheduling settings.

flowchart TD
  A[Authenticated roster request] --> B[Method descriptor]
  B --> C[Lazy roster handler]
  C --> D[Existing catalog and visibility owners]
  D --> E[Roster response]
  F[PostgreSQL process tests] --> G[Serial isolated CLI process lane]
Loading

Technical review

Best possible solution:

Keep the dedicated lazy roster family and existing serial process-test owner while preserving the current RPC contract and lifecycle assertions.

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

Source confirms the shared cold import and previous test ownership; the PR supplies contention failures and comparisons, but this read-only review did not rerun them.

Is this the best way to solve the issue?

The change removes unnecessary imports through the existing lazy-registration mechanism and reuses established process isolation without increasing deadlines or introducing state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 153168fd09e4.

Provenance checked

  • Roster handler ownership changes intended behavior with a stated reason (3de2d07: Localize internal helpers with their consumers; the extracted roster now has an independently useful lazy-loading boundary.)
  • Lazy method registration keeps the original intent (0e94d23: Table-drive lazy handler registration while keeping method metadata canonical.)
  • PostgreSQL lifecycle test scheduling changes intended behavior with a stated reason (f920a7e: Qualify graceful shutdown and crash recovery separately with real processes and unchanged 90-second budgets.)
  • Permission-read bookkeeping keeps the original intent (f7ec430: Count existing permission-reader references per file and reject expanded authority reads.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +3, Tests +24, Other 0. Total +27 across 13 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 159 156 +3
Tests 8 36 12 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 13 196 169 +27

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • 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.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

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

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-29T09:57:33.475Z sha 2659d86 :: passed. :: none
  • reviewed 2026-11-29T13:07:01.841Z sha 1a7b10d :: needs changes before merge. :: [P2] [P2] Reconcile permission-read bookkeeping with the handler move

Reviewed November 29, 2026, 8:37 AM ET / 13:37 UTC (Revision 3).

roboclaw-bot and others added 3 commits November 29, 2026 10:43
Reconcile the PR with current main before comparing the original regressions. Keep both process startups within the cron case and time the first roster request without preloading the handler.

Co-authored-by: daniel-lxs <[email protected]>
Keep both real Gateway boots and the first roster RPC inside their unchanged deadlines.

Co-authored-by: daniel-lxs <[email protected]>
Worked on by:
- @daniel-lxs

Co-authored-by: daniel-lxs <[email protected]>
OpenClaw-Publication: 54de04c6-19f0-4298-a230-8537de2b62e5
@roboclaw-bot roboclaw-bot changed the title fix: keep fixture startup out of Gateway cron and roster test deadlines fix: avoid competing Gateway test boots and cold agent mutation imports Nov 29, 2026
@daniel-lxs
daniel-lxs marked this pull request as ready for review November 29, 2026 13:01
@daniel-lxs

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 9a569f1f094241c6ec7e784769c3e7323beae48b
  • Maintainer: @roboclaw-bot
  • Repository role: maintain

These security sensitive changes were made:

  • src/gateway/methods/core-descriptors.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Nov 29, 2026
Move the six existing permission-reader references to the lazy roster module in the admission-file guard. Keep the per-file count and the exact-count regression.
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 29, 2026
@daniel-lxs

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 29, 2026
@daniel-lxs
daniel-lxs merged commit a20fd1c into main Nov 29, 2026
226 of 228 checks passed
@daniel-lxs
daniel-lxs deleted the openclaw/postgres-cron-and-agents-list-346093 branch November 29, 2026 14:16
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
## Class: foreign updater records must not grant admission

Instances: #203486, #205736, #203917, and the modern release route refusing an old unfinished recovery.

The release preparation owner now takes its existing lock, checks the installation and physical restore guard, then records other unfinished runs as `failed: interrupted` and continues. It preserves its current run and the serving trial's handed-over run. The bounded drain reads current rows, not an enclosing Doctor snapshot.

In modern release preparation, the two recovery refusals remain: a positively live in-place lease holder, and `.openclaw-restore-*` that may contain the original state. Current modern locks/trials and normal preflight still apply.

## What disappears

- The 808-line interrupted plugin-cohort settlement owner, its run/finalize/repair discovery and replay paths, and obsolete killed-driver/death-proof suites.
- Foreign saved-row permission for plugin peer links, snapshot collection, interruption/reconciliation and terminal capture. Foreign cohort rows remain unchanged; another update does not replay their rollback.
- The critical-path retained-runtime census and its timeout branches. Existing owned-release path collection runs after ready; Doctor retains its separate old-runtime cleanup.
- Current mutation and Gateway completion read only their named pair. Main's existing all-row admission reader is retained only by the shipped package-finalization bridge, as the accepted fallback below.

Current source/executor/lifecycle/transaction/finalizer checks remain. Explicit repeated repair uses its existing abandonment and exclusive-ownership checks, not a foreign stored-recovery veto; it does not replay the saved cohort. Snapshot collection defers only inside this operation's existing live publication capture, preserving its rollback bytes without consulting foreign records. The shipped `finishInterruptedUpdate` export keeps its real staged finalization, pinned as a source build entry because the compatibility inventory names it.

No new state, flag, timer, death proof, schema/stored shape, or launcher/Gateway protocol change. Doctor-compatible reads remain for legitimate current cross-build bookkeeping, not foreign admission.

**Accepted legacy edge:** package-only finalization retains main's `recoveryAdmission` worker, coherent facts and assertion on its selected service/history roots. The schema-refusal/copy-cost cleanup is not redesigned here. Ordinary readiness guards keep their original no-recovery early return; modern release admission remains physical-only.

## Size

`tokei` on this PR's 39 runtime source files, excluding tests/support/harnesses and fixtures, against merged main `1e6d3f9bd9ecdbb061908ed30090bcf2fd6d7c2f` (original before-code base: `5c815265d5281c7929ab7483bd4e471e54e5c0ff`):

| | Before | After | Net |
| --- | ---: | ---: | ---: |
| Production code lines | 11,335 | 10,362 | **−973** |
| Test/support lines | | | **−2,447** |

Tooling routing/inventory and the update implementation contract are updated with the cut; their deletions are not counted as runtime savings.

## Verification

- Current head `b4e588ff5f9e35a27faa20232819c7f73e100d4a`, tree `12b76c0debe4b9b4ee2274c3459acce54acc1c3d`, fixes the landing review's lease-permission regression: slot inspection opens through the existing lease-store preparation owner, not direct identity capture. The existing slot table now covers an idle owned `0644` store being repaired to `0600` without refusing admission or changing history. Normal hooks passed; **current-head CI is pending**. Predecessor `63010e7d0af9` completed 87 successful checks with no failures/pending checks, including schema, copy-cost, healthy-caller, type, lint, ratchet and extension-boundary gates ([run](https://github.com/openclaw/openclaw/actions/runs/45952703299)).
- Corrected AWS Linux base proof: seven selected contracts, **six meaningful failures and one terminal-history control pass**. A pre-repair repeated-repair comparison selected two positive cases; both failed meaningfully. This supersedes the initial host-only baseline, which is not counted as Linux proof.
- AWS `747bd654fa01`: **145 passed, two skipped** across nine files; core/core-test/scripts/tooling types, changed lint/format and dead-export scans passed. AWS `9901b03a6ae4`: **132 passed** across six affected files, including real snapshot rollback and CLI deadline integration; core/core-test types, scoped lint/format and dead-export scans passed. [Final run](https://crabbox.openclaw.ai/portal/runs/run_95deb2b3c2b56df85ff53e839750f5c5). These are qualified source snapshots, not exact `2dfc213fbdc6` proof.
- The final local identity ratchet could not resolve the original base object after normal synthetic-source sync; that is a setup gap, not a policy verdict. Current CI owns the ratchet and the later two-root schema repair. Both owned AWS leases were released with exact `stop --wait` receipts; no paid resource remains.
- Predecessor `63010e7d0af9` passed the Linux published-to-head [`docker-seed-e2e` / `release-update-survivor` lane](https://github.com/openclaw/openclaw/actions/runs/45952703299/job/140352861920) in 2,615 seconds; healthy/crash/downgrade receipts are artifact 15179778195. Latest-head CI remains the landing gate. The standalone fixture-kit producer remains unsupported unchanged on AWS Linux because it requires Studio/macOS-only ocx cloning; no kit patch, host build, shim or separate paid campaign was used.
- Two local review rounds completed. The first review's request to restore foreign cohort settlement is [explicitly rejected](#206295 (comment)) under Ayaan's rule; its concrete repeated-repair case, build reachability and real path-state testing concerns are addressed. The second review's current-operation snapshot-retention finding is fixed through the existing live capture, not a foreign-row permission check. The maintainer reviews only this final delta.
- The active-list query now excludes the two protected named rows before its limit; `run.ts` has no ID comparisons and the identity allowlist does not grow. Four CI failures that asserted the deliberately retired foreign-record refusal were removed or migrated while retaining current-operation, service-profile and saved-evidence assertions.
- `47d896edda06` passed the two split-root schema cases but added a second snapshot on the common readiness path (`update-command-recovery-cost.test.ts:77`). Per maintainer direction, the move is reverted and main's admission is retained only for package finalization. Both schema assertions and the copy-cost assertion remain unchanged. Current reporting refusal remains; only the retired global-malformed-row policy tail is deleted. Current CI owns the fallback's qualification; earlier AWS snapshots do not prove it. Runner-shutdown ratchets and WebKit apt 403 were infrastructure failures, not product verdicts.
- Maintainer landing review and latest-head CI remain required; no worker merge performed.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 91d4912)

Release adaptation: Port the modern release preparation admission boundary only: retain the published package updater’s existing recovery contract, check live in-place custody and restore directories, interrupt only unowned run history, and preserve beta.2 release/runtime cleanup outside that boundary. No schema or row-shape changes.

Later same-path commits from the pinned scan (separate behavior unless named as folded/selected below): f84b705 fix: preserve lower-token guidance for unaffordable requests (#201392); dae01a9 fix: keep other agents running when one store is refused (#208364); a20fd1c fix: avoid competing Gateway test boots and cold agent mutation imports (#208203); c9f7a98 fix: keep container Gateway commands from rolling back host updates (#208271); edb6820 fix: let the Gateway restart while boot plugin maintenance is running (#208074); 516166c fix: exit once when gateway run rejects an argument after an update (#208068); 07e96dc fix: restart the Gateway after real plugin repairs (#208207); 13059ef fix: keep the PostgreSQL Doctor preflight test from timing out on module loading (#208225); 50d7708 fix: keep Claude fork compaction out of the parent chat (#208192); bd48ff6 fix: avoid restarting the Gateway for plugin timestamp changes (#208119); 259f71c fix: stop Linux service starts from copying the whole agent database (#207969); 7cb8975 fix: keep forked Claude chats separate after a Gateway crash (#208048); 407b523 fix(slack): thread queued DM replies under the triggering message (#208133); 43b5b52 chore(release): close out 2026.11.11 on main (#208114); 5d5284c fix(ci): add tagged reply control to the PR wrapper inventory (#208120); 1782ab0 fix: keep confirmed sends in the receiving chat's model history (#208049); 6d300d3 fix: restart launcher-managed Gateways after exit 78 (#207972); c4a675f fix: avoid reloading unchanged plugins after Gateway boot (#207949); 13c67a1 fix: let updates back up deeply nested databases (#207756); e2fcd4d fix: acknowledge updates when the Gateway first becomes ready (#207819); 8933edd fix: name safe recovery when agent schema markers disagree (#207705); 19e9dd6 fix(gateway): keep Linux legacy lock recovery explicit (#207340); 3256a47 test(update): move package ownership coverage to preparation (#207581); fbf1aae fix: give safe update ownership guidance and restore legacy result delivery (#207640); a922203 refactor(update): remove native post-activation Doctor subprocess (#207585); 7ac87ad fix: avoid taking service-account ownership during updates (#207563); b3902a2 fix(update): allow in-place updates without a full state copy (#207448); ece7a74 improve(workboard): apply the Control UI glossary and style to Workboard copy; 1c89587 fix: update system service packages without root state changes (#207304); dfd17d0 fix(docker): avoid pre-boot Doctor delays on container recreation (#207200); b616036 refactor(subagents): simplify ACP spawn relay ownership (#207023); 93ca762 improve: reduce allocations when preparing session rows (#207109); adb3716 fix(update): surface boot plugin repair advisories (#207163); f79ef8c fix: finish updates of 2026-11-17 main checkouts automatically on Linux and macOS (#207062); 3c4362b fix(update): preserve exception causes in failure history (#207085); 539f37f perf(gateway): keep legacy lease inspection out of heartbeats (#207084); 7a20389 fix: preserve source ranges in compaction requests (#207045); 20c92a4 fix: converge plugins after every Gateway boot (#206926); 3078862 fix(update): clean up rejected Git update worktrees (#207040); 73cb180 improve: reduce peak memory during Gateway startup update checks (#207073); 9993328 refactor(subagents): simplify kill claim and ownership handling (#207025); 97815bd refactor(subagents): consolidate registry cleanup and publication guards (#207064); 49c5e3e fix: let the end-of-turn recovery request reuse the turn's cached prompt (#207052); e94f799 refactor(subagents): centralize requester turn matching (#206584); e2e0974 fix(doctor): skip the state schema repair when its read-only plan finds nothing (#206694); 15e840e fix(ci): clear stale restart-sentinel exports from the dependency report (#206911); a72dcc9 fix(agents): resolve utility models against the session owner's role (#206962); 8ae0874 improve(gateway): avoid redundant cleanup for empty legacy auth stores (#206867); af1f26c improve: avoid unused proxy runtime in local text replies (#206931); 179e0c4 fix: label conversation data in system updates; ea77ca3 refactor: report update failures from recorded runs (#206700); 18e53d8 fix: finish Linux upgrades after a legacy Gateway crashes (#206530); f0e7d96 fix: preserve large snapshots in trajectory exports (#206810); c7ea9f4 improve: reduce memory used to renew state leases (#206798); 4d7e00b fix: let started participant runs and requests finish after an access change (#206747); dff00f3 fix(mcp): bound unavailable server notices in each turn (#206318); 9845bf5 fix(test): keep readiness abort fixtures alive until stopped (#206660); 844bfbf improve(build): trim unused imports from standalone relays (#170187); d4d45a7 improve: reduce memory when reading saved credentials (#206686); 461f650 fix(ci): keep startup helpers internal (#206649); f89ae43 refactor(subagents): use cleanup and terminal owners in sweeps (#206533); a882e0f fix(agents): preserve task answers when sessions are reused (#126263); 5c5f629 perf(config): keep update inspection out of ordinary config reads (#206607); ccb6d81 fix: finish core updates when the Gateway is ready (#206560); 74f02b4 fix: refuse root updates of a system service that runs as another account (#206343); 01032b1 fix(update): keep acknowledged run IDs when status is unavailable (#206562); cbdd907 fix: finish release updates after a slow launcher response (#206503); ad676f4 improve: reduce memory used by Gateway ownership checks (#206516); 81fc833 refactor(subagents): own dormant child Stop decisions (#206479).
Later PR-number mentions: `ccb6d8168658` fix: finish core updates when the Gateway is ready (#206560), `ea77ca3d602c` refactor: report update failures from recorded runs (#206700) Later commit-SHA mentions: `238c6daf2ba6` perf: import llm-core types from their leaf entry (#206518), `ccb6d8168658` fix: finish core updates when the Gateway is ready (#206560)
Pinned PR grep: ea77ca3 refactor: report update failures from recorded runs (#206700); ccb6d81 fix: finish core updates when the Gateway is ready (#206560); 91d4912 fix(update): stop using foreign recovery records as admission (#206295); 41afc0f fix(update): keep successful plugin reload warnings advisory (#206372)

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 29, 2026
)

Supersedes #207992.

## Problem

An isolated automation turn (`gateway call agent` with its own session key, `channel: telegram`, `to: <dm>`, `deliver: false`) sends a Telegram DM with the `message` tool. The user sees the message, replies, and the DM's assistant has no record of it.

Cause: `commitConfirmedVisibleMessage` decided "the producer's own turn already wrote this" by comparing the producer session's stored `delivery.context` with the send address (`createProducerMatcher`), and returned a silent skip. The gateway `agent` request stores its `channel`/`to` routing hint on the isolated session even with `deliver: false`, so the hint matched the DM address and the DM history write was dropped.

## Fix

- Own-turn is decided only by conversation identity: canonical store key of the producer === canonical store key of the resolved destination. The address matcher and both call sites are removed.
- Every remaining not-recorded outcome carries a diagnostic (`skipped()` now requires one).
- The unused `skipDestinationHistory` opt-out is removed (`deliver-contracts.ts`, `message.ts`, `deliver-core.ts`, its test).
- `docs/refactor/conversation-transcript-ownership.md` describes own-turn by key only.

Production diff: 5 files, net negative.

## User impact

A message the user saw from an automation or another session now lands in the destination chat's model history. A same-chat turn's own final reply still gets no second row. No config, schema, protocol or migration change.

## Evidence

- Red on base, green here: `src/sessions/confirmed-visible-message.integration.test.ts` "records an isolated producer's send despite matching DM routing hints=true". The test that asserted the old "context" skip is deleted.
- No duplicate on the real dispatch path (`src/auto-reply/reply/dispatch-visible-history.integration.test.ts`): Telegram DM with `dmScope` `main` and `per-channel-peer`, Telegram forum topic, Discord channel, Control UI/webchat. Each resolves the same outbound route key as the inbound session, so no key-parity fix was needed.
- Affected consumer tests (30 files) passed locally.
- Real Telegram (Test Server, real model), base `a65ac074b3d6`: the isolated producer's DM arrived once; the DM transcript and the DM agent's next model request did not contain it, and the agent answered with an older reply.
- Real Telegram, head `ee6eed48a208` (same entry point): `gateway call agent` with `sessionKey: agent:main:bedtime-e2e`, `channel: telegram`, `deliver: false`; the agent sent "It's 10:15 pm, time for bed. The amber bookmark can wait until morning." once with the `message` tool. The DM session (`agent:main:main`) then had that text as one assistant row (no duplicate). The user asked "what did you just send me?" and the DM agent answered: "I just sent: “It's 10:15 pm, time for bed. The amber bookmark can wait until morning.”"
- Local ClawSweeper review on `ee6eed48a208`: patch correct, zero findings.
- CI: every check passed except `check-lint-core-5`, which fails on three lint errors in Workboard e2e files from #207839 that are on `main` and not in this diff (#208070; override comment on this PR).

## Not changed here (decision recorded)

Plugin-action settlement (`outbound-send-service.ts` `onHandled`): a base test showed a plugin action that sends through durable delivery and also returns a native receipt can write two destination rows (different `deliveryId`s). Deleting the `onHandled` writer would drop history for third-party handlers that send natively and return only a receipt. Routing those through delivery settlement is a new design, so it is a follow-up, not part of this cut.

## Follow-ups

- Exactly-once native receipt settlement that keeps receipt-only plugin handlers.
- Registry-first destination resolver; sessions not created by inbound must not claim chat addresses (removes the "ambiguous" skip).
- Store the not-recorded reason on the delivery queue row (schema change).
- Route direct channel notices through the owner: Telegram `bot-message.ts`, `dm-access.ts`, native command replies; Discord `native-command-reply.ts`; Signal/Matrix approval handlers.
- Inbound "accepted ⇒ in transcript" for queue drop/summarize paths; failed-delivery and overlap-dedupe history on the agent side.

## Merge risk

Revert restores the old skip. Rows already appended stay.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 1782ab0)

Later same-path commits from the pinned scan (separate behavior unless named as folded/selected below): a20fd1c fix: avoid competing Gateway test boots and cold agent mutation imports (#208203); edb6820 fix: let the Gateway restart while boot plugin maintenance is running (#208074); 50d7708 fix: keep Claude fork compaction out of the parent chat (#208192); 94ee07a fix: approval prompts sent to another chat now enter that chat's history (#208204); b904594 fix: record an announced send in the chat it reached (#208169); 407b523 fix(slack): thread queued DM replies under the triggering message (#208133); 5b7efcd fix(outbound): record a plugin action's visible send once (#208130).
Later PR-number mentions: `16a2d4b59d75` refactor(ui): lowercase log search text only once (#207383), `21786f65ed93` refactor(ui): stop sending 28 additional unused labels to translators (#207982), `34d4f8f308ba` improve: list Docker streams and flag unconfirmed cleanup in Doctor (#201292), `5b7efcd4c02e` fix(outbound): record a plugin action's visible send once (#208130), `94ee07a60057` fix: approval prompts sent to another chat now enter that chat's history (#208204), `9cec330df50d` refactor(workboard): group session tiles without rescanning each column (#207380), `b904594b0377` fix: record an announced send in the chat it reached (#208169), `eb378faead30` fix(workboard): clear lint errors in the board settings modal (#208113) Later commit-SHA mentions: none

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 30, 2026
…ts (openclaw#208203)

Route agents.list through its own lazy read handler so a cold roster request avoids loading agent mutations. Run the PostgreSQL cron and Doctor CLI fixtures in isolated serial forks, keeping both Gateway boots inside the existing 90-second case.

Co-authored-by: daniel-lxs <[email protected]>
OpenClaw-Publication: cf4cd4e2-346e-449c-8eef-19758a8b9062
OpenClaw-Publication: 54de04c6-19f0-4298-a230-8537de2b62e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts security-sensitive-changed size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants