Repository navigation
refactor(harness): share prompt preparation and context policies - #159779
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: blocked before merge. Reviewed September 27, 2026, 1:08 PM ET / 17:08 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch moves admitted-message preparation, hook restriction classification, cron context exclusion, and workspace-memory routing into shared harness helpers used by Codex and AgentsAPI, with accompanying tests and documentation. Merge readiness⛔ Blocked before merge - 2 items remain Keep this PR open. Current main and the latest release lack the shared preparation path, and the open stacked AgentsAPI PR depends on it. Source review found no discrete patch defect; focused validation and the repository-required test-cost measurements remain outstanding. Priority: P3 Review scores
Verification
How this fits togetherThe agent harness takes admitted user messages, plugin hook results, workspace configuration, and available tools to prepare prompt context. Codex and AgentsAPI adapters then pass that context to their respective agent runtimes. flowchart LR
A[Admitted user message] --> C[Shared harness preparation]
B[Plugin hooks and available tools] --> C
C --> D{Runtime context allowed?}
D --> E[Workspace memory routing]
E --> F[Backend prompt adapter]
F --> G[Native agent turn]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +13, Tests +94, Docs +18. Total +125 across 12 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one harness owner for admitted input and shared context policy while the adapters retain backend-specific workspace selection, native prompt delivery, and tool enforcement. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR is a refactor and reports no failing current-main behavior. Source comparison establishes the separate preparation paths it consolidates. Is this the best way to solve the issue? Yes: the existing harness is the narrow owner for shared prompt policy, while the adapters retain their distinct native behavior. Focused caller validation is still needed. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2948123d63d1. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
eea2ffc to
3a253f5
Compare
|
@clawsweeper re-review Please review the current head after the main-branch conflict resolution and formatting repair. The maintainer explicitly authorizes merging this refactor without a live test or attached live proof; do not treat live runtime evidence as a merge requirement. The existing string currentUserMessage and separate currentUserMessageId inputs remain supported. Existing instruction-builder callbacks that consume toolsAllow remain valid; hasToolRestrictions is an additional supplied field. Existing caller tests remain alongside the shared normalization and policy tests. The new context policy helpers are exposed only through the existing production-private harness entrypoint. Backend workspace selection, tool-name normalization, prompt wording, and failure behavior are preserved. The child prompt-hook implementation remains separate. Please identify any concrete remaining compatibility defect rather than requiring live proof for the additive shared contract. |
|
🦞👀 Re-review progress:
|
72e8fdf to
9b6c6e9
Compare
|
@clawsweeper re-review The previous exact-review workflow completed but did not update the durable PR verdict. The current head additionally fixes the CI no-shadow errors in the shared memory-routing test; the focused lint check passes. That latest repair changes only test parameter names and formatting, with no production changes. Please review the current head with the existing maintainer decision: merge this refactor without live tests or attached live proof. Existing string/currentUserMessageId inputs and toolsAllow callback consumers remain supported, and the backend-specific prompt behavior is preserved. CI is running on the repaired head. |
|
🦞👀 Re-review progress:
|
…nclaw#159779) * refactor(agents): share harness prompt input preparation * refactor(harness): share runtime context and memory routing policy * style(harness): format shared prompt preparation * test(harness): avoid shadowed memory routing fixtures --------- Co-authored-by: Sarah Fortune <[email protected]>
…ess runtimes (#169558) ## What Problem This Solves Fixes: context a plugin queues for a conversation's next turn (`api.session.workflow.enqueueNextTurnInjection`) is silently dropped when that turn runs on a harness runtime (Codex app-server, ACPX, Agents API, Copilot). OpenAI models use the Codex runtime by default, so most installs never receive these injections. ## User Impact Plugins that queue next-turn context now reach the agent on every runtime, not only the built-in one. Turns with nothing queued produce byte-identical prompts, so prompt caching is unchanged. ## Why This Change Was Made Only the built-in runner drained the durable injection queue and ran `agent_turn_prepare`. The harness prompt builder skipped both, and returned early when no prompt hooks were registered. One module now owns queue draining, the per-run retry cache, and `agent_turn_prepare`. The built-in runner and the harness prompt builder both use it, in the existing order: queued injections, `agent_turn_prepare`, heartbeat contribution, `before_prompt_build`. Harness runs release the retry cache when the run ends. History is still loaded only when a prompt hook needs it. ## Evidence - **Live, real OpenAI API, isolated Gateway, Codex runtime (default for `openai/gpt-6.1-sol`):** a plugin queued a correction after a turn, and the next turn was asked to quote any note it received. - Before (current `main`): the agent answered "No, my context for this turn does not include a note starting with 'Progress review (OpenClaw Labs)'." - After: the agent quoted the queued note verbatim. - **Regression test:** `src/agents/harness/prompt-compaction-hook-helpers.test.ts` "delivers queued injections". With a real enqueued injection and no prompt hooks registered, the prompt contains the text once, a same-run retry reuses it, and the queue is drained. It fails on `main` (`prompt.match(...)` is null) and passes with this change. - **Focused tests:** harness helper 12/12, embedded prompt helpers 6/6, host-hook contract injection cases 7/7. - Maintainer-intent check: #159779 and #159375 shaped this helper and the Agents API hooks. This change keeps their contract: no-hook and heartbeat-only attempts still do not read history, and the Agents API `config` move only places it in the shared host-side context (`buildAgentHookContext` does not forward `config` to plugins). - Not run locally: full lint (the plugin-SDK boundary declaration prep timed out on a loaded host). Left to hosted CI. **Merge danger:** two-way door; a revert restores the old behavior. Blast radius: harness runtimes now drain the injection queue, so plugins that already queue next-turn context (for example on Codex) will start seeing it delivered. Co-authored-by: Ayaan Zaidi <[email protected]>
…ess runtimes (openclaw#169558) ## What Problem This Solves Fixes: context a plugin queues for a conversation's next turn (`api.session.workflow.enqueueNextTurnInjection`) is silently dropped when that turn runs on a harness runtime (Codex app-server, ACPX, Agents API, Copilot). OpenAI models use the Codex runtime by default, so most installs never receive these injections. ## User Impact Plugins that queue next-turn context now reach the agent on every runtime, not only the built-in one. Turns with nothing queued produce byte-identical prompts, so prompt caching is unchanged. ## Why This Change Was Made Only the built-in runner drained the durable injection queue and ran `agent_turn_prepare`. The harness prompt builder skipped both, and returned early when no prompt hooks were registered. One module now owns queue draining, the per-run retry cache, and `agent_turn_prepare`. The built-in runner and the harness prompt builder both use it, in the existing order: queued injections, `agent_turn_prepare`, heartbeat contribution, `before_prompt_build`. Harness runs release the retry cache when the run ends. History is still loaded only when a prompt hook needs it. ## Evidence - **Live, real OpenAI API, isolated Gateway, Codex runtime (default for `openai/gpt-6.1-sol`):** a plugin queued a correction after a turn, and the next turn was asked to quote any note it received. - Before (current `main`): the agent answered "No, my context for this turn does not include a note starting with 'Progress review (OpenClaw Labs)'." - After: the agent quoted the queued note verbatim. - **Regression test:** `src/agents/harness/prompt-compaction-hook-helpers.test.ts` "delivers queued injections". With a real enqueued injection and no prompt hooks registered, the prompt contains the text once, a same-run retry reuses it, and the queue is drained. It fails on `main` (`prompt.match(...)` is null) and passes with this change. - **Focused tests:** harness helper 12/12, embedded prompt helpers 6/6, host-hook contract injection cases 7/7. - Maintainer-intent check: openclaw#159779 and openclaw#159375 shaped this helper and the Agents API hooks. This change keeps their contract: no-hook and heartbeat-only attempts still do not read history, and the Agents API `config` move only places it in the shared host-side context (`buildAgentHookContext` does not forward `config` to plugins). - Not run locally: full lint (the plugin-SDK boundary declaration prep timed out on a loaded host). Left to hosted CI. **Merge danger:** two-way door; a revert restores the old behavior. Blast radius: harness runtimes now drain the injection queue, so plugins that already queue next-turn context (for example on Codex) will start seeing it delivered. Co-authored-by: Ayaan Zaidi <[email protected]>
Why This Change Was Made
Codex and AgentsAPI need the same backend-neutral prompt preparation. Centralize the existing admitted-message normalization, hook tool-policy classification, lightweight-cron context exclusion, and workspace-memory routing decisions before adding the AgentsAPI prompt-hook caller.
What Problem This Solves
The shared prompt builder accepts an admitted message, extracts its text and identity, and tells its instruction builder whether the hook restricted tools. Both backends also use shared helpers for runtime-context inclusion and deciding whether admitted memory tools reach the selected prompt workspace.
The context helpers use the existing private harness SDK entrypoint. Backend workspace selection, tool-name normalization, prompt wording, failure handling, native restriction enforcement, and lifecycle ownership remain with their current owners. Copilot is unchanged. No new interface, class, configuration option, or public SDK contract.
User Impact
No intended behavior change. This is the first PR in the stack; #159375 adds the AgentsAPI implementation on top.
Evidence
git diff --checkpassed. GitHub confirms the refactor is based on main and the child remains based on this branch.git range-diffconfirms the child implementation patch is unchanged by the restack.eea2ffc416153cc6dcfd91350eafc2b7ded4a577completed with no P0-P2 findings. The earlier prompt-input refactor and feature implementation also received source review with no P0-P2 findings.