Skip to content

Stop the prompt-routing hook from routing on words inside backticks - #4564

Closed
vilano93 wants to merge 1 commit into
garrytan:mainfrom
vilano93:fix/skill-route-ignores-code-spans
Closed

vilano93 wants to merge 1 commit into
garrytan:mainfrom
vilano93:fix/skill-route-ignores-code-spans

Conversation

@vilano93

@vilano93 vilano93 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The prompt-routing hook no longer routes a prompt because of words inside backticks or code blocks; only the prose around them can match a trigger.

Why: a tool that wakes a session with "Run <cli> … check …" got a /verify hint on every message, and "Run gh pr review 123" got a /review hint.

Nothing to do: "run the checks", "verify my change" and other prose requests route as before, on Claude Code and Codex.

Why (in your own words)

I run Claude Code sessions as workers under a coordinator. The coordinator wakes a session by typing one line into it, for example:

You have 1 orchestration message. Run `<cli> orchestration check --run run_<run-id> --terminal term_<terminal-id>`.

With skill_routing on (the default since 1.101), every one of these lines got this request fits /verify. Run /verify with the Skill tool before you start. In a coordinator session that happens dozens of times a day, and the model has to decide each time to ignore an instruction from gstack. Nothing in the line asks for checks. "run" comes from the prose, and "check" is a subcommand inside the code span, so the two content words of the /verify trigger "run the checks" are both "present" and the trigger scores 1.0.

Related, but a separate cause: #4423 (messages from other sessions routed as if a person asked). This PR doesn't detect injected messages. It fixes the narrower rule that applies to typed prompts too: a command quoted in backticks is not a request in words.

Live evidence

Same prompt, same installed skills (~/.claude/skills), dry run with gstack-skill-route --explain:

Installed 1.102.0.0:

candidates:
  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"; ...): this request fits /verify. Run /verify with the Skill tool before you start, ...

This branch:

candidates:
  (none)
route: none (below-threshold)

Counter-checks on this branch: run the checks → route: /verify; verify my change in `src/app.ts` → route: /verify; Run `gh pr review 123 --approve` once CI is done. → route: none (on 1.102: /review via "review this pr").

The new test was red before the fix, on the first prompt:

(fail) scorer > words inside inline code or a fenced code block never match a trigger; the prose around them still routes
-   [],
+   [
+     "verify",
+   ],

Every negative case routed before the fix, checked one by one against the real /review, /qa and /verify triggers:

"You have 1 orchestration message. Run `<cli> orchestration check --run …`."  -> verify (run the checks)
"Run `gh pr review 123 --approve` once CI is done."                            -> review (review this pr)
"Run ``tool lint check --fix`` and paste the output."                          -> verify (run the checks)
"Pasted from CI:\n```\n$ make check\nall tests pass\n```\nWhat does this output mean?" -> verify (make the tests pass)

Scope

  • Changed:
    • lib/skill-route.ts:
      • A new function, proseText, blanks out Markdown code as CommonMark reads it. That covers fenced blocks (``` or ~~~, closed by a fence of the same character that is at least as long; an unclosed fence runs to the end) and inline code spans (a backtick run closed by a run of the same length; an unmatched backtick stays text).
      • scorePrompt and the find-bugs phrase check in routePrompt score promptWindow(proseText(prompt)).
      • bugReport still reads the raw prompt, because an exception name in backticks (`ValueError`) is evidence of a bug report.
    • Codex: hosts/codex/hooks/codex-skill-route-hook.ts calls the same routePrompt, so it gets the fix with no change. The test asserts both hosts.
    • test/skill-route.test.ts: one test with four prompts that must not route (the wake-up line, gh pr review in a span, a double-backtick span, a fenced CI paste) and six that must still route to /verify (plain prose, prose next to code, an unclosed backtick).
    • docs/skill-routing-and-contracts.md: one bullet on the rule.
    • changelog.d/fix-skill-route-ignores-code-spans.md: the changelog fragment.
  • Verified live by: the --explain runs above on macOS (Apple Silicon, Bun 1.4.4). bun test test/skill-route.test.ts test/codex-hooks.test.ts has 56 passing tests. That includes the 60 plain prompts and the B1 in-sample set, unchanged. bun run typecheck is clean, and bun run typecheck:test reports none new.
  • Full free suite: bun run test exits 1 on this machine both on this branch and on an untouched upstream/main checkout (bd04289): 92 test files red on the branch, 101 on main. That's shared-HOME and concurrency noise across the pre-PR checks, cso, update-check and other suites, and no skill-route file is among them. Two files were red only on the branch run, shard-engine-equivalence and strict-output-formats. Run alone, they pass on the branch and fail on main, so they're flaky here. CI is the judge for the full suite.
  • Did NOT test:
    • The paid evals (skill-routing-e2e). The hint text is unchanged; only which prompts get it.
    • Linux and Windows.
  • Known limit: a bare shell command with no backticks ("Run tool check now") still matches. Without Markdown there is no reliable line between a command and prose, so that case belongs with Skill routing routes messages from other agents and sessions as if a person asked #4423's question of telling injected messages apart.

Liveness proof (required for external contributors)

SCR-20261120-obxg

Checklist

  • Liveness screenshot attached (GSTACK PR typed live into a real surface) or PR author is @garrytan (owner exemption)
  • This is not a generated-file-only diff (I edited the source/template and regenerated)
  • No ETHOS.md edits, and no changes to voice / founder perspective / YC references
  • New public command / external service / host adapter has an accepted issue linked (or N/A)
  • Linked issue or reproduction: reproduction above; related Skill routing routes messages from other agents and sessions as if a person asked #4423

🤖 Generated with Claude Code

A prompt such as "Run `tool check --run <id>`", typed into a session by an
orchestration tool to wake it, routed to /verify on the trigger "run the
checks": "check" inside the inline code span supplied the second content
word. "Run `gh pr review 123`" routed to /review the same way.

Trigger scoring (scorePrompt, and the find-bugs phrase check in routePrompt)
now reads the prompt's prose: inline code spans and fenced code blocks are
blanked out as CommonMark reads them. Unmatched backticks stay plain text.
The bug-report signs still read the code, where an exception name often
sits. Claude Code and Codex share routePrompt, so both hooks get the fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trunk-io

trunk-io Bot commented Nov 20, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Thank you @vilano93. I reproduced this on current main (92c6c8a): gstack-skill-route --explain 'Run \mycli check` now'` routes to /verify on the word inside the backticks. We're picking this up as today's small outside fix. It will land on main with you credited, and this PR will be closed with a link when it does.

@capy-ai capy-ai Bot added bug Something isn't working S3 Severity 3: everything else labels Nov 20, 2026
capy-ai Bot added a commit that referenced this pull request Nov 20, 2026
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.

Co-authored-by: vilano93 <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=red-team
Review-Finding: p1/specialist-batched#2 reader=testing
@capy-ai

capy-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Thank you, @vilano93. This was a clear report with a good repro. We rebuilt the fix on current main in #4566, which is now merged, and you're credited as co-author. Words inside backticks and fenced code blocks no longer route a prompt to /verify or /review. #4566 also stops a --fix flag or a log line inside code from making a prompt read as a bug report. Closing this one as superseded by #4566.

@capy-ai capy-ai Bot closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working S3 Severity 3: everything else

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant