Repository navigation
Conversation
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. This PR should close because the cache-stability problem it targets is now covered by the merged maintainer implementation in #95624 on current main. The remaining timestamp idea is separable session-repair semantics, not a reason to keep this older conflicting cache branch open. Canonical path: Keep the merged #95624 implementation; if deterministic synthetic timestamps are still desired, review them as a narrow standalone session-repair PR. So I’m closing this here and keeping the remaining discussion on #95624. Review detailsBest possible solution: Keep the merged #95624 implementation; if deterministic synthetic timestamps are still desired, review them as a narrow standalone session-repair PR. Do we have a high-confidence way to reproduce the issue? Yes. The original bug was source-reproducible through exact older-first aggregate prompt projection; current main now has a replacement implementation and regression coverage proving stable historical projections. Is this the best way to solve the issue? No. This PR is no longer the best fix because #95624 landed a more complete maintainer-owned per-attempt projection design, while the timestamp change should be split if still wanted. Security review: Security review cleared: No concrete security or supply-chain concern is visible; the diff touches agent prompt/session logic and tests only. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against a1828110704f; fix evidence: commit 3053cbc8a5d7, main fix timestamp 2026-06-22T09:48:14+08:00. |
612b80a to
59456f4
Compare
59456f4 to
7c730ba
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
7c730ba to
2b80905
Compare
2b80905 to
b2278f6
Compare
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Date.now()timestamps on synthetic missing tool-result placeholders with deterministic numeric timestamps derived from the source assistant/tool-use message, with0as the fallback when no source timestamp exists.ToolResultMessage.timestamp: numbercontract for runtime and persisted synthetic repair messages.Linked context
Which issue does this close?
Closes #
Which issues, PRs, or discussions are related?
Related #15409
Related #58036
Was this requested by a maintainer or owner?
No maintainer request. This was prompted by live OpenClaw cache-trace investigation showing repeated prefix-cache invalidation during tool-heavy sessions.
Real behavior proof
Behavior or issue addressed:
timestamp: Date.now(), creating non-deterministic transcript bytes when placeholders were regenerated.b2278f63ee87805e60b188e8407a3bcb23c05017.Real environment tested:
Local OpenClaw gateway on NixOS, OpenClaw
2026.6.5, after rebuild/switch and gateway restart.Running process inspected from
/proc:Cache tracing source:
/home/ltrump/.openclaw/logs/cache-trace.jsonl.Controlled proof session:
agent:main:tui-fa8b100b-b024-40d1-a589-6fd489022a47.Main controlled proof run:
17d7842f-dbd7-4a20-86bc-24454f17485b.The local Nix-packaged gateway dist was inspected and matched the current PR head behavior before collecting traces.
Exact steps or command run after this patch:
Rebuilt/switched the local OpenClaw gateway and restarted it.
Verified the running process path with
psand/proc/<pid>/exe.Inspected the running dist chunks with
rg:Ran a controlled cache-trace workload in a fresh TUI session:
/home/ltrump/.openclaw/workspace/tmp/cache-proof-large.txt, about 4.74 MB;readtool calls on different offsets, eachlimit=2000;exectool calls.Parsed
/home/ltrump/.openclaw/logs/cache-trace.jsonlforstream:contexttransitions, aggregate tool-result size, common-prefix preservation, synthetic missing tool-result timestamps, and providercacheReadvalues.Evidence after fix:
Running dist verification showed live/estimate quantum opt-in and deterministic synthetic timestamps:
Which paths use the 20% aggregate quantum:
truncateOversizedToolResultsInMessages()usesaggregateReductionQuantumRatio: AGGREGATE_REDUCTION_QUANTUM_RATIObecause it is the live prompt-projection path. It does not rewrite the session file, and it is the path that directly affects provider prompt-cache prefix stability during tool loops.estimateToolResultReductionPotential()also uses the same ratio so pressure/possible-reduction estimates match the live projection behavior that will actually run.Which paths intentionally do not use the quantum:
truncateOversizedToolResultsInExistingSessionManager()/ session-manager recovery paths leaveaggregateReductionQuantumRatioundefined.truncateOversizedToolResultsInSession()persisted session-file recovery paths leaveaggregateReductionQuantumRatioundefined.buildAggregateToolResultReplacements()uses a 1-char quantum, i.e. exact shaving.Redacted runtime log excerpt from
cache-trace.jsonl, controlled aggregate trace from run17d7842f-dbd7-4a20-86bc-24454f17485b:With
toolResultMaxChars = 128000, the aggregate budget is approximately128000 * 4 = 512000chars. Atseq 17 -> seq 18, exact overflow would have been only a few thousand chars:Instead, aggregate tool-result text dropped to
414,634, implying a reduction of about103kchars:That matches the configured 20% live projection quantum:
This confirms the running gateway used chunked aggregate reduction rather than exact byte shaving for live prompt projection.
Prefix stability after the read-heavy phase:
These are the 6 small
execappends after the aggregate quantum reductions. They preserved the full previous prefix, which is the intended hysteresis behavior.Redacted runtime log excerpt, provider cache-read evidence from the same controlled session:
Redacted runtime log excerpt, deterministic synthetic timestamp trace over the current-head trace window:
Overall cache-trace summary for the current-head proof window:
Observed result after fix:
103k, matching a~512k * 20%quantum, instead of exact overflow shaving of only a few thousand chars.cacheRead=1,641,621andnote: stable cache inputs.What was not tested:
Proof limitations or environment constraints:
cacheReadfields.Before evidence:
Before the aggregate reduction change, sessions with total tool-result text near the aggregate cap showed repeated old tool-result rewrites as new tool results were appended.
Example observed pattern: old tool-result projections at stable message indices changed lengths between adjacent prompt assemblies, breaking the common prefix far before the newly appended messages.
Before the timestamp change,
makeMissingToolResult()emitted:Tests and validation
Which commands did you run?
Result:
Additional source/runtime checks:
What regression coverage was added or updated?
ToolResultMessage.timestamp: numbercontract.What failed before this fix, if known?
totalChars - aggregateBudgetCharsin all paths.Date.now(), making regenerated placeholders non-deterministic.If no test was added, why not?
Risk checklist
Did user-visible behavior change? (
Yes/No)No.
Did config, environment, or migration behavior change? (
Yes/No)No.
Did security, auth, secrets, network, or tool execution behavior change? (
Yes/No)No.
What is the highest-risk area?
How is that risk mitigated?
20%) and preserves the existing oldest-first truncation strategy.details.openclawSyntheticMissingToolResult, and message ordering/content fields are unchanged.timestamp, preserving the shared message contract.Current review state
What is the next action?
Maintainer review and CI on the force-pushed current head.
What is still waiting on author, maintainer, CI, or external proof?
b2278f63ee87805e60b188e8407a3bcb23c05017.20%is the right default live prompt-projection quantum ratio.Which bot or reviewer comments were addressed?
0instead ofDate.now().