8000 feat(scaling): auto scaling groups, rules and approvals, with This machine as the first provider by adeelahmad · Pull Request #556 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

feat(scaling): auto scaling groups, rules and approvals, with This machine as the first provider - #556

Merged
adeelahmad merged 5 commits into
mainfrom
claude/project-thread-azm2mb
Oct 18, 2026
Merged

adeelahmad merged 5 commits into
mainfrom
claude/project-thread-azm2mb

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Description

Before: Lens ran a fixed number of workers. When jobs piled up nothing added capacity, and nothing let idle capacity go.

After: auto scaling groups add workers when work waits and let them go when it doesn't, like a cloud's auto scaling groups. A group launches units on a provider between min and max, picked by target, step and schedule rules, within a monthly budget. Every launch, join, drain, termination and hour of cost lands in the activity ledger. It is off until an admin turns it on, and a group launches nothing until a person approves its terms in Settings › Auto scaling. Agents propose and manage groups over the API, MCP and the assistant, and never approve one.

How: domain/scaling.py holds providers (credentials sealed per provider and field), groups, rules, approvals and the scaler loop. The scaler holds a lease in one process, reconciles each unit with its provider and its worker's heartbeat, drains busy workers before letting them go, stops a group at its budget's cap, and pauses a group after three failures. domain/scaling_drivers.py is the driver interface. Its first driver, This machine, runs more lens worker processes at no cost. Cloud, Proxmox, SSH and model-host drivers are planned and build on this interface. A unit gets a one-hour, one-use mesh join token when the mesh is on, never a long-lived secret.

Motivation and Context

Adeel asked for auto scaling providers for models and worker nodes, with AWS-style rules, all auditable and agent-native. This PR is the core plus the first provider. Design: /mnt/project-files/autoscaling/design.md in the project.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md. (n/a: the title and docs/scaling.md say it)

Done questions (AGENTS.md)

  • Goal: delivers what the user wanted, merged on green CI. The core and the first provider; cloud and model providers come in the next PRs.
  • Agents: REST /api/v1/scaling, MCP tools scaling, propose_scaling_group, change_scaling_group, set_scaling_desired, pause_scaling_group, terminate_scaling_unit, and the same in the assistant's server tools.
  • Zero setup: nothing to install. Drivers that need a library fetch it when a provider of their kind is first saved.
  • Fewest clicks: one switch, and one Approve per group. A group made or changed by a person in the web app is approved as it's saved.
  • Configurable: Settings › Auto scaling has the switch and the timings, with defaults. Nothing in the setup wizard.
  • Light: off by default. While off with nothing running, the scaler doesn't even take its lease.
  • Private and secure: credentials sealed and shown only as set. Approval only from a signed-in web session. Threat model: entry point plus P-SCALING.
  • Cost: every unit's cost is accrued into the activity ledger as an estimate. Group budgets are real Lens budgets (scale_group:<id>), and the all budget stops groups too.
  • User decides: nothing launches without the person's approval of the terms. Widening the terms takes the approval away. Turning scaling on from the assistant always asks. Existing defaults are unchanged.
  • Upgrades: new SCHEMALESS tables only, defined idempotently. No change to stored data.
  • Honest: docs and README label it in progress. This machine is built; other providers are planned.
  • Tests, docs and generated files: 27 backend tests and 3 web tests. docs/scaling.md, README, requirements, budgets and the threat model are updated. The OpenAPI client was regenerated with make openapi.
  • Open: no new dependency.
  • Reported in the project thread. "Refine later" is in docs/scaling.md.
  • Reuse: budgets, the activity ledger, sealing, the job workers' drain, the services lease, schedule's cron and the assistant's approvals.

Local checks: the full backend suite passed (1649 passed, 23 skipped), along with ruff, mypy, mkdocs build --strict, check_requirements, validate_threat_model and jest for the new section. ci/local-ci.sh --pr follows on this PR.


Generated by Claude Code

Providers with sealed credentials, scaling groups with target, step and schedule
rules, approvals only a web session gives, budgets as Lens budgets, a scaler loop
with a lease, REST routes, schemas, settings and tables.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALjNbLobvPe7VwvDL8j7V3
…chine as the first provider

Scaling groups launch units on a provider between min and max, by target, step
and schedule rules, within a monthly budget, and launch nothing until a person
signed in to the web app approves their terms. Agents propose and manage groups
over the API, MCP and the assistant, and never approve. The scaler holds a
lease, accrues each unit's cost into the activity ledger as an estimate, stops
a group at its budget's cap, drains busy workers before letting them go, and
pauses a group after three failures. This machine runs more lens worker
processes at no cost. Threat model: P-SCALING.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALjNbLobvPe7VwvDL8j7V3
…h group's terms

The web app gets an Auto scaling section under System: the master switch,
the scaler's timings, and each group with its terms in words, an Approve
button for a group waiting on the person, and Pause or Resume.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ALjNbLobvPe7VwvDL8j7V3
…-azm2mb

# Conflicts:
#	fastapi_backend/app/api/v1/router.py
#	fastapi_backend/app/domain/ai_tools.py
#	nextjs-frontend/app/openapi-client/sdk.gen.ts
#	nextjs-frontend/app/openapi-client/types.gen.ts
#	nextjs-frontend/openapi.json
#	threat-model.md
@adeelahmad
adeelahmad merged commit c0b75a7 into main Oct 18, 2026
12 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-azm2mb branch October 18, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0