openclaw - 💡(How to fix) Fix [Bug]: Duplicate embedded-run clear emits handle mismatch noise [2 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Embedded runner cleanup can clear the same run twice, causing repeated run clear skipped / reason=handle_mismatch diagnostic noise after terminal lifecycle cleanup.

Root Cause

Embedded runner cleanup can clear the same run twice, causing repeated run clear skipped / reason=handle_mismatch diagnostic noise after terminal lifecycle cleanup.

Fix Action

Fixed

Code Example

Trace/proof:
- gateway-dev.log:280
  "run clear skipped: sessionId=[redacted session id] reason=handle_mismatch"
- gateway-dev.log:30372
  "run clear skipped: sessionId=[redacted session id] reason=handle_mismatch"
  traceId=[redacted trace id] spanId=[redacted span id]
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

Embedded runner cleanup can clear the same run twice, causing repeated run clear skipped / reason=handle_mismatch diagnostic noise after terminal lifecycle cleanup.

Steps to reproduce

  1. Run an embedded PI agent turn that reaches terminal lifecycle cleanup.
  2. Observe the terminal lifecycle path clear the active embedded run before emitting terminal lifecycle events.
  3. Observe the attempt finally path clear the same run handle again.
  4. Inspect gateway diagnostics for run clear skipped with reason=handle_mismatch.

Expected behavior

Once terminal lifecycle cleanup has cleared the active embedded run, the later same-handle finally cleanup should be idempotent and should not emit a handle-mismatch diagnostic. A mismatch should still be logged when another active run owns the same session.

Actual behavior

The duplicate same-handle clear reaches clearActiveEmbeddedRun after the active map entry has already been removed, so the missing entry is reported as reason=handle_mismatch. Local evidence recorded 265 matching run clear skipped lines, correlated with no_active_run and lane-wait traces.

OpenClaw version

Current origin/main at 16ef041b5d865c3049020e4cfdd86136c264599f.

Operating system

NOT_ENOUGH_INFO

Install method

pnpm dev

Model

NOT_ENOUGH_INFO

Provider / routing chain

NOT_ENOUGH_INFO

Additional provider/model setup details

NOT_ENOUGH_INFO

Logs, screenshots, and evidence

Trace/proof:
- gateway-dev.log:280
  "run clear skipped: sessionId=[redacted session id] reason=handle_mismatch"
- gateway-dev.log:30372
  "run clear skipped: sessionId=[redacted session id] reason=handle_mismatch"
  traceId=[redacted trace id] spanId=[redacted span id]

Relevant current code paths:

  • src/agents/pi-embedded-runner/run/attempt.ts clears before terminal lifecycle events.
  • src/agents/pi-embedded-runner/run/attempt.ts clears again in finally.
  • src/agents/pi-embedded-runner/runs.ts logs reason=handle_mismatch when the active handle does not match.

Impact and severity

Affected: embedded PI agent run lifecycle diagnostics.

Severity: Medium; this appears potentially harmless at runtime but produces misleading handle-mismatch noise and can obscure true lifecycle races during debugging.

Frequency: Local evidence recorded 265 matching log lines.

Consequence: Duplicate cleanup looks like an unexpected handle race even when the same completed run is being cleared a second time.

Additional information

The fix should keep real stale-handle replacement diagnostics intact: if a session still has an active handle and the caller clears a different handle, reason=handle_mismatch should still be logged.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Once terminal lifecycle cleanup has cleared the active embedded run, the later same-handle finally cleanup should be idempotent and should not emit a handle-mismatch diagnostic. A mismatch should still be logged when another active run owns the same session.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug]: Duplicate embedded-run clear emits handle mismatch noise [2 pull requests]