/agent-traffic-control:cjk-structured-llm-output-truncates-json-needs-2x-tokensfrom agent-traffic-control
When generating LONG Chinese/Japanese/Korean (CJK) STRUCTURED output (a big JSON report, a multi-section document) from an LLM chat API, the response truncates mid-JSON and your parser throws "no parseable JSON" / "Expecting ',' delimiter" / JSONDecodeError — even though the SAME prompt in English worked. Root cause: CJK is token-heavy (≈1–2 tokens per character vs ≈0.25 for English), so a report that fit your max_tokens in English overflows it in Chinese. Some models ALSO hard-cap output well below what you request (e.g. qwen-max caps at 8192) and silently truncate. Use when: a zh/ja/ko structured-generation run fails JSON parsing, worked in English, or a specific model truncates while others on the same prompt succeed. Covers the ~2× token budget rule, per-model output caps, and a salvage that recovers the complete sections from a truncated object.
Trending skills
7-day visitors to each skill page
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You ask an OpenAI-compatible LLM for a long JSON report. In English it returns valid JSON. In Chinese
(or Japanese/Korean) the identical request returns a string that starts with valid JSON but is cut off
mid-object → json.loads fails, your regex \{.*\} grabs an unbalanced blob, and you get "no parseable JSON".
max_tokens that comfortably fit the English report
truncates the Chinese one.max_tokens above a model's hard cap is either
rejected (400 ... Range of max_tokens should be [1, 8192]) or silently clamped, then the long CJK report
truncates. Observed: qwen-max hard-caps at 8192 (can't emit a full Chinese report); glm-4.6 / minimax ≈16K;
qwen-plus / qwen3-235b / glm-5.2 / kimi / deepseek handle 24–32K. Reasoning models also spend tokens on
reasoning_content before the JSON, compounding it.400 appears — binary-search max_tokens (a tiny call that 400s vs 200s reveals the
ceiling). For reasoning models, leave headroom for reasoning_content.}:
def salvage(c):
s = c[c.find("{"):]; depth=0; instr=False; esc=False; cut=None
for i,ch in enumerate(s):
if esc: esc=False; continue
if instr:
if ch=="\\": esc=True
elif ch=='"': instr=False
continue
if ch=='"': instr=True
elif ch in "{[": depth+=1
elif ch in "}]":
depth-=1
if depth==1: cut=i+1
if cut:
try:
d=json.loads(s[:cut].rstrip().rstrip(",")+"}")
if isinstance(d,dict) and len(d)>=MIN_SECTIONS: return d
except Exception: pass
return None
Truncation then degrades gracefully — the report keeps its complete sections, and the missing tail shows up as
lower "comprehensiveness" in scoring rather than a hard failure.<think>…</think>
before the JSON (MiniMax-M3) — re.sub(r"(?is)^.*?</think>","",c) first.The run produces valid JSON with all expected top-level keys for every model; a model that still truncates is hitting a hard output cap (flag it — that cap is itself a real production limitation for long-CJK tasks, not just a config bug). Salvaged reports parse and carry ≥ your minimum section count.
openai-compatible-chinese-llm-client-divergences (provider quirks),
bq-query-default-max-rows-100-silent-truncation (a different silent-truncation trap).8 models × 3 rollouts writing the same ~7-section brand report in Chinese. English runs were ~10–60K chars and fit 8–16K tokens; the Chinese runs truncated at the same caps. Bumping to 16–32K fixed most; qwen-max (8192 hard cap) could not be fixed and truncated every long rollout → it ranked last on a truncation artifact, which was reported as a genuine production disqualifier. The brace-depth salvage turned the remaining truncations into judgeable partial reports.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verifyDisarming auto-merge on a PR whose agent is still running does not hold it —
the agent re-arms within minutes and the PR merges, because arming is a step in
the agent's brief and disarming is not an instruction to the agent at all. Use
when: (1) you want to STOP a pull request from merging that an agent opened and
armed, for review, for a rethink, or because it is landing into a queue you are
trying to drain; (2) a PR you disarmed merged anyway; (3) you are telling agents
which PRs are on hold and want the hold to be enforced rather than announced;
(4) you are about to run `gh pr merge --disable-auto` and have not decided what
to do about the agent. The order is KILL THE AGENT FIRST, THEN DISARM, THEN
VERIFY the disarm by reading `autoMergeRequest` back — a disarm you did not read
back is not a hold. The stronger form needs no ordering at all: convert the PR
to a draft with `gh pr ready --undo`. A draft cannot merge whatever any agent
does to it, so the hold survives an agent you missed, an agent that restarts,
and an agent you did not know about.
/batch-member-cites-a-path-only-a-non-member-addsYou wrote something correct that the default reader cannot reach: a batch member citing a
path only a NON-member adds, or a rule, ruling or ledger sitting on an unlanded branch.
/batch-merge-subject-is-not-evidence-a-member-landedYou are about to close, delete the branch of, or mark as landed a pull
request because a batch, roll-up or merge-train commit on the target branch
names it in the subject line, and because the member's own commits all
predate that merge by wall clock. Neither of those is evidence. A batch
branch is assembled at some moment BEFORE it merges, so anything the member
pushed after assembly is outside it, and the subject records INTENT at
assembly time rather than CONTENT at merge time. Use before closing a
member, when an ancestry check against a squashed batch says no, or when a
member's branch still shows commits ahead of the target. Compare file
content against the target branch instead, expecting exactly one legitimate
difference: the shared aggregate file every member appends to.
/check-a-stale-branch-is-not-undoing-newer-main-workA branch built on an out-of-date main is about to merge, or has merged, and may undo work
that landed since. Use when a green, conflict-free PR deletes files you never touched,
newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger
(tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a
reviewer says your small PR touches dozens of files you did not change.
/ci-leg-skipping-moves-minutes-it-does-not-remove-themYou are about to propose, price or approve a CI cost saving that works by
making a job or matrix leg SKIP on pull requests — a path filter, a safe
list, a changed-files gate, an exemption list. Check first whether the
pipeline runs a complement or backstop on merge, on push, or nightly:
many do, and then the legs a pull request skipped are exactly the legs some
later run executes, so a branch that goes green once and merges bills the
same total either way and the wall clock does not move at all. Use when
pricing a filter change, when a percentage saving is quoted with no basis,
or when choosing between filtering legs and batching pull requests. The
question that separates money from bookkeeping is whether the change
removes RUNS or merely moves LEGS.