Skip to content

Resolve _send_llm_request default max_tokens binding to support runtime overrides#235

Merged
git-miku[bot] merged 2 commits into
mainfrom
copilot/fix-code-for-review-comment-3532389379
Jul 7, 2026
Merged

Resolve _send_llm_request default max_tokens binding to support runtime overrides#235
git-miku[bot] merged 2 commits into
mainfrom
copilot/fix-code-for-review-comment-3532389379

Conversation

Copilot AI commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the review comment about Python default argument evaluation in _send_llm_request: max_tokens was bound at function definition time, so later runtime updates to the module default were ignored. The change makes default resolution dynamic when callers omit max_tokens.

  • Runtime default resolution

    • Changed _send_llm_request(max_tokens=...) from a definition-time constant to an optional parameter resolved inside the function body.
    • This ensures monkeypatched/config-updated _DEFAULT_MAX_TOKENS values are used by defaulted calls.
  • Focused regression coverage

    • Added a targeted test that monkeypatches termstory.ai._DEFAULT_MAX_TOKENS and asserts the outbound request payload uses the patched value when max_tokens is not passed.
def _send_llm_request(..., max_tokens: Optional[int] = None, ...):
    if max_tokens is None:
        max_tokens = _DEFAULT_MAX_TOKENS

@git-miku git-miku Bot added the do-not-merge/needs-star PR author has not starred this repo — run /check-star after starring label Jul 6, 2026
@git-miku

git-miku Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for the PR, @copilot!

To get this PR reviewed, please ⭐ star this repo — it's free and helps others discover it. Once starred, run :miku /check-star on this PR and I'll start helping out.

A do-not-merge/needs-star label has been applied to block merge until then.

@git-miku

git-miku Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

👋 Thanks for the PR, @copilot!

To get this PR reviewed, please ⭐ star this repo — it's free and helps others discover it. Once starred, run :miku /check-star on this PR and I'll start helping out.

A do-not-merge/needs-star label has been applied to block merge until then.

Copilot AI changed the title [WIP] Fix code based on review comment 3532389379 Resolve _send_llm_request default max_tokens binding to support runtime overrides Jul 6, 2026
Copilot AI requested a review from bitflicker64 July 6, 2026 22:31
@bitflicker64 bitflicker64 marked this pull request as ready for review July 7, 2026 06:59
@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the Python default argument evaluation issue in _send_llm_request where max_tokens was bound to _DEFAULT_MAX_TOKENS at function definition time, preventing runtime overrides. The fix changes the signature to max_tokens: Optional[int] = None with an in-body fallback, and adds a targeted test using monkeypatch to verify the behaviour.

  • termstory/ai.py: Signature change from max_tokens: int = _DEFAULT_MAX_TOKENS to max_tokens: Optional[int] = None with a runtime resolution guard inside the function body.
  • tests/test_ai.py: New test test_send_llm_request_uses_runtime_default_max_tokens monkeypatches ai._DEFAULT_MAX_TOKENS and calls _send_llm_request without passing max_tokens, asserting the patched value propagates to the outbound payload.

Confidence Score: 5/5

Safe to merge — the change is a minimal, well-targeted fix with a corresponding regression test.

The fix correctly moves default resolution from definition time to call time, the new test directly verifies the monkeypatching scenario, and no call paths are broken. The only outstanding item is a pre-existing style note about redundant explicit pass-throughs at five call sites, which was already raised in the previous review cycle.

No files require special attention.

Important Files Changed

Filename Overview
termstory/ai.py Signature change to _send_llm_request fixes definition-time default binding; 5 existing call sites still pass max_tokens=_DEFAULT_MAX_TOKENS explicitly (P2 style issue, already flagged in prior review).
tests/test_ai.py Adds a focused regression test for the runtime default resolution; test is correctly structured and assertions are accurate.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Caller invokes _send_llm_request(...)"] --> B{max_tokens passed?}
    B -- "Yes (explicit value)" --> D["Use caller-supplied max_tokens"]
    B -- "No (None / omitted)" --> C["Read _DEFAULT_MAX_TOKENS\nat call time"]
    C --> D
    D --> E["Build request body\nwith resolved max_tokens"]
    E --> F["POST to LLM endpoint"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["Caller invokes _send_llm_request(...)"] --> B{max_tokens passed?}
    B -- "Yes (explicit value)" --> D["Use caller-supplied max_tokens"]
    B -- "No (None / omitted)" --> C["Read _DEFAULT_MAX_TOKENS\nat call time"]
    C --> D
    D --> E["Build request body\nwith resolved max_tokens"]
    E --> F["POST to LLM endpoint"]
Loading

Reviews (2): Last reviewed commit: "fix(ai): resolve max_tokens default at r..." | Re-trigger Greptile

@bitflicker64

Copy link
Copy Markdown
Owner

@copilot fix whatever greptile flagged

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix whatever greptile flagged

Addressed in ad2dcc4: the greptile flag around default binding/monkeypatch behavior is fixed by resolving max_tokens at runtime in _send_llm_request, and tests/test_ai.py now validates the runtime override path without raising=False.

@bitflicker64

Copy link
Copy Markdown
Owner

@greptile-apps review

@bitflicker64

Copy link
Copy Markdown
Owner

/lgtm /approve /merge

@git-miku git-miku Bot added the lgtm This PR has been approved by a maintainer label Jul 7, 2026

@git-miku git-miku Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved via Miku.

@git-miku git-miku Bot merged commit 58363e0 into main Jul 7, 2026
7 checks passed
@git-miku

git-miku Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

miku /lgtm

✅ LGTM! Label added by @bitflicker64.

Use :miku /lgtm cancel to retract.


miku /approve

✅ Approved! 🎉


miku /merge

✅ Merged! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/needs-star PR author has not starred this repo — run /check-star after starring lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants