Skip to content

Prompt-routing hook ignores words inside backticks (#4564) - #4566

Merged
capy-ai[bot] merged 2 commits into
mainfrom
skill-route-ignores-code-in-backticks
Nov 20, 2026
Merged

capy-ai[bot] merged 2 commits into
mainfrom
skill-route-ignores-code-in-backticks

Conversation

@garrytan

@garrytan garrytan commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

The prompt-routing hook no longer acts on words inside backticks or code blocks, so a prompt that quotes a command (Run mycli check now) stops getting a wrong "run /verify" or "run /review" line.
Why: routing is on by default, so any session that quotes commands got these hints; this fixes the report in #4564 by @vilano93, rebuilt on current main.
Nothing to do: plain requests ("run the checks", "review this pr", bug reports in words) route as before.

What changed

Before: a prompt that only quotes a command in backticks was told to run /verify. After: it routes nowhere.

Before: a prompt that only quotes a command in backticks was told to run /verify. After: it routes nowhere.

Tests
  • bun --no-env-file test test/skill-route.test.ts: 31 pass, 0 fail, 331 expect() calls
  • bun run typecheck: clean
  • Full free suite in CI (free-tests run 44776960088 at this tree): green, 1718 test files
Before/after as text: Before: a prompt that only quotes a command in backticks was told to run /verify. After: it routes nowhere.
--- Before · before.txt · captured output
+++ After · after.txt · captured output
@@ ⋯ 1 unchanged ⋯ @@
 threshold: 0.66
 skills: 65 scanned in /home/user/.claude/skills
 candidates:
+  (none)
+route: none (below-threshold)
-  1.00  /verify  "run the checks" (2 words, gstack)
-  0.50  /review  "check my diff" (1 words, gstack)
-route: /verify
-hint: gstack skill routing (UserPromptSubmit hook; matched the installed /verify trigger "run the checks"; off: gstack-config set skill_routing off): this request fits /verify. Run /verify with the Skill tool before you start, and tell the user in one sentence that gstack routed this to /verify.
 

People quote commands in backticks all the time, and the routing hook read those words as a request: "Run gh pr review 123" was told to run /review, and a --fix flag or the word broken in a pasted log made a prompt look like a bug report. The hook now splits a prompt into prose and Markdown code the way CommonMark reads it (inline code spans, fenced blocks with backticks or tildes) and matches triggers and bug-report signs on the prose only. One sign still reads the code, since an exception name such as KeyError or a pasted traceback still marks a bug report. The split takes a single pass over the prompt, so even a prompt near the hook's 256 KB input limit that is full of stray backticks is handled in milliseconds, well inside the hook's 1.5 second deadline. Claude Code and Codex share the same code, and the docs and changelog say what changed.

Why

"Run mycli check now" should not be told to run /verify (#4564). With routing on by default, every session that quotes a command could get a wrong skill hint; now only the words around the code decide where a prompt goes.

Blast radius

Only lib/skill-route.ts changed in product code; its callers are the Claude Code and Codex routing hooks and gstack-skill-route --explain, which all read the same routePrompt result shape. That is safe because a prompt without backticks or fences takes the same path as before (repro: the full routing test file passes on both hosts, and the new single-pass split matched the earlier regex on 500,000 random strings in two separate fuzz runs).

Pre-Landing Review

Two findings in the first review, both below the blocking floor and fixed in 5760b4d: a reviewer finding whose details are recorded privately, and a test gap (no test for a traceback inside a fenced block, and none showing a helper name such as handleError in code is not a bug report), now covered. A follow-up read of the fix found nothing. A second-model adversarial read of the final tree raised four low notes, none blocking; they are listed below.

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL lib/skill-route.ts:272 CRLF prompts: FENCE and PARAGRAPH_BREAK do not see \r\n line endings, so a stray backtick can pair across paragraphs and leave prose out of routing (the hint fails open).
  • INFORMATIONAL lib/skill-route.ts:290 An unclosed fence or a ~~~~~~~~ separator line sends the rest of the prompt to code; matches CommonMark and the documented behavior.
  • INFORMATIONAL lib/skill-route.ts:297 A backslash-escaped backtick opens a code span here, while CommonMark treats it as a literal backtick; a few prose words can be left out of routing.
  • INFORMATIONAL lib/skill-route.ts:355 splitCode runs over the whole prompt three times per route (scorePrompt, bugReport, routePrompt); bounded by the 256 KB stdin cap, about 53 ms on 100 KB worst case.
Exploratory QA

Surface: the Claude Code routing hook (hosts/claude/hooks/skill-route-hook.ts), fed hook JSON on stdin with an isolated state root. On the final tree: "run the checks" routes to /verify (capture 008), "Run mycli check now" routes nowhere (009), and a 242 KB single-paragraph prompt with 60 unmatched backtick runs finishes in 60 ms (010). Before the fix that last prompt took 4954 ms and 5080 ms (006, and its replay 007), past the hook's 1.5 s deadline; that is the defect fixed in 5760b4d. The QA tool reports the run as inconclusive: capture 001 was a malformed first probe (its stdin redirect sat outside the capture, so the hook saw no prompt), and its contract was rerun correctly as 004 and 008. The Codex hook was not probed directly; it shares this code and the test file checks it.

Eval Results

No prompt, template, judge or eval-harness file changed, so no paid eval ran. The selector lists 106 behavioral probes that depend on lib/skill-route.ts; they stay with scheduled and release coverage.

Review bot comments

No review bot comments.

Scope Drift

Scope Check: CLEAN

Plan Completion

Plan completion audit: not run (no plan is bound to this branch and no docs/designs/ file matches). This is a bug fix, exempt from planning.

Issues

Refs #4564
Refs p1/specialist-batched#1
Refs p1/specialist-batched#2

Verification Results

No plan verification obligations (bug fix, no plan). The failing-first test from #4564 fails on main 92c6c8a and passes here; the new speed test fails on the earlier split (5259 ms) and passes on the final tree.

TODOS

No TODO items completed in this PR.

Documentation

Scope: The committed diff from 92c6c8a to HEAD covers lib/skill-route.ts, test/skill-route.test.ts, docs/skill-routing-and-contracts.md and changelog.d/skill-route-ignores-code-spans.md. Nothing was staged, unstaged or new.

Result: Current, with no edits. The routing doc already explains that triggers and bug-report signs read only the prose and leave out inline code and fenced blocks, with an exception name in code still counting as a bug report. That matches splitCode and EXCEPTION_NAME in the code. The changelog fragment describes the same behavior.

Debt: None found. README.md, docs/skills.md and CLAUDE.md have nothing about routing that this change makes stale.

Agent notes

Outside code: #4564's diff was read as text only; the fix is rewritten on main 92c6c8a. No network, secrets, permissions, workflows, install scripts or dependencies are touched. Issue GST-3292.

Approvals

No approvals recorded for branch skill-route-ignores-code-in-backticks.
Plan: exempt: bug fix with a failing-first test (#4564)
Plan check: exempt bug fix

REVIEW_LOOP: passes=1 blocking_found=0 deferred=0 noted=4 fixed=2 scope=frozen unbound=1 ledgers_read=3 fix_checks=1 dispatches=1
Gate edits: none detected (1 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)

{
  "schema_version": 1,
  "pr": 4566,
  "head": "5760b4d5140399a77dd56807eae309d3f2d1fcd4",
  "version": "1.102.0.0",
  "base": "main",
  "gate": {
    "test": {
      "pass": 1718,
      "fail": 0,
      "skip": 0
    },
    "skill-route": {
      "pass": 31,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "test",
      "run": 44776960088,
      "attempt": 1,
      "tree": "ec8f4d62a3373a2e9b79fc1a870dc35e99743562"
    }
  ],
  "calls": 29,
  "session_kind": "unattended",
  "run": "/home/user/.capy/work/ship-4566",
  "head_tree": "ec8f4d62a3373a2e9b79fc1a870dc35e99743562",
  "product_patch_id": "91ae9b6a5e86c28edd563127ad59df07a1183ff0",
  "gstack_version": "1.102.0.0",
  "review_depth": {
    "depth": "light",
    "class": "code",
    "runtime_lines": 72,
    "rules": "3e7e9d5d0a0d8879",
    "base": "6121a195910a23ac81489cb377362c978533d021",
    "registry": "6121a195910a23ac81489cb377362c978533d021",
    "gate_scan": {
      "tagged": 0,
      "head": "5760b4d5140399a77dd56807eae309d3f2d1fcd4"
    },
    "reasons": [
      "runtime=72"
    ],
    "risk": [],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @ec8f4d62a337 (8 checks, current for 5760b4d51403)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/44776960088/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/44776960088/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=ec8f4d62a337 tests=38511 skipped=67 runs=44776960088/1 profiles=ci-reuse/free-tests heads=5760b4d51403 verified=2026-11-20T16:56:34.742Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [
      4564
    ],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/ and README.md (diff 92c6c8a..HEAD: lib/skill-route.ts, test/skill-route.test.ts, docs/skill-routing-and-contracts.md, changelog.d fragment)"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 0,
    "deferred": 0,
    "noted": 4,
    "fixed": 2,
    "scope": "frozen",
    "fix_checks": 1,
    "rounds": 2,
    "ledgers_read": 3,
    "unbound": 1,
    "dispatches": {
      "specialist": 1
    }
  },
  "gate_dispositions": []
}
{"head":"5760b4d5140399a77dd56807eae309d3f2d1fcd4","run":"ship-4566","status":"started","review_loop":{"passes":1,"blocking_found":0,"deferred":0,"noted":0,"fixed":2,"scope":"frozen","rounds":1,"dispatches":{"specialist":1}}}

A prompt that quotes a command in backticks, such as "Run `mycli check` now",
was told to run /verify, and a --fix flag or the word broken in a pasted log
made a prompt read as a bug report. Triggers and bug-report signs now read only
the prose; an exception name in code still marks a bug report.

Co-authored-by: vilano93 <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

… with stray backticks no longer stalls the hook

A 242 KB prompt with 60 unmatched backtick runs took about 5 s in the
routing hook, past its 1.5 s deadline. Each backtick run now looks up its
closing run once. Adds tests for a traceback in a fenced block and a
helper name such as handleError in code.

Review-Finding: p1/specialist-batched#1 reader=red-team
Review-Finding: p1/specialist-batched#2 reader=testing
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit 6287c75 into main Nov 20, 2026
78 checks passed
@garrytan garrytan mentioned this pull request Nov 20, 2026
capy-ai Bot added a commit that referenced this pull request Nov 20, 2026
- Two /ship approval records stop needing workarounds. (#4549)
- For contributors: the paid auto-decide check counts a start step that ran while the skill loaded. (#4543)
- The destructive-command check closes three ways past its disk-wipe and force-push blocks. (#4534)
- A green CI run still counts when the repository's artifact storage is full. (#4536)
- `/cso` now audits repositories that track symlinks. (#4567)
- A doc-sync eval stops failing when the audit child drops one field from its result line. (#4555)
- The browse daemon no longer picks port 10080, which Chromium refuses to open. (#4554)
- Opted-in telemetry now says why a skill run ended, which coding agent and model family ran it, and whether an upgrade worked. (#4542)
- A preregistration with only its write-up and plain data now gets the write-up review: one reviewer, one round. (#4544)
- When owner rulings don't clear a stopped review, `gstack-review-read` now says which findings are left. (#4553)
- The prompt-routing hook now names your installed bug-fix skill on bug reports, alone, and never puts /verify ahead of it. (#4539)
- Owner rulings now close a stopped review whose findings were logged in a findings file. (#4568)
- /ship can finish after the owner accepts a stopped review's findings as open notes. (#4552)
- /ship no longer starts the full test suite on your machine when CI's earlier run can't be reused (GST-3277). (#4565)
- The prompt-routing hook no longer acts on words inside backticks. (#4566)
- In Claude Code, a gstack skill's start step now runs when the skill loads, so the model can't skip it. (#4509)
- gstack's telemetry backend only accepts writes through its own validated endpoint, and the community dashboard now counts real use. (#4537)
- gstack now says what it's adding before it adds a background job or a browser extension. (#4538)
- For contributors: every flaky pass in Free Tests is now recorded. (#4572)
- For contributors: Free Tests on pull requests starts its test shards one round of small jobs sooner. (#4570)
- Secret values written as `name=value` at the end of a path are now hidden. (#4571)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@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.

1 participant