Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/context-guru-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ func main() {
h.API().SetWindows(windows)
// The keeper's ping plan, so /api/cachestate can say how long a cache is held warm.
h.API().SetKeepAlivePlans(h.KeepAlivePlans)
// The account's per-wait plan settings, so the calculator replays the policy that runs (#868).
h.API().SetWaitPolicy(h.DashWaitPolicy())
h.API().SetPingStates(h.KeepAlivePingStates)
// The configuration the adapt reports compare against: each account's in hosted mode, this
// proxy's own (with any applied override) otherwise.
Expand Down
4 changes: 4 additions & 0 deletions dash/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/rossoctl/context-guru/apply"
"github.com/rossoctl/context-guru/internal/modelinfo"
"github.com/rossoctl/context-guru/keepalive"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -52,6 +53,9 @@ type API struct {
// pingable says per thread whether a manual ping can be sent. nil = never stated.
pingable func(tenantID string, allTenants bool, session string) map[string]PingState
kaPlans func(tenantID string, allTenants bool, session string) map[string]KeepAlivePlan
// waitPolicyFn reads a tenant's per-wait ping plan settings for the keep-alive calculator and
// recommendation (#868). nil = the shipped plan, on.
waitPolicyFn func(tenantID string) keepalive.Policy
// pricer values the pre-instrumentation split figure on read. nil = that figure is omitted.
pricer modelinfo.Pricer
// windows resolves a model's context window, and is separate from pricer because the two
Expand Down
3 changes: 2 additions & 1 deletion dash/cachelifetime_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dash

import (
"github.com/rossoctl/context-guru/keepalive"
"math"
"testing"
"time"
Expand Down Expand Up @@ -247,7 +248,7 @@ func TestKeepAliveCalcJudgesAnExpiryAgainstItsOwnLifetime(t *testing.T) {
{"anthropic", "aws/claude-sonnet-5", 0},
} {
fx := newKAFixture(t, exp("s", c.provider, c.model)...)
out, err := fx.db.KeepAliveCalc(Filter{TenantAll: true}, 280, 100_000, c.model, price, 2)
out, err := fx.db.KeepAliveCalc(Filter{TenantAll: true}, 280, 100_000, c.model, price, 2, keepalive.Policy{})
if err != nil {
t.Fatal(err)
}
Expand Down
424 changes: 342 additions & 82 deletions dash/keepalive.go

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions dash/keepaliveapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@ import (
"net/http"
"strconv"
"time"

"github.com/rossoctl/context-guru/keepalive"
)

// SetWaitPolicy supplies an account's per-wait ping plan settings (keepalive_wait_plan and its three
// counts) for the calculator and the recommendation. dash holds no tenant configuration of its own,
// so the host answers. nil: the shipped plan, on.
func (a *API) SetWaitPolicy(fn func(tenantID string) keepalive.Policy) { a.waitPolicyFn = fn }

// waitPolicy is the plan settings of the caller's account. The base count is set by the caller.
func (a *API) waitPolicy(tenantID string) keepalive.Policy {
if a.waitPolicyFn == nil {
return DefaultWaitPolicy(0)
}
return a.waitPolicyFn(tenantID)
}

// The keep-alive tab's six read routes.
//
// All in API.routes(), which is the table Mount walks AND the table both scoping tests walk —
Expand Down Expand Up @@ -137,7 +152,7 @@ func (a *API) keepAliveCalc(w http.ResponseWriter, r *http.Request) {
model = m
}
}
out, err := db.KeepAliveCalc(f, x, prefix, model, a.priceFn(r), k)
out, err := db.KeepAliveCalc(f, x, prefix, model, a.priceFn(r), k, a.waitPolicy(f.Tenant))
if err != nil {
httpErr(w, http.StatusInternalServerError, err.Error())
return
Expand Down Expand Up @@ -177,7 +192,7 @@ func (a *API) keepAliveRecommend(w http.ResponseWriter, r *http.Request) {
a.unauthorized(w)
return
}
rec, err := a.db(r).KeepAliveRecommend(f)
rec, err := a.db(r).KeepAliveRecommend(f, a.waitPolicy(f.Tenant))
if err != nil {
httpErr(w, http.StatusInternalServerError, err.Error())
return
Expand Down
Loading
Loading