Skip to content

fix: prevent max_tokens state mutation and clean up dead code#465

Open
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:optimize/llmcore-fixes
Open

fix: prevent max_tokens state mutation and clean up dead code#465
Kailigithub wants to merge 1 commit into
lsdefine:mainfrom
Kailigithub:optimize/llmcore-fixes

Conversation

@Kailigithub
Copy link
Copy Markdown
Contributor

Three targeted fixes in the LLM core and browser driver:

  1. Prevent max_tokens state mutation (llmcore.py):

    • ClaudeSession.raw_ask and NativeClaudeSession.raw_ask were mutating self.max_tokens to 8192 when None.
    • This caused the default to "stick" after the first call, preventing subsequent calls from using a different value.
    • Fix: use a local variable max_tokens = self.max_tokens or 8192 instead.
  2. Replace redundant JSON round-trip with copy.deepcopy() (llmcore.py):

    • ToolClient.chat() used json.loads(json.dumps(tools, ensure_ascii=False)) to deep-copy the tools schema.
    • copy.deepcopy() is cleaner, faster for non-JSON-serializable objects, and clearer in intent.
  3. Fix dead code in TMWebDriver (TMWebDriver.py):

    • connected() callback created a string but never printed or returned it.
    • Added the missing print() call to match handle_close() behavior.

Verification:

  • Both files pass python3 -m py_compile
  • No new lint violations introduced

- Use local variable instead of mutating self.max_tokens in
  ClaudeSession.raw_ask and NativeClaudeSession.raw_ask
- Replace json.loads(json.dumps(...)) with copy.deepcopy() in
  ToolClient.chat for more efficient deep copy
- Fix dead code in TMWebDriver connected() callback (missing print)
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.

1 participant