Skip to content

refactor: keep internal wakes out of message channels - #132986

Merged
steipete merged 2 commits into
mainfrom
codex/typed-internal-turn-source
Aug 30, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/typed-internal-turn-source

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Related: #132817, #132890

What Problem This Solves

Internal cron and background-process wakes were represented as message providers such as cron-event and exec-event. That let a wake reason leak into delivery routing and subagent tool context, requiring downstream exceptions. The CLI MCP grant also preferred this label over an explicit real message channel.

Why This Change Was Made

Carry the wake cause in MsgContext.InternalTurnSource and keep transport/reply routing separate. The heartbeat owner produces the typed field; session reset, reply-route inheritance, participant observation, and prompt assembly consume it. Shipped SDK legacy inputs normalize at ingress. The CLI grant now uses the same channel precedence and resolver as embedded tools.

The transient event queue and wake scheduler remain necessary for work that happens after a user turn, but they no longer need to pretend to be channels. This change does not alter event persistence, notification policy, transcript provenance, execution authority, configuration, or Gateway protocol. Shipped Gateway internal source hints remain accepted; the two unshipped cron-event/exec-event exceptions from #132890 are removed.

Production LOC: +78/-70 (net +8). Tests and QA: +570/-219. Docs: +17/-0. The remaining production growth is the single typed-source and SDK normalization boundary; repeated source predicates and the CLI-specific channel wrapper were removed.

User Impact

Cron and exec completion turns retain their session and reply route and can delegate work without passing a fake channel to a child. Plugin authors can use the typed source directly; legacy SDK callers remain supported.

Evidence

Before-change regression proof: the original ingress and CLI-grant modules fail all six new source/route cases, with 50 existing tests passing. The failures show legacy labels winning over Telegram and missing typed source normalization.

All 741 focused tests passed, including Gateway rejection of the two unshipped pseudo-channels. node scripts/check-changed.mjs passed all typecheck targets, lint, dependency/boundary guards, dead-export checks, and runtime import-cycle checks. Exact-head CI is required before landing.

Independent Codex autoreview passed with no accepted findings at its default P0 threshold; maintainer code reading covered producer, ingress, session metadata, routing, queue handoff, CLI/embedded tool construction, and the pinned Codex turn-input contract.

Live QA requires naturally fired main-session cron and delayed background exec completion to spawn successful children. Each child must actually read and return a random marker absent from the parent instruction. Exec completion is released only after its initial turn ends. The scenario uses the isolated QA channel; current routeless exec-output suppression is deliberately preserved.

Final live proof passed on both embedded OpenClaw and Codex app-server, using real Gateway processes and live models in an isolated Testbox lease. All four cron/exec children succeeded, read and returned their hidden random markers, and reached delivered status. No tool errors appeared in retained parent or child transcripts. Both exec timelines prove initial-turn completion before process completion, followed by accepted spawn and successful child completion. The lease and its two retained temporary roots were cleaned up after evidence collection.

Reproduction: run openclaw qa suite --provider-mode live-frontier --runtime-pair openclaw,codex --scenario internal-event-subagent-spawn-live --concurrency 1 through the repository Testbox wrapper. The final 30-file source snapshot is SHA-256 c1b73f892aaeb579847739d1612b0793a013e76898b63025e14b1c0dd5ccf224. Ordinary CLI execution is covered by focused grant-context tests, not this live runtime matrix.

Earlier live attempts corrected fixture assumptions: completion output is intentionally truncated, and the Codex tool is named gateway_exec. The final fixture gives prior user authorization and short completion metadata within that contract. An intermediate fixture additionally requested sessions_yield and exposed requester settlement retrying despite transcript-visible child output. The final scenario does not request yield; its original spawn, real-read, hidden-marker, and chronology assertions remain intact.

Named follow-up: Yielded internal-turn requester settlement rejects transcript-visible results without confirmed requester delivery. The settlement and visibility owners are unchanged, but the captured intermediate artifacts do not expose the exact requester origin, delivery target, and final delivery status. Capture those inputs and compare the identical yielding scenario on the base before classifying this as preexisting or attributing it to this refactor. This PR does not claim to repair that separate settlement path.

The first hosted CI run exposed missed test expectations in the real-heartbeat cron integration, CLI grant/tool projection, and QA lane catalogue. The follow-up changes only those four test files: assert the typed cron source and absent pseudo-provider, preserve explicit Telegram precedence, and include the new scenario in the exact catalogue count/list. The full affected suites passed (124 cron/CLI tests and 150 QA tests), and the test-only follow-up passed independent review. Production and live-scenario bytes remain identical to the recorded live snapshot.

@clawsweeper

clawsweeper Bot commented Aug 30, 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 gateway Gateway runtime agents Agent runtime and tooling extensions: qa-lab size: L maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 01:38
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 9:57 PM ET / August 30, 2026, 01:57 UTC.

ClawSweeper review

What this changes

Moves heartbeat, cron, and exec-completion wake identity out of message-channel fields into typed internal context, updates routing and CLI tool grants, and adds regression coverage plus a live cron/exec scenario.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the branch coherently replaces recently introduced pseudo-message-channel wake labels with a typed internal-source field and preserves real delivery routing; no introduced functional defect was found. It still needs normal exact-head CI completion and compatibility review before landing.

Priority: P2
Reviewed head: b1002a65b8b0d7bc805d662abf4e483275bf81c1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch uses the appropriate owner boundaries and focused coverage, with a remaining compatibility-boundary check before merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The PR body supplies an after-fix Testbox scenario exercising real cron and delayed exec wakes through the production reply and runtime paths for embedded and bundled Codex app-server runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body supplies an after-fix Testbox scenario exercising real cron and delayed exec wakes through the production reply and runtime paths for embedded and bundled Codex app-server runs.
Evidence reviewed 7 items Typed-source owner boundary: The branch adds InternalTurnSource to message context, normalizes legacy internal wake labels at ingress, and removes them only from delivery-related context fields.
Producer and routing preserve delivery metadata: Heartbeat execution emits a typed exec, cron, or heartbeat source while retaining the originating delivery fields; reply routing uses the persisted route for internal wakes.
Shared channel validation is reused: The CLI MCP grant resolves messageChannel before messageProvider and validates the result with the existing Gateway channel resolver, matching the embedded tool path.
Findings None None.
Security None None.

How this fits together

Heartbeat and system-event jobs enter the reply pipeline with delivery metadata and an internal wake reason. The reply pipeline selects a real reply route, then CLI and embedded runtimes pass only validated message channels to Gateway tool execution.

flowchart LR
  A[Heartbeat and cron events] --> B[Internal wake context]
  B --> C[Reply pipeline]
  C --> D[Effective reply route]
  D --> E[CLI or embedded runtime]
  E --> F[Validated Gateway tool call]
  F --> G[Subagent or channel action]
Loading

Before merge

  • Resolve merge risk (P1) - The latest supplied release predates merged PR fix: allow subagent spawns from system events #132890, while this branch removes that current-main pseudo-channel acceptance; confirm that direct uses of those aliases have no released or documented compatibility contract.
  • Resolve merge risk (P1) - Exact-head CI is still incomplete, so landing should wait for the required checks and the latest review context.
  • Complete next step (P2) - An active maintainer PR needs exact-head CI completion and confirmation of its public compatibility boundary, not a parallel repair branch.
Agent review details

Security

None.

PR surface

Source +14, Tests +50, Docs +17, Other +295. Total +376 across 34 files.

View PR surface stats
Area Files Added Removed Net
Source 17 88 74 +14
Tests 15 265 215 +50
Docs 1 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 1 295 0 +295
Total 34 665 289 +376

Review metrics

Metric Value Why it matters
Production versus test delta production +76/-67 (net +9); tests/QA +572/-222; docs +17/-0 The small production increase establishes a shared typed boundary; most of the change is focused regression and scenario coverage.

Merge-risk options

Maintainer options:

  1. Verify the compatibility boundary (recommended)
    Before merge, confirm that legacy SDK ingress normalization covers supported callers and that pseudo-channel acceptance added after the latest release is intentionally not a public contract.
  2. Accept main-only alias removal
    Accept removal of cron-event and exec-event as Gateway channels if maintainers confirm they were never a released or documented caller contract.

Technical review

Best possible solution:

Land the typed wake-source boundary once exact-head checks pass and maintainers confirm that legacy Provider normalization is the intended compatibility boundary rather than retaining wake labels as message channels.

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

Yes: source establishes the reported scheduled system-event to CLI MCP to Gateway validation path, and the PR body reports an after-fix live cron and delayed-exec scenario.

Is this the best way to solve the issue?

Yes: placing wake identity in typed ingress and producer context while reusing the existing real-channel resolver removes the fake-channel exception rather than expanding it.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 731230b6f6fe.

Labels

Label changes:

  • add P2: This is a bounded reliability refactor for system-event subagent workflows, without evidence of an active released outage.
  • add merge-risk: 🚨 compatibility: The PR changes the public message-context shape and removes currently accepted pseudo-channel aliases from Gateway validation.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix Testbox scenario exercising real cron and delayed exec wakes through the production reply and runtime paths for embedded and bundled Codex app-server runs.
  • 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 (logs): The PR body supplies an after-fix Testbox scenario exercising real cron and delayed exec wakes through the production reply and runtime paths for embedded and bundled Codex app-server runs.

Label justifications:

  • P2: This is a bounded reliability refactor for system-event subagent workflows, without evidence of an active released outage.
  • merge-risk: 🚨 compatibility: The PR changes the public message-context shape and removes currently accepted pseudo-channel aliases from Gateway validation.
  • 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 (logs): The PR body supplies an after-fix Testbox scenario exercising real cron and delayed exec wakes through the production reply and runtime paths for embedded and bundled Codex app-server runs.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix Testbox scenario exercising real cron and delayed exec wakes through the production reply and runtime paths for embedded and bundled Codex app-server runs.

Evidence

Acceptance criteria:

  • [P1] Review required exact-head CI results.
  • [P1] Confirm supported legacy SDK ingress callers normalize Provider wake labels before Gateway routing.

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for exact-head CI to complete successfully.
  • Confirm legacy Provider alias handling is the intended supported compatibility commitment.

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Compatibility boundary confirmed for the ClawSweeper review and rank-up move: cron-event/exec-event Gateway channel acceptance was introduced only by 1d17226 (#132890, August 29). No release tag contains that commit. The current release list still predates it (latest prerelease August 28); the v2026.7.1 channel allowlist contains neither alias. The docs/SDK/protocol search found no direct Gateway channel contract for these aliases; the hooks documentation mentions exec-event only as a system-run category.

The supported compatibility commitment is legacy SDK Provider input. It remains normalized by the inbound finalizer and raw session metadata/conversation-identity entry points into InternalTurnSource, preserving real channel/account/target/thread fields. The focused legacy-ingress and session-accessor tests cover this, while Gateway tests deliberately reject the two unshipped channel aliases. Older shipped Gateway source hints remain accepted. This is the intended boundary for this refactor; no additional runtime alias is needed.

The final branch has passed 741 focused tests and live embedded/Codex cron+exec delegation; production and live-scenario bytes are unchanged after the CI test-only correction. Exact-head CI is still finishing its final test shard and remains a required pre-merge gate. The latest independent Codex review found no actionable findings at the workflow's default P0 threshold.

@steipete
steipete merged commit a1914a7 into main Aug 30, 2026
256 of 257 checks passed
@steipete
steipete deleted the codex/typed-internal-turn-source branch August 30, 2026 02:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
* refactor: keep internal wakes out of message channels

* test: align internal wake integration expectations
steipete added a commit to Marvinthebored/openclaw that referenced this pull request Sep 5, 2026
Keep conversation metadata separate from execution authority. Consume only
selected event occurrences, retain reminders after unconfirmed delivery, and
settle pending final delivery on its exact execution-session owner.

Integrate main at 47b8889 through an ordinary merge while preserving original
contributor ancestry. Related: openclaw#132986.

Co-authored-by: Marvinthebored <[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 docs Improvements or additions to documentation extensions: qa-lab gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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