Skip to content

fix: answer after tool-only turns when a context engine omits message timestamps - #201766

Merged
jalehman merged 1 commit into
mainfrom
fix/settled-finalization-timestamp
Nov 21, 2026
Merged

jalehman merged 1 commit into
mainfrom
fix/settled-finalization-timestamp

Conversation

@jalehman

@jalehman jalehman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Sometimes an agent runs a tool and then ends its turn without a final answer. A typical case is a reply of NO_REPLY to a sessions_send request that needs a result. OpenClaw then runs a short tool-free step to get the answer. That step crashed with RangeError: Invalid time value before it made any model call when the session used a context engine that adds messages without a timestamp. Lossless Claw adds summary, focus-brief and recall messages that way. The requester got no answer and the turn was logged as incomplete (incident run bd2d3478-18a1-4ee0-b7db-43c2d83dd497, 2026-11-19).

User Impact

User impact: sessions that use a timestamp-less context engine such as Lossless Claw get a real final answer again after a tool-only turn, instead of an "incomplete turn" error. Ordinary turns send the same model requests as before.

Why This Change Was Made

The tool-free step first trims the turn's messages to fit the model-context limit. To do that it builds temporary bookkeeping entries, and it gave each one a timestamp converted from its message's timestamp. A message without a timestamp made that conversion throw. Every entry now gets the same fixed timestamp. Nothing reads these timestamps: the trimming logic does not look at them, and the entries are never saved or sent to the model. Sizing and model input come from the messages themselves, so request bytes are unchanged.

Rejected alternative: filling in missing timestamps where the context engine's output enters OpenClaw. OpenClaw adds a time stamp to user-message text from the message timestamp, so this would change summary text the model sees. A current time would break the prompt cache, and a fixed time would show the model a 1970 date. A separate Lossless Claw change will add timestamps on the plugin side. This PR is the guard on the OpenClaw side.

Accepted risk: if a later change makes the trimming logic read entry timestamps, this path would give it the 1970 value. The new test checks the trimmed result, not just that nothing throws, so such a change would fail it. No other new Date(x).toISOString() call in src/agents/embedded-agent-runner or src/agents/harness converts a timestamp taken from a message. The others use the current clock or validated dates.

Evidence

Regression test (attempt-history-prepare.test.ts, two cases). The tool-free step gets a summary-style user message with no timestamp, one with a NaN timestamp, and an exec tool call and result. With the default limit, all four messages reach the agent unchanged. With a tight limit, the large tool result is replaced by the usual omission notice while the timestamp-less messages stay. Both cases fail on origin/main with RangeError: Invalid time value and pass with the fix. Neighboring suites pass: settled-turn-finalization, finalization-scope and attempt-prompt-phase (79 tests). pnpm check:changed passes, including typecheck, lint and format.

Real behavior on the Mac Studio. Each commit ran in a Crabbox local-container lease launched on the Studio (node:24.22.1-trixie, image sha256:f1e03497…, 8 CPU / 24 GB) from a clone at the pushed commit. Each run used:

  • a real isolated Gateway
  • the real Claude Opus 5.5 model through ClawRouter, with a pass-through proxy that records request bodies and no headers
  • a small test context engine that adds one Lossless Claw-style { role: "user", content } summary message with no timestamp to every assembled context

I used a small test engine instead of Lossless Claw 40833c3 because it isolates the one trigger, missing timestamps, and needs no Lossless Claw database setup. The scenario matches the incident. A requester session asks the model to call sessions_send into a WebChat session. There the model runs one exec, then replies NO_REPLY, which the request does not allow.

base f250a678 (lease cbx_0c02ea0561f9) fix 5f3bb45b (lease cbx_b865184e14f8)
Tool-free finalization step crashed before calling the model ran: one tool-free model request (0 tools, 3,811 bytes; the first message is the timestamp-less summary)
Target session's final answer none (payloads=0 tools=1) a plain-text summary of the exec result
What the requester got back NO_REPLY_RECEIVED error REPLY: The exec tool ran 'echo settled-proof-01aca19e' once, and it returned 'settled-proof-01aca19e'. …
Side effects 1 exec 1 exec (finalization had no tools and repeated nothing)
New warnings 4 failure lines (below) none; only the expected "running isolated finalization" line

Base log, which matches the incident. Inside the container the RangeError text reads Invalid Date because the test runtime uses the OpenClaw Bun fork. Node says Invalid time value.

[agent/embedded] settled post-tool turn lacked a final answer: runId=a120535b-… — running isolated finalization
[agent/embedded] settled-turn finalization failed: runId=a120535b-… error=Invalid Date — preserving failed recovery
[agent/embedded] incomplete turn detected: runId=a120535b-… stopReason=stop … payloads=0 tools=1 replaySafe=no … — surfacing error to user
[context-engine] discarded unaccepted turn advancement: …: run ended without host acceptance

Ordinary turns are unchanged. I compared the three model requests whose inputs are the same in both runs: the ordinary turn, the requester's first request, and the target's first incident request. After masking per-run values (container hostname, lease workdir path, UUIDs, timestamps), the request bodies are byte-identical between base and fix, including the system prompt and tools. The raw size difference is 2 bytes in each case, all from the container hostname length.

CI note: the first checks-ui-e2e (1/2) attempt on 5f3bb45b (job 135492776612) failed before any test ran. Installing WebKit system packages timed out on the apt mirrors (WebKit system packages did not download from the fallback archive mirrors (exit 124)), and openclaw/ci-gate failed only because of that job. This was an infrastructure flake, not a failure inherited from main: recent main runs of the same workflow are green, and this PR touches only the embedded-runner file and its test. One rerun passed (job 135515231051), and ci-gate for that run now passes.

Commands

On the Studio, from a clone under ~/crabbox-src/sft checked out at each commit:

crabbox run --provider local-container --local-container-image node:24.22.1-trixie \
  --local-container-cpus 8 --local-container-memory 24g \
  --local-container-volume ~/crabbox-proof/sft:/proof --allow-env CLAWROUTER_API_KEY \
  --no-hydrate --timing-json --shell -- 'set -eu; git rev-parse HEAD; \
  corepack pnpm install --frozen-lockfile --store-dir .pnpm-store; \
  cp /proof/settled-finalization-timestamp.proof.live.test.ts src/agents/; \
  SFT_PROOF=1 SFT_PROOF_LABEL=<base|fix> SFT_PROOF_OUT=/proof/out OPENCLAW_LIVE_TEST=1 \
  node scripts/run-vitest.mjs run --config test/vitest/vitest.live.config.ts \
  src/agents/settled-finalization-timestamp.proof.live.test.ts'

Both runs exited 0 and both leases reported "leaseStopped":true. The proof harness is not committed. The API key was passed only through the environment.

🦞 Made with OpenClaw

@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Nov 19, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR uses a fixed timestamp for temporary finalization bookkeeping so context-engine messages without valid timestamps cannot prevent an answer.

Example: A context engine supplies a summary message without a timestamp, and a sessions_send target runs exec before returning NO_REPLY.

  • Before: Finalization throws RangeError before contacting the model, and the requester receives NO_REPLY_RECEIVED.
  • After: One tool-free model request produces the final answer without repeating exec.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-verified repair with relevant real Gateway evidence and two useful regression cases; broad browser validation remains unexecuted after dependency setup failed.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied pinned-head Gateway run exercises sessions_send, a real model, one exec and a timestamp-less assembled summary; isolated finalization returns an answer through one tool-free request without repeating the operation, with a failing pinned-base comparison.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A result-required agent request receives no answer when isolated finalization encounters a context-engine message without a valid timestamp.
Reason: The repair restores final-answer generation without adding configuration, changing the selected context or repeating completed tools.

Regression provenance

Regression provenance — verified: source commit 1714e2026713 by Eric Cai; canonical PR #186288 (blame-to-merge-commit).

Merge readiness

✅ Ready for maintainer review

This PR fixes a confirmed final-answer failure still present on main, with no actionable patch defects found; the CI gate remains blocked after WebKit dependency installation failed before browser tests ran.

Priority: P1
Reviewed head: 5f3bb45b60f5d6a03bc3c3438df270973aa41af0

Before merge

None.

Findings

None.

Agent review details

How this fits together

The embedded runner takes the settled context-engine message view, bounds it using the shared context selector, and passes the resulting messages to isolated final-answer generation.

flowchart LR
  A[Settled tool turn] --> B[Selected context messages]
  B --> C[Temporary selection entries]
  C --> D[Shared context selector]
  D --> E[Tool-free model request]
  E --> F[Final answer]
Loading

Technical review

Best possible solution:

Keep the fixed timestamp inside the existing temporary-entry adapter while preserving selected messages, context limits and transcript ownership.

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

The current-main conversion deterministically throws for undefined or NaN message timestamps, and the PR supplies matching base-versus-head Gateway output; this read-only review ran no target code.

Is this the best way to solve the issue?

This is the smallest complete repair: replace irrelevant temporary metadata at its consumer rather than modifying context-engine messages or model-visible timestamps.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Eric Cai: Raw commit 1714e20 adds src/agents/embedded-agent-runner/run/attempt-history-prepare.ts:30 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1714e2026713; files: src/agents/embedded-agent-runner/run/attempt-history-prepare.ts)

PR surface

Source +3, Tests +44. Total +47 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 1 +3
Tests 1 44 0 +44
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 48 1 +47

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported production trigger prevents result-required agent requests from receiving a final answer after a completed tool operation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 November 19, 2026, 5:31 AM ET / 10:31 UTC.

@jalehman
jalehman merged commit 9156690 into main Nov 21, 2026
188 of 191 checks passed
@jalehman
jalehman deleted the fix/settled-finalization-timestamp branch November 21, 2026 18:59
@jalehman

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
…1766)

(cherry picked from commit 9156690)

Release adaptation: Keep the stable full-prefix test. Exercise in-budget and omitted tool results using stable’s 16 MiB cap; stable no longer sizes this context from contextTokenBudget.

Companion audit: #204028, #203901, #202306 and #203536 are separate finalizer-budget, custody, project-transfer and context-window changes; not dependencies of the timestamp guard.

Co-authored-by: RomneyDa <[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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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