Skip to content

refactor(routing): reuse prepared event session targets - #140454

Merged
steipete merged 1 commit into
mainfrom
codex/perf53-event-routing-prepared
Sep 6, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf53-event-routing-prepared

Conversation

@steipete

@steipete steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Event-triggered work repeatedly parses the same direct-session key while preparing routing policy. Allowlist selection also evaluates all six configuration locations even when the first one is already authoritative.

Why This Change Was Made

Carry the parsed direct target into the private allowlist resolver, short-circuit the existing allowlist readers with nullish coalescing, and remove an outer parse already implied by successful direct-target parsing. This deletes duplicate work without introducing a cache or a second routing path.

The six-location precedence, authoritative empty arrays, named and blank overrides, agent ownership, thread handling, route-binding preservation, cron mapping, and wildcard/multiple-owner behavior stay unchanged. Production −8 lines; tests +90. No config, API, protocol, schema, or authorization change.

User Impact

Less local work when preparing event routing. There is no intended routing or delivery change, and this does not claim faster complete Gateway turns or cron execution.

Evidence

122 focused tests passed. All 29 normal checks are covered by qualified recovery: the original gate passed 18 checks before a disk safety stop; recovery completed the remaining checks. A test-only unused callback name and its formatting were corrected after lint/format failures. The successful stages were not replayed. Fresh independent Codex review is clean. Every failure and process-closure receipt remains recorded; this is not described as one uninterrupted gate pass.

Fixed B0/C0/C1/B1 measurement on Node 26.8.1 at baseline 81050949f524ee1e486db5ef973366196dcdeb0a: 32 fixtures expand to 128 repeated/rotating policy/composed rows, 545,024 checked calls, 4,352 retained first outputs and 4,096 batch means. Independent audit decoded every V8 output (including undefined properties), reconstructed fixture expectations, and recomputed all 768 statistics. Warmup/timed outputs were checked in process; only first outputs were retained. Saved input JSON omits undefined fields; original input V8 bytes were not archived.

Configured-precedence policy medians improved 23.25–43.54%; override composition improved 15.45–27.10%; binding-preserved composition improved 29.62–38.62%. The fuller first-precedence repeated/composed row was near-flat: −2.78% forward / +2.40% reverse. All 9/256 adverse medians, 12 means and 40 maximum batch means remain included. Largest median adverse: +8.09% (+105 ns) on an explicit-allowlist control; largest maximum-batch adverse: +119.14% (+1.66 µs) on a missing-channel control. These maxima are not individual latency percentiles.

Native whole-child wall improved 16.04%/11.13%, but reverse system CPU increased 11.76% and forward peak RSS increased slightly. No uniform memory or end-to-end claim. All phase/reducer processes closed, source was restored, and selected pins remained stable. This exercises the actual exported policy/key/wake composition; it does not dispatch a heartbeat, contact a channel, or use provider credentials. Real-Gateway campaign measurements remain separate.

@clawsweeper

clawsweeper Bot commented Sep 6, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 21:21
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 5:27 PM ET / 21:27 UTC.

ClawSweeper review

What this changes

The PR reuses parsed event-session targets and stops allowlist lookup at the first configured list, with tests protecting existing routing behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this is a focused optimization that remains absent from inspected main and preserves the routing contract. No actionable correctness defect was found.

Likely related people: Peter Steinberger and Vincent Koc are unverified routing candidates from available file history.

Priority: P3
Reviewed head: 43fee68f6e98bc6e970a8b6d44c12326e190b544

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization with useful contract coverage and no identified merge-blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored internal optimization is exempt from the external-contributor proof gate. Its supplied measurements cover exported routing composition; actual heartbeat dispatch and channel delivery are explicitly outside that evidence, and no material authority change requires additional proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored internal optimization is exempt from the external-contributor proof gate. Its supplied measurements cover exported routing composition; actual heartbeat dispatch and channel delivery are explicitly outside that evidence, and no material authority change requires additional proof.
Evidence reviewed 8 items Verified introduced production changes: The pinned introduction diff replaces eager allowlist selection with the same ordered nullish chain, passes the already-parsed target into the private resolver, and removes redundant outer parsing. Public signatures and routing guards remain unchanged.
Current-main necessity: Inspected main still reparses the direct target inside allowlist resolution, evaluates all six readers eagerly, and performs the redundant outer parse. The optimization therefore remains useful.
Release comparison: The event-routing implementation has no diff between v2026.9.2 and inspected main; neither contains this optimization.
Findings None None.
Security None None.

How this fits together

Event-session routing maps background execution and scheduled events to the session that should receive them. It combines session identifiers, configured allowlists, and route bindings to select event destinations and heartbeat wake targets.

flowchart TD
  A[Background or scheduled event] --> B[Parse session target]
  C[Allowlist and route configuration] --> D[Prepare routing policy]
  B --> D
  D --> E[Preserve direct session or select main]
  E --> F[Event destination]
  E --> G[Heartbeat wake target]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -8, Tests +90. Total +82 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 20 -8
Tests 1 90 0 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 102 20 +82

Review metrics

None.

Technical review

Best possible solution:

Keep one canonical routing flow that reuses prepared targets while preserving allowlist precedence, empty-list semantics, agent ownership, and route bindings.

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

Not applicable: this PR optimizes existing behavior rather than repairing a reported functional failure; redundant parsing and eager allowlist evaluation are directly visible in main.

Is this the best way to solve the issue?

Yes: reusing the existing parsed target and short-circuiting array-or-undefined readers removes duplicate work without adding a cache, API, or competing routing path.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded internal performance cleanup with no intended user-visible routing change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored internal optimization is exempt from the external-contributor proof gate. Its supplied measurements cover exported routing composition; actual heartbeat dispatch and channel delivery are explicitly outside that evidence, and no material authority change requires additional proof.

Label justifications:

  • P3: This is a bounded internal performance cleanup with no intended user-visible routing change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored internal optimization is exempt from the external-contributor proof gate. Its supplied measurements cover exported routing composition; actual heartbeat dispatch and channel delivery are explicitly outside that evidence, and no material authority change requires additional proof.

Evidence

What I checked:

  • Verified introduced production changes: The pinned introduction diff replaces eager allowlist selection with the same ordered nullish chain, passes the already-parsed target into the private resolver, and removes redundant outer parsing. Public signatures and routing guards remain unchanged. (src/infra/event-session-routing.ts:112, 43fee68f6e98)
  • Current-main necessity: Inspected main still reparses the direct target inside allowlist resolution, evaluates all six readers eagerly, and performs the redundant outer parse. The optimization therefore remains useful. (src/infra/event-session-routing.ts:59, 270762e51d65)
  • Release comparison: The event-routing implementation has no diff between v2026.9.2 and inspected main; neither contains this optimization. (src/infra/event-session-routing.ts, 270762e51d65)
  • Parser and ownership invariants: Direct-target parsing still validates the agent prefix and direct peer shape after stripping the terminal thread suffix. Main-session resolution retains agent matching, single-owner allowlist matching, and route-binding preservation. The removed outer parse adds no independent restriction for a successfully parsed direct target. (src/infra/event-session-routing.ts:64, 43fee68f6e98)
  • Behavioral test coverage: Added cases exercise all six allowlist precedence positions with populated and empty lists, explicit and blank overrides, and valid and malformed thread keys. Existing tests protect wildcard/multiple-owner rejection, route-bound sessions, and cron wake mapping. Tests were inspected, not executed. (src/infra/event-session-routing.test.ts:12, 43fee68f6e98)
  • Supplied validation and proof scope: The captured PR body reports 122 focused passing tests, qualified recovery of normal checks, and Node 26.8.1 measurements of actual exported policy/key/wake composition against baseline 8105094. It explicitly excludes heartbeat dispatch, channel transport, and end-to-end performance claims. These are contributor-reported results, not reviewer-executed validation; captured context sourceRevision is 236d0fdf383dc4438b04b142192e5b6c6a5412918eba97311fdd2fdb1f405cf5. (43fee68f6e98)

Likely related people:

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

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
steipete merged commit 6bfa520 into main Sep 6, 2026
246 checks passed
@steipete
steipete deleted the codex/perf53-event-routing-prepared branch September 6, 2026 21:35
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 6, 2026
* commit '294df333c58f2da104eccffc623ccb3c4d43d4d8': (1802 commits)
  fix: clear stale diagnostics after Gateway changes (#140426)
  fix: keep plugin catalogs intact after discovery timeouts (#140441)
  perf(tui): prepare session picker rows once per overlay (#140462)
  refactor(config): reuse environment substitution for write-back (#140460)
  refactor(discord): remove retired auto-presence templates (#140463)
  fix(ui): finish roster refreshes during session activity (#140459)
  fix(setup): match prepared credentials to the model provider (#140461)
  fix: keep MiniMax discovery on the selected credential (#140438)
  refactor(tests): remove unused parent context cache reset (#140456)
  fix: avoid repeated xAI OAuth refresh during discovery (#140434)
  perf(routing): reuse prepared event session targets (#140454)
  fix(media): keep deferred audio and extraction providers discoverable (#139231)
  refactor(codex): remove redundant app-server forwarding (#140451)
  fix(test): avoid false native polling timeouts (#140119)
  test(gateway): retain saved source in reload fixtures (#140453)
  fix(gateway): reduce repeated model work when listing sessions (#140414)
  fix(feishu): fall back to post mode over table limit (#136382)
  fix: use the bundle-compatible Proxyline runtime under Bun (#140411)
  refactor(trace): reuse the canonical usage counter type (#140444)
  refactor(node-host): share execution policy result fields (#140446)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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