Skip to content

refactor: consolidate Gateway and session owners - #180432

Merged
steipete merged 10 commits into
mainfrom
deslop/z33-76-gateway-session-owners-20261015
Oct 22, 2026
Merged

steipete merged 10 commits into
mainfrom
deslop/z33-76-gateway-session-owners-20261015

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway and session code repeat preference projection, request validation, error shaping, FIFO operation queues, and delivery-context projection that already have shared owners.

What Changed

Reuse the existing session preference projector for verbose/trace and execution host settings; remove the orphan level-override module and its stale test mock. Migrate push and ClawHub handlers to the existing validated Gateway handler, keeping the original request-options identity and effect-time authority checks. Reuse the existing file-error, async-lock, memory-pressure subscription, physical-path fallback, heartbeat type, and delivery-context owners.

This is the Gateway/session AREA slice of a larger measured cleanup: 26 paths, 192 net production lines removed, and 168 net test lines added. The original accumulator touched 99 paths, so the campaign requires separate below-500 area PRs for attribution. The other open slice does not touch these production files.

No intended user-visible behavior, error text, protocol/config shape, schema, dependency, or public Plugin SDK contract changes. The legacy and current delivery-target predicates retain their different policies. Main's unrelated inline route-metadata projection stays inline.

Best-effort tradeoffs accepted

None introduced in this slice. Validation, authorization after awaits, FIFO ordering, failure recovery, joined cleanup, durability, and public contracts remain in place; this removes private duplicate implementations, not their safeguards. Phase E standalone session-memory machinery and tests are untouched.

Evidence

  • Full-area independent review is scoped-clean at P0–P2.
  • Supported Node 26.12.1 proof passes formatting, targeted native typechecking, type-aware lint, all 497 focused cases across 21 files (293 seconds including worker preparation), wrapper closure (3 cases), and prompt-prefix stability (6 cases). Runtime and static import cycles are both zero.
  • The actual assertion-safety and mock-export ratchets pass; changed-check selection dry-run passes. No whole-graph local typecheck was used.
  • The suppression audit remains failed (13 cases pass, 1 fails): three pre-existing rows in unchanged cron/UI and src/transcripts/library.query-budget.test-support.ts produce 103 actual versus 100 expected. The third row is present verbatim in this branch's newer base 04a0bdfa; the complete diff adds no suppression. The two cron/UI rows also have a retained identical clean-base replay from the preceding area. No allowlist was widened, and this failure is not reported green.
  • Tests retain tri-state preference projection, first-error/no-partial-apply behavior, request authority identity, malformed/forbidden/catalog-error responses, FIFO failure recovery, worker pressure retirement, delivery precedence, and lexical/physical service paths.
  • Exact-head PR CI is the broad proof. No local whole-graph typecheck, build, E2E, or broad test suite was run.

Use the existing validated Gateway handler owner for all three catalog
methods. Keep the current error mapping, logging, exact request options,
and all six Labs checks before I/O and immediately before each reply.

Extend existing boundary coverage for preview revocation, malformed
inputs, and typed versus unknown public failures. All 16 owner/validator
cases pass before and after the cut. Targeted native types, typed lint,
format and planner pass; independent P0-P2 review is clean.

Removes 18 net production lines without a new helper or public contract.
Best-effort tradeoffs accepted: none newly introduced.
@clawsweeper

clawsweeper Bot commented Oct 22, 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. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 22, 2026 08:06
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling labels Oct 22, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T08:09:51.855761Z ecf0b56 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR consolidates Gateway validation, session preference projection, delivery helpers, operation queues, and worker resource bookkeeping.

Example: Patch an existing session with execHost set to " GATEWAY ".

  • Before: The execution-settings helper stores "gateway".
  • After: The shared preference projector stores the same "gateway" value.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful consolidation with no actionable defect found; validation is harness-based, and persisted-format compatibility is supported by unchanged projection and migration expressions.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal refactor is outside the ordinary contributor proof gate; its supplied evidence is focused test and static validation, and inspection found no material authority-chain change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Duplicate internal implementations increase the chance that equivalent Gateway and session operations drift apart.
Reason: The maintainer-authored direction removes private duplication without adding settings, state owners, or public contracts.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR removes duplicate implementations using existing owners, with no concrete introduced regression found.

Priority: P3
Reviewed head: ecf0b5630ee04c4cc6b29c2237e1c8c3e85c3f25

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied validation covers focused tests and harnesses; no shipped Gateway, mobile-device, or latest-stable upgrade run is claimed.
Agent review details

How this fits together

Gateway handlers receive validated RPC requests, preserve request authority, and invoke session, notification, catalog, and filesystem owners that return responses or commit existing state.

flowchart TD
  Clients --> GatewayHandlers
  GatewayHandlers --> SharedValidation
  SharedValidation --> SessionPreferences
  SharedValidation --> PushAndCatalogOwners
  SessionPreferences --> ExistingSessionState
  PushAndCatalogOwners --> ResponsesAndEffects
Loading

Technical review

Best possible solution:

Land the existing-owner consolidation once the exact-head required checks complete successfully.

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

No failing user scenario is claimed for this refactor, and no target code was executed during the read-only review.

Is this the best way to solve the issue?

The change appropriately reuses existing owners while preserving distinct policies, request identity, error envelopes, and cleanup ordering.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Gateway validation and Web Push preferences keeps the original intent (refactor(gateway): move Web Push preferences to SQLite workers #163355: Keep subscription custody and current profile authority across asynchronous preference operations; the consolidation retains these checks and their ordering.)
  • Claws catalog handlers keeps the original intent (feat: add Claws as ordinary agents and resources #171623: Expose Claws as ordinary resources while retaining explicit trust boundaries; catalog gating and public error distinctions remain intact.)
  • Session preference projection keeps the original intent (0afa9be: Centralize normalized session preference projection; the PR extends that existing owner while preserving omitted, cleared, and explicit values.)
  • Installed-agent execution preferences keeps the original intent (feat: select and manage installed agents from Models #150224: Retain session-owned execution choices and incarnation-bound native consent; moving execHost normalization leaves node binding, sandbox restrictions, and consent retirement unchanged.)
  • Canonical delivery and legacy recovery keeps the original intent (refactor: canonicalize session delivery state #113225: Maintain one canonical durable delivery state and migration-owned legacy recovery; only identical internal-context and merge operations are shared.)
  • Transcript worker pressure subscriptions keeps the original intent (fix(runtime): release retired SQLite worker pressure listeners #157584: Release retired listener references while retaining active and retryable cleanup custody; the shared subscription helper preserves the same custody predicate and callback.)
  • Serialized mobile, Tailscale, and snapshot operations keeps the original intent (07795a1: Tailscale operations serialize route ownership changes; mobile observations and snapshot staging similarly serialize their owner operations, and the pinned shared lock preserves FIFO and failure release.)
  • Snapshot staging resource custody keeps the original intent (46c2c45: Retain independent staging sessions across Doctor inspection contexts and retry failed cleanup without replaying completed retirement; session selection and cleanup remain unchanged.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced change and current-main context: Reviewed the pinned merge-base-to-head hunks; fetched main retains the pre-refactor production implementations. The checkout remained clean. (ecf0b5630ee0)
  • Request authority identity preserved: The existing validation wrapper passes the exact options object to its handler; push guards and Claws pre-I/O and pre-reply checks remain in their existing execution positions. (src/gateway/server-methods/validation.ts:75, d08aeb1d984a)
  • Persisted delivery semantics preserved: The extracted merge uses the same channel, target, account, and thread expressions; legacy migration retains its distinct external-target predicate and canonical recovery logic. (src/infra/state-migrations.legacy-session-store.ts:366, ecf0b5630ee0)
  • Historical worker-preference contract: refactor(gateway): move Web Push preferences to SQLite workers #163355 establishes subscription custody across asynchronous preference operations; this PR preserves that interval, worker calls, profile checks, and recipient selection. (src/gateway/server-methods/push.ts:355, 2a8538469f45)
  • Discussion and exact-head checks: The full body and comments supply focused test and static-check results, with no shipped-entry-point run claimed. Paginated checks show three PostgreSQL conformance jobs in progress, a pending CI gate, and a cancelled auto-response job; no failed product check was observed. (ecf0b5630ee0)
  • Pinned dependency contract inspected: The patch imports createAsyncLock from this dependency, pinned to 0.26.8, making its contract applicable. Its source queues callers synchronously, awaits the preceding operation, and releases in finally after success or failure; its complete root policy was also read. (src/async-lock.ts:1, 5c9d7c1b5fbb)

Likely related people:

  • Peter Steinberger: Raw commit 0afa9be adds src/gateway/sessions-patch.ts:302 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0afa9bed5d37; files: src/gateway/sessions-patch.ts)

PR surface

Source -192, Tests +168, Other -1. Total -25 across 26 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 15 340 532 -192
Tests 10 204 36 +168
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 26 544 569 -25

Review metrics

Metric Value Why it matters
Production versus test LOC Production +340/-532; tests +204/-36 Production shrinks by 192 lines; test growth covers preference retention, validation, stale authority, FIFO failure recovery, and path fallback contracts.

Labels

Label changes:

  • add P3: This is internal consolidation with no intended user-visible behavior change or demonstrated urgent defect.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P3: This is internal consolidation with no intended user-visible behavior change or demonstrated urgent defect.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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.

Reviewed October 22, 2026, 4:23 AM ET / 08:23 UTC.

@steipete
steipete merged commit b109428 into main Oct 22, 2026
217 of 218 checks passed
@steipete
steipete deleted the deslop/z33-76-gateway-session-owners-20261015 branch October 22, 2026 08:30
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
* refactor(gateway): share Claws catalog validation and errors

Use the existing validated Gateway handler owner for all three catalog
methods. Keep the current error mapping, logging, exact request options,
and all six Labs checks before I/O and immediately before each reply.

Extend existing boundary coverage for preview revocation, malformed
inputs, and typed versus unknown public failures. All 16 owner/validator
cases pass before and after the cut. Targeted native types, typed lint,
format and planner pass; independent P0-P2 review is clean.

Removes 18 net production lines without a new helper or public contract.
Best-effort tradeoffs accepted: none newly introduced.

* refactor(daemon): reuse service path fallback owner

* refactor(gateway): share push request validation

* refactor(sessions): share patch preference projection

* refactor(gateway): share file operation error envelopes

* refactor(gateway): reuse normalized exec host projection

* refactor(heartbeat): reuse shared summary type

* refactor(sessions): share legacy delivery merge helpers

* refactor(core): reuse async lock for operation queues

* refactor(sessions): reuse worker pressure subscription owner
tideclaw-bot pushed a commit that referenced this pull request Nov 4, 2026
Adapt #190982 to the existing stable plugin handoff. Internal callers without an external recipient resume through webchat rather than the last recorded external route. Preserve current authority, target identity, cleanup, and settlement checks. Export only the existing internal-route predicate from #180432.

The composed consumer test uses the host-owned SQLite shard for actual idle and queued dispatch and managed message-tool rejection.

Adapted from e375530; helper export only from b109428.

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

1 participant