Skip to content

fix(chat): parse same-line option markers and refuse a nested one - #30465

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:feat/option-marker-grammar-fixes
Nov 17, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:feat/option-marker-grammar-fixes

Conversation

@rnoack1

@rnoack1 rnoack1 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the web [OPTIONS:] marker parse the shapes models really write, without ever deleting prose the user should see.

The web marker grammar in website/src/app-sdk/protocol/optionMarker.ts loses pills or hides text in a few shapes:

  • Body [OPTIONS: A] [OPTIONS: B]: only the last marker matched, so the first leaked as raw text.
  • [OPTIONS: dropped [OPTIONS: A | B]: the inner marker parsed although the outer one never closed.
  • [OPTIONS: A] [OPTIONS:]: an earlier marker's options vouched for a last one that renders none, so the row was emptied and showed neither prose nor pills.

Why it matters

The marker is model output, so every shape here is reachable without anyone trying. A lost pill costs the user a typed reply. Hidden prose is worse: the user never learns it was there.

Not a goal

What changed (motivation → approach → change)

Approach. The marker pattern on main is unchanged and still finds each line's final marker. A small line scan decides the rest of that line: the earlier markers on it, and whether the final one sits inside an unclosed head. No regex is added or widened. Every refused shape stays visible as written.

Change, 6 files, +375/-21, all in website/src:

  • Two markers on one line. markersBefore walks the line once with a stack of brackets typed by the existing PAIR_OPENERS / PAIR_CLOSERS tables. It finds a head by exact, case-folded comparison against a small head table, one plain string per head. When a head closes and blanks then another head follow, that span is a sibling. Each sibling must match the same pattern and bracket-balance check as the final marker, and the siblings must run unbroken up to it. Then all of them strip and the last one supplies the options.
  • One line, one verdict. If the final marker on a line is refused, no marker on that line parses.
  • Nested heads. A marker inside a head that never closed is refused. A citation like [1] inside an open head does not close it.
  • A comma after a closed head. In Use [OPTIONS: A | B], then pick [OPTIONS: Yes | No], ], continues the label list only when the next bracket on that line is a closer, so the final marker keeps its pills.
  • A head cap. A message with more than 256 marker heads parses no marker, which bounds the work per message.
  • A row is never emptied by a marker that renders nothing. stripMarkersForDisplay keeps the raw text when the last marker offers no pill. parseOptions and searchableText both call it, and search strips markers before widgets, as the transcript does.
  • optionsOf is the one label split, shared by parseOptions and the display rule.

Backwards compatibility

No public signature changed. optionsOf and stripMarkersForDisplay are new exports. Every shape that parsed before still parses, except a marker nested in an unclosed head, a line whose final marker does not balance, and any marker in a message with more than 256 marker heads. All three now render as written text.

Tests

  • optionMarkerSameLine.test.ts: same-line pairs, a chain that does not reach the line end, and a row whose last marker offers nothing, on screen and in search.
  • optionMarkerNestingDepth.test.ts: a nested marker is refused; the comma rule keeps the line-final marker, with three controls.
  • optionsMarkerTerminator.test.ts: a same-line chain whose sibling does not balance offers nothing and deletes no prose, a broken chain does not poison another line, a 256-marker line decided in one walk, and the head cap. The stray-opener cases under what the check gives up stay as controls.
  • Negative control: 8 of these tests fail against main's grammar. Removing each scanner rule on its own (siblings, the nesting check, the comma rule) fails the tests for that rule.
  • The 8 marker test files pass: 274 tests. tsc, eslint and npm run i18n:check are clean, with [added-lines] and [vs-base] at 0.

Manual verification

None beyond the tests: the change is parser-only and renders through the existing pills.

Screenshots / video

No UI change: the pills and the text rendering are unchanged. Only which marker text counts as a marker changed.

Related Issues

Split out of #6823 to bring it under the size cap. #6823 keeps the close chip and rebases onto this once it merges.

Sibling sweep

Swept: git grep -nE "stripOptionMarkers|findOptionMarkers|findLastOptionMarker|parseOptions(" -- website/src
Sibling: website/src/utils/searchableText.ts -- changed here
Sibling: website/src/app-sdk/protocol/options.ts -- changed here
Sibling: website/src/pages/chat/TurnBlock.tsx -- not affected -- it calls the shared helpers, which carry the fix

Pattern harvest

Not generalizable: the fix is specific to this one marker grammar, which already keeps its pattern private behind one acceptance function.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Nov 5, 2026
@rnoack1
rnoack1 marked this pull request as ready for review November 5, 2026 14:52
@rnoack1
rnoack1 requested review from a team and KiroCrewCaptain as code owners November 5, 2026 14:52
@rnoack1
rnoack1 requested a review from bolichen97 November 5, 2026 14:52
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 463d890caf28db4f8fda9645e25e75de511306ca via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change is parser-only, every shape it now refuses shows as written text, and a revert walks it back cleanly.

Notes

  • The web grammar now accepts same-line pairs and refuses nested heads, but the Python grammar used by the other channels does not change here (the PR lists it as not a goal). The same model output will parse differently in the web dashboard and in Slack or Discord until the Python grammar is updated to match. Open a follow-up issue to track that.
  • HEAD_CAP refuses every marker in a message once it carries more than 256 heads, so one long message loses all its pills. That is reversible, but it is a cliff rather than a gradual limit. A short note in the spec saying the cap is a cost bound, not a grammar rule, would stop a later reader treating it as accidental.

[DESIGN-REVIEWED] 463d890

Description read

[DESCRIPTION-READ] c65a541578f81c623e0de24d525373a3fd6b5f124519e2fc406310e8d3e93890

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of 463d890caf28db4f8fda9645e25e75de511306ca via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. This is a parser-only change: no control, string or component is added or changed. The existing pills and text rendering simply apply to more of the marker shapes models write.

[UX-REVIEWED] 463d890

Description read

[DESCRIPTION-READ] e583f396104fa3b11a1197f2a73349eddff5eee8e0e9943c82f3abcaea36a957

That sha256 names everything this verdict read: the PR description, plus the 3 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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 463d890caf28db4f8fda9645e25e75de511306ca via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Each reported shape has a reproduction test, and the fix is in the grammar itself rather than at the call sites. Three subtractions are left as notes.

Notes

  • Item 5 — duplicate of HEAD_RE (optionMarker.ts:279): const markerHeads = ['[options:', '[option:'] plus the hand-folded headAt spells /\[OPTIONS?:/i a second time in the same file. Subtraction: delete markerHeads/headAt and test the head with a sticky clone of HEAD_RE at i.
  • Item 4 — inherited: "bounds the work per message" cites no measured cost, and the line walk already runs once per line. Subtraction: delete HEAD_CAP and its spy test, or keep it only with a measured shape that needs it.
  • Item 6 — oversized: the describe('two markers on ONE line') block in optionsMarkerTerminator.test.ts copies three of the cases in optionMarkerSameLine.test.ts. Subtraction: delete the copy.

What this change ships

Inventory (6 items) — 3 justified

Intent: make the chat's option pills appear for every marker shape that models actually write, without hiding prose. This is a FIX.

  1. Two markers on one line both get stripped, and the last one supplies the pills — justified
  2. A marker nested inside an unclosed head now stays visible as text — justified
  3. A row whose last marker offers no pills keeps its raw text, both on screen and in search — justified
  4. A message with more than 256 marker heads shows no pills at all — oversized; no measured cost
  5. A head-matching table separate from HEAD_RE — duplicate of optionMarker.ts:279 HEAD_RE
  6. Duplicate same-line test block — oversized

[FIRST-PRINCIPLES-REVIEWED] 463d890

Description read

[DESCRIPTION-READ] 77b1266c2c65622631781ea977e165bfa31335ee07f8b37546d8c08bb1c64900

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 463d890caf28db4f8fda9645e25e75de511306ca via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 463d890

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 463d890caf28db4f8fda9645e25e75de511306ca via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 463d890

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. The two bugs are real: a second same-line marker leaked as raw text, and a span nested in an unclosed head parsed as its own marker. The tests describe them well.

One blocking point, under our rule of no new or wider regex in product code for parsing text or detecting markers. app-sdk/protocol/optionMarker.ts grows the marker grammar as regex:

  • OPTION_MARKER_RE is rebuilt with new RegExp from new pieces: SIBLING_CHAIN lookahead, LABEL_PAIRS, TAIL_LINE_WRAPPED;
  • new CONTINUES_AT (sticky), HEAD_RE built from MARKER_HEADS, OPENER_RE;
  • the escape helper ch.replace(/[.*+?^${}()|[\]\\]/g, …);
  • an inline /[\n\r\u2028\u2029]/.test(...) in acceptMarkers.

Please solve the same-line and nesting cases with a small scanner instead of a wider pattern. acceptMarkers and unclosedMarkerFlags already walk the text with a bracket stack, so they are most of the way there:

  • walk each line once;
  • find a head by exact comparison ([OPTION: / [OPTIONS:, case-folded);
  • track bracket pairs with the existing PAIR_OPENERS / PAIR_CLOSERS index tables;
  • close a marker on its own closer when what follows is end of line or another head.

That gives the same linear bound without new regex. You don't need to touch the regex that was already on main for this; just don't widen it. The new tests should carry over unchanged.

Happy to re-review once it's up.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@rnoack1
rnoack1 force-pushed the feat/option-marker-grammar-fixes branch from 5a344c1 to 8b875d9 Compare November 5, 2026 17:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 5, 2026
@rnoack1

rnoack1 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks, done in 8b875d9.

  • The regex in optionMarker.ts is back to main byte for byte: OPTION_MARKER_RE, HEAD_RE and the partial-head patterns. SIBLING_CHAIN, CONTINUES_AT, OPENER_RE, the escape helper and the inline line-break test are gone. The only regex uses added are fresh clones of main's OPTION_MARKER_RE and HEAD_RE.
  • markersBefore is the scanner. It walks the line once, finds a head by case-folded comparison, and tracks brackets with PAIR_OPENERS / PAIR_CLOSERS. A marker closes on its own closer when blanks and then another head follow. Each sibling it finds must match main's pattern over its own span and pass labelsHaveUnmatchedOpener, so siblings follow the same grammar as the final marker.
  • The new test files carry over unchanged. In optionsMarkerTerminator.test.ts, one test pinned the removed lookahead in the pattern source. It now asserts the source has no (?=\[ lookahead, and that a 256-marker line parses in one walk. AssistantMessage.test.tsx is back to main, because its pattern pin was only rewritten for the composed regex. I also restored what the check gives up as controls.
  • Against main's grammar, 8 of the new tests fail. At this head, all 274 tests in the 8 marker test files pass.

@rnoack1
rnoack1 force-pushed the feat/option-marker-grammar-fixes branch from 8b875d9 to 38398eb Compare November 5, 2026 17:55
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 5, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, the regex point is fixed. The same-line and nesting cases are now handled by a scanner (headAt, closerContinues, afterLinkClose, markerSpanning) with no new pattern, and only main's existing OPTION_MARKER_RE and HEAD_RE are reused.

One small blocking point, Frontend Ratchets & i18n. Two zero-tolerance checks fail on lines this PR wrote ([added-lines] and [vs-base]):

app-sdk/protocol/optionMarker.ts:234  disallow literal string: ['[OPTIONS:', '[OPTION:'] [i18n-strict:all-caps-const]

The i18n gate reads an ALL_CAPS const array of literal strings as UI copy. These two marker heads are protocol tokens, so please build them the way main's MARKER_HEADS is built, from a regex literal's .source (the comment above it explains why the gate does not read that as copy), rather than as an ALL_CAPS literal array.

That push should also re-run the fork AI lanes, which could not run on this head. I'll re-review once they report.

@bolichen97

Copy link
Copy Markdown
Contributor

Correction to my last review: please don't use a regex literal for the heads. A plain string constant works, either kept out of the ALL_CAPS const pattern the i18n gate reads or marked with the gate's own exemption comment. These are protocol tokens, not UI copy.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@rnoack1
rnoack1 force-pushed the feat/option-marker-grammar-fixes branch from 38398eb to 4fcf64e Compare November 5, 2026 20:15
@rnoack1

rnoack1 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks, fixed in 4fcf64e.

  • The head table is now a plain string constant with a lower-case name: const markerHeads = ['[options:', '[option:']. It holds one entry per head, so another head is one more entry. There is no regex literal and no .source.
  • The heads are spelled lower-case because the i18n lint already excludes that token shape. headAt still matches any casing: it compares each character with the head's character and with its upper case. The gate runs with --no-inline-config, so an eslint-disable comment would not exempt the line.
  • npm run i18n:check with I18N_BASE_REF set to this PR's base: [added-lines] 0 and [vs-base] 0. At the old head, scripts/check-i18n-strings.mjs against the same base reported the two all-caps-const findings on optionMarker.ts:234.
  • All 274 tests in the 8 marker test files pass, and eslint and tsc are clean.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 5, 2026
bolichen97
bolichen97 previously approved these changes Nov 5, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, re-checked at 4fcf64e. The i18n point is fixed with a plain string constant: the marker heads are now markerHeads = ['[options:', '[option:'], lower-case protocol tokens the i18n gate does not read as copy, and headAt folds the case per character. No regex is added: the scanner (headAt, closerContinues, afterLinkClose, markerSpanning) does the work, and only main's existing OPTION_MARKER_RE and HEAD_RE are reused.

Frontend Ratchets & i18n is green, E2E passes, and every fork lane passes on this head (Opus 5.5, GPT 6.1, Design, First Principles, UX, Security Scope, Content Scan). Only backend shards and PR Readiness are still running, and none has failed. Approving.

@bolichen97
bolichen97 enabled auto-merge (squash) November 5, 2026 21:22
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@rnoack1
rnoack1 force-pushed the feat/option-marker-grammar-fixes branch from 4fcf64e to 17be6e9 Compare November 9, 2026 16:01
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 9, 2026
@rnoack1

rnoack1 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@bolichen97 this PR conflicted with main after your approval, so I rebased it as 17be6e9. The push cleared your approval. Could you take another look?

  • The only conflict was with fix(chat): fold an inline thinking block into the reasoning row #30724, in options.ts and searchableText.ts. Both files now keep both changes: the inline <thinking> strip runs first, then stripMarkersForDisplay.
  • Nothing else changed. The commit is the same apart from those two resolutions.
  • The marker and inline-thinking tests pass, 381 of 381, and so do tsc, eslint, the i18n check ([added-lines] and [vs-base] at 0) and the flake ratchet.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Nov 9, 2026
Two [OPTIONS:] markers on one line both strip and the last supplies the options; a line is accepted or refused whole. A marker inside an unclosed head is refused, a comma after a closed head no longer keeps it open, and a row whose last marker offers nothing keeps its text on screen and in search.
@rnoack1
rnoack1 force-pushed the feat/option-marker-grammar-fixes branch from 17be6e9 to 463d890 Compare November 13, 2026 20:42
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 14, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own.

I'm approving this PR. It changes only how the web chat parses option markers. I checked each new rule against the code in optionMarker.ts:

  • Two markers on one line. The line scan in markersBefore treats an earlier marker as a sibling only when the full marker pattern matches that exact span and its brackets balance. The siblings must also run without a break up to the line's last marker. Anything else on the line is left as written, so prose can only be removed when it is itself a valid marker.
  • One verdict per line. When the line's last marker is refused (an unmatched opener, or markersBefore returns null), nothing on that line is stripped.
  • Nested heads. A marker inside a head that never closed is refused and stays visible as text.
  • Comma rule. closerContinues stops at the next bracket on the line, so its scans stay linear.
  • Empty last marker. stripMarkersForDisplay keeps the raw text only when stripping would leave the row empty and the last marker offers no options. The pills still come from the last marker.
  • Search. searchableText now strips markers before removing widgets. That matches the transcript, which passes the whole message (w

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 463d890caf · 396 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 15, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. On head 463d890 the review compared the merge-base and head parsers on about 40 marker shapes (sibling pairs and chains, link-close tails, nested heads, the comma rule, case folding, the 256-head cap). No shape deleted prose, and every new refusal shows visible text. The PR's 72 tests pass, 8 of them fail against main's grammar as the body says, and the added tests use no sleeps, clocks or randomness. Every caller of parseOptions, searchableText and the TurnBlock predicates was checked at the head.
Done well: each sibling span must pass the same existing marker match and balance check as the line-final marker, and a line is accepted or refused as a whole. So the change cannot admit anything the grammar did not already admit.
Optional:

  • Backwards compatibility could name two more effects. A closed marker followed by | (for example [OPTION: Yes] | [OPTION: No]) now refuses the final marker. Also, the backend has_options still counts the nested and over-cap shapes as an ask, so the Waiting lane can list a session that shows no pill. A follow-up issue for the Python twin would help.
  • Three closerContinues branches in optionMarker.ts (comma then closer, |, immediate closer) have no test that fails when they are removed. The two CONTROL rows use a single line-final marker, so the loop never reaches them. A row like [OPTIONS: Alpha ], Bravo ] [OPTIONS: C] expecting text '' and options [C] would pin them.
  • HEAD_CAP applies to the whole message, so 257 heads anywhere drop valid pills on other lines too. The uncapped scan measured linear, so scoping the cap to one line, or removing it, would be enough.

@bolichen97
bolichen97 merged commit 270688f into kirodotdev:main Nov 17, 2026
95 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants