Skip to content

Workbench budget management + other tweaks - #3948

Open
michaeljguarino wants to merge 3 commits into
masterfrom
fix-mermaid
Open

Workbench budget management + other tweaks#3948
michaeljguarino wants to merge 3 commits into
masterfrom
fix-mermaid

Conversation

@michaeljguarino

@michaeljguarino michaeljguarino commented Aug 2, 2026

Copy link
Copy Markdown
Member

This will allow for a token-bucket style budget mechanic within workbenches. If the monthly quota has exceeded, jobs cannot be spawned until the refill has happened.

Also

  • add difficulty and token price sheet schemas
  • bump mermaid_validator with fix for rust panic in underlying lib
  • persist local server cache between restarts

Test Plan

Test environment: https://console.plrldemo.onplural.sh/cd/clusters/a1748282-ce8b-48ab-ae7e-326e74fce04e/services/f3f89a54-d1a7-4bc8-9152-daa07ede918d/components

Checklist

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have deployed the agent to a test environment and verified that it works as expected (required only when changing agent code).

Plural Flow: console

@michaeljguarino
michaeljguarino requested a review from a team August 2, 2026 17:39
@michaeljguarino michaeljguarino added the enhancement New feature or request label Aug 2, 2026
@soffi-ai

soffi-ai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Soffi AI Summary

This PR introduces a token-bucket budget management system for AI Workbenches, allowing operators to cap monthly AI spending (in dollars or tokens) so that new agent jobs cannot be spawned once the quota is exhausted until the bucket refills. Alongside this core feature, it lands several supporting improvements and fixes:

  • Workbench budget schema (WorkbenchBudget / WorkbenchBudgetAttributes): new GraphQL types expose enabled, maximum, minFree, last, lastUpdated, and unit (DOLLAR or TOKEN) fields on Workbench, wired through to the Elixir server, Go client, and generated TypeScript types.
  • AI price sheet schema (AiPriceSheet / AiPriceSheetAttributes): per-model token pricing (input/output cost per token, provider, model name) added to AiSettings, enabling cost-aware budget tracking across LLM providers.
  • PR difficulty metadata (PullRequestDifficulty, PrChangeType enum): new optional field on PullRequest to classify the estimated complexity and change type (APPLICATION / CONFIGURATION / GITOPS) of a pull request, also surfaced on create/update attributes.
  • Persistent local server ETS cache (PersistentEts): the local cache layer (used for local Elixir server mode) now persists its ETS table contents to disk and reloads them on restart, avoiding cold-cache overhead across restarts.
  • Cloud schemas tool (cloud_schemas.ex): a new AI workbench infrastructure tool that exposes cloud resource schema metadata to agents, backed by a new GetSchemas RPC in the cloud-query gRPC service.
  • Model selection module (model_selection.ex): new Elixir module centralising LLM model-selection logic, likely supporting price-sheet-aware routing.
  • Mermaid validator bump: dependency updated to fix a Rust panic in the underlying library.
  • Workbench heartbeat and environment improvements: minor tuning of the agent heartbeat logic and workbench environment setup.
  • Dead cost-query code removed: lib/console/cost/queries.ex deleted (77 lines removed).

Commits

Commit Summary
0458f31 Core feature commit: introduces Workbench budget management (token-bucket quota with DOLLAR/TOKEN units), AI price sheet schema (per-model input/output pricing in AiSettings), PR difficulty metadata (PrChangeType enum + PullRequestDifficulty), persistent ETS local-server cache (survives restarts), a new cloud_schemas AI tool backed by a new GetSchemas gRPC RPC in cloud-query, and the model_selection module for centralised LLM routing. Also removes dead cost-query code and regenerates all GraphQL/protobuf clients and TypeScript types.
c614342 Fixes the cloud_schemas tool: corrects how schema metadata is fetched and surfaced to AI agents via the cloud-query gRPC service.
604f9b3 Small tuning pass: adjusts workbench heartbeat timing, workbench environment initialisation, memoizer behaviour, and deployment-operator agent args.

Deploy in Soffi


Updated: 2026-08-03 12:45 UTC

@greptile-apps

greptile-apps Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds token-bucket workbench budgets, pull-request difficulty and AI pricing schemas, persistent local cache metadata, and several deployment/runtime tweaks.

  • Adds budget admission checks and usage-based budget consumption for workbench jobs
  • Persists local server ETS cache state across process restarts
  • Extends GraphQL, OpenAPI, TypeScript, and Go generated contracts
  • Adds pull-request difficulty and per-model AI price-sheet embeds
  • Updates global-service throttling and the Mermaid validator dependency

Confidence Score: 4/5

The PR should not merge until budget admission is made atomic and restored cache entries recover when their backing tarballs are missing.

Concurrent requests can spawn jobs from the same remaining budget, while a process restart during the cache sweep/flush window can restore metadata for deleted tarballs and make content fetches fail persistently.

Files Needing Attention: lib/console/deployments/workbenches.ex, lib/console/deployments/local/server.ex, lib/console/deployments/local/persistent_ets.ex

Important Files Changed

Filename Overview
lib/console/deployments/workbenches.ex Adds budget admission and accounting, but job admission is not atomic with persisted budget state.
lib/console/schema/workbench.ex Defines the refillable budget embed and arithmetic; consumption can become negative after admitted work completes.
lib/console/deployments/local/persistent_ets.ex Adds periodic ETS snapshots, but restoration does not validate external files referenced by table entries.
lib/console/deployments/local/server.ex Restores local cache metadata and trusts restored hits even when their tarball files have been removed.
lib/console/schema/deployment_settings.ex Adds validated embedded AI price sheets without an identified defect.
lib/console/schema/pull_request.ex Adds an embedded pull-request difficulty shape with matching persistence migration.
priv/repo/migrations/20260801162842_increase_custom_stack_run_name.exs Adds map columns required by the new Workbench budget and PullRequest difficulty embeds.
lib/console/deployments/global.ex Adjusts global-service stream throttling without an identified correctness issue.
mix.exs Bumps mermaid_validator to the panic-fix release.

Comments Outside Diff (1)

  1. lib/console/deployments/local/server.ex, line 48-50 (link)

    P1 Restored cache hits can be stale

    When the server crashes after a sweep deletes a tarball but before the updated ETS state is flushed, restart restores metadata for the deleted file and this fast path returns it without validation, causing subsequent content fetches to fail with enoent instead of regenerating the artifact.

    Knowledge Base Used: Deployments Engine

Reviews (1): Last reviewed commit: "Workbench budget management + other twea..." | Re-trigger Greptile

Comment thread lib/console/deployments/workbenches.ex Outdated
|> allow(user, :read)
|> when_ok(:insert)
|> notify(:create, user)
with true <- budget_available?(wb) do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Budget admission is non-atomic

If two job-creation requests overlap while the remaining budget is just above min_free, both check the same unlocked workbench state and insert jobs before usage is deducted, causing work to run beyond the configured quota.

Knowledge Base Used: Schema and Repo: Console's Data Model

@michaeljguarino
michaeljguarino force-pushed the fix-mermaid branch 2 times, most recently from d647160 to a15f953 Compare August 2, 2026 18:13
This will allow for a token-bucket style budget mechanic within workbenches. If the monthly quota has exceeded, jobs cannot be spawned until the refill has happened.

Also
* add difficulty and token price sheet schemas
* bump mermaid_validator with fix for rust panic in underlying lib
* persist local server cache between restarts
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requested deployment GitOps PR has been created: https://github.com/pluralsh/plrl-up-demos/pull/2499

It deploys console image tag sha-0458f31b.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this, and wire up the cloud query image with the same sha tag

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitOps deployment PR: https://github.com/pluralsh/plrl-up-demos/pull/2500

Console and cloud-query are pinned to sha-f9b5e74.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment PR created for this revision: https://github.com/pluralsh/plrl-up-demos/pull/2501 (pins Console to sha-daa2a74; Plural Service: mgmt/apps).

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment GitOps PR: https://github.com/pluralsh/plrl-up-demos/pull/2502

Pins Console image tag sha-c6143427 and is annotated Plural Service: mgmt/apps.

@michaeljguarino
michaeljguarino force-pushed the fix-mermaid branch 2 times, most recently from b9f44ae to 7d29e52 Compare August 3, 2026 00:32
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitOps deployment PR

https://github.com/pluralsh/plrl-up-demos/pull/2503

Updates the console GitOps image tag to sha-7d29e52, targeting source revision 7d29e52b6cd1f2c5e871b77e07faa292b2245aac.

Plural Service: mgmt/apps

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment GitOps PR has been created: https://github.com/pluralsh/plrl-up-demos/pull/2504

@michaeljguarino
michaeljguarino force-pushed the fix-mermaid branch 2 times, most recently from 6a62e3d to 310d128 Compare August 3, 2026 02:52
@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment GitOps PR: https://github.com/pluralsh/plrl-up-demos/pull/2505

It deploys console image tag sha-310d128 from PR head 310d128aa02980e2bf3a5270e6e515b35afe53ef.

GitOps PR annotation: Plural Service: mgmt/apps.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment PR created: https://github.com/pluralsh/plrl-up-demos/pull/2506 — updates console to sha-e489f20 (commit e489f20).

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested deploy GitOps PR has been created: https://github.com/pluralsh/plrl-up-demos/pull/2507

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants