Skip to content

fix(spec-builder): refuse a spec name or slot key that ends in a newline - #34740

Merged
javenciu merged 1 commit into
mainfrom
fix/spec-builder-anchor-validators
Nov 10, 2026
Merged

javenciu merged 1 commit into
mainfrom
fix/spec-builder-anchor-validators

Conversation

@javenciu

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a Spec Builder spec name, slot key or approval hash that ends in a newline is refused, like every other malformed value.

spec_builder/backend/parsers.py checks four values with $-anchored patterns used with .match: _NAME_RE (spec name), _SLOT_KEY_RE (chat slot key), _SLOT_SUFFIX_RE (the eight hex digits at the end of a per-creation key) and _SHA256_RE (document hash). Python's $ also matches just before a trailing "\n". On main:

  • POST /specs/{name}/approve and POST /specs/{name}/run-task with "hash": "<64 hex>\n" pass the format check and answer 409 doc_changed instead of 400 invalid_hash.
  • index.json is writable by the agent the app runs. An entry keyed "live\n" is loaded as a usable spec, and an entry whose slot_key is "spec-builder-live-0123abcd\n" becomes the spec's slot key. That key is a session file name.
  • A stored approval whose hash ends in a newline is reported as an approval (stale) instead of being dropped.

test/test_regex_anchor_contract.py holds a package's request-path validators to \Z, package by package (#12161 began it; #34336, #34465, #34534 and #34592 registered Mochi, pptx-maker, Meetings and Design Tweak). Spec Builder is not registered there yet.

Why it matters

The name and the slot key are the gate between a request body or index.json and a directory name and a session file name. A value with a hidden newline passes the gate that is meant to allow only letters, digits, - and _.

Not a goal

  • No other package's patterns.
  • No change to what a valid name, key or hash is.
  • repository_duplicate.py already uses fullmatch for its digest check, so it is untouched.

What changed (motivation → approach → change)

Approach: the repo's existing fix for this class. Anchor at \Z, which matches only at the true end of the string, and register the package so the contract keeps it that way.

  • src/kiro_crew/apps/builtins/spec_builder/backend/parsers.py: _NAME_RE, _SLOT_KEY_RE, _SLOT_SUFFIX_RE and _SHA256_RE end at \Z, with the reason in a comment. The other modules of the package import these four, so one edit covers every use.
  • test/test_regex_anchor_contract.py: spec_builder.backend joins _REQUEST_PATH_PACKAGES, and the four patterns join _VALIDATORS with a valid input each.
  • src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py: new file. It checks the name, the slot key, a stored approval hash, the index loader (a name key and a slot_key that end in a newline) and the approve route (400, nothing recorded).

Backwards compatibility

Compatible for every valid value: the patterns accept exactly what they did, minus a value with one trailing newline. A client that sent a hash with a newline now gets 400 where it got 409.

Tests

  • Before: on main the 11 new or extended checks fail (4 patterns accept valid + "\n", the structural walk lists the four names, _usable_name("live\n") is true, _owns_slot_key accepts a key with a newline, the index keeps a "live\n" entry and a slot key with a newline, a stored hash with a newline reads as an approval, approve answers 409 instead of 400).
  • After: every test under the package's tests/, test/test_core_spec_builder_decoupling.py and test/test_regex_anchor_contract.py: 1219 passed, three runs in a row at -n0.
  • The whole backend suite, with every app's own tests/, on a local merge with current main fails only the tests this environment fails on main itself (optional dependencies it lacks).
  • No test creates a file or directory whose name holds a newline.
  • flake8, isort, the black gate, the comment-history gate, CI's semgrep rules, frontend, source and mypy checks, and the flake-pattern and wait-discipline ratchets pass locally.
  • Reproduce: python -m pytest src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py test/test_regex_anchor_contract.py -n0
  • Proof: PROVEN src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py::test_a_spec_name_ending_in_a_newline_is_not_usable, src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py::test_a_slot_key_ending_in_a_newline_is_not_owned_by_the_spec, src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py::test_an_approved_hash_ending_in_a_newline_is_not_an_approval, src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py::test_the_index_drops_an_entry_whose_name_ends_in_a_newline, src/kiro_crew/apps/builtins/spec_builder/tests/test_trailing_newline.py::test_the_index_ignores_a_slot_key_that_ends_in_a_newline (head 2086f97)

Manual verification

N/A: the tests call the route handler and the helpers, on real temporary directories.

Sibling sweep

Swept: every module-level compiled pattern under src/kiro_crew/apps/builtins/spec_builder/backend with an unescaped $ and no re.MULTILINE; the contract's structural walk lists none after this change. _TASK_LINE_RE uses re.MULTILINE on purpose (per-line anchors over tasks.md) and is exempt.
Sibling: src/kiro_crew/apps/builtins/spec_builder/backend/parsers.py -- changed here

Pattern harvest

Rule candidate: none new. test/test_regex_anchor_contract.py already states the rule; this registers one more package under it.

Screenshots / video

Why no screenshot: no markup change; a refused value is answered the way other malformed values are.

Related Issues

None open for Spec Builder. Same class as #34199, #34238, #34336, #34465, #34534 and #34592; the contract began in #12161.

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

Python's $ also matches just before a trailing newline, so the spec name
check accepted "live\n" as a second spelling of "live", the slot key
check accepted a key with a newline that becomes a session file name,
and the approval hash check let "<digest>\n" reach the document
comparison (409 instead of 400). Anchor the Spec Builder backend's
validators at \Z and register the package in the regex-anchor contract.
@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners November 10, 2026 19:15
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 2086f97830106dca166c0616b402d06b16fdbe1b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@javenciu
javenciu enabled auto-merge (squash) November 10, 2026 19:16
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2086f97830106dca166c0616b402d06b16fdbe1b — 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

Nothing blocks: a fix at mechanism level, using the repo's existing \Z contract, with every sibling in the package covered.

What this change ships

Inventory (4 items) — 4 justified

Intent: stop Spec Builder from accepting a spec name, slot key or approval hash that has a hidden trailing newline (FIX).

  1. A spec name or slot_key in index.json that ends in a newline is now dropped instead of being used — justified
  2. Approve and run-task with a hash that ends in a newline now answer 400 invalid_hash where they answered 409 — justified
  3. A stored approval whose hash ends in a newline is now discarded instead of being reported as stale — justified
  4. spec_builder.backend is now registered in test_regex_anchor_contract.py, so a new $ anchor fails CI — justified

[FIRST-PRINCIPLES-REVIEWED] 2086f97

Description read

[DESCRIPTION-READ] 47e8e0ef3aa1a0471f25b8702dbef5390f1b8180c86d0dc7f49644a408ecd50a

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 2086f97830106dca166c0616b402d06b16fdbe1b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2086f97

Verdict parsed from the review's SHA-scoped output markers for commit 2086f97830106dca166c0616b402d06b16fdbe1b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2086f97830106dca166c0616b402d06b16fdbe1b false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 2086f97830106dca166c0616b402d06b16fdbe1b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. This uses the repo's existing \Z anchor fix and registers the package in the anchor contract. Spec Builder is not in adoption-pins.json, so the fix belongs in place here.

[DESIGN-REVIEWED] 2086f97

Description read

[DESCRIPTION-READ] c1abba3f4f73ebfc7d8b80c95aeb31d883dae5640c75a94bfe745dd4ab699685

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 2086f97830106dca166c0616b402d06b16fdbe1b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2086f97

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2086f97830106dca166c0616b402d06b16fdbe1b false-positive: <reason, 20 to 500 characters>

@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 Nov 10, 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.

Approved. The review checked this head (2086f97) and found nothing blocking. In parsers.py, the anchors on _NAME_RE, _SLOT_KEY_RE, _SLOT_SUFFIX_RE and _SHA256_RE change from $ to \Z. The callers in controls.py, execution_state.py, repository.py, runtime.py and repository_duplicate.py pick that up, and every valid name, slot key and hash is still accepted. The new test file and test_regex_anchor_contract.py pass on this head (101 passed). Putting $ back on each pattern makes at least one test fail, so every changed anchor is pinned.
Done well: the tests go through the real entry points. They cover the index loader dropping a planted "live\n" key, the slot key fallback, and the approve route answering 400 with nothing recorded. No test creates a file name that contains a newline, so they stay safe on Windows.
Optional:

  • A stricter validator counts as a take-away change. You could add a Reader: line under ## Backwards compatibility naming website/src/apps/spec-builder/api.ts approve. It sends back the hash the server served, which never ends in a newline. This is a body edit, so no push is needed.
  • Only the approve route has a route-level test for the new 400. A run-task case next to it would cover the second call site in controls.py. The Proof: line could also list the approve route test.
  • When spec_builder moves out under #26967, that change should delete the spec_builder imports and entries in test/test_regex_anchor_contract.py.

@javenciu
javenciu merged commit f6fd7ae into main Nov 10, 2026
98 checks passed
@javenciu
javenciu deleted the fix/spec-builder-anchor-validators branch November 10, 2026 20:53
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 10, 2026
KiroCrewCaptain added a commit to KiroCrewCaptain/kirocrew-app-spec-builder that referenced this pull request Nov 15, 2026
Port every backend change the built-in took after the snapshot this
repository was ported from, so an adopted user runs them:

- put a popped worker slot back only onto a free key
  (kirodotdev/KiroCrew#31829)
- keep pasted blocks and the send id on the stored user row, queued or
  not, with the id checked by the host (kirodotdev/KiroCrew#31799,
  kirodotdev/KiroCrew#23167)
- find a decision answer folded into a merged queue-drain row by every
  folded id, so it is not dispatched twice (kirodotdev/KiroCrew#33324)
- refuse a name, slot key or hash ending in a newline
  (kirodotdev/KiroCrew#34740)
- deliver a restored note hold above the next turn's row on a gateway
  without the chat slot seam (kirodotdev/KiroCrew#36128)
- move the earlier decision record only as a regular file with one
  name, and settle an empty one when there is none, so a file planted
  at the old location later is never imported
  (kirodotdev/KiroCrew#33589)

The test dependency moves to Kiro Crew af94fac51f so the new host
names resolve where the suite runs; the tests the built-in added with
these changes come along.
KiroCrewCaptain added a commit to KiroCrewCaptain/kirocrew-app-spec-builder that referenced this pull request Nov 15, 2026
Port every backend change the built-in took after the snapshot this
repository was ported from, so an adopted user runs them:

- put a popped worker slot back only onto a free key
  (kirodotdev/KiroCrew#31829)
- keep pasted blocks and the send id on the stored user row, queued or
  not, with the id checked by the host (kirodotdev/KiroCrew#31799,
  kirodotdev/KiroCrew#23167)
- find a decision answer folded into a merged queue-drain row by every
  folded id, so it is not dispatched twice (kirodotdev/KiroCrew#33324)
- refuse a name, slot key or hash ending in a newline
  (kirodotdev/KiroCrew#34740)
- deliver a restored note hold above the next turn's row on a gateway
  without the chat slot seam (kirodotdev/KiroCrew#36128)
- move the earlier decision record only as a regular file with one
  name, and settle an empty one when there is none, so a file planted
  at the old location later is never imported
  (kirodotdev/KiroCrew#33589)

The test dependency moves to Kiro Crew af94fac51f so the new host
names resolve where the suite runs; the tests the built-in added with
these changes come along.

Co-authored-by: KiroCrewCaptain <312312717+KiroCrewCaptain@users.noreply.github.com>
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.

2 participants