Repository navigation
fix(plugins): supply the admitted request to before_prompt_build on embedded and CLI runs - #161773
xydigitLybnnnn wants to merge 17 commits into
Conversation
…uild The embedded runner and the CLI backend emitted only `prompt` and `messages` on the `before_prompt_build` event, so a plugin could not bind a turn to its original request. `active-memory` then fell back to the assembled prompt for intent detection and to the query text for its deterministic-recall reuse key, letting independent same-text submissions share one recall result. Both producers now read `currentUserMessage` and `currentUserMessageId` from the recorder-owned admitted request, matching the harness contract, and share one event builder with the harness path.
|
🦞👀 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. What this changesThe PR supplies recorder-owned request text and admission identity to embedded and CLI before_prompt_build hooks through a shared event builder. Example: A recorder-backed CLI turn admits "latest ask" with identity "cli-admitted-request".
Review scores
ProductKind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial Merge readiness⛔ Blocked before merge - 1 item remains This PR fills a verified gap on current main and has sufficient proof for its changed event behavior, but acceptance of the additive plugin contract remains an owner decision. Priority: P2 Decision needed
Before merge
FindingsNone. Agent review detailsHow this fits togetherPrompt preparation combines admitted input with conversation context, dispatches plugin hooks, and passes the resulting prompt toward model execution. flowchart TD
A[Admitted input] --> B[Transcript recorder]
B --> C[Embedded prompt preparation]
B --> D[CLI prompt preparation]
C --> E[Shared event builder]
D --> E
E --> F[Plugin prompt hooks]
F --> G[Model prompt]
Technical reviewBest possible solution: Accept the recorder-backed informational contract while preserving recorder-less omission and keeping broader origin and continuation guarantees separately scoped. Do we have a high-confidence way to reproduce the issue? Current-main embedded and CLI producers visibly omit the fields, and the contributor supplies an embedded before/after failure plus Gateway traces; no target code was executed during this read-only review. Is this the best way to solve the issue? Using the existing recorder and one shared event builder is a focused solution that preserves empty-input and legacy semantics, subject to acceptance of the producer contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8e4fe46d59c0. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +98, Tests +433, Docs +2. Total +533 across 13 files. Added test files: 3. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. 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 HistoryReview history (14 earlier review cycles; latest 8 shown)
Reviewed October 13, 2026, 8:50 PM ET / October 14, 2026, 00:50 UTC (Revision 15). |
…uild The embedded runner and the CLI backend emitted only `prompt` and `messages` on the `before_prompt_build` event, so a plugin could not bind a turn to its original request. `active-memory` then fell back to the assembled prompt for intent detection and to the query text for its deterministic-recall reuse key, letting independent same-text submissions share one recall result. Both producers now read `currentUserMessage` and `currentUserMessageId` from the recorder-owned admitted request, matching the harness contract, and share one event builder with the harness path. Runs without a recorder keep the legacy identity-free event, so only admitted requests gain the new fields.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Assert the CLI producer delivers the admitted request identity on before_prompt_build when a transcript recorder owns the turn, next to the existing recorder-less legacy assertion.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…rent input Boot the repo Gateway on the bundled Claude CLI backend with a fake CLI on PATH and assert a registered before_prompt_build plugin receives the admitted request text and identity on that process turn.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…ld proof Assert the fake CLI wrote its turn markers and its reply reached the channel, so the CLI backend case proves a real child process ran the turn rather than only echoing the shared hook event.
…-prompt-current-input Resolve prompt-compaction-hook-helpers.ts by keeping the shared buildPromptBuildHookEvent builder and upstream's agent_turn_prepare message resolution.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
A data point for the decision above, from a plugin consumer on the embedded runtime. On the published 2026.11.10 package the gap is unchanged, with the same shape reported on 2026.11.3 in #199547. With a plugin that records only field names in The consumer is a memory plugin that checks a write against the request admitted for the current turn. The hook docs say to use the explicit request for intent detection and not to parse envelope markers to recover request boundaries, so on embedded runs there is no supported way to do that today. Omitting the fields on recorder-less runs, as proposed here, works for this use: a missing field can be treated as unknown and the write skipped. |
Related: #160232
What Problem This Solves
Fixes: a plugin registered on
before_prompt_buildcannot tell which admitted request a turn belongs to when that turn runs on the embedded runner or the CLI backend. The event carried onlypromptandmessages, althoughcurrentUserMessageandcurrentUserMessageIdare part of the documented event contract and are already supplied by the Codex, Copilot, and ACPX harness runtimes.User Impact
Plugins that scope their work to the current request now receive the request text and its stable admission identity on the default runtimes, exactly as they already did on the harness runtimes. The bundled
active-memoryplugin is the concrete consumer: without the fields it fell back to the assembled prompt for intent detection and to the query text for its deterministic-recall reuse key, so two independent turns with identical text could share one recall result.Compatibility: the two fields are added only for turns whose admitted request is owned by a transcript recorder. A run with no recorder keeps the previous identity-free event, so a plugin that branches on field omission — including
active-memory's legacy path — sees no change for those runs. No config, schema, storage, migration, or default changes.Maintainer decision requested. This makes
currentUserMessage/currentUserMessageIdinformational on recorder-backed embedded and CLI turns, matching the contract the harness runtimes already implement. Requesting the plugin API owner's acceptance of that additive, omission-preserving event contract (the previous review'sDecision needed); nothing else is pending on the contributor side.Why This Change Was Made
currentUserMessage/currentUserMessageIdwere introduced for the harness prompt path in #149180. The embedded runner assembles its prompt through a different function and never passed them, and the CLI backend reuses that same helper, so both producers were affected. Both now read the fields from the recorder-owned admitted request — the representation Codex uses — and share one event builder with the harness path instead of copying the text/identity derivation.currentUserMessageIdis the recorder'sidempotencyKey: stable across retries and rebuilds of one admission and different between admissions. An admitted request without text (for example image-only input) is reported as an explicit empty string rather than falling back to the assembled prompt, which may contain reconstructed history.🤖 AI-assisted: This PR was developed with AI assistance.
Evidence
1. Real end-to-end turns on both changed runtimes
extensions/qa-lab/src/embedded-prompt-build-current-input.e2e.test.tsboots the repo Gateway from source, registers a probe plugin onbefore_prompt_build, sends a real qa-channel message, and asserts the event the plugin actually received — no injected assembly input:claude-clibackend with a fakeclaudeonPATHimplementing the stdio protocol), so a real CLI child process runs the turn.CLI process observation (redacted). The CLI case asserts that the child process actually ran the turn —
turn-started.jsonandturn-finished.jsonwritten by the fake CLI, and its reply delivered to the channel — as well as the hook event:{ "turnStarted": true, "turnFinished": true, "reply": "fake-claude reply <uuid>" }Raw hook event captured by the probe on the embedded harness (synthetic text, synthetic session, id truncated):
[ { "keys": ["currentUserMessage", "currentUserMessageId", "messages", "prompt"], "hasCurrentUserMessage": true, "currentUserMessage": "PROBE_TRACE_MARKER", "hasCurrentUserMessageId": true, "currentUserMessageId": "channel-user:v1:ec6ff72264a1a0e1…", "promptHead": "PROBE_TRACE_MARKER", "messageCount": 0, "trigger": "user", "inputProvenanceKind": null } ]Before this change the same producers emitted only
{ prompt, messages }— the shape reported in #160232.2. Before / after on the embedded prompt-assembly entry point
3. CLI backend producer — recorder-backed hook event at its preparation entry
src/agents/cli-runner/prepare.tsresolves the recorder message and passes it to both the ordinary and the authorized prompt-build dispatch.src/agents/cli-runner/prepare.test.tsprepares a realclaude-cliturn whose admitted request is owned by a transcript recorder and asserts the event the hook runner received:Observed dispatch (asserted in the test):
The recorder-less fixture already in that file keeps its previous assertion with no fields, which is the compatibility case above.
4. Harness runtimes unchanged by the shared-builder extraction
$ pnpm test src/agents/harness/prompt-compaction-hook-helpers.test.ts Test Files 1 passed (1) Tests 25 passed (25)5. Static gates
The extensions test typecheck is the lane that caught the earlier synchronous cleanup callback; it is green with the async callback.
Cost of the tests added
extensions/qa-lab/src/embedded-prompt-build-current-input.e2e.test.ts: 298.0 s of test time (1922 s wall including the E2E runtime preparation build) for two Gateway boots on the QA-lab product-proof tier; one file, 300 s per-test timeout, no sleeps.src/agents/cli-runner/prepare.test.ts: +1 case, 1.5 s.What was not tested
active-memoryrecall behaviour itself was not re-measured end to end; only the event contract it consumes is covered.pnpm check:changeddid not complete on this host: it aborted withFATAL ERROR: Ineffective mark-compacts near heap limit - JavaScript heap out of memory, and a retry with--max-old-space-size=12288produced no output after ~25 minutes. The gates in section 5 cover the same changed-scope lanes for these files.