Skip to content

fix(planetscale): set the deploy request throttler on the endpoint the API serves - #962

Draft
aparajon wants to merge 1 commit into
mainfrom
armand/ps-throttler-endpoint
Draft

fix(planetscale): set the deploy request throttler on the endpoint the API serves#962
aparajon wants to merge 1 commit into
mainfrom
armand/ps-throttler-endpoint

Conversation

@aparajon

@aparajon aparajon commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Why this matters

Every schemabot volume command against a PlanetScale deploy request 404'd. SchemaBot sent PUT /deploy-requests/{n}/throttle with a fractional ratio; the API serves PATCH /deploy-requests/{n}/throttler with a whole percentage. The operator saw an accepted request and the deploy request kept running at its original speed — the worst shape for a throttle control, since it is reached for precisely when something needs to slow down.

What it does

  • Calls the endpoint and body the API actually serves. The wire format converts inside the client, so volume mapping and the local emulator keep carrying the ratio as a fraction.
  • Registers the corrected route and body in the emulator, so it exercises the same contract as the API instead of masking a mismatch.
  • Attaches a bounded, sanitized excerpt of the response body to a failing call. A status line alone cannot distinguish a moved endpoint from a deleted deploy request. The excerpt is log-safe only and is never rendered into PR markdown.

🤖 Generated with Claude Code

…e API serves

Volume on PlanetScale PUT /deploy-requests/{n}/throttle with a fractional
throttle_ratio. The API serves PATCH /deploy-requests/{n}/throttler with a whole
percentage, so every volume command 404'd: the operator saw an accepted request
and the deploy request kept running at its original speed.

The wire format converts inside the client, so volume mapping and LocalScale keep
carrying the ratio as a fraction. LocalScale registers the corrected route and
body, so the emulator exercises the same contract as the API instead of masking
a mismatch.

A failing call now carries a bounded, sanitized excerpt of the response body:
the status line alone cannot distinguish a moved endpoint from a deleted deploy
request. The excerpt is log-safe only and must not be rendered into PR markdown.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 7, 2026 19:10

Copilot AI 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.

Pull request overview

This PR fixes PlanetScale deploy request throttling by aligning SchemaBot’s client and LocalScale emulator with the API contract the server actually serves (method/path + request body), and adds targeted tests to lock the contract in.

Changes:

  • Switch PlanetScale throttling from PUT .../throttle with fractional throttle_ratio to PATCH .../throttler with integer ratio percent, converting units inside the client.
  • Update LocalScale’s route registration and handler to accept the new ratio percent contract while preserving internal fractional storage/behavior.
  • Add unit tests covering wire contract, ratio conversion, and error excerpt sanitation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/psclient/client.go Updates the throttling HTTP call to the served endpoint/body, adds ratio conversion + bounded response excerpt sanitization.
pkg/psclient/client_test.go Adds tests for the throttler endpoint contract, percent conversion, and error excerpt behavior.
pkg/localscale/server.go Registers the emulator route as PATCH .../throttler.
pkg/localscale/handlers_actions.go Updates the emulator handler to decode integer percent ratio and convert to internal fractional throttle ratio.
pkg/engine/planetscale/volume.go Clarifies the meaning of PreviousVolume in the PlanetScale volume result.
Suppressed comments (1)

pkg/psclient/client.go:257

  • sanitizeResponseExcerpt claims the excerpt “cannot break log or table formatting downstream”, but it doesn’t neutralize Markdown table delimiters like |. Since this excerpt can be rendered into PR markdown via existing error plumbing, replacing | with a space (or another safe rune) would better match the safety intent.
// sanitizeResponseExcerpt reads a bounded prefix of an error response body and
// makes it safe to embed in an error string: newlines collapse to spaces and
// non-printable runes are dropped, so the excerpt cannot break log or table
// formatting downstream.
func sanitizeResponseExcerpt(body io.Reader) string {
	raw, err := io.ReadAll(io.LimitReader(body, maxResponseExcerptLen*4))
	if err != nil {
		return "<response body unreadable>"
	}
	cleaned := strings.Map(func(r rune) rune {
		if r == '\n' || r == '\r' || r == '\t' {
			return ' '
		}
		if !unicode.IsPrint(r) {
			return -1
		}
		return r
	}, string(raw))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/psclient/client.go
Comment on lines +228 to +234
// throttleRatioPercent converts SchemaBot's fractional throttle ratio to the
// whole percentage the PlanetScale API expects. Out-of-range values are passed
// through so the API's own validation reports them rather than being silently
// clamped into a ratio the caller did not ask for.
func throttleRatioPercent(ratio float64) int {
return int(math.Round(ratio * 100))
}
Comment thread pkg/psclient/client.go
Comment on lines 217 to +223
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("throttle request failed: %s", resp.Status)
// The status alone does not say why — a 404 on a moved path and a 404 on
// a deleted deploy request read identically. Carry a bounded, sanitized
// excerpt of the body so the cause survives to the logs. Callers must not
// render this into PR markdown.
return fmt.Errorf("throttle deploy request %d (%s/%s) failed: %s: %s",
req.Number, req.Organization, req.Database, resp.Status, sanitizeResponseExcerpt(resp.Body))
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