-
Notifications
You must be signed in to change notification settings - Fork 6.1k
fix: add persistent cost to prevent under-reporting spent value #7763
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
base: dev
Are you sure you want to change the base?
Conversation
…iving from the messages array max 100 messages are kept in the store/memory which leads to misreporting of the actual spend value
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
|
||
| const cost = createMemo(() => { | ||
| const total = messages().reduce((sum, x) => sum + (x.role === "assistant" ? x.cost : 0), 0) | ||
| const total = session().cost ?? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you would want to fallback to the messages cost right cause otherwise opening old sessions would show 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be handled by the migration script for old sessions as well, but yeah it makes more sense to fallback to the old method instead of defaulting to zero. updated.
|
|
||
| export const getCost = fn(Identifier.schema("session"), async (id) => { | ||
| const read = await Storage.read<Info>(["session", Instance.project.id, id]) | ||
| return read.cost ?? 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer leaving as undefined so we can properly do checks in frontend right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, updated
this informs the caller function that cost can be undefined so it can properly handle it, instead of just defaulting to 0.
What does this PR do?
This PR adds a persistent cost field to sessions to fix incorrect cost reporting in the sidebar when sessions exceed 100 messages. Previously, cost was calculated from the last 100 messages only, causing under-reporting for long sessions.
Key changes:
How did you verify your code works?
Verified with before/after testing on the same long session:
OpenCode v1.1.12
OpenCode local
Fixes #7767 #6989