Skip to content

feat: manager-controlled keep-alive strategies - #107

Merged
OsherElhadad merged 6 commits into
mainfrom
feat/keepalive-strategies
Aug 25, 2026
Merged

OsherElhadad merged 6 commits into
mainfrom
feat/keepalive-strategies

Conversation

@OsherElhadad

Copy link
Copy Markdown
Collaborator

Summary

Adds a manager-controlled layer above the existing keep-alive mechanism: a strategy is a durable, scheduled rule (idle interval, max pings, time windows in a timezone, and a target of all tenants or a specific list) that a manager creates from a new dashboard tab. A matching strategy forces the keep-alive ping on for a request, overriding that tenant's own account-level off switch — evaluated live per request, so an "all tenants" strategy automatically covers tenants created after it was set up.

This sits above the existing per-account config switch and below the existing per-session override, both of which are unchanged:

account config -> matching active strategy (forces on) -> session override (still wins on top)
  • New control routes (/api/keepalive/strategies*), all manager-only, with an explicit role re-check inside each handler in addition to the route-table gate.
  • New table keepalive_strategies in the tenant registry DB, loaded into the keeper's memory and refreshed on every write — unlike per-session overrides, a strategy is meant to survive a restart.
  • New nullable keepalive_strategy_id column on requests, additive, never backfilled.
  • New dashboard read route (GET /api/keepalive/strategies/{id}/ledger) and a new manager-only "Strategies" tab; a small keep-alive savings callout on the Overview tab for every user.
  • Design doc: docs/superpowers/specs/2026-08-25-keepalive-strategies-design.md.

Test plan

  • go build ./..., go vet ./... clean
  • go test ./proxy/... ./dash/... ./tenant/... ./config/... — all pass
  • go test -race on proxy, dash, tenant — no races
  • Unit tests: window/timezone matching (incl. DST transition), strategy-vs-strategy precedence, session override still wins over a matching strategy, validation bounds, persistence across a simulated restart
  • Live end-to-end: drove a real Claude Code session through a local hosted proxy build, created a strategy with a window covering the current time, confirmed a real ping fired after the idle threshold and landed correctly attributed in GET /api/keepalive/strategies/{id}/ledger
  • Security review pass: fixed a missing defense-in-depth role re-check in the four new control handlers, and an audit-trail gap where a failed audit write on update left the change persisted with no audit row

Osher-Elhadad added 5 commits August 25, 2026 09:56
Scheduled, cross-account keep-alive policies (time windows, targets,
per-strategy cost-vs-savings) layered above the existing per-account
config and per-session override mechanisms.

Signed-off-by: Osher-Elhadad <[email protected]>
The idle keep-alive ping mechanism was reachable only two ways: a manager
flipping one account-wide boolean, or arming a single session for up to 12h.
There was no way to run a schedule ("only during Israel business hours"), no
way to apply one policy across every account at once, and no way to see cost
vs. savings broken out per policy per account.

This adds a manager-authored, durable Strategy: Idle/MaxPings/MinPrefixTokens/
MaxUSDPerPing plus one or more time-of-day Windows (day-of-week, HH:MM, IANA
timezone) and a Target (every account, or a named list). It slots into the
keep-alive's existing resolution chain between account config and the
per-session override: account CachePolicy -> highest-priority matching ACTIVE
strategy -> session override (unchanged, still wins on top, still cannot widen
MaxUSDPerPing). Precedence among matching strategies is fixed, not
configurable: a list-target strategy beats an all-target one, and ties go to
the most recently updated.

Persistence lives in the tenant registry (new keepalive_strategies table),
because a strategy is a standing rule a manager expects to survive a deploy,
unlike a per-session override which is deliberately memory-only. It is loaded
into the keeper's memory at boot and reloaded on every write through the new
control routes, so a strategy created through the API matches on the very
next request with no restart.

New control routes (all manager-only, audited): GET/POST
/api/keepalive/strategies, PATCH/DELETE /api/keepalive/strategies/{id}.
Validation reuses the existing per-session override's numeric bounds for
Idle/MaxPings/MinPrefixTokens, plus its own checks for windows, timezone and
target shape.

A ping fired under a matching strategy is tagged with the strategy's id on its
own dash.Event (a new nullable, never-backfilled keepalive_strategy_id column
on `requests`), which a new dashboard route
(GET /api/keepalive/strategies/{id}/ledger) reads to show pings, ping cost and
each tenant's own keep-alive credit, grouped by tenant.

The dashboard gains a manager-only "Strategies" tab (create/edit form, a
table with active/pause/edit/delete and a per-tenant ledger), and every user's
Overview tab gets a small keep-alive savings callout reusing the existing
account ledger response.

One stdlib-only addition beyond the letter of the design: a blank import of
time/tzdata, so IANA zone data is compiled into the binary rather than
depending on the deployed image's OS packages (the shipped Dockerfile does
not install tzdata), which would otherwise make every window silently fail to
resolve its timezone.

Signed-off-by: Osher-Elhadad <[email protected]>
…lers

The four new keep-alive strategy control routes relied only on the route
table's ctlManager gate. Every other handler in this file's neighbourhood
(ctlKeepAliveArm) re-checks the role inside the handler itself as
defense in depth, and the list handler did not call webPrincipal at all.
Add the same check to list/create/patch/delete.

Also revert a strategy's PATCH when its audit write fails, the same way
create already deletes what it cannot account for, so a strategy update
never stands without an audit row.

Signed-off-by: Osher-Elhadad <[email protected]>
docs/superpowers/ holds working design docs for the skill that authored
them, not published site content. mkdocs build --strict was failing
because the new keep-alive strategies spec had no nav entry.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad
OsherElhadad merged commit 9e73d17 into main Aug 25, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Aug 25, 2026
OsherElhadad pushed a commit to OsherElhadad/context-guru-1 that referenced this pull request Aug 26, 2026
Resolves overlap with rossoctl#107 (manager-controlled keep-alive strategies,
already on main) and rossoctl#108 (dash/api.go, dash/schema.go caching/index
fixes). The predictor pipeline in this branch was built as a superset
of rossoctl#107's base feature, so every conflict resolves by keeping this
branch's version (already contains rossoctl#107's content plus the predictor
gate on top); rossoctl#108's caching and index additions land untouched
alongside it.

Signed-off-by: Osher-Elhadad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant