Skip to content

refactor: reduce live digest scheduling allocations - #137655

Merged
steipete merged 1 commit into
mainfrom
codex/perf7-observer-note-readiness
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf7-observer-note-readiness

Conversation

@steipete

@steipete steipete commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Live session digests repeatedly allocated pending-note arrays just to decide whether four notes were ready. Disposed observers also kept up to 256 contextless terminal-run entries while the service remained referenced.

Why This Change Was Made

The note producer already maintains increasing sequence numbers and evicts only an oldest prefix. Readiness can inspect the fourth note from the end; actual digest execution still captures the same pending-note snapshot. Disposal now clears its bounded contextless-terminal map alongside the other owned maps.

User Impact

Digest timing, selected notes, visibility behavior and model output stay unchanged. Scheduling does less collection work, and disposal releases the remaining bounded terminal bookkeeping.

Evidence

An unchanged before/after public-owner probe matched all 11 stage snapshots, four model calls, four broadcasts and persisted digests. It covers the three/four-note threshold, the 12-second boundary, count/byte eviction, cursor retirement, visibility suspension/resumption and rollover. Note-filter arrays fell from 25 to 4; inspected notes from 204 to 43. Disposal retained 256 contextless entries before and zero after. These are operation counts and bounded-retention evidence, not a whole-Gateway RSS or latency claim.

All 41 existing observer, digest-budget and note-producer tests passed. The canonical full changed gate passed, and independent Codex review found no actionable P0–P2 findings.

node scripts/check-changed.mjs -- src/gateway/session-observer.ts

Production +6/−5 (net +1); tests unchanged. The remaining line is justified by disposal cleanup and the ordered-note invariant comment after deleting the old readiness helper. No protocol, configuration, dependency, storage schema or retention-policy changes. Combined-build live Gateway validation remains pending before landing.

The twelve-change composite abbd728d2d602594eaf04fc56bdaf8adccfca651 passed the unchanged ten-admission real OpenAI Gateway workload (14 stages, 50 observations), with independent offline acceptance. Separate live integration delivered eight observer events during six successful file reads, including utility-model assessment and terminal completion. Side chat also passed explicit workspace reads, reset, in-flight cancellation, empty-state verification and recovery. All owned Gateway/CLI processes exited cleanly and their ports/runtime were released.

The first untimed feature attempt is retained as failed: a vague recovery question did not recover a fact absent from inherited user/assistant text. The corrected attempt asks the same explicit file-read question before and after cancellation, without supplying the answer. No product source changed to obtain that pass. This does not isolate the readiness threshold or disposal memory effect; the owner proof above does.

ClawSweeper follow-up: its requested CI and combined-build proof are now complete. The failed lint job had timed out downloading pnpm before lint ran; one failed-only retry passed at the unchanged PR head. The combined run observed lower idle RSS, but no per-PR RSS benefit is claimed.

@clawsweeper

clawsweeper Bot commented Sep 3, 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 gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Sep 3, 2026
@steipete
steipete marked this pull request as ready for review September 3, 2026 23:34
@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 3, 2026
@clawsweeper

clawsweeper Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 7:56 PM ET / 23:56 UTC.

ClawSweeper review

What this changes

The PR avoids allocating a pending-note array during live-digest readiness checks and clears contextless terminal-run bookkeeping on observer disposal.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open. The introduced scheduling check is equivalent to the prior filtered-count check under the note producer’s ordered, prefix-evicted buffer invariant, and the disposal cleanup is owner-aligned; the failed exact-head CI gate and pending combined-build Gateway validation remain landing blockers.

Priority: P3
Reviewed head: 70e09d8207549acd6b0965fe33616495bd957e03

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The compact owner-boundary change is behaviorally sound from source and existing coverage; exact-head CI and the stated combined-build validation remain required before landing.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied probe description is supplemental evidence rather than a required contributor action.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied probe description is supplemental evidence rather than a required contributor action.
Evidence reviewed 7 items Introduced scheduling and cleanup change: The pinned PR delta replaces the allocation-producing readiness filter with a fourth-from-end sequence check, while retaining filtering for actual digest execution and clearing the contextless terminal map during disposal.
Ordered-note invariant: Each retained note receives an increasing sequence number, is appended, and bounded retention removes only the oldest prefix; this makes the fourth-from-end sequence an exact readiness witness for four post-cursor notes.
Digest owner preserves the selected snapshot: Before requesting a digest, the observer still flushes assistant activity, filters the exact post-cursor suffix, and advances the cursor monotonically to its final sequence.
Findings None None.
Security None None.

How this fits together

The Gateway session observer turns agent activity into ordered notes, schedules utility-model progress digests, then broadcasts and persists them for the Control UI. Its disposal path releases the observer’s in-memory lifecycle bookkeeping.

flowchart LR
A[Agent events] --> B[Activity note producer]
B --> C[Ordered bounded note buffer]
C --> D[Digest readiness check]
D --> E[Utility-model digest]
E --> F[Control UI broadcast and persistence]
G[Observer disposal] --> H[Clear terminal bookkeeping]
Loading

Before merge

  • Resolve merge risk (P1) - The exact-head CI gate is currently failing, and the PR body identifies combined-build live Gateway validation as still pending; do not merge until that landing evidence is resolved.
  • Complete next step (P2) - Resolve the failed exact-head CI gate and complete the pending combined-build Gateway validation before merge.
Agent review details

Security

None.

PR surface

Source +1. Total +1 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 6 5 +1
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 6 5 +1

Review metrics

Metric Value Why it matters
Production versus test delta production +1 net (6 added, 5 removed); tests unchanged The small production increase is the disposal cleanup and ordering-invariant comment after removing the duplicated readiness helper.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the single ordered-buffer readiness check and disposal cleanup, then complete the failed exact-head CI and combined-build Gateway validation before merge.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the single ordered-buffer readiness check and disposal cleanup, then complete the failed exact-head CI and combined-build Gateway validation before merge.

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

Not applicable: this PR is a behavior-preserving internal refactor, and source inspection establishes the relevant ordered-buffer invariant.

Is this the best way to solve the issue?

Yes. It reuses the note producer’s existing sequence and prefix-eviction contract, while preserving exact filtering only where the digest snapshot is actually needed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 0b3c5f9dc1b9.

Labels

Label changes:

  • add P3: This is a small internal allocation and lifecycle-cleanup refactor with no intended user-visible behavior 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: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied probe description is supplemental evidence rather than a required contributor action.

Label justifications:

  • P3: This is a small internal allocation and lifecycle-cleanup refactor with no intended user-visible behavior 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: This maintainer-authored PR is exempt from the external-contributor proof gate; the supplied probe description is supplemental evidence rather than a required contributor action.

Evidence

What I checked:

  • Introduced scheduling and cleanup change: The pinned PR delta replaces the allocation-producing readiness filter with a fourth-from-end sequence check, while retaining filtering for actual digest execution and clearing the contextless terminal map during disposal. (src/gateway/session-observer.ts:289, 70e09d820754)
  • Ordered-note invariant: Each retained note receives an increasing sequence number, is appended, and bounded retention removes only the oldest prefix; this makes the fourth-from-end sequence an exact readiness witness for four post-cursor notes. (src/agents/session-activity-notes.ts:153, 70e09d820754)
  • Digest owner preserves the selected snapshot: Before requesting a digest, the observer still flushes assistant activity, filters the exact post-cursor suffix, and advances the cursor monotonically to its final sequence. (src/gateway/session-observer.ts:325, 70e09d820754)
  • Gateway entry point and lifecycle owner: The runtime subscription owner creates the session observer and disposes it during agent-event unsubscription, so clearing the observer-owned map belongs in this lifecycle path. (src/gateway/server-runtime-subscriptions.ts:132, 70e09d820754)
  • Existing behavioral coverage: Current tests cover the four-note/twelve-second threshold, post-digest bursts, digest budget rollover, and contextless terminal routing and duplicate suppression. (src/gateway/session-observer.test.ts:22, 70e09d820754)
  • Current-main comparison: Fetched current main still contains the previous pending-note filter, so the central allocation reduction is not already implemented there. (src/gateway/session-observer.ts:273, 0b3c5f9dc1b9)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu: 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.

  • Resolve the failed exact-head CI gate and complete the pending combined-build Gateway validation before merge.

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 cd8c748 into main Sep 4, 2026
383 of 385 checks passed
@steipete
steipete deleted the codex/perf7-observer-note-readiness branch September 4, 2026 00:16
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 4, 2026
…date-command

* origin/main:
  fix(ci): retry transient npm advisory timeouts (#137716)
  fix: keep restored Usage navigation from being replaced by Chat (#137402)
  fix: keep Usage day totals within the selected session scope (#137396)
  refactor: reduce live digest scheduling allocations (#137655)
  fix(ui): submit selected slash arguments in new sessions (#137571)
  fix(ui): expand collapsed task progress on final (#137569)
  fix(test): prevent auth discovery from stalling MCP replacement proof (#137639)
  test(cli): reuse canonical directory mock call helper (#137640)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime 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: XS 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