Repository navigation
improve(agents): explain unknown tool outcomes and assert append-only request history - #163379
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. |
|
Codex review: needs maintainer review before merge. Reviewed October 2, 2026, 8:30 AM ET / 12:30 UTC (Revision 6). ClawSweeper reviewWhat this changesThe PR adds safer guidance for unrecorded tool results, preserves repair provenance during replay, and detects unexpected request-history edits with warnings and an optional strict assertion. Merge readiness✅ Ready for maintainer review This remains useful work: current main lacks the central changes, the earlier mutation finding is resolved, and no new blocking defect was found. Priority: P2 Review scores
Verification
How this fits togetherThe embedded agent runner converts session transcripts into model requests. Transcript repair fills missing tool results, while cache observation checks whether successive requests preserve their earlier conversation prefix. flowchart TD
A[Session transcript] --> B[Tool result repair]
B --> C[Model context projection]
C --> D[Request history check]
E[Declared compaction and pruning] --> D
D --> F[Provider request]
D --> G[Warning or optional assertion]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +122, Tests +306, Docs +7, Other 0. Total +435 across 41 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep recovery guidance conservative and let the existing transcript owners distinguish intentional history rewrites from accidental edits. Do we have a high-confidence way to reproduce the issue? Not applicable as a diagnostic feature review; source inspection confirms the earlier mutation defect is covered by focused regressions, and no runtime reproduction was executed during this review. Is this the best way to solve the issue? Yes. Shared recovery text and observation at the converted-request boundary keep the behavior with its existing owners while preserving legacy transcript recognition. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 71b1c049f4c0. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
c5e329a to
5d5aa04
Compare
|
Live Anthropic proof for the append-only history assertion (direct API key,
Note on the ratchet warning: |
Use shared unknown-outcome guidance while preserving the Responses-family aborted convention. Retain synthetic provenance in model context so late real results can replace repair placeholders without changing existing detection or stored transcript rows.
Track converted message prefixes and record declared compaction, pruning, runtime-context, and image rewrites. Notify every cache-affinity baseline for the same session identity. Memoize message/content and schema fingerprints, with strict assertions enabled only by an opt-in environment flag.
5d5aa04 to
e902736
Compare
|
Fixed the stale fingerprint finding in
The requested observability, cache-stability, session-boundary, and parent-fork suites pass 98/98 in total. Touched production/test type lanes, lint, formatting, and the line-cap ratchet pass. Fresh autoreview is scoped-clean at P2 and above. For CI run 36986346080 on the preceding head
History was checked with both the requested literal |
…-text-history-assert
Include packages/llm-core/src/types.ts in the PR wrapper's extracted source inventory. Main commit 93625aa pulled tool-result-pairing.ts into that graph, so its existing shared tool-result text import must be included for standalone wrapper execution.
…-text-history-assert
|
Merged via squash.
|
The system-update custom-type constant was counted as an environment variable name; rename it so the budget only counts real names. Raise the budget to 477 for OPENCLAW_PROMPT_CACHE_ASSERT (#163379), the owner-approved prompt-cache assertion switch.
… request history (openclaw#163379) * fix(agents): describe unrecorded tool results as unknown outcomes Use shared unknown-outcome guidance while preserving the Responses-family aborted convention. Retain synthetic provenance in model context so late real results can replace repair placeholders without changing existing detection or stored transcript rows. * improve(agents): assert provider request history stays append-only Track converted message prefixes and record declared compaction, pruning, runtime-context, and image rewrites. Notify every cache-affinity baseline for the same session identity. Memoize message/content and schema fingerprints, with strict assertions enabled only by an opt-in environment flag. * fix(agents): pin the shared tool-result text for the request wrapper Include packages/llm-core/src/types.ts in the PR wrapper's extracted source inventory. Main commit a35612b pulled tool-result-pairing.ts into that graph, so its existing shared tool-result text import must be included for standalone wrapper execution.
The system-update custom-type constant was counted as an environment variable name; rename it so the budget only counts real names. Raise the budget to 477 for OPENCLAW_PROMPT_CACHE_ASSERT (openclaw#163379), the owner-approved prompt-cache assertion switch.
What Problem This Solves
An interrupted tool call can look like an ordinary failure even when its operation already had side effects, and rewritten request history can silently invalidate prompt-cache reuse.
User Impact
Unrecorded tool results now tell the model that the outcome is unknown, to retry only read-only or idempotent operations, and to verify state before repeating operations with side effects. Responses-family APIs retain
aborted. Undeclared history edits warn once per session key;OPENCLAW_PROMPT_CACHE_ASSERT=1makes them fail immediately during development and testing.Why This Change Was Made
One shared constant owns the recovery guidance. Model-context hydration and projection preserve the existing synthetic marker, so a late real result still replaces a placeholder while opaque tool details stay out of model context. Existing persisted rows, storage format, and synthetic-result detection remain unchanged.
The observer compares ordered fingerprints of converted messages between requests. Per-block memos check primitive keys and values before reuse; nested block values and message envelopes are checked on every observation. This detects in-place edits under both reused messages and rebuilt wrappers while avoiding repeated hashing of large unchanged text or image data. String-content hashes live with the bounded history baseline. Compaction, new pruning rounds, runtime-carrier removal/movement, and image cleanup declare their changes at their existing owners; replaying an unchanged projection does not repeatedly waive the assertion. Model, transport, and retention changes restart history comparison. Tool schemas now use the cycle-safe serializer with an identity memo, so each schema object is hashed once rather than traversed on every request. In a synthetic benchmark with 100 schemas over 500 calls, repeated collection decreased from 149.4 ms to 16.8 ms.
Production LOC is +122: +25 for guidance/provenance and +97 for history observation. Tests/support are +306, docs +7. The obsolete assertion-baseline row is removed separately (one configuration line). The non-test-source count includes four lines of UI test configuration. The custom schema walker and redundant transport/tracker code were removed; the remaining growth preserves late-result replacement and handles legitimate history changes. Further reductions would require broader transcript-normalization changes or removing tested legacy behavior, so the neutral target was not forced through unrelated cleanup.
Evidence
The wrapper extraction repair in
9f821ed19729changes onlyscripts/pr-lib/wrapper-components.txt(+1 inventory entry; production/test LOC unchanged). The shared-text files remainpackages/llm-core/src/types.ts,packages/agent-core/src/harness/session/tool-result-pairing.ts, and the narrow source alias inui/vitest.config.ts.The inventory now includes
packages/llm-core/src/types.tsbecause main commit93625aa3d10dbroughttool-result-pairing.tsinto the extracted wrapper graph, making its shared-text import a required source dependency.Current proof: eager-import closure 17/17, Bun UI headline 25/25, session transcript repair 58/58, and prompt-cache observability 42/42 pass; core/package/UI typechecks, scoped lint, formatting, and diff checks pass. The two Gateway roster failures remain classified as inherited, reproduced on clean main
6046d4fcb687, and are handled by a separate main-side repair.The earlier import, fixture, and baseline repairs remain folded into the two topic commits:
@openclaw/llm-core/typesmodule. UI Vitest resolves that leaf directly to source, avoiding generated AI-package artifacts. The headline test passes all 25 cases under Node and under Bun withui/vitest.config.ts; resolver traces confirm the source path.convertToLlm; its shared test fixture now supplies the real converter with the matching required type. All five skills-policy cases and the session-boundary tests pass.OPENCLAW_PROMPT_CACHE_ASSERTadds oneOPENCLAW_*name: 472 against budget 471. The environment budget remains unchanged; a bump is pending owner approval. This is advisory under GitHub Actions, where the max-lines check passes with a warning; strict local budget execution exits 1.The mutation follow-up adds 46 production lines and six regression cases. Both reported text-mutation cases and nested argument mutation failed on the old code before the fix. All four requested suites now pass (98 tests, 106.78 s combined wrapper wall), along with touched type lanes, lint, formatting, and the line-cap ratchet. Fresh autoreview is scoped-clean at P2 and above. The earlier full build predates these follow-ups; it was not repeated for the fingerprint-only repair.
git diff --checkpass.Commands and per-file cost
Each table entry ran through
node scripts/run-vitest.mjs <file> --maxWorkers=1, using a task-localTMPDIR. Wall times include runner setup; two independent one-worker runners used separate filesystem module caches. Follow-up owner runs passed after the fixture and projection-owner fixes.packages/ai/src/providers/google-interactions-shared.convert.test.tspackages/ai/src/transports/openai-responses-compaction-replay.test.tssrc/agents/embedded-agent-runner/prompt-cache-observability.test.tssrc/agents/embedded-agent-runner/run/attempt-prompt-submit.test.tssrc/agents/embedded-agent-runner/run/attempt-session-boundary.test.tssrc/agents/embedded-agent-runner/run/attempt.llm-boundary.cache-stability.test.tssrc/agents/embedded-agent-runner/run/attempt.test.tssrc/agents/session-transcript-repair.test.tssrc/agents/embedded-agent-runner/run/attempt.skills-policy.test.tssrc/agents/transport-message-transform.test.tssrc/agents/sessions/session-manager-model-context.test.tssrc/gateway/server-methods/chat-send-synthetic-repair.integration.test.tsAdditional owner/sibling targets:
packages/agent-core/src/harness/session/session-context.test.ts,packages/ai/src/transcript-transform.import-boundary.test.ts,src/agents/transport-message-transform.async.test.ts,src/agents/embedded-agent-runner/run/attempt.llm-boundary.test.ts,src/agents/embedded-agent-runner/run/history-image-prune.test.ts,src/agents/embedded-agent-runner/run/attempt-execution-phase.test.ts,src/agents/embedded-agent-runner/run.compaction-runtime.test.ts,src/agents/embedded-agent-runner/compact.delegate.test.ts,src/agents/embedded-agent-runner/compact.delegate-resources.test.ts, andsrc/agents/embedded-agent-runner/tool-result-truncation.cache-ttl.test.ts.CI has not yet run the new mutation cases. On the prior head, parent-fork passed all 17 CI cases before a suite teardown admission failure; it also passed 17/17 on three standalone local runs (111.62 s cold, 40.91 s, 30.69 s wrapper walls). That raw-snapshot path does not enter the changed model hydration. Recent main lifecycle work includes
57e0aaa1c190and54885d54a038; neither is claimed to fix the observed race. The ACP case timed out at 120,446 ms and left 18 skills watchers open; its owner and test were unchanged, with no test edits in the preceding 48 hours and no established fingerprint link. Both shard failures are classified unrelated and unresolved, not fixed by local replay. The initial end-to-end failure was fixed at synthetic provenance hydration/projection. A subsequent fixture failure was fixed by supplying its required real converter. The ordinary test router excludes live files; explicit live-config collection succeeded.Current follow-up proof (all pass):