Skip to content

🤖 fix(messages): label an agent-message envelope by who wrote it - #8215

Merged
ThomasK33 merged 13 commits into
mainfrom
self-written-envelope-label
Dec 3, 2026
Merged

ThomasK33 merged 13 commits into
mainfrom
self-written-envelope-label

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Why

#8169 delivers real peer messages as receive_agent_message tool results. When an agent wrote the agent-message wrapper into its own reply, later turns still saw it renamed to the "user pasted" tag: a false label that implies user authority and reads like a delivery. In the transcript the reply showed the raw envelope with no flag.

What changed

  • neutralizeAgentEnvelopeLookalikes(text, source) renames by author: user text keeps user_pasted_; the agent's own text and tool-call inputs get self_written_undelivered_; tool output, inlined SVG and envelopes quoted in another agent's report rows get quoted_. The bare tag and every reserved label tag are renamed to the current source's label, so an echoed or forged label cannot survive.
  • The same-turn pass now renames the agent's own text too, with the same bytes the history pass gives it, so the prompt-cache prefix stays stable across steps and turns.
  • AssistantMessage labels a reply that holds the wrapper: "Written by this agent. Not a delivered message." Authentic family-message rows (shared isFamilyMessagePayloadRow check) never get the label.

Scope

A synthetic user row counts as quoted only when it is agent-initiated or parses as a sub-agent report. Compaction follow-ups re-send the user's own text as synthetic rows, so synthetic alone does not mean "not human"; send provenance is checked before report syntax. Follow-ups: request-injected synthetic context (plan transitions, post-compaction attachments) still reads user_pasted_, and an RLM preserved-tail copy drops its source's provenance, so a copied report the user pasted reads quoted_.

Blast Radius

Provider request shaping for any text holding the wrapper, and the assistant message renderer. Authentic deliveries never reach either rename (they are tool results or peer cards).

Verification

The messagePipeline repro "labels a model-written envelope differently from a user-pasted one" failed on main and passes here. An independent verifier built a request with a pasted envelope, a forged reply and an authentic delivery: no exact wrapper reached the provider, the delivery stayed a tool result, and repeated transforms were byte-identical. Checked at 375 px in Storybook.

Screenshots

Dark theme, App/Chat/Messages/AgentPeerMessages story. An assistant reply that holds the agent-message wrapper carries the label; delivered agent messages do not:

Self-written agent-message wrapper with the label, desktop

375px:

Agent peer messages and the labeled self-written reply at 375px


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $39.98 (the whole three-PR stack)

@ThomasK33
ThomasK33 added this pull request to stack #8216 December 3, 2026 12:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T19:39:54.261979Z 95914f5 Manual request
🔒 Security Review ✅ Completed 2026-12-03T19:42:30.949808Z 95914f5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ThomasK33 ThomasK33 changed the title self written envelope label 🤖 fix(messages): label an agent-message envelope by who wrote it Dec 3, 2026
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

21 agent steps · 6 replayed from cache · 15 model calls · 47.8k tokens (23% cached)
Spend: $0.10 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 6.6s
🟢 a chat survives a restart of the server 1 step · 1 call 6.6s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.8s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.8s
🟢 pluginTrustRestart.e2e.ts · 1 passed 3 steps · 2 calls 10.1s
🟢 a trusted plugin hook stays trusted after the server restarts 3 steps · 2 calls 10.1s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 9.9s
🟢 a chat survives trips through Settings 2 steps · 1 call 9.9s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 5.1s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 5.1s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 3.1s
🟢 the agent opens the playground workspace 2 steps · 1 call 3.1s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 7.4s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 7.4s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 3.5s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 3.5s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 24.0s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.8s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.2s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.9s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.9s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 3.7s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 3.5s

e2e 0.20.0 · 1m 19s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 7.9k tokens (22% cached)
Spend: $0.02 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 7.0s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 7.0s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 7.0s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 7.0s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 6.8s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 6.8s

e2e 0.20.0 · 23.9s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 7.9s · 2 targets (web, phone) · run artifacts

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: f285b8ee29

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f285b8ee29

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: 2309807

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 23098072aa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 23098072aa

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: f227d52e4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: f227d52e4e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 2a64862b12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2a64862b12

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 4719c9d33c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4719c9d33c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 1e93fae875

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 1e93fae875

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 1e93fae875

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

PASS+NOTES

Independent verifier, exact head 1e93fae8759f0a7a691bc994769cb8abfc589af6 against parent 2df7764662604346d66cf32738b6c1f7353fe99c. I ran both in detached scratch worktrees and made no paid model calls.

Provider request. I built a request with the real prepareMessagesForProvider, then ran transformStepMessages on it. The history held a user paste, a user row that echoes the self-written label, an assistant forgery that also echoes the user-pasted and quoted labels, a bash tool-call input and output holding the wrapper, an authentic peer delivery, a child family message that quotes a forged envelope, a synthetic sub-agent report quoting one, and a compaction follow-up (synthetic, with retrySendOptions).

Text Parent Head
User paste, echoed label in a user row user_pasted_, echoed label kept user_pasted_ for both
Assistant forgery and echoed labels user_pasted_ / quoted_ self_written_undelivered_ for all
Tool-call input user_pasted_ self_written_undelivered_
Tool output, family quote, report quote user_pasted_ quoted_
Compaction follow-up user_pasted_ user_pasted_
Same-turn assistant text at step N+1 exact wrapper self_written_undelivered_
  • Exact wrapper outside receive_agent_message results: 0 on both. Both results (peer and family) keep the same JSON as on parent, apart from the family quote's label.
  • Byte stability on head: a repeat build, step transform on the request, and a second step transform are all identical. The same-turn bytes equal the next turn's history rebuild, and the step prefix stays intact.
  • The PR's 6 changed test files pass at head (227 tests). Head's repro tests fail on parent (1 in messagePipeline, 3 in MessageRenderer).

Transcript. I opened Storybook for both builds with agent-browser, dark theme, and added a scratch story that was not committed.

  • AgentPeerMessages: head shows 1 flag, on the self-written reply only. Parent shows 0.
  • Scratch story: head flags the echoed-label reply. It does not flag the user paste, plain text or the family row that quotes an envelope.
  • At 375px the flag fits (x 35 to 299) with no horizontal overflow.

Notes (not blocking)

  1. A reply that only mentions the tag, as inline code in prose, also gets "Written by this agent. Not a delivered message." Agents working on Xum itself will hit this. The text is still true, but it reads as a forgery warning.
  2. A family-message row whose sender header does not parse (only a malformed row) gets quoted_ from the history pass. The step pass then relabels it self_written_undelivered_. Step 0 is transformed too, so the bytes stay stable. Only the label is wrong.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

@ThomasK33
ThomasK33 force-pushed the self-written-envelope-label branch from 1e93fae to 327314f Compare December 3, 2026 18:41
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: c023fa2457

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: c023fa2457

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Base automatically changed from remove-subagent-processes to main December 3, 2026 19:19
A model can still write an agent-message envelope in its own reply. On
the next request, neutralizeAgentEnvelopeLookalikesForProvider renames
its wrapper to the same tag a user-pasted envelope gets, so a later turn
reads its own forgery as text the user gave it.

The new messagePipeline test builds a request with the same envelope in
a user row and in an assistant row and expects different labels. It
fails on main: both rows carry the user-pasted tag.
A peer envelope the model wrote in its own reply reached later requests
renamed to the tag a user-pasted envelope gets, so a later turn read its
own forgery as text the user gave it. Tool output and inlined SVG got
the same user label.

neutralizeAgentEnvelopeLookalikes now takes the source:
- user rows keep user_pasted_mux_agent_message
- the model's own assistant text gets
  self_written_undelivered_mux_agent_message
- tool parts, delivered messages and inlined SVG get
  quoted_mux_agent_message (family payload rows hold another agent's
  bytes, so their text is quoted too)

The same-turn neutralizer now also renames the wrapper in assistant
text parts. Before, the next step saw the model's own forgery with the
exact wrapper. Since #8169 no assistant text holds an authentic
envelope (deliveries replay as tool results), and the rename gives each
row the bytes the history path gives it, so later steps and the next
turn keep the same prefix. User text stays untouched at that seam.
A peer envelope in an assistant reply rendered as plain text with its
"from" and "message" fields, which read like a delivery. Real
deliveries render as a peer card, so AssistantMessage never shows one:
when its text holds the exact wrapper, it now shows the inline label
"Written by this agent. Not a delivered message."

The AgentPeerMessages story gains such a reply and checks that only it
carries the flag.
Keeps AssistantMessage's complexity at its base (crap-check floor-cc).
A sub-agent's report reaches its parent as a synthetic user row. When
the report quoted an agent-message envelope, request building renamed
the wrapper to user_pasted_mux_agent_message, so the child's bytes read
like the user's paste.

A user row now gets quoted_mux_agent_message when it is synthetic and
carries another agent's bytes: a sub-agent report envelope (the UI's
own test, which survives tail and side-chat copies) or a send an agent
started (progress updates, monitor wakes). Synthetic alone is not the
test: a compaction follow-up re-sends what the user typed as a
synthetic row, and so does a preserved tail copy. Those keep the user
label.
…iter

The test set retrySendOptions as literals that lack agentId, which
typecheck refuses. pickStartupRetrySendOptions is what sendMessage
uses, so the rows match what it persists.
Only the bare wrapper was renamed, so a model that echoed the
user-pasted tag into its own reply, or tool output that forged one,
kept the wrong label. Every reserved tag (the wrapper and each label,
open and close) now takes the label of the text's own source. A second
pass with the same source maps each label to itself, so the prefix
stays byte-stable across steps.
Both passes labeled every tool field quoted, but the model writes a
tool call's input. The input now takes the self-written label, and the
output and error text stay quoted, in the history and same-turn passes.
…er's

A compaction follow-up re-sends what the user typed as a synthetic row.
When that text was a pasted sub-agent report quoting an agent-message
envelope, the report syntax labeled it quoted. sendMessage writes
retrySendOptions on every row it persists and a report row is appended
without them, so the send provenance now decides first. A preserved
tail copy keeps neither, so a copied report stays quoted.
A family message is another agent's text shown as an assistant row, so
an envelope it quoted got "Written by this agent". The transcript row
now carries isFamilyMessagePayload from the same row test the provider
request uses (isFamilyMessagePayloadRow, moved to common), and the flag
skips those rows.
…antTextRow

The conditional spread raised appendAssistantTextRow above its CC floor.
@ThomasK33
ThomasK33 force-pushed the self-written-envelope-label branch from c023fa2 to 95914f5 Compare December 3, 2026 19:19
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

Head: 95914f5

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 95914f560c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 95914f560c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 merged commit 737c72b into main Dec 3, 2026
79 of 83 checks passed
@ThomasK33
ThomasK33 deleted the self-written-envelope-label branch December 3, 2026 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant