Skip to content

crane-serve: Wire stop-sequence and handle max_completion_tokens - #118

Merged
lucasjinreal merged 2 commits into
lucasjinreal:mainfrom
cryptomilk:asn-serve
Sep 4, 2026
Merged

crane-serve: Wire stop-sequence and handle max_completion_tokens#118
lucasjinreal merged 2 commits into
lucasjinreal:mainfrom
cryptomilk:asn-serve

Conversation

@cryptomilk

Copy link
Copy Markdown
Contributor

I will need that soon :-)

cryptomilk and others added 2 commits September 3, 2026 18:19
`stop` was deserialized from chat/completion/generate requests but never
reached the engine, which could only stop on EOS tokens or max_tokens.
Agentic clients rely on stop strings to bound tool-call blocks and turn
boundaries, so requests setting `stop` had no effect.

Sequence now accumulates decoded text per token and checks it against the
request's stop strings alongside the existing EOS/length checks, and
finish_sequence truncates the returned text at the first match instead of
flushing the tokenizer's trailing buffer.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
max_tokens is OpenAI's legacy field name; newer clients send
max_completion_tokens instead, which Crane silently ignored, falling
back to the 4096 default regardless of what the client requested.
@lucasjinreal

Copy link
Copy Markdown
Owner

Hi, what does this fix

@cryptomilk

Copy link
Copy Markdown
Contributor Author

It is for OpenCode, it isn't wired yet, but I'm working on MoE support.

@cryptomilk

Copy link
Copy Markdown
Contributor Author

In OpenCode you can also stop a model by just pressing ESC. That sends the stop command. However we do not have support for it which does this.

@lucasjinreal
lucasjinreal merged commit 3209251 into lucasjinreal:main Sep 4, 2026
4 checks passed
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