Repository navigation
fix(webhooks): keep the restored-context frame to the intake - #37786
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the scrub runs at the one place the frame is created, follows the existing background-context pattern, and is easy to revert. Notes
[DESIGN-REVIEWED] 6fdba83 Description read[DESCRIPTION-READ] b8af15305fc0b7fad06312e28662365097457cc313d898c21a08fdf830ae9b92 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix scrubs both untrusted inputs before the frame is built, which is where the problem starts. It follows the existing Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: Make sure a resumed webhook session's restored-context frame can only come from the intake, not from the posted message or the saved summary. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 6fdba83 Description read[DESCRIPTION-READ] b0698aa9c5c0cbb76dae3c77567a585d735101e72dc0e62f21a579a468b944b9 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own. The PR scrubs the restored-context frame from both the webhook payload and the saved summary before the intake writes the genuine frame. It does this on every webhook turn, using the shared span-local marker matcher (NFKC fold, zero-width removal). I verified the call site, the stale-banner interaction, the length limits downstream, the facade export list and the new test, which would fail without the change. The remaining issues are false positives on benign text (documented), an out-of-scope look-alike edge case, and a missing call-site test. None blocks. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
The review verified head 6fdba83. The scrub runs where the frame is built, inside the existing try, and off the event loop through asyncio.to_thread. The intake's own stale-context banner matches neither pattern, and both regexes stayed linear on 200 KB pathological inputs. The new test fails on 6 of 6 mutants (each pattern, each scrub call, the early return). The overlapping open PRs #37824 and #36027 touch different hunks.
Done well: the banner is matched by shape on the NFKC-folded view. So two patterns close fullwidth, zero-width, Cyrillic and quoted forgeries, and a === b and the rest of each line stay byte-exact.
Optional:
- Both rules also rewrite benign payload text on every turn, including turns with no saved context. For example,
Title\n=====becomesTitle\n[marker-removed], andrestored_contextkeys and conflict markers change too. Narrowing the line rule would lose the look-alike coverage, so the trade is fair. The Backwards compatibility section should still say that benign text changes. src/kiro_crew/docs/inbound-webhooks.md:477says the whole line is replaced. Only the leading punctuation and=run are replaced.- If
hooks.py:1216-1217goes back to main'sif saved_context:guard, none of the 163 webhook tests fails. One_run_hook_agenttest with an empty saved context and a forged banner would pin this.
The restored-context frame scrub added in #37786 rewrote ordinary webhook text: any line opening with `==` (pytest summary banners, setext headings, merge-conflict markers, `==> step` logs) lost its leading run, and the phrase rule spanned sentence punctuation, so `Service restored. Context:` lost two words. - The phrase gap no longer crosses sentence punctuation or a line break. - A `==`-opening line still loses its leading run unless it is a known-plain shape: after NFKC with invisible characters dropped it is ASCII and is a `==>` log arrow, or carries no words outside the pytest run-banner words (which covers word-free underlines and conflict markers). The check stays fail closed: it never guesses whether a line's words resemble the frame. - docs/inbound-webhooks.md describes the new rule. Every forged-frame case in the existing test is still refused.
The restored-context frame scrub added in #37786 rewrote ordinary webhook text: any line opening with `==` (pytest summary banners, setext headings, merge-conflict markers, `==> step` logs) lost its leading run, and the phrase rule spanned sentence punctuation, so `Service restored. Context:` lost two words. - The phrase gap no longer crosses sentence punctuation or a line break. - A `==`-opening line still loses its leading run unless it is a known-plain shape: after NFKC with invisible characters dropped it is ASCII and is a `==>` log arrow, or carries no words outside the pytest run-banner words (which covers word-free underlines and conflict markers). The check stays fail closed: it never guesses whether a line's words resemble the frame. - docs/inbound-webhooks.md describes the new rule. Every forged-frame case in the existing test is still refused.
The restored-context frame scrub added in #37786 rewrote ordinary webhook text: any line opening with `==` (pytest summary banners, setext headings, merge-conflict markers, `==> step` logs) lost its leading run, and the phrase rule spanned sentence punctuation, so `Service restored. Context:` lost two words. - The phrase gap no longer crosses sentence punctuation or a line break. - A `==`-opening line still loses its leading run unless it is a known-plain shape: after NFKC with invisible characters dropped it is ASCII and is a `==>` log arrow, or carries no words outside the pytest run-banner words (which covers word-free underlines and conflict markers). The check stays fail closed: it never guesses whether a line's words resemble the frame. - docs/inbound-webhooks.md describes the new rule. Every forged-frame case in the existing test is still refused.
…7921) * fix(webhooks): keep ordinary == lines and prose in webhook bodies The restored-context frame scrub added in #37786 rewrote ordinary webhook text: any line opening with `==` (pytest summary banners, setext headings, merge-conflict markers, `==> step` logs) lost its leading run, and the phrase rule spanned sentence punctuation, so `Service restored. Context:` lost two words. - The phrase gap no longer crosses sentence punctuation or a line break. - A `==`-opening line still loses its leading run unless it is a known-plain shape: after NFKC with invisible characters dropped it is ASCII and is a `==>` log arrow, or carries no words outside the pytest run-banner words (which covers word-free underlines and conflict markers). The check stays fail closed: it never guesses whether a line's words resemble the frame. - docs/inbound-webhooks.md describes the new rule. Every forged-frame case in the existing test is still refused. * fix(webhooks): cut a frame banner split over lines again A bare == line next to another plain banner loses its opening whatever the words between them, so ===/End Restord Contxt/=== is scrubbed as on main, blank lines or not. A frame word anywhere in the body (letters only, stand-in digits or symbols read as letters, look-alike scripts) turns every plain == shape off and widens the phrase match. One heading underline, one conflict marker, ==> arrows, pytest banners and prose without frame words still pass. Adds 'ran' to the pytest banner words and one test per plain-shape guard. --------- Co-authored-by: Joe Guo <zejiangg@amazon.com>
Problem / Motivation
Goal: Only the webhook intake can write the restored-context frame a resumed webhook session reads.
When a webhook call resumes a saved workflow, the intake wraps the hook's saved summary in a
=== Restored Context (from prior session) ===...=== End Restored Context ===frame and puts the posted message after it. Neither input was cleaned of that frame first, so either one could carry its own copy.Why it matters
A copy of the frame in the posted message or the saved summary reads to the model like the genuine frame the intake wrote.
Not a goal
_STRUCTURAL_MARKER_RES): the genuine frame rides the user turn, which that scrub covers, so it would remove the real frame too.What changed (motivation → approach → change)
The frame was written around text that was never scrubbed of it. The fix follows the background-context frame's pattern: scrub the content before the frame is minted.
context_assembly/markers.py: newneutralize_restored_context_frame. It replaces the phraserestored context(any non-word run between the words) and any line that opens with an==run. Matching a banner line by its shape, not its words, covers look-alike letters and other wording.===inside a line, such asa === b, is kept.hooks_webhook_intake._with_restored_context: scrubs the posted message and the saved summary, then mints the frame. It is now called on every webhook turn, so a forged frame in a message with no saved summary is scrubbed too.docs/inbound-webhooks.md: says what is replaced.Other untrusted text that reaches the same assembler (memory, history, channel text) is not changed: it sits in the session-context block ahead of the request, where the frame has no meaning, and webhook sessions start fresh with no replay.
Backwards compatibility
Compatible: the frame and guidance text are unchanged; only copies of the frame inside the payload or summary are rewritten.
Removes nothing: no field, route or capability changes; payload text matching the frame is rewritten to
[marker-removed].Tests
test/test_webhooks_store.py::TestFreshness::test_restored_context_frame_cannot_be_forged_by_payload_or_summary: forged open/close frames (case, zero-width, fullwidth, look-alike letter, quoted line) in both inputs leave only the genuine two frame lines;a === bsurvives.Proof: PROVEN test/test_webhooks_store.py::TestFreshness::test_restored_context_frame_cannot_be_forged_by_payload_or_summary (head 6fdba83)
Manual verification
N/A — unit coverage sufficient: the change is a pure string transform at one call site.
Related Issues
Closes #37784
Sibling sweep
Swept: git grep -n "Restored Context" -- src/
Sibling: src/kiro_crew/session_summary.py:47 -- not affected -- reads the genuine frame prefix, which is unchanged
Sibling: src/kiro_crew/dashboard/chat_turn/turn_context.py -- not affected -- background-context frame already scrubbed the same way
Pattern harvest
Rule candidate: review-prompt
Pattern: a frame minted around untrusted text with no content-time scrub of that frame
Checklist