Skip to content

Add global state storage size logging with threshold filter #3810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

KJ7LNW
Copy link
Collaborator

@KJ7LNW KJ7LNW commented May 22, 2025

Context

This PR adds a utility function to log global state storage sizes with a configurable threshold filter (default 10KB) to help users identify large items.

Implementation

  • Created a new utility file src/utils/storageUtils.ts with:
    • formatBytes function to convert byte sizes to human-readable format
    • logGlobalStorageSize function with threshold parameter (default 10KB)
  • Updated extension.ts to use the new utility functions
  • Added comprehensive tests for the formatBytes function
  • Changed logging to use console.log instead of outputChannel

How to Test

  • Run the extension and check the console output
  • Verify that only storage items larger than 10KB are shown
  • Verify that total size and number of skipped items are displayed

Fixes #3809


Important

Adds utility to log global state storage sizes with a threshold filter and updates logging behavior in the extension.

  • Behavior:
    • Adds logGlobalStorageSize in storageUtils.ts to log global state items exceeding a size threshold (default 10KB).
    • Updates extension.ts to use logGlobalStorageSize during activation.
    • Changes logging from outputChannel to console.log in extension.ts.
  • Utilities:
    • Adds formatBytes in storageUtils.ts to convert byte sizes to human-readable format.
  • Testing:
    • Adds tests for formatBytes in storageUtils.test.ts.

This description was created by Ellipsis for 2f7ab2d. You can customize this summary. It will automatically update as commits are pushed.

Adds a utility function to log global state storage sizes with a configurable
threshold filter (default 10KB) to help users identify large items.

This provides visibility into which global state items are consuming significant
storage space, making it easier to diagnose performance issues.

Fixes: cline#3809
Signed-off-by: Eric Wheeler <[email protected]>
@KJ7LNW KJ7LNW force-pushed the storage-size-threshold branch from 2f7ab2d to bcb4268 Compare May 22, 2025 02:05
@KJ7LNW
Copy link
Collaborator Author

KJ7LNW commented May 22, 2025

@cte @mrubens @hannesrudolph what does knip test?

It looks like the intention is to prevent files that are not used, but this new file is definitely used (imported by extension.ts) and I cannot figure out how to fix this error:

Run npm run knip
  npm run knip
  shell: /usr/bin/bash -e {0}
  env:
    NODE_VERSION: 20.18.1

> [email protected] knip
> knip --include files

src/utils/storageUtils.ts  
Error: Process completed with exit code 1.

@webpro
Copy link

webpro commented May 22, 2025

First of all, apologies for my creepy unsolicited entrance. Creator of Knip here. Sometimes I see projects using Knip and this caught my eye. Feel free to ignore me! But I noticed that this is a monorepo and the root "." workspace could be better configured like so:

{
	"$schema": "https://unpkg.com/knip@latest/schema.json",
	"workspaces": {
		".": {
			"entry": ["src/extension.ts", "src/workers/countTokens.ts", "src/**/__tests__/**/*{b,B}enchmark.ts"],
			"project": ["src/**/*.ts"]
		},
		"webview-ui": {
			"entry": ["src/index.tsx"],
			"project": ["src/**/*.{ts,tsx}"]
		}
	},
	"ignore": ["**/__mocks__/**"]
}

This way, there's no need to ignore as much! In the next release of Knip you'll be able to remove that "**/__mocks__/**" from ignore as well (and they'll automatically be added as entry files by the Jest and Vitest plugins).

Have a great day ☀️

@KJ7LNW
Copy link
Collaborator Author

KJ7LNW commented May 22, 2025

First of all, apologies for my creepy unsolicited entrance. Creator of Knip here. Sometimes I see projects using Knip and this caught my eye. Feel free to ignore me! But I noticed that this is a monorepo and the root "." workspace could be better configured like so:

{
	"$schema": "https://unpkg.com/knip@latest/schema.json",
	"workspaces": {
		".": {
			"entry": ["src/extension.ts", "src/workers/countTokens.ts", "src/**/__tests__/**/*{b,B}enchmark.ts"],
			"project": ["src/**/*.ts"]
		},
		"webview-ui": {
			"entry": ["src/index.tsx"],
			"project": ["src/**/*.{ts,tsx}"]
		}
	},
	"ignore": ["**/__mocks__/**"]
}

This way, there's no need to ignore as much! In the next release of Knip you'll be able to remove that "**/__mocks__/**" from ignore as well (and they'll automatically be added as entry files by the Jest and Vitest plugins).

Have a great day ☀️

@webpro, Thank you for dropping in!

Do you understand what causes the following? As far as I can tell, src/utils/storageUtils.ts is being used by this PR but for some reason is it is getting triggered:

Run npm run knip
  npm run knip
  shell: /usr/bin/bash -e {0}
  env:
    NODE_VERSION: 20.18.1

> [email protected] knip
> knip --include files

src/utils/storageUtils.ts  
Error: Process completed with exit code 1.

@hannesrudolph hannesrudolph moved this from New to PR [Pre Approval Review] in Roo Code Roadmap May 22, 2025
@webpro
Copy link

webpro commented May 23, 2025

In a monorepo, the top-level entry and project options are not effective, because these should be in the root workspace config at workspaces["."]. Use --debug and look for "Included workspace configs" to see the config Knip uses.

Knip could def need some more config validation, etc. but we're not there yet.

Btw the ignore option in the config I posted can be removed entirely after installing [email protected] (or later).

@KJ7LNW
Copy link
Collaborator Author

KJ7LNW commented May 23, 2025

In a monorepo, the top-level entry and project options are not effective, because these should be in the root workspace config at workspaces["."]. Use --debug and look for "Included workspace configs" to see the config Knip uses.

Knip could def need some more config validation, etc. but we're not there yet.

Btw the ignore option in the config I posted can be removed entirely after installing [email protected] (or later).

thank you I am going to reference this in a new issue

@hannesrudolph hannesrudolph moved this from PR [Needs Review] to TEMP in Roo Code Roadmap May 26, 2025
@daniel-lxs daniel-lxs moved this from TEMP to PR [Needs Review] in Roo Code Roadmap May 27, 2025
@hannesrudolph hannesrudolph added the Followup Needs followup from support or code team label May 27, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Hey @KJ7LNW This is great to help us debug potential issues that users might run into with the global state while we fix the implementation, just a nit on the size calculation for the undefined values in the global state, everything else lgtm

stateSizes.forEach((item) => {
if (item.size === -1) {
// Already logged error
} else if (item.size === undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the loop where items are logged, there's a check for item.size === undefined. If context.globalState.get(key) actually returns undefined, JSON.stringify(undefined) produces the string "undefined", so size would be 9. Could we clarify how explicitly undefined values retrieved from globalState should be handled or reported here? For instance, if a key exists but its value is undefined, should that be logged differently than an error in size calculation?

Copy link
Collaborator Author

@KJ7LNW KJ7LNW May 27, 2025

Choose a reason for hiding this comment

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

Interesting point.

That code is correct, however, as it should measure len(json).toString() because the size-estimate assumption is that the global state backend storage size is stored as JSON text, so that is the size of the element. (Even if vscode's global state does not store on disk as JSON, it still correctly provides the magnitude of key sizes and the sort order would still be correct as well, and that is all we care about here.)

In any event, the result of a size being only 9 is rather moot: the entire point of this is to provide inspection of large global state sizes, because when the global state gets too big (ie, megabytes) it causes problems, hence PR #3785 and possibly related issues about memory crashes.

This pull request is a result of inspecting global state storage for #3785 to generally see where the problems lie: I thought it could be useful in general for logging Roo startup, to keep an eye on things, and also give users a way to report information like this if troubleshooting is necessary (ie, paste your console logs into this ticket)---however I did not think it should be part of #3785 since that is getting big and I want to keep it focused.

@daniel-lxs daniel-lxs moved this from PR [Needs Preliminary Review] to PR [Needs Review] in Roo Code Roadmap May 27, 2025
@daniel-lxs daniel-lxs removed the Followup Needs followup from support or code team label May 27, 2025
@KJ7LNW KJ7LNW marked this pull request as draft May 27, 2025 23:50
@KJ7LNW
Copy link
Collaborator Author

KJ7LNW commented May 27, 2025

blocked by #3884

@daniel-lxs daniel-lxs moved this from PR [Needs Review] to PR [Draft / In Progress] in Roo Code Roadmap May 28, 2025
SmartManoj pushed a commit to SmartManoj/Raa-Code that referenced this pull request Jun 13, 2025
* Added Cerebras as a Provider

* prettier fix

* prettier

---------

Co-authored-by: sam <[email protected]>
@KJ7LNW
Copy link
Collaborator Author

KJ7LNW commented Jun 27, 2025

this is a good idea but I do not see it getting off the ground. someone can reopen if they want the feature

@KJ7LNW KJ7LNW closed this Jun 27, 2025
@github-project-automation github-project-automation bot moved this from PR [Draft / In Progress] to Done in Roo Code Roadmap Jun 27, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Global state storage size information not available to users
4 participants