getappmap / appmap-js

Client libraries for AppMap
48 stars 17 forks source link

/tokenlimit does not appear to be overriding the TOKEN_LIMIT env var #2031

Open kgilpin opened 1 month ago

kgilpin commented 1 month ago

I am asking:

/tokenlimit=8000 plan

The token limit is set in the environment as:

"APPMAP_NAVIE_TOKEN_LIMIT":"19827"

In the log, I am observing:

15756 [Stderr] Using token limit 19827
...
15756 [Stderr] User option tokenlimit=8000
...
15756 [Stdout] [search-context] Requested char limit: 51564
...
15756 [Stdout] Remaining characters before context: 51564
15756 [Stdout] Added 31286 characters out of a requested limit of 51564.

So it appears that the /tokenlimit override is not being applied correctly.

github-actions[bot] commented 1 month ago

Title: Ensure User-Specified Token Limit Overrides Environment Variable

Problem: The user-specified token limit (/tokenlimit=8000) is not overriding the environment variable APPMAP_NAVIE_TOKEN_LIMIT as expected. The logs indicate that the token limit utilized by the application is still taken from the environment variable rather than the user input.

Analysis: Typically, in a configuration setting where both environment variables and user inputs are involved, the hierarchy of precedence generally gives higher priority to user inputs. The issue here suggests that the overriding logic might not be functioning correctly. A review of the logic handling the token limit could reveal if the user input value is appropriately captured and takes precedence over the environment variable.

The OPTION_SETTERS object in navie-local.ts indicates where settings like tokenLimit are configured. It's crucial to ensure that when a token limit is specified by the user, it should be properly parsed and assigned, surpassing any associated value set by environment variables.

Proposed Changes:

  1. File: packages/cli/src/rpc/explain/navie/navie-local.ts

    • Within the OPTION_SETTERS for tokenLimit, ensure there's logic in place that checks if a user input value (/tokenlimit) exists and override the environment-based value. Confirm that this setter is correctly invoked when a user specification is present and parsed before the environment variable setting.
  2. File: packages/client/src/loadConfiguration.ts

    • Examine how settings from the environment are loaded. If APPMAP_NAVIE_TOKEN_LIMIT influences other areas affecting token limit, ensure the logic accounts for user-provided values as a possible override.
  3. Testing Workflow:

    • After implementing changes, create and test scenarios where the token limit is specified by a user, both alongside and in the absence of an environment variable.
    • Verify the logs to ensure the application responds accurately to the /tokenlimit user input and reflects it in processing metrics and output.

Reviewing the current setup and ensuring a robust precedence rule for configuration values will provide a reliable override mechanism for user-specified settings.