Skip to content

fix: grow token buffer when piece exceeds 256 bytes (#17) - #39

Merged
anikchand461 merged 1 commit into
smollabs:mainfrom
rajshree051205-cloud:fix/token-piece-buffer-17
Nov 22, 2026
Merged

anikchand461 merged 1 commit into
smollabs:mainfrom
rajshree051205-cloud:fix/token-piece-buffer-17

Conversation

@rajshree051205-cloud

Copy link
Copy Markdown
Contributor

Fixes #17

llama_token_to_piece returns -(required size) when the buffer is too small.
Engine.run ignored that case, so long tokens were silently dropped.

  • Add readPiece helper: on a negative return, grow the buffer to the required size and retry once. The buffer only grows when needed and is reused for later tokens.
  • Use it in Engine.run.
  • Add tests for the grow path, the short-token path (no growth) and the empty path.

Note: tests cover the plain-Go helper in isolation. go test on the cgo package fails in my Codespace because -L.../lib/linux-${GOARCH} in the #cgo LDFLAGS isn't expanded, which is unrelated to this change.

@anikchand461
anikchand461 merged commit cfbf98d into smollabs:main Nov 22, 2026
1 check 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.

Tokens longer than 256 bytes are silently dropped from replies

2 participants