Skip to content

Studio: deterministically load explicitly mentioned skills before generation - #12538

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
wasimysaid:workbench/auto-load-explicitly-mentioned-skills-c5d1e0
Oct 4, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
wasimysaid:workbench/auto-load-explicitly-mentioned-skills-c5d1e0

Conversation

@wasimysaid

@wasimysaid wasimysaid commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem and behavior

Explicit @skill-name mentions previously depended on the model choosing to call read_skill. Studio now securely reads the enabled skill's complete SKILL.md before the first generation, including retries and follow-ups. This loads instructions, not scripts or skill creation.

  • Preserve account discovery, effective Code/model/tool-capability gates and scoped approval; refuse oversized manifests whole.
  • Persist backend-authored Loaded/unavailable cards separately from model calls; exclude them from outbound history and reject forged provider control frames.
  • Exact plain-text mentions only; code, quotes, blockquotes, URLs, prefixes and old history remain inert. Contract: studio/SKILL_MENTIONS.md.

Scope and provenance

Merged October 4 by danielhanchen, merge 9d74ab7a2661aad0e96577caff1a53e4a5585b38, source head d9484d07a5a995a8fe89bcb606d7856844567db4: 23 files, +1,081/−34 against 619cd71ec226310a40a859c2c65f26ddfeb9cfaf. No workflows, dependencies or artifacts.

Credit: wasimysaid (ef8cb3edbb, 1357179ead, a7cdd39129, 6eeef4a3b5) and subsequent source-branch fixes; related #10247 and #12118. Clean publication fe57748642 preserved the original patch byte-for-byte. The merged head includes later discovery, approval-flush, tool-withdrawal, Markdown and effective-Code fixes and is not production-blob-identical to the earlier live-tested head.

Verification and post-merge follow-up

  • Historical checks at fe57748642: 5,594 backend passed / 1 existing skip, 218 repo, 833 frontend; compile/typecheck/applicable lint passed. Informational Biome/ESLint failures were disclosed.
  • Historical rendered/GPU proof at a7cdd39129: native Gemma4 12B Q4_K_M original prompt and same-chat follow-up received the complete 1,171-character manifest before generation with zero model reads; Qwen and negative gates completed. Retained evidence is not a current-head live rerun.
  • Fork #219 now carries six post-merge Codex parser fixes and model-visible approval-denial context at 5f67fede1036703292801682e89d1596527ee708: 2 existing files, +146/−35, 24 table cases, two safetensors route cases and one existing denial test parameterization, no dependency changes. Final scoped checks passed (123 backend, compile/lint/publication hooks, five red/green controls); earlier recovery broad checks passed (5,607 backend / 1 existing skip, 218 repo, 833 frontend, typecheck). Actual Codex round 6 response reviewed exact fork head 5f67fede10: “Didn't find any major issues.” No new inline findings; no actionable findings remain.

Those post-merge fixes are fork-only and are not included in this merged PR. No lifecycle change or duplicate PR was made. Remote CI waiting is waived; no new GPU or live hosted-provider validation is claimed. The earlier quota-exhaustion attempt was not convergence.

Historical Gemma4 original and follow-up loaded cards

Before / after on a local GGUF (Qwen3-1.7B Q4_K_M, Code on)

Before: the model never reads the skill and says it has no secret word. After: a "Loaded secret-word · SKILL.md" card appears before the reply, context grows from 106 to 1.2k tokens, and the model answers with the skill's token.

Same prompt @secret-word what is the secret word? on two isolated Studio installs (merge base vs this PR). Before, Qwen3-1.7B never calls read_skill; after, Studio loads the complete SKILL.md before generation and the reply follows it.

Preserve the exact net fix and final provider-turn regression test from fork PR #219 (ef8cb3e, 1357179, a7cdd39, 6eeef4a). Reapply on fresh upstream main without unrelated fork ancestry.
@danielhanchen

Copy link
Copy Markdown
Member

The Frontend build + bundle sanity failure (over the startup budget: transfer 1800.x KB > 1796.9 KB) is main's, not this PR's: #11491 pushed main's eager startup bundle past the budget. #12560 re-measures it; a re-run or push after it lands should clear the check.

@danielhanchen danielhanchen added >3000# affects UI# new-feature# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard labels Oct 3, 2026
@danielhanchen

Copy link
Copy Markdown
Member

This adds the full SKILL.md content to the system message whenever a skill is mentioned, which changes what the model sees on those turns. Could you confirm how this interacts with existing system prompts and chat templates that expect a single fixed system message, and whether this context is ever repeated across follow-up turns?

@danielhanchen danielhanchen self-assigned this Oct 4, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 4, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #12538, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#380.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 465803b76 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/backend/core/inference/skill_mentions.py (on the mirror)

@@ -0,0 +1,176 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Backend-authored @skill loads before generation; contract in studio/SKILL_MENTIONS.md."""
+
+from __future__ import annotations
+
+import hashlib
+import re
+import uuid
+
+from core.inference.skills import SkillError, list_skills, read_skill_instructions
+from state.tool_approvals import (
+    abort_tool_decision,
+    begin_tool_decision,
+    new_approval_id,
+    wait_tool_decision,
+)
+from state.tool_policy import normalize_tool_permissions
+
+_TOKEN = re.compile(r"(?<!\S)@([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)(?=$|\s|[.,;:!?)](?:$|\s))")

P2 Badge Accept one-character skill names in mention parsing

A valid skill name may contain one character, but this expression always requires both the initial and final alphanumeric groups, making the minimum matched length two. Consequently, an enabled skill such as a can be listed and read normally but an explicit @a mention is silently ignored instead of loading its instructions.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Not reproducible: the tail group is optional, so mentioned_skill_names('@A hi') already returns ['a'].

Round 2: reviewed mirror 8f15e50b0 (no equivalent commit found on this PR)

chatgpt-codex-connector[bot] on studio/backend/core/inference/skill_mentions.py (on the mirror)

@@ -0,0 +1,182 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Backend-authored @skill loads before generation; contract in studio/SKILL_MENTIONS.md."""
+
+from __future__ import annotations
+
+import hashlib
+import re
+import uuid
+
+from core.inference.skills import SkillError, list_skills, read_skill_instructions
+from state.tool_approvals import (
+    abort_tool_decision,
+    begin_tool_decision,
+    new_approval_id,
+    wait_tool_decision,
+)
+from state.tool_policy import normalize_tool_permissions
+
+_TOKEN = re.compile(r"(?<!\S)@([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)(?=$|\s|[.,;:!?)](?:$|\s))")
+_MAX_LOAD_BYTES = 32_000
+
+
+def mentioned_skill_names(text: str) -> list[str]:
+    """Only prose outside code, Markdown blockquotes, and balanced quotation spans."""
+    lines = []
+    fence = None
+    for line in text.splitlines(keepends = True):
+        stripped = line.lstrip()
+        marker = re.match(r"(`{3,}|~{3,})", stripped)

P2 Badge Respect indentation when detecting fenced-code markers

Because lstrip() removes unlimited indentation before matching, a fence-like line indented by four spaces or a tab is treated as an opener/closer even though Markdown considers it indented code (or literal content inside an existing fence). For example, in ```\n ```\n@skill-creator\n```, the indented backticks incorrectly close the fence and the following mention is loaded despite still being fenced code, violating the documented exclusion and potentially injecting a skill merely being discussed in a code sample. Only recognize fence markers with at most three leading spaces.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Below the bar: a fence-like line indented 4+ spaces inside a fenced block is an exotic input; the contract is deliberately not a full Markdown parser (studio/SKILL_MENTIONS.md), and the worst case is loading an enabled skill the user named.

Round 3: reviewed mirror 6dc8e1593a (this PR's d9484d07a)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 6dc8e1593a

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 6dc8e1593a (this PR's d9484d07a).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

affects UI# new-feature# regresses# security# Moves a security boundary: sandbox, allowlist, permission or network guard >3000#

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants