Skip to content

refactor(logging): share memory pressure threshold selection - #157164

Merged
vincentkoc merged 2 commits into
mainfrom
refactor/diagnostic-memory-threshold-selection-20260924
Sep 24, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
refactor/diagnostic-memory-threshold-selection-20260924

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

What Problem This Solves

Memory-pressure selection repeated the same threshold comparison and result construction in four branches. This cleanup puts that shared decision in one private selector while keeping the priority explicit.

Maintainer-sponsored refactor: @vincentkoc requested this duplication cleanup and authorized landing.

User Impact

No user-visible change. Threshold defaults, inclusive boundaries, event contents, critical notifications and repeat suppression stay the same. No configuration, schema, migration or operator action is introduced.

Why This Change Was Made

Four ordered readonly tuples now feed one comparison loop: RSS critical, heap critical, RSS warning, then heap warning. The first match returns the original memory snapshot; no match still returns null. Growth-pressure selection and notification ordering are unchanged.

Production changes by −20 lines (+11/−31); tests add 59 lines. The five public-entry cases cover all four priority/equality outcomes and no match without testing the private tuple representation.

Evidence

  • Independent source review and fresh scoped autoreview found no actionable findings on the exact final diff. Signed head f999bd18a2d5f18db1bf84b341224c01c76aa744 preserves the tested owner and test bytes.
  • One managed remote proof ran the baseline owner on candidate context, then restored and ran the candidate owner. Both phases passed the same whole suites: 45 memory cases and 15 growth cases, including the new boundary cases and existing cumulative worker-lifecycle/critical-repeat coverage.
  • Standalone single-worker memory command: pnpm test src/logging/diagnostic-memory.test.ts --maxWorkers=1. Baseline-owner command wall was 18.70 s (Vitest 16.72 s); candidate wall was 17.89 s (Vitest 15.87 s). These are single-sample verification costs, not evidence of a runtime speedup.
  • Targeted formatting passed unchanged. The canonical changed-gate summary reports all 31 rows OK, including core typechecking, 25 core-test type graphs, and lint. Source guards and candidate restoration passed; the managed CLI exited 0 and stopped its Testbox.
  • Same-policy owner metrics: score 36.025→34.136; cloned SLOC 78→54; SLOC 363→348; raw CC 75→73; cognitive complexity 65→64. Maximum CC/cognitive complexity remains 14/17 and the existing high-complexity functions are unchanged. The erosion fractions rise (CC 50.56%→52.75%, cognitive 37.42%→38.53%) because lower-complexity mass shrinks; this is reduced duplication, not an across-the-board complexity improvement.

An initial proof guard failed before installation or tests because it did not decode its JSON input. Correcting that harness left the product bytes unchanged; the completed proof above is the corrected run. A nonfatal portal-sync timeout followed the confirmed Testbox stop. Hosted exact-head CI is pending.

@vincentkoc vincentkoc self-assigned this Sep 24, 2026
@clawsweeper

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

@vincentkoc
vincentkoc marked this pull request as ready for review September 24, 2026 09:08
@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 24, 2026
@clawsweeper

clawsweeper Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 24, 2026, 11:59 AM ET / 15:59 UTC (Revision 2).

ClawSweeper review

What this changes

The PR consolidates Gateway memory-pressure threshold selection into one ordered comparison and adds event-level tests for priority and inclusive boundaries.

Merge readiness

✅ Ready for maintainer review

Keep open: the cleanup remains absent from current main and the latest release. Source review found no blocking defect, and the prior completed review reported no findings.

Priority: P3
Reviewed head: 8dd083caf2342b63496f790286374b06e65831ee

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused simplification with relevant event-level coverage and reported comparative validation has no supported blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This member-authored internal refactor is exempt from the external-contributor proof gate. The body reports comparative runs of the diagnostic-memory and growth suites through the exported sampler, but this review did not execute them; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member-authored internal refactor is exempt from the external-contributor proof gate. The body reports comparative runs of the diagnostic-memory and growth suites through the exported sampler, but this review did not execute them; no stored-data contract changes.
Evidence reviewed 7 items Introduced selector: The introduced hunk replaces four ordered branches with comparisons in the same priority order and returns the original memory snapshot on the first match.
Boundary tests: Five added cases call the exported sampler and assert emitted pressure events for the four priority outcomes and no match.
Current-main behavior: Current main still uses the four explicit branches; its two affected files match the pinned base, so the PR's central cleanup remains distinct.
Findings None None.
Security None None.

How this fits together

The Gateway samples process and worker memory during diagnostic heartbeats. Its memory sampler selects a pressure level, records a diagnostic event and log, and signals idle-worker retirement for critical pressure.

flowchart LR
A[Gateway heartbeat] --> B[Memory sample]
B --> C[Threshold selection]
C --> D[Pressure event]
D --> E[Diagnostic log]
C -->|critical| F[Critical notification]
F --> G[Idle worker retirement]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -20, Tests +59. Total +39 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 31 -20
Tests 1 59 0 +59
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 70 31 +39

Review metrics

Metric Value Why it matters
Reported one-worker suite cost 17.89 s candidate; 18.70 s baseline The PR body measures the existing memory suite with the added boundary cases, without claiming a runtime speedup.

Technical review

Best possible solution:

Land the focused simplification through normal exact-head gates while preserving critical-worker notifications and pressure-repeat suppression.

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

Not applicable: this PR addresses duplication rather than a reported failure; the old and proposed selection paths can be compared directly in source.

Is this the best way to solve the issue?

Yes: the existing diagnostic-memory owner is the narrowest place for the shared selection, and the tests observe its emitted events without exposing a new API.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is an internal logging cleanup with no claimed 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 member-authored internal refactor is exempt from the external-contributor proof gate. The body reports comparative runs of the diagnostic-memory and growth suites through the exported sampler, but this review did not execute them; no stored-data contract changes.

Evidence

What I checked:

Likely related people:

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

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-24T09:16:31.546Z sha f999bd1 :: needs maintainer review before merge. :: none

@vincentkoc
vincentkoc merged commit 44a2be6 into main Sep 24, 2026
196 checks passed
@vincentkoc
vincentkoc deleted the refactor/diagnostic-memory-threshold-selection-20260924 branch September 24, 2026 16:19
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 24, 2026
* commit '9a1a6f7db9783d0b8abaf918bfe12978ea745b57': (26 commits)
  fix(maintainer): restore cold PR worktree provisioning (#157394)
  feat(ios): establish native Cloudflare Access sign-in sessions (#146996)
  fix: restore the Gateway after interrupted Doctor maintenance (#156854)
  refactor(line): retire the Express webhook adapter (#157369)
  refactor(cron): consolidate unavailable delivery targets (#157393)
  ci: apply Go memory defaults to architecture checks
  fix(cli): preserve the first PowerShell completion test failure (#157267)
  refactor(agents): consolidate transcript-tail model selection (#157382)
  fix(release): honor frozen validation contracts (#157034)
  fix(perf): use settled Kova terminal CPU accounting (#157029)
  chore(windows): verify packaged repair worker lifecycle (#157047)
  refactor(logging): share memory pressure threshold selection (#157164)
  fix(release): verify bundled fs-safe native bindings (#157027)
  perf(skills): skip warm prompt search when minimum cannot fit (#157343)
  fix(ui): avoid retaining detached tooltip anchors (#157226)
  perf(ci): reuse compiler state and shorten guard and UI tests (#157265)
  perf(ui): preserve model caches on unrelated metadata updates (#157254)
  chore: remove the tracked PR-body artifact and ignore .artifacts (#157296)
  refactor: consolidate duplicate MCP lifecycle tests (#157360)
  test(qa): consolidate CLI runtime fixtures (#118496)
  ...
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…w#157164)

* refactor(logging): share memory pressure threshold selection

* chore(ci): refresh diagnostic memory validation base

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

Labels

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