Skip to content

fix(logging): identify sampled work beneath stall callers - #188474

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-stall-profile-attribution-20261030
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-stall-profile-attribution-20261030

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Main-thread stall profiles can stop at eight shared inclusive callers, hiding the sampled work beneath them and making a multi-second stall impossible to attribute.

User Impact

Operators can see sampled leaf work, its nearest OpenClaw caller, and hot stack tails in one bounded stall report. No configuration or schema changes are required. This does not claim to have identified or removed the cause of the previously observed long stall.

Why This Change Was Made

The recorder now reports up to ten self-time entries and three deepest stack tails, preserving sanitized locations and complete JSON within a hard 2 KiB payload cap. Native sampling truncation and report-budget truncation remain separate. It aggregates samples by leaf before walking ancestry, avoiding repeated traversal of identical stacks.

The source audit also found an unnecessary schema-handle inventory scan in the lifecycle deletion guard. The schema owner now records whether any restricted handle has ever been admitted: before that point there is nothing to scan. Expired scopes still reject first; after any restricted admission the existing checks remain permanently enabled, including alias and failed-cleanup handling.

Evidence

  • New attribution regression fails on the base for both ordinary and long frame names; candidate recorder suite: 15 passed, one native-only test skipped by the test runner. Existing event-loop-health consumer: 19 passed.
  • Standalone real Node 26.12.1 proof: node --import ./scripts/tsx.mjs scripts/perf/main-thread-stall-measure.mjs flight. A 1.2-second crypto block produced a 984-byte report with 42 samples, identifying the native leaf, pbkdf2Sync, and its OpenClaw caller. Later unrelated scryptSync work was excluded. This runs the real native profiler independently of the skipped Vitest case.
  • Schema regression: 100 admission checks trigger 200 inventory-iterator calls on base and zero on candidate before the first restricted admission. The whole schema-policy file passes all 46 tests, including scope expiry and restricted-handle safety.
  • Changed-file formatting/lint and whitespace checks; independent subagent review (autoreview route unavailable), clean verdict.
  • No production Gateway or Team load was started. Focused owner proof only; no whole-Gateway latency/CPU claim.

Source coverage and remaining synchronous work

#188386 moved existing-state worker-read source probes to asynchronous preparation. It covers the initial deletion-journal read used during handoff preparation; it does not remove every synchronous callback in repeated assertOwnerCurrent / assertEffectCurrent checks.

The lifecycle deletion guard consumes prepared committed journal facts (or transaction-local facts). The composed run assertion itself only invokes its source and operator owners. Those owners can still reach synchronous database-identity probes in session-delivery-generation.ts and prepared session-entry sources, revision-triggered reads of native transaction-local session generations, and opaque SDK callbacks. Configured-agent/source/policy collections are also traversed. An opaque callback can perform arbitrary synchronous SQLite or filesystem work, so the old inclusive chain cannot identify which of these caused the stall.

These remaining checks have not been weakened or represented as off-thread. Moving them safely requires changing the owning effect boundary: the filesystem dependency currently requires synchronous final-mutation callbacks, and raw native transaction checks must observe uncommitted state. Earlier asynchronous preparation alone would leave a replacement/revocation gap. Leaf attribution is the missing evidence for selecting the next concrete owner change.

Owner measurement

Used the existing committed state-db-cache-admission-measure.ts on a synthetic 10,000-row fixture (8 KiB payload per row), with five serial counterbalanced base/candidate launches, 5,000 retained lease resolutions per arm, and separate untraced timing and sampled-allocation passes. Startup and fixture writes were excluded. One-minute host load ranged from 26.81 to 30.46.

Metric per 5,000 resolutions Base Candidate Paired mean delta
Mean CPU 1,208.25 ms 1,136.25 ms −72.00 ms (−5.96%)
Mean sampled allocation 178.43 MB 177.79 MB −0.63 MB (−0.35%)
Median wall time 1,201.95 ms 1,090.12 ms mean −82.16 ms

CPU pairs had mixed signs (base range 1,076.69–1,335.81 ms; candidate 830.41–1,554.17 ms), so timing is inconclusive context, not a claimed speedup. This is a small allocation/work-count improvement, not a measurement of the original stall. Command per arm: node --expose-gc --import ./scripts/tsx.mjs scripts/perf/state-db-cache-admission-measure.ts --state-dir <owned-synthetic-fixture> --payload-kib 8 --iterations 5000 --rounds 1.

Runtime production delta is +87 lines: +81 for the explicitly requested bounded attribution capability and +6 for the owner-held admission fact. Existing benchmark script +36, tests +75, docs +16. No new modules, exports, budget increases, or competing source-authority owner.

@clawsweeper

clawsweeper Bot commented Oct 30, 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 docs Improvements or additions to documentation scripts Repository scripts size: M labels Oct 30, 2026
@steipete
steipete marked this pull request as ready for review October 30, 2026 15:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T15:36:23.947484Z 086288a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds bounded sampled-leaf and stack-tail attribution to stall reports and skips handle inventories before any restricted schema admission.

Example: A 1.2-second PBKDF2 block appears beneath more than eight shared callers.

  • Before: The inclusive-frame limit can hide pbkdf2Sync behind its ancestors.
  • After: The report includes sampled leaf work and its nearest OpenClaw caller within a 2,048-byte payload.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with no actionable defect found; supplied behavior evidence reaches the native owner harness rather than the shipped Gateway entry point.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; its supplied evidence exercises the production recorder with the real Node 26 native profiler and separately measures the schema owner.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot identify sampled work when shared inclusive callers consume the entire stall-report frame limit.
Reason: The supplied maintainer-authorship fact establishes direction, and bounded leaf attribution provides concrete diagnostic value without claiming to fix the original stall.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it adds useful diagnostic attribution absent from current main, has maintainer-approved direction, and introduces no definite correctness or security defect found in this review.

Priority: P2
Reviewed head: 086288a989cfbb94527d034d7d916404dbcfe55c

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied runs do not show the new self/deepest fields in a warning emitted through a running Gateway.
Agent review details

How this fits together

The Gateway event-loop monitor passes a captured stall interval to the native CPU-profile recorder, which selects matching samples, sanitizes frames, and returns a warning payload; the shared-state schema owner separately controls restricted-handle admission.

flowchart TD
A[Gateway event-loop monitor] --> B[Captured stall interval]
B --> C[Native profile recorder]
C --> D[Shared frame sanitizer]
D --> E[Bounded attribution report]
E --> F[Gateway warning log]
Loading

Technical review

Best possible solution:

Keep attribution in the existing bounded recorder and retain the schema owner's permanent post-admission checks.

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

Current-main source caps inclusive output at eight entries, so shared ancestors can hide sampled leaves; the added fixture directly constructs this case, and the body reports it failing on the base.

Is this the best way to solve the issue?

The change reuses the recorder, sanitizer, interval selection, and schema-admission owner; bounded leaf aggregation addresses the diagnostic gap without weakening the remaining synchronous authority checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 1d6f75fd7450.

Provenance checked

  • Stall-profile aggregation and sanitization keeps the original intent (abfd6a2: Provide bounded, sanitized native stack evidence for otherwise unattributed stalls.)
  • Captured-interval sample selection keeps the original intent (c372613: Prevent unrelated work after a stall from being reported as its cause.)
  • Restricted schema-handle inventory checks keeps the original intent (3c4c111: Allow managed nodes to consume existing state without taking over the installation's schema-repair ownership.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit abfd6a2 adds src/logging/diagnostic-stall-flight-recorder.ts:101 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: abfd6a283312; files: src/logging/diagnostic-stall-flight-recorder.ts)

PR surface

Source +87, Tests +75, Docs +16, Other +36. Total +214 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 92 5 +87
Tests 2 76 1 +75
Docs 1 16 0 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 1 36 0 +36
Total 6 220 6 +214

Labels

Label changes:

  • add P2: Better stall attribution improves operator diagnosis without changing normal request handling or resolving the underlying stall.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Better stall attribution improves operator diagnosis without changing normal request handling or resolving the underlying stall.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 30, 2026, 11:51 AM ET / 15:51 UTC.

@steipete
steipete merged commit ad4cf26 into main Oct 30, 2026
206 of 208 checks passed
@steipete
steipete deleted the steipete/fix-stall-profile-attribution-20261030 branch October 30, 2026 16:02
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…88474)

Report sampled leaf time, nearest OpenClaw callers, and hot stack tails within a hard 2 KiB stall-profile payload cap. Preserve sanitization and distinguish report-budget truncation from native sampling truncation.

Skip schema-handle inventory scans before the first restricted admission while preserving expired-scope rejection and all subsequent restricted-handle checks.

Proof: red/green attribution and work-count regressions, 80 focused tests passed, real Node 26 native attribution proof, and exact-head PR CI. The broader synchronous source/effect-boundary migration remains separate; this does not claim to identify or eliminate the original long stall.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M 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