Repository navigation
fix(dashboard): refuse malformed /context keys and scope the dedup to the live session (replaces #11666) - #18759
iamwhatever wants to merge 1 commit into
Conversation
… live session
`POST /api/chat/slots/{slot}/context` treats `contextKey` as a dedup identity, but
the boundary rewrote it before comparing (clipped an overlong key, stripped control
chars/whitespace) and matched expired or cross-session entries — so a repost was
answered 200 and silently dropped nothing into the queue.
- `_validate_context_key` refuses a non-string, a control char (before strip),
leading/trailing whitespace, and an over-cap key with 400s, mirroring `_validate_source`.
- The /context dedup now suppresses only an unexpired, same-content entry owned by the
current session (positive `ctxSession` stamp), and audits the suppressed return.
- `drain_pending_context` (now in `chat_turn/turn_context.py`) drops a keyed entry whose
`ctxSession` names a session this slot has since left.
- `context_key`/`ctxSession` are live-queue only and do not survive a reload.
Fixes #18757
Replaces #11666
Co-authored-by: Robert Noack <69695077+rnoack1@users.noreply.github.com>
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — 🔴 BLOCKPremise-level review of First-Principles-Verdict: BLOCK The described "fix" targets a Not justified as shipped
What this change shipsInventory (5 items) — 1 justifiedIntent: stop
Blockers
[FIRST-PRINCIPLES-REVIEWED] 71c89da Description read[DESCRIPTION-READ] e0c45d5246ea1657fb2edf0c8f552e6c573b9b2ccecd049ba88a50c3c6418f0f That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS There is no Watch
[DESIGN-REVIEWED] 71c89da Description read[DESCRIPTION-READ] 1d1bb1e8aa833a6757f8eee669b731cd17a6b92ef2172c8508ae6fc33bbb1c17 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 |
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: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsFINDING — src/kiro_crew/dashboard/chat_handlers.py:10490 — a repost with a matching key is answered 200 but appends nothing, and it does not refresh the existing entry's [OPUS-REVIEWED] 71c89da Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
|
Closing this without merging. On re-check against current The code port itself was clean (the drain hunk re-homed to Original work: #11666 by @rnoack1 — left open for a maintainer to decide whether the |
Problem
POST /api/chat/slots/{slot}/contextaccepts an optionalcontextKey, which thelive-queue reload-dedup compares to decide whether an arriving post repeats one
already queued. That makes the key an identity, and the boundary silently rewrote
it before the comparison, or matched the wrong entry:
sharing a 64-char prefix collapsed onto one;
the strip, so
"\nv7"matched the earlier"v7";delivered) or one posted under a different session (before a cron/rebind).
In each case the second post matched the first, was answered 200, and appended
nothing — content acknowledged and silently dropped, with no surface reporting it.
A false
200is worse than a400: the caller has no reason to retry.What changed
chat_handlers.py— new_validate_context_keyrefuses a non-string, a rawcontrol char (checked before the strip), leading/trailing whitespace, and an
over-cap key, with
invalid_context_key/context_key_too_longcodes, mirroring_validate_source. The /context dedup now suppresses only an unexpired,same-content entry owned by the current session (positive
ctxSessionstamp), and the suppressed return is SEL-audited like every other 200.
context_key/ctxSessionare threaded through_build_pending_context_entry/_enqueue_pending_context, live-queue only (neither survives a reload).chat_turn/turn_context.py—drain_pending_contextdrops a keyed entry whosectxSessionnames a session this slot has since left (re-ported here: the functionmoved out of
chat_runner.pyon main).Tests
test/test_ctx_boundary_key_and_label.py(new, 11 cases): refusals keep the keyverbatim, the ownership/content/expiry rules for a genuine repeat, and the drain's
refusal to deliver a keyed entry into a session it was not posted under.
Replaces #11666 by @rnoack1, re-ported onto main after
drain_pending_contextmovedto
chat_turn/turn_context.py. Original authorship preserved (commit author + aCo-authored-bytrailer).Fixes #18757