Skip to content

fix(prompt): keep code fences on their own lines - #22614

Merged
KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/fence-output-contract
Oct 21, 2026
Merged

KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/fence-output-contract

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Models are told to keep code fences on their own lines, so fewer replies hide their summary inside a diff chip.

A closing fence glued to prose, such as ```**Summary**, makes the renderer treat the rest of the reply as code. #18405 recovers from this at render time. This PR adds the matching instruction at write time.

Why it matters

The render-time recovery only fixes a fence the parser can recognise as glued. Asking for well-formed fences up front reduces how often the parser has to guess.

Not a goal

What changed (motivation → approach → change)

context_assembly/output_contract.py gains one constant, _FENCE_RULE: "Each opening and closing ``` stands alone on its line, and a blank line follows a closing fence." It is appended to both _DIFF_RULE_DASHBOARD and `_DIFF_RULE_CHANNEL`. Their existing wording is unchanged.

config/prompt.md's Output Format section states the same sentence. To keep prompt.md under its 41385-byte ceiling in test_prompt_compact_contract.py without raising it, the six-line example diff block above it is removed; the format sentence before it already names the headers, the hunk and /dev/null. The file goes from 38364 to 38360 bytes.

The widget skill gains one line saying <mcwidget> goes on its own line after a blank line, never glued to a closing fence.

The sentence is in both prompt.md and the critical rules on purpose. A minimal-context run gets prompt.md but returns before the critical rules are appended, and a custom agent gets the critical rules without prompt.md. A code comment above _FENCE_RULE records this.

Backwards compatibility

Compatible: the diff requirement and its wording on each surface are unchanged; each surface gains one sentence.

Removes nothing: no setting, key, export or stored data is removed or renamed.

Tests

  • test/test_context_composition_contract.py re-pins the critical_rules and critical_rules_channel sha256 entries. The _GOLDEN scenario hashes are unchanged.
  • test/test_memory_v1_golden.py updates the [CRITICAL RULES extent from 3192 to 3289 and EXPECTED_TOTAL from 6788 to 6885.
  • scripts/run_scoped_tests.py --surface backend passes, 1067 tests, including the prompt byte ceiling.

Manual verification

N/A. The change is prompt text; the tests pin the delivered bytes. They cannot show how often models now keep fences on their own lines.

Screenshots / video

Why no screenshot: no UI code changes; only prompt and rule text sent to the model changes.

Related Issues

Fixes #22613

Follows #18405.

Pattern harvest

Rule candidate: none
Pattern: a rule that must reach every session needs a copy on each delivery path. I checked src/kiro_crew/context_assembly and src/kiro_crew/config/prompt.md: the critical rules and prompt.md are the two paths, and both now carry the sentence.

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

Contributions are accepted under the project's Apache-2.0 license.

@Pearcekieser
Pearcekieser requested review from a team and KiroCrewCaptain as code owners October 21, 2026 00:12
@Pearcekieser
Pearcekieser requested a review from buluoray October 21, 2026 00:12
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision cefbc31e194c15bfeee1a5c311d284f0aa476520 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of cefbc31e194c15bfeee1a5c311d284f0aa476520 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that dropping the worked diff example from prompt.md, done to fit the byte ceiling, doesn't hurt diff-header compliance on minimal-context runs, which rely on prompt.md alone.

[DESIGN-REVIEWED] cefbc31

Description read

[DESCRIPTION-READ] b9087eeb2c2e092d66ea2c09551374ef64fa3aab0859b3796cd5d6025c54f64a

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 Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of cefbc31e194c15bfeee1a5c311d284f0aa476520 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check whether removing the six-line example diff from prompt.md, done only to stay under the byte limit, makes models worse at writing diff headers.

Not justified as shipped

What this change ships

Inventory (4 items) — 3 justified

Intent: get models to keep code fences on their own lines, so a reply's summary no longer disappears inside a diff block. FIX (it adds a prompt instruction that complements the render-time recovery from #18405).

  1. prompt.md Output Format now tells the model each code fence goes on its own line, followed by a blank line — justified
  2. The dashboard and channel critical rules both carry the same fence sentence (_FENCE_RULE) — justified
  3. The example diff block in prompt.md is removed to stay under the byte limit — justified
  4. The widget skill now says <mcwidget> goes on its own line after a blank line — rides along, outside the code-fence Goal

[FIRST-PRINCIPLES-REVIEWED] cefbc31

Description read

[DESCRIPTION-READ] 4f9ff5c8cc7a356742a6594d642bce7716210d5a7af09321fe38c4a6be175808

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.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): "Answer first, diffs after" is a deliberate change to output order

The order rule is intended. In the reply that #18405 fixed, the summary came after a diff block whose closing fence was glued to it, so the summary was the text that went missing. If the answer comes before any diff, a malformed diff fence can only swallow the diff blocks after it, not the answer. The dashboard rule already says built-in edits render as diff cards and should not be repeated, so on the dashboard this rule only covers shell-made changes.

You're right that nothing here measures whether glued fences become less common. The tests pin the delivered text, and the PR body says they can't show model behaviour. The render-time recovery from #18405 stays in place either way, so the prompt change is extra protection, and the renderer doesn't depend on it.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] cefbc31

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] cefbc31

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note: E2E (stub ACP backend, offline) at 778b9cd is the known gateway-stall flake

The job failed with "the gateway exited with -14 after 878s; stopped Playwright instead of letting its retries replay against it". Exit -14 is the loop-stall alarm killing the E2E gateway, the failure tracked in #18632 and #22314. This PR changes only prompt and rule text: config/prompt.md, context_assembly/output_contract.py, one line in the widgets skill and two test pins. It touches no gateway, memory or dashboard code. Once the other lanes on this head have reported, I'll push the same tree again in a CI slot to get a fresh run.

@Pearcekieser Pearcekieser changed the title fix(prompt): one fence output contract for diffs and prose fix(prompt): keep code fences on their own lines Oct 21, 2026
@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 Oct 21, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (non-blocking): "Answer first, diffs after" reorders every reply outside the Goal

Outcome: fixed in cefbc31 by deleting the sentence from _FENCE_RULE in context_assembly/output_contract.py and from prompt.md's Output Format. The remaining rule only says each fence stands alone on its line with a blank line after a closer, which already stops a closer from swallowing the summary. This also answers the Design lane's question about the order change.

@Pearcekieser
Pearcekieser force-pushed the fix/fence-output-contract branch from 778b9cd to cefbc31 Compare October 21, 2026 03:11
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (non-blocking): the shorter diff wording drops emphasis from the channel rule for a 10 to 12 byte saving

Outcome: fixed in cefbc31. _DIFF_RULE_DASHBOARD and _DIFF_RULE_CHANNEL are back to main's text byte for byte, _DIFF_FORMAT is gone, and _FENCE_RULE is only appended to each. The channel rule keeps (create, edit, append, delete) and MUST get a diff block. prompt.md's diff sentence is main's too. Its example diff block is still removed, now for a stated reason: with the fence sentence added, the file would be 41480 bytes against the 41385-byte ceiling in test_prompt_compact_contract.py, and dropping the example keeps it under without raising the budget.

@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 Oct 21, 2026
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): dropping the worked diff example from prompt.md on minimal-context runs

Kept as is. A minimal-context run still gets main's format sentence word for word: unified diff with --- old_path, +++ new_path and an @@ hunk, and /dev/null for new or deleted files. The example only repeated those four parts, so the run loses an illustration, not a rule. The other way to keep it is to raise PROMPT_BYTE_CEILINGS["prompt.md"] by about 100 bytes, and that comment says a maintainer raises the budget in a reviewed change when a rule earns the space. If a maintainer would rather keep the example and raise the ceiling, it's a two-line change and I'll make it.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 21, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 21, 2026 05:02

@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.

Tier 1 auto-approve: fix (5 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: the output rules now say every code fence stands on its own line with a blank line after it, so a widget tag is not glued to a closing fence; golden test hashes and sizes updated to match.

@KiroCrewCaptain
KiroCrewCaptain merged commit 05bec2f into kirodotdev:main Oct 21, 2026
100 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 21, 2026
@rubencu rubencu mentioned this pull request Oct 22, 2026
5 tasks done
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.

Prompt does not ask for well-formed code fences

2 participants