Repository navigation
fix(agents): keep the system prompt stable when task suggestions are not granted - #197893
Conversation
…not granted suggest_task and dismiss_task are offered only when the turn's requesting client is an operator UI with the task-suggestions capability. Inter-session turns (sessions_send, subagent settle), cron and wakes in the same session have no such client, so the cached deferred-tool directory and the Session routing section changed between these turns and user turns. Each alternation re-wrote the whole conversation. Both tools are now run-granted, like skill_library: the cached directory omits them and the granting turn lists them in its own runtime context. Session routing no longer renders a suggest_task bullet; the tool description already carries that guidance. Who receives the tools does not change. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesKeep task-suggestion grants out of the cached system prompt and advertise them in the granting turn’s runtime context. Example: An operator UI conversation receives a sessions_send message from another session.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open. This maintainer-authored PR fixes a current prompt-cache defect using existing machinery; no actionable correctness or security findings were identified. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway client capabilities determine task-suggestion availability; agent prompt assembly separates stable discovery text from turn-specific grants before sending requests to the provider. flowchart TD
A[UI or inter-session input] --> B[Gateway capability selection]
B --> C[Agent tool catalog]
C --> D[Stable system prompt]
C --> E[Turn grant context]
D --> F[Provider request]
E --> F
Technical reviewBest possible solution: Use the existing run-granted metadata and turn-context owner while preserving task-suggestion access and tool-local guidance. Do we have a high-confidence way to reproduce the issue? Current-main source shows grant-dependent directory rows and routing guidance, and the PR supplies a matching Gateway A/B reproduction; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete repair for the demonstrated task-suggestion churn: it reuses grant handling, removes the varying embedded guidance, and preserves the tool description and generic renderer used by other callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 00b62dd84752. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource -1, Tests +21. Total +20 across 4 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
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 Reviewed November 12, 2026, 3:02 PM ET / 20:02 UTC. |
…not granted (openclaw#197893) Co-authored-by: obviyus <[email protected]>
…not granted (#197893) Co-authored-by: obviyus <[email protected]> (cherry picked from commit da21556) Co-authored-by: RomneyDa <[email protected]> Backport-adaptation: Test existing suggest_task/dismiss_task grants; beta.4 intentionally lacks the unrelated skill_library feature.
Problem
A Control UI (or TUI) session renders one system prompt for the user's own turns and a different one for turns that arrive from elsewhere:
sessions_sendfrom another session, subagent settle, cron, wakes. Every alternation re-writes the whole conversation at Anthropic cache-write price.On a production gateway the
[prompt-cache]detector repeatedly reportedsystemPromptSuffixchanges in the Tooling and Session routing sections ontrigger=user provenance=inter_session:*turns. A fix that merged earlier for completion wakes (run-grantedskill_library) covered part of the Tooling difference; it did not cover this one.Root cause
suggest_taskanddismiss_taskare offered only when the turn's requesting client is an operator UI withoperator.adminand thetask-suggestionscapability:src/gateway/server-methods/chat-send-request.ts(supportsTaskSuggestions) andsrc/gateway/agent-turn/agent-run-execution-phase.tssettaskSuggestionDeliveryMode: "gateway"from the client connection.src/agents/openclaw-tools.tsadds the two tools only in that mode.A turn without that client (inter-session, cron, wake) does not have the tools. The cached system prompt changed in two places:
suggest_task/dismiss_taskrows.src/agents/delegation-guidance.ts) lost itssuggest_taskbullet.Fix
Use the mechanism that already exists for run-granted tools:
runGrantedincore-tool-facts.ts, likeskill_library. The cached directory omits them, and the turn that holds the grant lists them in its own runtime context ("Deferred tools granted for this turn"). The flag also stops "unavailable core tool" allowlist warnings for them, which is correct because they are absent on some turns by design.suggest_taskbullet. The tool's own description already carries that guidance (records a card only; not for explicit requests to start a session).Which turns get the tools does not change. The Codex app-server thread prompt, which renders its own delegation section, is not changed.
Proof
Real route, before vs after. Isolated throwaway Gateway (scratch state, no channels), real Anthropic-compatible provider route,
cacheRetention: short. A logging proxy recorded the provider's owncache_read_input_tokens/cache_creation_input_tokensand the system-prompt digest. User turns were sent as an operator UI client (TUI identity:operator.admin+task-suggestions, throughchat.send), the same gate the Control UI passes. Target session: UI turn, UI turn, then another session'ssessions_sendinto it, then a UI turn.sessions_sendturnsessions_sendturn's prompt differed exactly by the twosuggest_task/dismiss_taskdirectory rows and the Session routing bullet (diffed from captured bodies), and re-wrote 20.3k tokens.sessions_sendturn does not.Separate from this change, the second request of a fresh session (UI turn 2 above) re-wrote ~19k in both arms. I reproduced it with plain UI turns and no inter-session input, and found no byte difference in system, tools, parameters or message prefix. It happens once per session, on this route only. I did not investigate it further here.
Focused tests:
tool-search-directory.test.ts: the cached directory is identical with or without each run-granted tool (skill_library,suggest_task,dismiss_task). The grant is listed separately.delegation-guidance.test.ts: Session routing renders the same with or without the task-suggestion grant.Not covered
Skills-only suffix changes in production also happen on ordinary user turns (8 of 15 with no provenance). They track environment changes (skill catalog edits and the remote-node availability line inside the Skills section), not the trigger. Separate follow-up.