Skip to content

Fix stale inter-session orphan prompt merge#78094

Closed
Patrax wants to merge 4 commits into
openclaw:mainfrom
Patrax:fix/drop-stale-inter-session-orphans
Closed

Fix stale inter-session orphan prompt merge#78094
Patrax wants to merge 4 commits into
openclaw:mainfrom
Patrax:fix/drop-stale-inter-session-orphans

Conversation

@Patrax

@Patrax Patrax commented May 5, 2026

Copy link
Copy Markdown

Summary

  • drop orphaned trailing user leaves that came from inter-session provenance when a fresh prompt is already present
  • keep existing queued-user-message repair for normal user prompts intact
  • add regression coverage for stale inter-session messages shadowing fresh prompts

Why

A stale inter-session subagent completion can be left as a trailing user leaf. The orphan repair path currently prepends that leaf ahead of a newer prompt, so stale control text such as NO_REPLY can shadow the fresh user/voice request and route incorrectly.

Inter-session leaves are system-delivered completion context, not user text that arrived while a previous turn was active. When a fresh prompt exists, the safer repair is to remove the stale leaf rather than merge it into the new prompt.

Test plan

  • git diff --check
  • corepack pnpm exec vitest run src/agents/pi-embedded-runner/run/attempt.test.ts src/agents/pi-embedded-runner/run/transcript-repair-runtime-contract.test.ts

Real behavior proof

  • Behavior or issue addressed: Stale inter-session trailing user leaves such as NO_REPLY are dropped instead of prepended to a fresh user/voice prompt.
  • Real environment tested: Local OpenClaw checkout on this PR branch (fix/drop-stale-inter-session-orphans), rebased onto origin/main at 2daf3d332f; Node 22.22.0 with pnpm/corepack on Linux.
  • Exact steps or command run after this patch:
    corepack pnpm exec tsx -e 'import { mergeOrphanedTrailingUserPrompt } from "./src/agents/pi-embedded-runner/run/attempt.prompt-helpers.ts";
    const result = mergeOrphanedTrailingUserPrompt({
      prompt: "fresh voice request",
      trigger: "user" as never,
      leafMessage: {
        content: [{ type: "text", text: "NO_REPLY stale inter-session completion" }],
        provenance: { kind: "inter_session" },
      },
    });
    console.log(JSON.stringify(result, null, 2));
    if (result.prompt.includes("NO_REPLY") || result.merged || !result.removeLeaf) process.exit(1);'
  • Evidence after fix: Live terminal output from the patched branch:
    {
      "prompt": "fresh voice request",
      "merged": false,
      "removeLeaf": true
    }
  • Observed result after fix: The fresh prompt stayed as fresh voice request; the stale NO_REPLY inter-session leaf was not merged; the helper returned merged: false and removeLeaf: true.
  • What was not tested: A full live voice session with a naturally occurring stale inter-session orphan; this proof exercises the actual runtime repair helper on a real patched checkout.

After-fix verification

  • Rebased onto latest origin/main and resolved the CHANGELOG.md conflict.
  • Scrubbed unrelated rebase/verification lint cleanups from the PR diff; the PR now only changes CHANGELOG.md, attempt.prompt-helpers.ts, and the two focused regression test files.
  • git diff --check origin/main...HEAD — passed locally.
  • corepack pnpm exec vitest run src/agents/pi-embedded-runner/run/attempt.test.ts src/agents/pi-embedded-runner/run/transcript-repair-runtime-contract.test.ts — passed locally: 4 files, 272 tests.

This also proves the concrete repair behavior through the added runtime-contract regression: an inter-session-provenance trailing user leaf is removed instead of prepended when a fresh prompt exists, while normal queued user prompt repair still merges.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 5, 2026

@byungskers byungskers left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! The inter-session provenance check is a clean way to avoid shadowing fresh prompts with stale orphan leaves. Good test coverage too — the runtime contract test makes the behavior explicit. 👍

@clawsweeper

clawsweeper Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. I reviewed the branch, and this PR is not a good landing base for OpenClaw.

Close this PR as a useful but no-longer-viable landing branch: it is conflicting, its runtime/test edits target the removed pi-embedded-runner tree, and the remaining stale-reply work is already owned by the open canonical issue.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #76888
Summary: This PR is a candidate fix for the canonical queued/orphaned user-message stale-reply issue, but the branch is not a viable current-main patch as submitted.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

So I’m closing this PR rather than keeping an unmergeable branch open. A new narrow PR that carries only the useful part is welcome.

Review details

Best possible solution:

Close this stale branch as a landing vehicle and keep #76888 as the canonical place for a fresh current-path embedded-agent-runner repair.

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

Yes at source level: current main still prepends orphan text before the active prompt, and the canonical issue supplies logs from that repair path. I did not run a live channel reproduction in this read-only pass.

Is this the best way to solve the issue?

No. The helper idea is plausible, but this branch is not the best solution because it targets the removed runner path and treats all non-empty-prompt inter_session leaves as stale.

Security review:

Security review cleared: No concrete security or supply-chain concern was found; the diff touches TypeScript runner logic, focused tests, and a changelog entry without dependency, workflow, permission, or secret changes.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • vincentkoc: Authored and merged the active-turn queued-user prompt preservation PR, and current blame on the sampled active helper/runner orphan-repair lines routes through recent embedded-runner history by Vincent Koc. (role: introduced behavior and recent area contributor; confidence: high; commits: fcae3bf9433b, 4684bbba978d; files: src/agents/embedded-agent-runner/run/attempt.prompt-helpers.ts, src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/run/attempt.test.ts)
  • zhangguiping-xydt: Authored the closed unmerged current-path repair PR for the same canonical issue with embedded-runner/session/provider proof, so this is useful routing context for any replacement fix. (role: adjacent repair contributor; confidence: medium; commits: 59e8754bdcc2, 52a689055d67, 70280c22bb0e; files: src/agents/embedded-agent-runner/run/attempt.ts, src/agents/embedded-agent-runner/run/attempt.prompt-helpers.ts, src/agents/embedded-agent-runner/run/attempt.spawn-workspace.context-engine.test.ts)

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

@Patrax
Patrax force-pushed the fix/drop-stale-inter-session-orphans branch from 969cb03 to 98ec473 Compare May 6, 2026 17:41
@Patrax
Patrax force-pushed the fix/drop-stale-inter-session-orphans branch from 98ec473 to 89d894b Compare May 6, 2026 18:02
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed extensions: codex triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 6, 2026
@Patrax
Patrax force-pushed the fix/drop-stale-inter-session-orphans branch from 89d894b to 2b0034c Compare May 7, 2026 14:54
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 7, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 7, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@Patrax
Patrax force-pushed the fix/drop-stale-inter-session-orphans branch 2 times, most recently from 36d816b to 6229a85 Compare May 12, 2026 16:09
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@Patrax
Patrax force-pushed the fix/drop-stale-inter-session-orphans branch from da826f2 to 90f6372 Compare May 12, 2026 19:48
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 16, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 16, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 31, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels May 31, 2026
@barnacle-openclaw barnacle-openclaw Bot removed the stale Marked as stale due to inactivity label May 31, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels May 31, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants