Repository navigation
fix(subagents): mark background results as non-user messages (#875) - #935
Merged
Merged
Conversation
pi's `convertToLlm` replays every `custom` message to the model as a plain `user` turn with its content verbatim, and a background subagent's completion is delivered through `sendCustomMessage`. Compaction then summarizes from those converted messages under a prompt that asks what *the user* is trying to accomplish and which constraints *the user* mentioned, so the subagent's report is read as user intent and lands in the summary's Goal / Constraints sections. Prefix the notification with a fixed marker (`SUBAGENT_NOTIFICATION_PREFIX`) stating that it is a subagent report rather than a user message. Doing it in code instead of in the subagent's prompt keeps the marker from being dropped by the model. Foreground `Agent` and `get_subagent_result` results are unchanged: they are already `toolResult` messages and need no marker. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JUMhHkpdSYbRoYva7SXjDx
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
…) (agegr#935) pi's `convertToLlm` replays every `custom` message to the model as a plain `user` turn with its content verbatim, and a background subagent's completion is delivered through `sendCustomMessage`. Compaction then summarizes from those converted messages under a prompt that asks what *the user* is trying to accomplish and which constraints *the user* mentioned, so the subagent's report is read as user intent and lands in the summary's Goal / Constraints sections. Prefix the notification with a fixed marker (`SUBAGENT_NOTIFICATION_PREFIX`) stating that it is a subagent report rather than a user message. Doing it in code instead of in the subagent's prompt keeps the marker from being dropped by the model. Foreground `Agent` and `get_subagent_result` results are unchanged: they are already `toolResult` messages and need no marker. Claude-Session: https://claude.ai/code/session_01JUMhHkpdSYbRoYva7SXjDx Co-authored-by: Claude <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
…) (agegr#935) pi's `convertToLlm` replays every `custom` message to the model as a plain `user` turn with its content verbatim, and a background subagent's completion is delivered through `sendCustomMessage`. Compaction then summarizes from those converted messages under a prompt that asks what *the user* is trying to accomplish and which constraints *the user* mentioned, so the subagent's report is read as user intent and lands in the summary's Goal / Constraints sections. Prefix the notification with a fixed marker (`SUBAGENT_NOTIFICATION_PREFIX`) stating that it is a subagent report rather than a user message. Doing it in code instead of in the subagent's prompt keeps the marker from being dropped by the model. Foreground `Agent` and `get_subagent_result` results are unchanged: they are already `toolResult` messages and need no marker. Claude-Session: https://claude.ai/code/session_01JUMhHkpdSYbRoYva7SXjDx Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #875.
The problem is real
Traced through pi 0.87's shipped code to confirm the reported behavior:
custommessage —notifyParent()inlib/subagent-runtime.tscallssendCustomMessage({ customType: "pi-web:subagent-notification", ... }, { deliverAs: "followUp", triggerTurn: true }).custommessages to the model as plain user turns —convertToLlm()inharness/messages.jsmapscase "custom"to{ role: "user", content }with the content verbatim and no marker. The neighboringbranchSummary/compactionSummarybranches each prependBRANCH_SUMMARY_PREFIX/COMPACTION_SUMMARY_PREFIX— the pattern the issue points at.generateSummaryWithRequest(harness/compaction/compaction.js) callsconvertToLlm(currentMessages), under a prompt that asks## Goal [What is the user trying to accomplish?]and## Constraints & Preferences - [...mentioned by user].So the whole subagent report arrives unlabeled as user text and gets filed as user intent in the summary's Goal / Constraints sections.
The fix
subagentNotificationText()prefixes the report with a fixedSUBAGENT_NOTIFICATION_PREFIXstating that it is a subagent report, not a message from the user. Fixing it in code rather than through the subagent's prompt keeps the marker from being dropped by the model, as the issue suggests.Scope is limited to the background notification path. Foreground
Agentandget_subagent_resultresults keep the baresubagentFinalText()— they are alreadytoolResultmessages and are structurally distinct from user turns, so they need no marker. The existing foreground test asserts the unprefixed text and locks that in.lib/subagent-extension.ts— addSUBAGENT_NOTIFICATION_PREFIXandsubagentNotificationText()lib/subagent-runtime.ts—notifyParentdelivers the prefixed textAGENTS.mdNote on the UI
The prefix line renders inside the chat's custom-message card, which already has a
pi-web:subagent-notificationheader — so it is redundant for a human reader while being necessary for the model. I left it visible rather than stripping it inCustomMessageView, because hiding it would make the displayed text diverge from what is actually persisted and sent, which is misleading when debugging. Happy to change that if you would rather keep the card clean.Verification
node_modules/.bin/tsc --noEmit— cleannpm run lint— cleannpm test— 1247/1247 pass🤖 Generated with Claude Code
https://claude.ai/code/session_01JUMhHkpdSYbRoYva7SXjDx
Generated by Claude Code