Repository navigation
fix(agents): keep claimed hook replies in conversation history - #150078
herefindalex wants to merge 30 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
ddfd6a4 to
c69c938
Compare
|
Codex review: needs maintainer review before merge. What this changesThe PR records plugin-claimed replies in CLI and embedded session history while preserving attachment filenames and preventing duplicate assistant entries. Example: A before_agent_reply hook returns caption "caption" and media URL "https://example.com/photo.png".
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a conversation-history gap that remains on current main; the reviewed patch has no blocking findings and preserves the existing transcript ownership guards. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherAgent runners invoke plugin reply hooks before model execution; claimed replies now pass through the existing session transcript owner before their payloads reach delivery. flowchart TD
A[User or scheduled turn] --> B[CLI or embedded runner]
B --> C[Before agent reply hook]
C --> D[Claimed reply projection]
D --> E[Session transcript owner]
E --> F[SQLite conversation history]
D --> G[Reply delivery]
Technical reviewBest possible solution: Land the claimed-reply persistence repair through the existing transcript owners after the normal exact-head CI gates complete. Do we have a high-confidence way to reproduce the issue? Current-main CLI and embedded handled-hook branches visibly bypass assistant persistence, matching the linked report's failing real-SQLite history assertion; this read-only review did not execute target code. Is this the best way to solve the issue? The repair addresses the early-return producer, reuses existing transcript append and mirroring contracts, and carries ownership metadata to prevent downstream duplicates. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2c130c7039f2. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +387, Tests +744. Total +1131 across 12 files. Added test files: 1. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (27 earlier review cycles; latest 8 shown)
Reviewed October 13, 2026, 11:21 PM ET / October 14, 2026, 03:21 UTC (Revision 28). |
7e00aa9 to
87d4811
Compare
87d4811 to
351c7f4
Compare
Closes #149985
Related: #150011
What Problem This Solves
Fixes a case where plugin replies claimed by
before_agent_replycan be delivered without being recorded in session history. Media-only and captioned replies also lose attachment references when a text-only transcript receipt suppresses downstream mirroring.User Impact
Claimed replies remain available in conversation history and follow-up context without duplicate assistant entries. Media replies retain stable attachment filenames alongside captions. No configuration or schema migration is required.
Why Change Was Made
Both CLI and embedded early-return paths persist through the existing transcript owners before returning ownership and idempotency metadata. Media history uses the existing outbound-media transcript-mirror projection; delivered payloads are unchanged. Session writer guards and detached/room-event no-persistence behavior are retained. Run-current assertions now also reach asynchronous transcript commit admission.
Evidence
Conflict repair and validation (
e38c83e212cf7da6a94603af26cd80722e8b4dfc)Merged the fixed upstream
mainbaseline5dd456acfa35575c342b43b944a9d0dbb911b68einto the PR. Resolved four conflicts while retaining both the claimed-reply history tests and upstream's newer authority/diagnostic behavior:preReplyAssertCurrentthrough transcript preparation and final commit admission.onMessageCommittedhandling.providerStarted: false, so hook-authored replies are not counted as model responses.Functional proof: 248 selected tests passed. The four-file runner/transcript/diagnostic run passed 245 tests across three shards (691.59 seconds wrapper wall time). A separate reliability selection passed the three existing “keeps a committed final reply successful” cases (63.63 seconds); its other 59 tests were excluded by the filter, not executed. Coverage includes claimed text/media delivery and real SQLite/history readback, once-only persistence, cancellation before commit, replaced-writer authority, silent claims, provider-started diagnostics, and post-commit ownership.
node scripts/run-vitest.mjs \ src/agents/cli-runner.before-agent-reply-cron.test.ts \ src/agents/cli-runner/cli-run-transcript.test.ts \ src/agents/embedded-agent-runner/run.shared-integration.test.ts \ src/agents/diagnostic-model-response.test.ts node scripts/run-vitest.mjs \ src/agents/cli-runner.reliability.test.ts \ -t 'keeps a committed final reply successful'Static proof and limitations: core production typecheck,
agents-rootandagents-othertest typechecks, changed-file formatting and targeted type-aware lint passed. Conflict/line/assertion/SQLite/mock-export ratchets, dependency/config/plugin-boundary checks, coercion/deprecation checks, native schema, legacy-store, media, sidecar, import-cycle, webhook, and pairing guards passed. Stagedgit diff --checkagainst the incorporated baseline passed.The complete local changed-file gate is not green: it was deliberately stopped after the two relevant test type graphs passed, before completing the remaining 26 broad graphs (exit 143). Its remaining non-type checks were run separately. The unused-export check exited 1: 21 production findings and 9 full-tree findings, all in UI source, match the unmodified pinned upstream baseline exactly. Both candidate and baseline used the same repository scanner/configuration and Knip
6.32.2; the baseline was independently executed from an exported upstream source tree with the same installed dependencies. The script export scan passed on both. No UI exports, ignore rules, or scanner baselines were changed. Broad remaining type coverage belongs to the new-head CI; no full-local-gate success is claimed.Static selection:
Independent review: the candidate received a
scoped-cleanP0–P2 autoreview result with no actionable findings. Two status-only chunks could not assess source; the source-diff chunk reviewed the repair. No source edits followed review.Environment: Node
24.21.0, repository-pinned pnpm12.9.0; tested/reviewed candidate treeb0efdc6bd24b05a026799ff287cff9d297a02132.The preceding head
45014fa84c8cc44de442725c47f88137e11073cfhad green CI and ClawSweeper Revision 27 reported no findings. Those results do not certify this new merge commit. This update is local real-runner/SQLite proof, not a fresh installed-plugin, live-channel, or live-model capture. Earlier installed-plugin evidence below retains its original head labels. New-head hosted CI remains required.Previous conflict repair and validation (
45014fa84c8cc44de442725c47f88137e11073cf; historical)Merged upstream
mainat8c9999b298c4a5db2d60b531efff7f8ec20acbeb. Resolved conflicts in the CLI hook test, embedded run orchestrator, and reply normalization. Preserved upstream user-turn recording and exec-request context alongside claimed-reply history persistence. The claimed-history path now consumes upstream's canonicalstripMixedSilentReplyTokenshelper with?? rawTextfor its nullable unchanged-text result; the duplicate helper is removed.agent-command.compaction-rotation.test.ts. Incorporated upstream fix816dcc13e9ff0768c60f08bc6813e131c1c934caroutes this suite through the host-owned database worker.run.terminal-timeout-delivery.integration.test.tsin80239a7e6b2. It was not restored or counted as passing; the current runtime-refresh integration suite passed.captureSessionEntryMaintenanceAgeFact,SessionEntryMaintenanceAgeCapture,SqliteReclamationPreparedSource,GatewayApprovalEventPublisherV2,OpenClawAgentDatabaseWorkerCloseResult, twoGitHubConnectionsexports, andGitHubConnectionsContent. Their definitions and scanner/config inputs are unchanged from the pinned base. The local full-tree scan also reportsreconnectGatewayin unchanged UI test-support source; base CI stopped at the production scan, so no base full-tree execution result is claimed. No unrelated exports or scanner rules were changed.scoped-cleanP0–P2 autoreview result, with no actionable findings. Two status-only chunks could not assess source; the source-diff chunk reviewed the repair. No source edits followed review.24.21.0, repository-pinned pnpm12.9.0,@openclaw/fs-safe 0.26.0. Tested and reviewed candidate tree:56e4b74f1b37031cee7290f8b1fa950aff910faf.Functional validation:
Static selection:
node scripts/check-changed.mjs --staged --base 8c9999b298c4a5db2d60b531efff7f8ec20acbeb -- <the 12 PR-delta paths>. After its unused-export failure, the remaining commands from the same repository-generated plan were executed separately without skipping or weakening their guards.git diff --cached --checkagainst that base passed.This is local real-runner/SQLite evidence, not a new installed-plugin, live-channel, or live-model capture. Earlier installed-plugin evidence below remains labelled by its original head. Hosted CI must validate the new head; no all-green or merge-ready claim is made.
Previous conflict resolution and validation (
cd4bfe4222412efde2fd1701f4bd77889cc68e28; historical)Merged upstream
mainat43856f78ec629f0c72180359a0ce85f06759974f. The only conflict was concurrent additions totest/vitest/vitest.database-worker-core-paths.mjs; the resolution keeps both the claimed-reply CLI test and upstream's cron-grant test exactly once. The PR's added/deleted patch is unchanged after ignoring diff context and line numbers, and the existing cancellation/commit assertions are retained.test/scripts/database-worker-registry.test.ts, andtest/scripts/ci-node-test-plan.test.ts. This includes all four cancellation-during/after-preparation regressions.run.plugin-runtime-refresh.integration.test.tsandrun.terminal-timeout-delivery.integration.test.tspassed. Upstreambb5656bf89e230bb3d6c9040b1e9b86df0306439routes these suites through host-owned database-worker forks; that change is retained.git diff --checkalso passed. This mechanical merge reuses the prior review of the unchanged PR patch.Revision 24: cancellation at transcript commit admission (
f66173bdd5f63a7991600cede66b9c22f2891088)A claimed reply could still add an assistant history event when the run was cancelled after transcript preparation but before asynchronous commit admission. CLI and embedded runners now pass their existing run-current assertion to the same transcript append/worker owner; session fences, write hooks, and idempotency remain unchanged. No schema or configuration change.
b974ef10871c10bd7accd406e4999ce0482314db, with the new tests and lockfile-matching dependencies, both "cancelled after transcript preparation" cases failed: real SQLite history contained onelate claimed replyassistant event instead of zero.214bb47b4ec0809e357d2e497e0bf8fd5d9f31ebexited 0, including core production typecheck, all 27 core-test type graphs, three unused-export scans, formatting, type-aware lint, ratchets, and boundary/legacy-store/import-cycle guards.git diff --checkalso passed.scoped-cleanand no findings. Reviewed source did not change afterward.24.21.0, repository-pinned pnpm12.5.1, and@openclaw/fs-safe 0.23.0matching the lockfile.Functional revalidation:
Changed-file gate:
Known failure, not claimed fixed: replaying both failed files from CI run 37199547039 produced the same two
beforeAllsuite failures on this repaired tree and on untouched upstream parent214bb47b4ec0809e357d2e497e0bf8fd5d9f31eb:Both stop in shared harness warmup at
run.workspace-ownership.test-support.ts:68withreal workspace consumer was exercised: expected 0 to be greater than 0; all 16 tests are skipped. The assertion can mask an earlier warmup error, so the underlying cause remains unresolved. These test/harness files are unchanged from that upstream parent. No retries, weaker assertions, or unrelated source changes were used to obtain green results.This is real-runner/SQLite regression evidence, not a new installed-plugin, external-channel, or live-model trace. The head-labelled installed-plugin/local-channel-adapter proof below is historical. Hosted CI on the updated head remains the merge gate.
Earlier evidence (historical; see head labels)
routeReplydurable outbound pipeline, asserting unchanged transport arguments and once-only assistant history after delivery.git diff --checkpassed. The changed-file gate's earlier test type errors were corrected, and the failed typecheck plus remaining lint step reran successfully; other completed guards were retained.Installed plugin -> claimed text/media -> delivery -> SQLite/history proof
Executed against exact PR head
f57cd074e95ba2e0bbedb527d5c41ecfb7948cecwith Node 24.19.0 and pnpm 12.4.0, using isolatedHOME, config, state, and session storage.state/extensions/claimed-reply-proofand enabled it. A fresh process reported plugin version1.0.0,status: loaded, and channelclaimed-proof. The plugin declaredbefore_agent_reply, and the isolated operator config explicitly grantedhooks.allowConversationAccess: true.openclaw agent --local --deliver --reply-channel claimed-proofprocess loaded that installed plugin. The hook claimed a captioned media reply before model execution. The configured model endpoint was the intentionally unreachablehttp://127.0.0.1:9/v1.{ "payloads": [ { "text": "CLAIMED_TEXT_PR150078", "mediaUrl": "https://example.invalid/CLAIMED_MEDIA_PR150078.png", "mediaUrls": ["https://example.invalid/CLAIMED_MEDIA_PR150078.png"] } ], "deliveryStatus": { "requested": true, "attempted": true, "status": "sent", "succeeded": true, "resultCount": 1 } }{ "delivery_count": 1, "kinds": ["media"], "texts": ["CLAIMED_TEXT_PR150078"], "mediaUrls": ["https://example.invalid/CLAIMED_MEDIA_PR150078.png"], "sequences": [1] }loadTranscriptEventshistory accessor read exactly one assistant message from the same SQLite-backed session, with the media filename projected into transcript text:{ "eventCount": 2, "assistantCount": 1, "assistantTexts": [["CLAIMED_TEXT_PR150078\nCLAIMED_MEDIA_PR150078.png"]], "idempotencyKeys": ["before-agent-reply:3d73e0fa-50d0-4b6b-8ad0-839f89d51be2"] }assistant_count = 1anddistinct_idempotency_keys = 1for that session.This is a real disk installation and real routed-delivery adapter execution with SQLite/history readback. The adapter is a local proof channel; this is not a live external-channel API or live-model test.
Revalidated on PR head (2f60a04)
fabbb3462b7e77c2207c44a4c0ace86254ab6a26into the prior PR head. The two conflicts were an import moved into the upstream model-admission owner and a test-file routing list; the resolved PR diff retains the same claimed-reply persistence behavior.openclaw agent --local --deliver --reply-channel claimed-proofprocess loaded the installed proof plugin from isolated test state. Itsbefore_agent_replyhook claimed a captioned media reply. The configured model endpoint was unreachable (127.0.0.1:9), so no model response produced the reply. The CLI exited 0.CLAIMED_TEXT_PR150078and media URLhttps://example.invalid/CLAIMED_MEDIA_PR150078.png.loadTranscriptEventsaccessor returned 2 events and exactly 1 assistant message, containingCLAIMED_TEXT_PR150078\nCLAIMED_MEDIA_PR150078.pngwith idempotency keybefore-agent-reply:812995e1-f3d1-473d-b498-fc8153298c00. Direct SQLite readback found 1 assistant event and 1 distinct idempotency key for the same session.openclaw doctor --fixbefore this rerun; no operator state was used. This is real installed-plugin and local routed-delivery proof, not an external-channel API or live-model test.Silent-claim follow-up and exact-head proof (348ff05)
ClawSweeper's Revision 10 found that a hook returning
{ handled: true }withoutreplycould persist the syntheticNO_REPLYtoken as an assistant message. Both CLI and embedded runners now return the existing silent payload without appending an assistant transcript event; they mark that payload transcript-owned so downstream delivery cannot mirror it into history.NO_REPLYassistant message, then passed after the fix with zero assistant messages for silent claims.core-test-agents-root,core-test-agents-other, focused oxlint/oxfmt, andgit diff --checkpassed. An independent P0–P2 review of the follow-up diff found no actionable findings. Full exact-head CI remains the merge gate.deliveryStatus.status = sentwith one payload result. Its local channel adapter recorded exactly one captioned-media outbound call. The productionloadTranscriptEventsaccessor returned 2 events, including exactly one assistant message containingCLAIMED_TEXT_PR150078\nCLAIMED_MEDIA_PR150078.pngwith idempotency keybefore-agent-reply:8c457f24-5170-4e51-8de6-dc96116e9286. Direct SQLite readback found one assistant event and one distinct idempotency key for the same session.The installed-plugin proof uses an isolated local channel adapter and intentionally unreachable model endpoint, not an external-channel API or live-model test.
Cancellation authority and exact-head proof (31a58fd)
before_agent_replyhook. CLI and embedded paths now check current run authority after the hook, immediately around transcript preparation, and after persistence returns, before releasing a claimed payload.late claimed replyassistant event each; both pass now with zero assistant events. The focusedbefore_agent_replysuites pass 63/63 tests across CLI and embedded entry points.openclaw agent --local --deliverprocess loaded the installed proof plugin from isolated state. The plugin claimed a captioned-media reply; the local channel adapter recorded exactly one media send with unchanged captionCLAIMED_TEXT_PR150078and media URLhttps://example.invalid/CLAIMED_MEDIA_PR150078.png. CLI reporteddeliveryStatus.status = sent,succeeded = true, andresultCount = 1.loadTranscriptEventsread 2 session events, including exactly 1 assistant message with textCLAIMED_TEXT_PR150078\nCLAIMED_MEDIA_PR150078.pngand onebefore-agent-replyidempotency key. A direct read-only SQLite query independently returned assistant count 1 and distinct idempotency-key count 1 for that session. This is installed-plugin/local-adapter proof, not an external-channel API or live-model test.Explicit silent-token claim regression (941a8a3)
ClawSweeper Revision 14 identified a distinct edge: a plugin can return
{ handled: true, reply: { text: "NO_REPLY" } }. Outbound normalization suppresses that content-free payload, but both claimed-reply paths wrote an assistantNO_REPLYevent. Both runners now use the shared payload-level silent-content decision before transcript persistence; media, other sendable content, heartbeat-owned replies, and the existing cancellation fences keep their prior paths.c237892331314cdb5309159e832c7afa3a23c853: the new CLI and embedded runner tests each failed through the real runner entrypoint and SQLite history readback. Each found one assistant event containingNO_REPLYwhere zero were expected.941a8a3bc30f1ad6b713697ec670b0c32d77f8a4: the same two targeted tests passed (2/2). The nearbybefore_agent_replysuites passed 65/65, including text/media persistence and cancellation/replaced-writer cases. Delivery normalization suites passed 102/102, including silent-token, media, and heartbeat cases.pnpm test src/agents/cli-runner.before-agent-reply-cron.test.ts --maxWorkers=1 --reporter=dotpassed 44/44 in 52.51s wall;pnpm test src/agents/embedded-agent-runner/run.shared-integration.test.ts --maxWorkers=1 --reporter=dotpassed 167/167 in 213.50s wall. The shared embedded integration file is costly because it exercises the real runner/session/SQLite boundary and adjacent authority/media behavior; no new full-runner fixture was added.git diff --checkpassed. Core typecheck, all 25 core-test type graphs, and all three unused-export scans completed successfully duringcheck:changed. That broad local gate was interrupted during full-tree core lint after more than 30 minutes, so it is not claimed as a full pass. A separate lint command scoped to the six changed files completed without diagnostics. Exact-head GitHub CI remains the merge gate.The prior installed-plugin captioned-media proof was collected on
31a58fd, not rerun on this incremental silent-token fix; the new SQLite regressions above ran on the pushed head.Revision 15 follow-up: silent token with media (
1a58c8cf89772187adbc0b45f3e18b2a04890473)147394dfdb90c3e0915b98f257031510b8128810): the new registered-plugin CLI case delivered a media-only reply for{ text: "NO_REPLY", mediaUrl: "https://example.com/photo.png" }, but its SQLite/history readback containedNO_REPLY\nphoto.pnginstead ofphoto.png. The new assertion failed on that exact mismatch.photo.png, and delivery does not add a second event. The embedded real-session matrix also reads backphoto.pngfor persistent turns and preserves its existing non-persistent-turn expectations.node scripts/run-vitest.mjs src/agents/cli-runner.before-agent-reply-cron.test.ts src/agents/embedded-agent-runner/run.shared-integration.test.ts --maxWorkers=1passed; targeted oxlint and oxfmt passed for all five changed files;tsconfig.core.json,agents-root, andagents-othertypechecks passed;git diff --checkpassed. Independent incremental autoreview through P2 exited successfully.check:changedwas not rerun locally; exact-head CI is pending.Upstream conflict resolution and revalidation (
a0c2eb36ac86c73a7111386ee540b54f775e372e)mainata1ba139b5697bef432ad0d2d28e0aba75b8a43a6; the only manual conflict was the CLI test import block. The resolution retains both the PR's registry/SQLite imports and upstream's test scheduler import.pnpm install --frozen-lockfilepassed. The full CLI and embedded integration test files passed together with--maxWorkers=1(about five minutes of local wall time, including worker rebuild). Focused oxfmt and oxlint on the five changed files, production core typecheck,agents-rootandagents-othertest typechecks, and stagedgit diff --checkpassed.check:changedwas not rerun. Exact-head GitHub CI for this merge commit remains to be checked.Mixed silent-token text alignment (
e0010a48fd116ca88595d60033010e2d0c9f3ff7)Hello NO_REPLY, delivery removes the trailing control token while the claimed-reply transcript previously retained it. This affects text-only replies and media captions.a0c2eb36ac86c73a7111386ee540b54f775e372e. The transcript projection still passed the raw mixed text to SQLite.Hello, SQLite/history textHelloorHello\nphoto.png, and no second assistant event after delivery. Embedded real-session cases verify the same history projection for persistent turns and retain the non-persistent-turn expectations. The exactNO_REPLYplus media case remains covered.--maxWorkers=1(240 seconds local wall time). The existing reply-normalization test file passed. Focused oxfmt, oxlint, production core typecheck,agents-rootandagents-othertest typechecks,git diff --check, and independent incremental review through P2 passed.check:changedwas not rerun; exact-head GitHub CI remains pending.Follow-up: heartbeat claim/history parity (96bfb9e)
Follow-up: opaque control-token history (4ea7434)
Upstream sync and validation (
e1ba7fa79a2)mainat2aed86671065. This incorporates the upstream removal ofextensions/voice-call/runtime-api.ts, which the previous CI head still expected in the SDK runtime API guardrail.node scripts/run-vitest.mjs src/agents/cli-runner.before-agent-reply-cron.test.ts: 39/39 passed.node scripts/run-vitest.mjs src/plugins/contracts/plugin-sdk-runtime-api-guardrails.test.ts test/scripts/run-vitest-bounded.test.ts src/infra/heartbeat-runner.isolated-session-mirror.test.ts src/agents/embedded-agent-runner/run.shared-integration.test.ts: passed.git diff --checkpassed; independent diff review found no actionable issue.openclaw/ci-gateremains red. No CI success is claimed.2aed86671065, the subagent archive source-level test failed 1/25 with the samerunningversusterminalassertion as PR head (baseline usedOPENCLAW_E2E_SKIP_BUILD=1); native SDK admission failed 1/1 with a state-database borrower leak on both base and PR head. Hosted CI instead reported a 5-second native admission probe stall, so a shared root cause is not established.