-
Notifications
You must be signed in to change notification settings - Fork 542
feat(usage): filter usage queries by model call kind #5709
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
Open
ggbdpq
wants to merge
16
commits into
apache:main
Choose a base branch
from
ggbdpq:feat/usage-call-kind-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
25f1c95
feat(usage): filter usage queries by model call kind
ggbdpq 7a191e0
chore(protocol): bump the compatibility epoch for callKinds usage que…
ggbdpq 79dbb0b
chore: retrigger CI
ggbdpq 14de3ce
fix(desktop): hide the main cache rate when the main-only summary rea…
ggbdpq 3ce9980
test(desktop): exercise the injected preload failure behind the usage…
ggbdpq 3aad406
chore: retrigger CI (workhub browser presentation smoke flake)
ggbdpq e7e5cf4
fix(desktop,storage): degrade a crashed main-only usage read; documen…
ggbdpq ce5b42d
chore: retrigger CI (head event was not registered)
ggbdpq 04d5f35
Merge branch 'main' into feat/usage-call-kind-filter
ggbdpq f3a3533
Merge branch 'main' into feat/usage-call-kind-filter
ggbdpq 46e457c
Merge branch 'main' into feat/usage-call-kind-filter
ggbdpq f2d44c5
Merge upstream/main into feat/usage-call-kind-filter
ggbdpq 0a0d0fd
Merge upstream/main (d7dffca98)
ggbdpq 2d7ea34
Merge upstream/main (9b089f58e)
ggbdpq 671bc60
Merge remote-tracking branch 'upstream/main' into feat/usage-call-kin…
ggbdpq 2aed892
Merge remote-tracking branch 'upstream/main' into feat/usage-call-kin…
ggbdpq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import type { Result } from '@maka/core/result'; | ||
| import type { DesktopSessionUsageSummary } from './bridge-contract.js'; | ||
|
|
||
| /** The narrow invoke surface the usage overview needs; injectable for tests. */ | ||
| export type UsageSummaryInvoke = ( | ||
| channel: 'usage:summary', | ||
| scope: unknown, | ||
| args: Record<string, unknown>, | ||
| ) => Promise<Result<DesktopSessionUsageSummary>>; | ||
|
|
||
| /** | ||
| * The overview reads the Session's whole metered spend and, separately, the | ||
| * agent loop's own calls: auxiliary prompts do not share the main loop's | ||
| * cached prefix, so a blended rate under-reports it (#5691). | ||
| * | ||
| * The main-only read refines the cache rate; losing it must not lose the | ||
| * overview — but it must also not pass the blended rate off as the main | ||
| * loop's, so the failure is marked and the rate hides itself (#5691). | ||
| */ | ||
| export async function loadSessionUsageSummaryVia( | ||
| invoke: UsageSummaryInvoke, | ||
| session: { readonly scope: unknown; readonly sessionId: string }, | ||
| ): Promise<Result<DesktopSessionUsageSummary>> { | ||
| const summaryQuery = { range: 'all' as const, sessionId: session.sessionId }; | ||
| // A rejected secondary invoke (transport/IPC crash rather than an | ||
| // operation-level failure) must not take the whole overview down with it — | ||
| // it marks the summary unavailable like any other main-read failure (#5691 | ||
| // review). | ||
| const [summary, main] = (await Promise.all([ | ||
| invoke('usage:summary', session.scope, summaryQuery), | ||
| invoke('usage:summary', session.scope, { ...summaryQuery, callKinds: ['main'] }).catch( | ||
| () => ({ ok: false, error: { code: 'persistence_failed', message: 'usage read failed' } }), | ||
| ), | ||
| ])) as [Result<DesktopSessionUsageSummary>, Result<DesktopSessionUsageSummary>]; | ||
| if (!summary.ok) return summary; | ||
| return main.ok | ||
| ? { ...summary, data: { ...summary.data, mainSummary: main.data } } | ||
| : { ...summary, data: { ...summary.data, mainSummaryUnavailable: true } }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/runtime-host/protocol-compatible-changes/mechanical-candidate-sweep.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/runtime-host/protocol-compatible-changes/turn-snapshot-optional-fields.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "epoch": 200, | ||
| "epoch": 205, | ||
| "files": ["packages/runtime-host/src/protocol/turn.ts"], | ||
| "reason": "Reorganizes the local construction of already-supported optional Turn snapshot fields; it changes neither the wire keys nor accepted values." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
P3 —
Promise.allrejects if the main-onlyinvokerejects, so a transport or IPC error in the secondary read fails the whole overview even thoughsummarysucceeded.Promise.allSettled, or a.catch()that maps tomainSummaryUnavailable, would keep the totals. The{ok:false}branch also drops the error, so nothing records why the hit rate is missing.