Skip to content

fix(agents): detached tool runs lose their final reply - #189984

Merged
roboclaw-bot merged 1 commit into
mainfrom
loop/contributor-pr-167892
Nov 1, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
loop/contributor-pr-167892

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Detached tool runs can finish their work but lose the recovered final reply; a cancelled finalizer can also append that reply to its borrowed transcript after admission closes.

Supersedes #167892, thanks @ethanhawkes-gif.

User Impact

Detached runs return their recovered answer through the original transcript, and revoked runs cannot persist a late answer. No configuration or migration is required.

Why This Change Was Made

Reuse the existing harness admission for tool-free finalization, retain its native registration fingerprint, and carry the live run assertion into the borrowed manager's write admission. Current main already retains child writer context (#140399) and serializes session turns (#175837); these remaining finalizer boundaries still needed repair.

Production LOC is net zero (+43/-43): one finalizer parameter object replaces duplicate identity assembly, and redundant projection aliases are removed. The 210-line regression allocation covers the real runner/native-registration/tool/transcript composition that scripted backend tests miss.

Evidence

  • Unchanged two-case regression: 2 fail on pinned main 7db5a3f79d186d617ae96fa48f64ebb2f8d49b91, 2 pass with this change. The affected production files also match newer main.
  • Real runEmbeddedAgent, built-in harness, file write, native registration, private-session replacement, borrowed transcript and persistence. Only provider responses are scripted; no paid provider or production Gateway was used.
  • Negative control: restoring harness admission without the manager assertion recovers the answer but persists it after real run admission is closed; the revocation case fails.
  • Regression test time: under 2 seconds for both cases; cold wrapper wall time 38.3 seconds including compiler preparation. Broad CI passes: run 41265778749.
  • Seven affected harness, finalization, parent/child ownership, and prompt-prefix test files: 203 tests pass.
  • Reproduce with node scripts/run-vitest.mjs run src/agents/embedded-agent-runner/run/settled-turn-finalization.borrowed.test.ts --maxWorkers=1.
  • Focused typecheck (core-test-agents-other), changed-file lint/format and git diff --check pass.
  • Codex autoreview: final local candidate against 7db5a3f79d18, P0–P2, scoped-clean, no actionable findings. No reviewer configuration was changed.
  • Contributor code was read through GitHub and was never checked out or executed on this host.

Hosted ClawSweeper review of d4bacc15eb75: no findings or before-merge work.

Keep settled-turn finalization inside the existing harness admission and borrowed-manager write scope. Preserve the prepared native registration fingerprint and reject transcript appends after admission closes.

Co-authored-by: ethanhawkes-gif <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Nov 1, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 1, 2026 02:34
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves harness admission and native registration during finalization and rejects borrowed-transcript writes after run admission closes.

Example: A detached review writes note.txt, receives an empty post-tool response, and recovers “The review evidence has been saved.”

  • Before: Finalization can lose the recovered answer, or append it after admission closes.
  • After: The active run returns the answer through its borrowed transcript; a revoked run cannot append or return it.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, owner-preserving repair with meaningful production-path regression coverage; confidence is bounded by in-process proof and unfinished exact-head CI.
Proof confidence 🦐 gold shrimp (3/6) ✨ media proof bonus Sufficient (linked_artifact): For this maintainer-authored PR, the production-path authority harness exercises real runEmbeddedAgent, native registration, a real file write, private-session replacement, and the borrowed manager with scripted provider responses; reported red/green results and the negative control establish recovery for the active run and no final append or caller answer after actual admission closure.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Detached runs can complete tool work without returning the recovered final answer, and revoked finalizers can mutate the borrowed transcript.
Reason: This maintainer-authored repair restores the existing reply and revocation contracts without adding configuration, public APIs, or a competing owner.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a remaining detached-run finalization defect on current main. No introduced correctness or security defect was found; exact-head CI remains pending.

Priority: P2
Reviewed head: d4bacc15eb75b163ecca28a98bcb797530ce2b81

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: This replacement supplies production-path harness evidence rather than a current-head Gateway/model run; the predecessor's transport trace covers an older implementation.
Agent review details

How this fits together

The embedded runner sends settled tool context through the selected harness for a tool-free final answer, then appends through the existing session manager and prepares caller payloads.

flowchart TD
  A[Detached agent run] --> B[Completed tool work]
  B --> C[Settled turn finalizer]
  C --> D[Existing harness admission]
  D --> E[Tool free model response]
  E --> F[Session manager write assertion]
  F --> G[Borrowed transcript and caller reply]
Loading

Technical review

Best possible solution:

Keep finalization within the existing admitted harness and manager write owners while retaining tool-free execution and committed writer fencing.

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

Current-main source exposes the missing finalizer registration boundary, and the PR reports unchanged paired regressions failing on the pinned base and passing on this head; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch restores admission at the existing harness owner and carries liveness to the existing write owner; the simplification pass found no unnecessary production machinery or redundant test group.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned change and current-main comparison: The introduced diff contains the finalization admission wrapper, fingerprint propagation, manager write assertion, and paired regression. The three affected production files are unchanged between the pinned merge base and fetched main. (src/agents/harness/selection.ts:187, d4bacc15eb75)
  • Native registration boundary: Native registration requires an exact admitted operation or prepared detached tool-authority binding; the finalizer now enters that existing owner and carries its fingerprint into the built-in attempt. (src/agents/embedded-agent-runner/runs.ts:839, d4bacc15eb75)
  • Final-effect revocation coverage: The regression invokes real runEmbeddedAgent with a real write tool and borrowed manager, closes the actual prepared admission during finalization, and checks rejection plus absence of the recovered assistant message. The PR reports both cases failing on the base and passing on the head, including a negative control without the manager assertion. (src/agents/embedded-agent-runner/run/settled-turn-finalization.borrowed.test.ts:142, d4bacc15eb75)
  • Existing write owner: Manager append admission captures the scoped assertion and composes it with transcript and actor authority rather than introducing another persistence owner. (src/agents/sessions/session-manager-append-admission.ts:41, d4bacc15eb75)
  • Credited predecessor and proof limits: fix(agents): keep settled-turn finalization inside dispatched transcript custody #167892 documents the same borrowed-custody problem and an earlier production-transport recovery trace credited to ethanhawkes-gif; that older trace does not establish execution of this replacement head.
  • Merge and validation state: GitHub reports the reviewed head as mergeable with the aggregate CI gate pending; dependency review and security-sensitive review statuses pass. Pending checks establish no patch-caused failure. (d4bacc15eb75)

PR surface

Source 0, Tests +210, Other +2. Total +212 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 43 43 0
Tests 1 210 0 +210
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 5 255 43 +212

Review metrics

Metric Value Why it matters
Production versus regression LOC Production +43/-43; tests +210 Production reuses existing owners; the regression growth covers distinct successful-recovery and revoked-write failures through the real runner composition.

Root-cause cluster

Relationship: canonical
Canonical: #189984
Summary: This PR explicitly replaces the earlier borrowed-transcript finalization repair; internal fallback writer-fence work addresses an adjacent boundary.

Members:

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

Labels

Label changes:

  • add P2: Detached tool runs can lose their final answer after successful work; the affected workflow is specific and the repair is focused.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • 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: Detached tool runs can lose their final answer after successful work; the affected workflow is specific and the repair is focused.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 31, 2026, 10:40 PM ET / November 1, 2026, 02:40 UTC.

@roboclaw-bot
roboclaw-bot merged commit b9b7108 into main Nov 1, 2026
226 checks passed
@roboclaw-bot
roboclaw-bot deleted the loop/contributor-pr-167892 branch November 1, 2026 02:55
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 1, 2026
…89984)

Keep tool-free settled-turn finalization inside the existing harness admission and borrowed-manager write scope. Retain the native registration fingerprint and reject transcript appends after admission closes. Remove duplicate finalizer parameter assembly and projection aliases, keeping production LOC unchanged.

Supersedes openclaw#167892, thanks @ethanhawkes-gif.

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

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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