Skip to content

refactor(sessions): unify in-memory turn, queue, and stop ownership - #162433

Closed
roboclaw-bot wants to merge 1 commit into
mainfrom
openclaw/openclaw-issue-diligence-and-assessment
Closed

roboclaw-bot wants to merge 1 commit into
mainfrom
openclaw/openclaw-issue-diligence-and-assessment

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #160737

What Problem This Solves

Session turns, queued inputs, cancellation and mutations rely on overlapping owners, making it difficult to keep stale callbacks and unfinished cleanup from interfering with the next turn.

User Impact

The intended outcome is consistent ordering and cancellation across channel, Gateway, native and scheduled work, with successors and mutations waiting for the correct outstanding work to settle.

Draft for design/code review, not merge-ready. Full latest-source reply E2E and some isolated integration proof remain incomplete. This is a broad in-memory ownership cutover, not a claim of measured performance or maintenance-time improvement.

No SQLite schema change: no tables/columns, schema-version bump or migration; no durable mailbox is introduced. Existing persisted write/delete formats remain, but their admission and cleanup ordering change, including session deletion, maintenance preservation, startup orphan checks and delivery enqueue admission.

Why This Change Was Made

Extend the existing reply-operation owner into a physical-session controller rather than add another scheduler:

  • One mailbox/selector for queued inputs and native work; adapters retain authorization, routing, batching and delivery policy.
  • Exact store/incarnation, operation, source and backend-attempt identities for late callbacks, steering and cancellation.
  • Shared Stop and mutation coordination; an abort or terminal outcome is not proof of raw writer/source settlement.
  • Controller-owned progress/watchdog state; global capacity and database write fences remain separate owners.

The goal is correctness and maintainability, not a net line reduction. The implementation is larger and still uses imperative mailbox/lifecycle/Stop modules around a narrower pure phase/outcome reducer.

Umbrella issue coverage

“Addressed” below means implementation is present in this draft, not that each issue's full acceptance criteria are complete. No issue is auto-closed.

Issue Coverage in this draft Remaining qualification
Related: #160738 — statechart, invariants and model tests Partial: controller documentation, pure phase/outcome reducer and seeded models driving real boundaries Not the proposed complete pure controller transition/effect model; full shared acceptance and cost accounting remain open
Related: #160739 — busy state and run ownership Canonical controller ownership and attached native attempts replace independent turn ownership Distinct busy/admissible/injectable/settled projections remain intentional; cross-surface acceptance pending
Related: #160740 — queueing and steering Canonical mailbox, interrupt priority, collect/source custody and shared admission; old queue/adoption owners retired Full current reply/channel E2E pending; guarded steering during compaction preserves supported runtime behavior rather than blanket rejection
Related: #160741 — Gateway chat.send and agent RPC Shared input/turn admission; RPC source correlation replaces Gateway-owned queue/abort decisions Complete mixed-surface, UI and restart acceptance not claimed
Related: #160742 — Stop entry points Common captured-target cancellation with retained cleanup and source-specific scope Preserve legitimate source-specific effects/hooks; complete entry-point QA pending
Related: #160743 — mutations and per-session lanes Reset/delete/compaction coordination through controller; per-session turn lanes retired Global capacity, persisted fences and subordinate physical-effect custody remain; isolated integration proof pending
Related: #160744 — watchdog Operation-owned progress/deadlines/recovery, without session-lane reset as recovery Cancellation timeout cannot declare abort-insensitive work settled; complete issue-level acceptance remains open

Not addressed: #160745, the separately reviewed durable mailbox / restart-persistence stage. No SQLite schema work is included.

Evidence

Current focused evidence after pre-publication review corrections:

  • Required independent review completed all 11 passes. Its 7 findings were reproduced in 12 failing boundary cases, then corrected; this is a reconciled review, not a claim of a clean pre-fix verdict.
  • 92 passing cases across 9 complete owning test files, combining applicable receipts without double-counting. Coverage includes exact-input admission, physical-store dedupe, incarnation-scoped mutation, retry custody, deadlines, RPC execution projection, bounded lifecycle responses and seeded models.
  • Representative measured runner durations: archive lifecycle 18 cases / 20.59 s; queue dedupe 16 / 3.15 s; native lane controller 7 / 3.80 s. The final lifecycle-only rerun was 11 / 42.45 s, with 97% attributed to cold worker transformation, not sleeps; these tests exercise the real ownership boundary with deferred work/fake clocks.
  • Production core types and all 26 affected canonical test graphs passed; final local context-reuse cleanup received another core/owner-graph refresh. Scoped production/test lint, formatting, source line caps, assertion safety, import cycles, whitespace and all three native Knip scans passed (zero Knip entries).
  • Earlier broad-candidate proof included a normal full package build (318.67 s) and 35 type execution graphs (322.41 s). That build preceded the final review corrections; it is not presented as a rebuilt final-head artifact.

Known gaps / failures:

  • Full latest-source 222-case reply E2E is not complete. The last completed full run on an older candidate was 210 passed / 12 failed; later focused repairs are not a new full-suite pass.
  • Telegram loopback remains unresolved after question registration; two auxiliary root integration files still need genuinely isolated runtime proof.
  • Compound max-lines remains red on the inherited environment budget 477 > 476 at the pinned base; not waived and not raised.
  • Full changed-test cost accounting and current-head hosted CI remain pending. No CI reruns or workflow dispatches were used as proof.
Review navigation and size context

Start with docs/concepts/session-controller.md, then the controller state/mailbox, lifecycle/Stop and native attachment boundaries. The diff mixes ownership changes, caller migration and fixture changes; it is not 925 independent features.

Pre-publication path inventory (rename sides counted separately): 925 paths, including 96 untracked replacement files; +40,696 / -32,903, net +7,793. Filename-classified runtime: +18,923 / -15,203, net +3,720; tests/fixtures: +21,498 / -17,683, net +3,815. These are not GitHub's rename-aware display counts or a complexity/correctness score. The original estimate used a different baseline.

Worked on by

Work sessions


View the OpenClaw team session

Worked on by:
- @jalehman

Co-authored-by: jalehman <[email protected]>
OpenClaw-Publication: 280d4aaa-a70a-4ff0-a028-499a3e7486af
@clawsweeper

clawsweeper Bot commented Oct 1, 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 docs Improvements or additions to documentation channel: slack Channel integration: slack channel: telegram Channel integration: telegram app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling extensions: acpx extensions: codex extensions: copilot channel: sms Channel integration: sms extensions: agentsapi size: XL labels Oct 1, 2026
@jalehman

jalehman commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Superseded by #165957, which carries this work forward on oc-05e/session-controller-cutover with the final review findings resolved, the full owner-area test sweep, and live evidence from a maintainer Gateway. Discussion and tracking continue there.

@jalehman jalehman closed this Oct 6, 2026
This was referenced Oct 6, 2026
@RomneyDa
RomneyDa deleted the openclaw/openclaw-issue-diligence-and-assessment branch October 22, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui channel: slack Channel integration: slack channel: sms Channel integration: sms channel: telegram Channel integration: telegram cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: acpx extensions: agentsapi extensions: codex extensions: copilot gateway Gateway runtime size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants