fix: stabilize isolated cron prompt cache affinity#87309
Conversation
|
Codex review: needs maintainer review before merge. Reviewed May 27, 2026, 7:30 PM ET / 23:30 UTC. Summary PR surface: Source +101, Tests +328. Total +429 across 23 files. Reproducibility: yes. for the source-level payload identity: current main derives OpenAI prompt-cache affinity from rotating run session ids, and isolated cron intentionally creates fresh run sessions. Live OpenAI cache-hit telemetry was not reproduced in this review. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land after maintainers confirm the new Do we have a high-confidence way to reproduce the issue? Yes for the source-level payload identity: current main derives OpenAI prompt-cache affinity from rotating run session ids, and isolated cron intentionally creates fresh run sessions. Live OpenAI cache-hit telemetry was not reproduced in this review. Is this the best way to solve the issue? Mostly yes: a stable hashed cron key preserves transcript isolation while fixing transport affinity. The remaining solution-fit question is whether exposing AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against 92043f754796. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +101, Tests +328. Total +429 across 23 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
ClawSweeper PR egg ✨ Hatched: 🥚 common Brave Test Hopper Hatch commandComment Hatchability rules:
Rarity: 🥚 common. What is this egg doing here?
|
108b9e2 to
cba0e70
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
cba0e70 to
34c55eb
Compare
34c55eb to
9077c83
Compare
9077c83 to
6a1acda
Compare
ac11225 to
5ca161d
Compare
|
Verification for rewritten branch 5ca161d: Behavior addressed: isolated cron runs now use a stable prompt cache affinity key that is separate from the per-run session id and is forwarded through embedded runner, provider, proxy, custom stream, and observability paths. Real environment tested: local macOS checkout plus GitHub Actions PR CI. Exact steps or command run after this patch:
Evidence after fix: local focused Vitest passed 3 shards / 246 tests, local test typecheck passed, autoreview reported no accepted/actionable findings, and GitHub CI run 26544652281 passed required checks including checks-node-core-runtime-cron-isolated-agent and checks-node-agentic-agents. Observed result after fix: promptCacheKey is stable for isolated cron, valid for OpenAI prompt_cache_key, clamped before OpenAI-compatible payloads, suppressed when cache retention is disabled, and preserved across provider/proxy/custom stream paths. What was not tested: no live provider API call; this was verified through unit coverage and PR CI. |
Fixes #62809
Summary
AI assistance disclosure
AI assistance was used. I reviewed and understand the affected cron executor, embedded runner, stream-resolution, and OpenAI transport paths.
Real behavior proof
Behavior addressed: recurring isolated cron runs now keep stable OpenAI prompt-cache affinity while preserving fresh run sessions.
Real environment tested: local source checkout, actual OpenAI transport parameter builders, no live credentials.
Exact steps or command run after this patch:
with a small script invoking
buildOpenAIResponsesParamsandbuildOpenAICompletionsParamsusing a sanitized cron-stylepromptCacheKeyplus a distinct runsessionId.Evidence after fix:
Observed result after fix: OpenAI Responses and opted-in OpenAI-compatible Completions payloads use the stable cron prompt-cache key, while
cacheRetention: "none"omitsprompt_cache_keyand the run session identity remains separate.What was not tested: live OpenAI cache-hit telemetry was not exercised because it would require real provider credentials and billing-side cache observations. Testbox
pnpm check:changedwas also blocked because the local Crabbox wrapper could not find a usablecrabboxbinary.Root Cause
Isolated cron deliberately rotates the transcript/session identity for each run so recurring jobs do not accumulate an ever-growing transcript. The OpenAI payload builders used
sessionIdas theprompt_cache_keyfallback, so the same recurring isolated cron job also rotated its prompt-cache affinity across runs.Dependency contract
OpenAI's SDK exposes
prompt_cache_keyon Responses and Chat Completions request params as the cache-affinity field for similar requests. The local@earendil-works/[email protected]stream options exposesessionIdandcacheRetention, but no first-classpromptCacheKey; its OpenAI providers usesessionIdforprompt_cache_keywhen prompt caching is enabled. OpenClaw therefore needs a separate internal option so cache affinity can be stable without changing session semantics.Regression Test Plan
Focused tests cover:
runEmbeddedPiAgentforwards the key into the embedded attemptpromptCacheKeyoversessionId, and omit it when caching is disabledSecurity Impact
No credentials, lockfiles, config files, or secret-handling paths changed. The upstream cache key is derived from stable cron/provider/model identity but sent as a truncated SHA-256 digest, so raw cron names, local session labels, and per-run session ids are not exposed in
prompt_cache_key.Human Verification
I reviewed the affected runtime path from cron execution through embedded runner stream resolution and the OpenAI transport builders, then rechecked the diff against issue #62809 after focused validation.
CODEOWNERS / owner review
.github/CODEOWNERSonly namessrc/cron/stagger.tsandsrc/cron/service/jobs.tsunder cron. Neither file is touched, so no direct CODEOWNERS owner gate was found for this diff.Changelog
No
CHANGELOG.mdedit. This is a normal contributor bugfix PR.Review conversations
codex review --base origin/mainreported no actionable correctness issues after the final patch.Risks
Live OpenAI cache-hit telemetry was not tested. The local proof validates the outgoing request payload contract, not OpenAI's server-side cache accounting.
Behavior tradeoffs
The patch keeps transcript/session isolation and transport session identity separate from prompt-cache affinity. That means recurring isolated cron jobs can share cache buckets across runs without sharing a transcript.
Scope boundaries
This targets OpenClaw-managed embedded isolated cron OpenAI transport paths. It does not change session-bound cron jobs, CLI cron execution, prompt-prefix construction, source-dependent tool ordering, or arbitrary custom stream implementations that do not use OpenClaw's managed OpenAI transports.
Validation
Blocked broad validation: