Skip to content

fix(acp): recover from kiro-style SessionResumeRequiredError in persistent session resume#93315

Closed
xialonglee wants to merge 2 commits into
openclaw:mainfrom
xialonglee:fix/issue-87830-acp-session-resume-internal-error
Closed

fix(acp): recover from kiro-style SessionResumeRequiredError in persistent session resume#93315
xialonglee wants to merge 2 commits into
openclaw:mainfrom
xialonglee:fix/issue-87830-acp-session-resume-internal-error

Conversation

@xialonglee

@xialonglee xialonglee commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Thread-bound ACP sessions (Kiro) get stuck after backend invalidation — messages show processing signals but never return a normal text reply
  • Root cause: isRecoverableMissingManagerPersistentSessionError only matches resource not found and no matching session, but Kiro emits Internal error <- SessionResumeRequiredError
  • Fix: narrow the recovery matcher from generic internal error to SessionResumeRequiredError/SESSION_RESUME_REQUIRED in the error chain, preventing unrelated ACP -32603 internal failures from triggering session identity clear + turn replay
  • Regression test covers the exact Kiro error message pattern; negative test confirms generic Internal error without resume-required signal does NOT recover
  • Fixes [Bug]: Persistent ACP session resume fails for Kiro threads after backend invalidation #87830

Verification

  • pnpm test src/acp/control-plane/manager.turn-results.test.ts — 17 passed (1 Kiro SessionResumeRequiredError regression test + 1 negative Internal error no-recovery test)
  • pnpm check:changed — pending
  • Autoreview: clean

Real behavior proof

Behavior addressed: Kiro ACP persistent session threads stuck with no text reply after backend invalidation because Internal error <- SessionResumeRequiredError was not recognized as recoverable.

Real environment tested: Linux 4.19.112, Node 22.14, branch fix/issue-87830-acp-session-resume-internal-error at commit 8c9e518, no live Kiro backend.

Exact steps or command run after this patch:

pnpm test src/acp/control-plane/manager.turn-results.test.ts

Evidence after fix:

$ node scripts/test-projects.mjs src/acp/control-plane/manager.turn-results.test.ts
[test] starting test/vitest/vitest.unit-fast.config.ts

 RUN  v4.1.7

 Test Files  1 passed (1)
      Tests  17 passed (17)
   Start at  23:14:51
   Duration  2.32s (transform 852ms, setup 0ms, import 1.92s, tests 146ms, environment 0ms)

[test] passed 1 Vitest shard in 11.47s 

Observed result after fix: All 17 tests pass:

  • Existing resource not found / no matching session recovery tests continue to pass
  • Kiro-style Internal error <- SessionResumeRequiredError triggers fresh session retry
  • Generic Internal error without SessionResumeRequiredError does NOT retry (negative proof)

What was not tested: No live Kiro ACP backend was used; fix validated through the existing ACP mock-based test harness. The regression tests use the exact error format observed in production Kiro logs.

…stent session resume

Extend isRecoverableMissingManagerPersistentSessionError to also match
'Internal error' so that Kiro ACP threads can recover from stale
persistent sessions instead of getting stuck with no text reply.

Fixes openclaw#87830

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed June 15, 2026, 12:37 PM ET / 16:37 UTC.

Summary
The PR broadens ACP persistent-session stale-resume recovery to include Kiro-style resume-required errors and adds positive and negative manager turn tests.

PR surface: Source +3, Tests +192. Total +195 across 2 files.

Reproducibility: yes. at source level: the linked issue provides exact Kiro stale-resume logs, and current source shows the retry path depends on the manager matcher. I did not run a live Kiro backend in this read-only review.

Review metrics: 2 noteworthy metrics.

  • Recovery predicate change: 1 matcher family added. This predicate decides when OpenClaw clears persisted ACP identity and replays a user turn, so the accepted error shape matters before merge.
  • Structured signal gap: 1 detailCode path still unhandled. The ACP contract carries detailCode, but current thrown manager errors drop it before the retry matcher runs.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🧂 unranked krab
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Propagate or match SESSION_RESUME_REQUIRED as structured data and add a startTurn result regression test.
  • [P1] Add redacted live Kiro ACP terminal output, runtime logs, recording, or linked artifact showing stale-resume recovery after the patch.
  • After updating proof in the PR body, let ClawSweeper re-review automatically or ask a maintainer to comment @clawsweeper re-review if it does not run.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Mock-only: the PR body shows unit-test output and explicitly says no live Kiro backend was used, so the contributor should add redacted live terminal/log/recording proof and update the PR body for re-review or ask a maintainer to comment @clawsweeper re-review.

Risk before merge

  • [P1] ACPX startTurn failures can carry detailCode: SESSION_RESUME_REQUIRED while the thrown manager error only preserves message text, so this PR can still miss stale Kiro resume failures.
  • [P1] The contributor proof is mock-only and explicitly says no live Kiro ACP backend was used.
  • [P1] This retry path clears persisted ACP identity and replays the user turn once, so matcher mistakes can affect session state and whether a stuck thread receives a normal reply.

Maintainer options:

  1. Propagate structured resume matching (recommended)
    Preserve or pass SESSION_RESUME_REQUIRED into prepareFreshManagerRuntimeHandleRetry, add a startTurn result regression, and then require real Kiro proof or an explicit proof override.
  2. Accept maintainer-owned proof gap
    A maintainer may intentionally accept mock-only proof only if they have independent Kiro runtime evidence and choose to track any structured-detail cleanup separately.
  3. Pause for error-shape cleanup
    If maintainers want to stop matching rendered error text, pause this PR and first make ACP runtime errors preserve structured detail codes.

Next step before merge

  • [P1] Human follow-up is needed because the PR needs both a structured error-contract repair and contributor or maintainer real Kiro proof before merge.

Security
Cleared: The diff only changes ACP manager error matching and tests; it does not touch secrets, dependencies, workflows, package scripts, permissions, or code-loading surfaces.

Review findings

  • [P1] Propagate the structured resume-required signal — src/acp/control-plane/manager.runtime-resume-state.ts:26
Review details

Best possible solution:

Carry the structured resume-required signal into the manager retry predicate, cover both startTurn result and legacy event paths, and require redacted live Kiro proof or a maintainer proof override before merge.

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

Yes at source level: the linked issue provides exact Kiro stale-resume logs, and current source shows the retry path depends on the manager matcher. I did not run a live Kiro backend in this read-only review.

Is this the best way to solve the issue?

No: the PR is a useful direction but not yet the best fix because it still relies on rendered text instead of the structured ACP detailCode contract. The safer fix is to preserve that signal through the manager retry decision and test the startTurn result path.

Full review comments:

  • [P1] Propagate the structured resume-required signal — src/acp/control-plane/manager.runtime-resume-state.ts:26
    The new branch still only matches error.message. For startTurn failures, AcpRuntimeTurnResult.error.detailCode can carry SESSION_RESUME_REQUIRED, but errorFromTurnResult drops that field before prepareFreshManagerRuntimeHandleRetry runs, so a Kiro stale-resume result whose message is only the persistent-session wrapper plus Internal error will still fail without clearing the stale identity. Please preserve/pass the detail code and add a startTurn result regression.
    Confidence: 0.9

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The linked bug can leave thread-bound ACP conversations processing messages without returning a normal reply.
  • merge-risk: 🚨 session-state: The PR changes the conditions that clear persisted ACP resume identity and recreate a fresh persistent session.
  • merge-risk: 🚨 message-delivery: The recovery path can replay the user's turn once, affecting whether a stuck thread produces a normal reply or fails visibly.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🧂 unranked krab.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Mock-only: the PR body shows unit-test output and explicitly says no live Kiro backend was used, so the contributor should add redacted live terminal/log/recording proof and update the PR body for re-review or ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +3, Tests +192. Total +195 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 192 0 +192
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 196 1 +195

What I checked:

  • PR matcher change: The PR adds session resume required / SessionResumeRequiredError as message-text matches under the persistent ACP resume wrapper guard, but it still matches only params.error.message. (src/acp/control-plane/manager.runtime-resume-state.ts:26, 8c9e518d9929)
  • Retry path consumes only AcpRuntimeError message: Current main calls prepareFreshManagerRuntimeHandleRetry with an AcpRuntimeError, and the retry helper checks params.error.message before clearing persisted resume identity and retrying. (src/acp/control-plane/manager.turn-runner.ts:323, fa9b8c8c6b9d)
  • Structured detail is dropped from thrown result error: notifyTerminalResult forwards detailCode to the event callback, but errorFromTurnResult creates the thrown AcpRuntimeError from only normalized code and message, so the retry predicate will not see a result-only SESSION_RESUME_REQUIRED. (src/acp/control-plane/manager.turn-stream.ts:63, fa9b8c8c6b9d)
  • ACP runtime contract includes detailCode: The local ACP core runtime contract defines detailCode on both streaming error events and failed turn-result errors, making it a supported structured signal rather than an incidental message substring. (packages/acp-core/src/runtime/types.ts:121, fa9b8c8c6b9d)
  • Linked bug remains the canonical issue: The PR closes the open Kiro stale persistent-session bug, whose body includes observed SessionResumeRequiredError chains and user-visible no-reply symptoms after backend invalidation.
  • History and ownership pass: GitHub commit history for the central files points to recent ACP resume-state extraction, terminal-result handling, and ACP core extraction work by steipete, with adjacent SessionResumeRequiredError runtime-mode work by amknight. (src/acp/control-plane/manager.runtime-resume-state.ts:20)

Likely related people:

  • steipete: Recent GitHub history shows ACP resume-state extraction, ACP terminal-result handling, and ACP core extraction on the central files/contracts involved in this retry path. (role: recent area contributor; confidence: high; commits: 90329e28483f, 635b947e32e0, 77f1359612f6; files: src/acp/control-plane/manager.runtime-resume-state.ts, src/acp/control-plane/manager.turn-stream.ts, packages/acp-core/src/runtime/types.ts)
  • amknight: Merged adjacent ACPX runtime-mode validation work that explicitly handled a SessionResumeRequiredError failure mode at the runtime boundary. (role: adjacent ACPX runtime contributor; confidence: medium; commits: f29803c89920, 7a23c1883057; files: extensions/acpx/src/runtime.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Jun 15, 2026
@yzhkali

yzhkali commented Jun 15, 2026

Copy link
Copy Markdown

Thanks for jumping on this. I agree with the P1 review that adding internal error directly to the matcher is too broad for this retry path. This helper clears persisted resume identity and replays the turn once, so the new case should require a stale-resume signal in the error chain, not just the persistent wrapper plus a generic internal error.

Concrete boundary I would suggest:

  • keep the existing resource not found / no matching session cases
  • for Kiro, require the persistent resume wrapper plus SessionResumeRequiredError or SESSION_RESUME_REQUIRED plus Internal error, ideally by inspecting the formatted ACP error chain instead of only the top-level message
  • add negative tests for wrapper + generic Internal error without the resume-required signal, SessionResumeRequiredError without the persistent wrapper, and failures after user-visible output where retry must not happen

That should recover stale Kiro resumes without broadening unrelated ACP -32603 internal failures.

@xialonglee

Copy link
Copy Markdown
Contributor Author

@yzhkali
▎ Thanks for the review! I've revised the fix based on your feedback:

▎ 1. Narrowed the matcher: Replaced the generic internal error with SessionResumeRequiredError/SESSION_RESUME_REQUIRED check in the error chain (<-), using the formatAcpErrorChain output
▎ format. The outer persistent acp session .* could not be resumed guard is preserved, so only persistent-resume wrappers with a confirmed stale-resume signal trigger recovery.
▎ 2. Added negative test: does not retry after a persistent resume wrapper with generic Internal error without SessionResumeRequiredError — verifies that a matching wrapper with plain
▎ Internal error (no <- SessionResumeRequiredError) does NOT trigger retry and rejects with ACP_TURN_FAILED.

▎ All 17 tests pass (15 existing + 1 Kiro positive + 1 negative).

▎ The SessionResumeRequiredError without persistent wrapper case and the sawTurnOutput guard are already covered by existing code paths (params.meta.mode !== "persistent" and
▎ params.sawTurnOutput).

@xialonglee

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 15, 2026
@amersheeny

Copy link
Copy Markdown
Contributor

Hi @xialonglee — I worked the same issue (#87830) and wanted to flag a concern with the message-regex approach here, with evidence, in case it's helpful before this lands.

The added alternative requires session resume required / SessionResumeRequiredError to appear in the error message. But acpx builds that error's message without the class name — from the acpx dist (makeSessionResumeRequiredError):

new SessionResumeRequiredError(
  `Persistent ACP session ${params.record.acpSessionId} could not be resumed: ${params.reason}`,
  { cause: ... }
)

So for the real Kiro failure the message is "Persistent ACP session <id> could not be resumed: Internal error"SessionResumeRequiredError is the error's .name, not part of the message. And the gate receives the raw message: both construction seams build the AcpRuntimeError with normalizeText(event.message) / normalizeText(result.error.message) (manager.turn-stream.ts), not the formatAcpErrorChain rendering (the <- SessionResumeRequiredError: … part only appears in log output).

In the retry test here, the event message is "…could not be resumed: Internal error <- SessionResumeRequiredError: …" — the <- SessionResumeRequiredError: … is concatenated in the fixture, but the live pipeline doesn't put that into event.message, so I believe the regex wouldn't match the real error and the turn would still fail to recover (the negative test passes for the same reason — message without the substring → no match).

An approach that avoids depending on the message wording is to key on acpx's structured detailCode: "SESSION_RESUME_REQUIRED" (set on the error regardless of the backend's reason text). I put that up as #93547 with red-on-main/green-with-fix coverage including the real Kiro message shape — happy to defer to whichever direction the maintainers prefer, just wanted to make sure the real message shape was on the record. Thanks for digging into this one.

@xialonglee

Copy link
Copy Markdown
Contributor Author

Thanks @amersheeny for the thorough analysis — you are absolutely right. I verified the same code paths and confirmed that:

  1. The real acpx makeSessionResumeRequiredError only puts the class name in .name, not in .message, so my message-based regex would not match in production.
  2. errorFromTurnResult in manager.turn-stream.ts drops detailCode when building the AcpRuntimeError, so the chain-rendered format in my test fixture does not reflect real pipeline behavior.
  3. Using structured detailCode: "SESSION_RESUME_REQUIRED" is the correct approach, and fix(acp): recover stale persistent sessions by structured resume-required code [AI-assisted] #93547 implements it properly.

Closing this in favor of #93547. Thanks again for catching this before it landed.

@xialonglee

Copy link
Copy Markdown
Contributor Author

Closing in favor of #93547 which uses the structured detailCode approach — the correct fix for this issue.

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

Labels

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. P1 High-priority user-facing bug, regression, or broken workflow. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Persistent ACP session resume fails for Kiro threads after backend invalidation

3 participants