Skip to content

refactor: simplify tokenizer initialization — remove unnecessary Result wrapper#7744

Merged
DOsinga merged 1 commit intoblock:mainfrom
bioinfornatics:pr/21-token-counter-simplify
Mar 11, 2026
Merged

refactor: simplify tokenizer initialization — remove unnecessary Result wrapper#7744
DOsinga merged 1 commit intoblock:mainfrom
bioinfornatics:pr/21-token-counter-simplify

Conversation

@bioinfornatics
Copy link
Copy Markdown
Contributor

Summary

Simplifies token_counter.rs by removing an unnecessary Result wrapper from the static TOKENIZER.

Before

static TOKENIZER: OnceCell<Result<Arc<CoreBPE>, String>> = OnceCell::const_new();

After

static TOKENIZER: OnceCell<Arc<CoreBPE>> = OnceCell::const_new();

Rationale

  • Tokenizer init failure is unrecoverable (o200k_base BPE ships with the crate)
  • All callers already unwrap the Result
  • Removes one layer of wrapping, net -2 lines

Verification

  • ✅ cargo check
  • ✅ cargo clippy (0 warnings)
  • ✅ cargo test (5 token_counter tests pass)
  • ✅ cargo fmt

1 file changed, 5 insertions, 7 deletions

Simplify the static TOKENIZER from OnceCell<Result<Arc<CoreBPE>, String>>
to OnceCell<Arc<CoreBPE>>. Tokenizer init failure is unrecoverable, so
panic on failure via expect() rather than propagating an Err that callers
always unwrap anyway.

Cherry-picked from feature/cli-via-goosed.

Signed-off-by: Jonathan MERCIER <[email protected]>
@DOsinga DOsinga added this pull request to the merge queue Mar 11, 2026
Merged via the queue into block:main with commit 7247d61 Mar 11, 2026
19 checks passed
lifeizhou-ap added a commit that referenced this pull request Mar 12, 2026
* main: (270 commits)
  test(acp): align provider and server test parity (#7822)
  fix(acp): register MCP extensions when resuming a session (#7806)
  fix(goose): load .gitignore in prompt_manager for hint file filtering (#7795)
  fix: remap max_completion_tokens to max_tokens for OpenAI-compatible providers (#7765)
  fix(openai): preserve Responses API tool call/output linkage (#7759)
  chore(deps): bump @hono/node-server from 1.19.9 to 1.19.11 in /evals/open-model-gym/mcp-harness (#7687)
  fix: return ContextLengthExceeded when prompt exceeds effective KV cache size (#7815)
  feat: MCP Roots support (#7790)
  fix(google): use `includeThoughts/part.thought` for thinking handling (#7593)
  refactor: simplify tokenizer initialization — remove unnecessary Result wrapper (#7744)
  Fix model selector showing wrong model in tabs (#7784)
  Stop collecting goosed stderr after startup (#7814)
  fix: avoid word splitting by space for windows shell commands (#7781) (#7810)
  Simplify and make it not break on linux (#7813)
  Add preferred microphone selection  (#7805)
  Remove dependency on posthog-rs (#7811)
  feat: load hints in nested subdirs (#7772)
  feat(acp): add read tool and delegate filesystem I/O to ACP clients (#7668)
  Support secret interpolation in streamable HTTP extension URLs (#7782)
  More logging for command injection classifier model training (#7779)
  ...
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.

3 participants