Repository navigation
spec(admin): v0.1.25.26 — bulk-action budget endpoint - #55
Merged
Merged
Conversation
Add `POST /v1/admin/budgets/bulk-action` to resolve cycles-server-admin issue #99 ("Bulk Budget Reset at Tenant or Parent-Scope Level"). Operators rolling over a billing period can now issue one filtered bulk request instead of iterating listBudgets + per-row fundBudget. Single operation-discriminated endpoint following the existing tenant/webhook bulk-action pattern. The `action` enum (`CREDIT | DEBIT | RESET | RESET_SPENT | REPAY_DEBT`) mirrors BudgetFundingRequest.operation so any per-row fundBudget mutation is also expressible in bulk; the action determines which payload fields are required. New schemas (all additive): - `BudgetBulkFilter` — mirrors listBudgets query params; tenant_id REQUIRED for cross-tenant safety. Cascading reset across a scope subtree uses `scope_prefix` (no separate cascade flag). - `BudgetBulkActionRequest` — `filter` + `action` + `amount` (required for all current actions) + optional `spent` (RESET_SPENT only) + optional `reason` + `expected_count` + `idempotency_key`. - `BudgetBulkActionResponse` — per-row outcome envelope reusing `BulkActionRowOutcome` (succeeded[] / failed[] / skipped[]). Safety semantics match the existing tenant/webhook bulk-action contract: 500-row hard cap (HTTP 400 LIMIT_EXCEEDED), expected_count preflight (HTTP 409 COUNT_MISMATCH with no writes on drift), 15-min idempotency_key replay window. HTTP 200 even when rows fail; per-row codes BUDGET_EXCEEDED and INVALID_TRANSITION cover the common cases. AdminKeyAuth only. semantic_base unchanged at 0.1.25.9. Backward compatible (purely additive: one new path, three new schemas; no enum or existing schema changes). Merged admin artifact regenerated. Refs: runcycles/cycles-server-admin#99
…es, filter consistency Review-round fixes on `POST /v1/admin/budgets/bulk-action` (PR #55). No semantic change to the endpoint; consistency and accuracy only. - Action enum now truly mirrors BudgetFundingRequest.operation ordering: [CREDIT, DEBIT, RESET, REPAY_DEBT, RESET_SPENT]. The commit message on the parent claimed "mirrors BudgetFundingRequest" but the last two were swapped. - Added BUDGET_EXCEEDED to BulkActionRowOutcome.error_code known-codes list (was: INVALID_TRANSITION, NOT_FOUND, PERMISSION_DENIED, INTERNAL_ERROR). Budget bulk-ops can legitimately fail a row with BUDGET_EXCEEDED when DEBIT would take remaining negative; clients need to switch on it without treating it as INTERNAL_ERROR. Also clarified that this code set is intentionally broader than the top-level ErrorCode enum — row-level vs. request-level. - BudgetBulkFilter: added minProperties: 1 for consistency with TenantBulkFilter / WebhookBulkFilter. (Always vacuously satisfied because tenant_id is required; the schema shape now matches its siblings.) - Changelog entry corrected: previously implied INVALID_TRANSITION was a top-level ErrorCode enum value (it's a row-level outcome). Rewrote the backward-compat paragraph to distinguish request-level ErrorCode enum additions (none) from the row-level known-codes update (BUDGET_EXCEEDED added). Merged admin artifact regenerated. Idempotent. All checks pass (spectral: 0 errors, validate_changelogs: OK).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
POST /v1/admin/budgets/bulk-actionto resolve cycles-server-admin#99 — operators rolling over a billing period can now issue one filtered bulk request instead of iteratinglistBudgets+ per-rowfundBudget.Single operation-discriminated endpoint following the existing tenant/webhook bulk-action pattern. The
actionenum (CREDIT | DEBIT | RESET | RESET_SPENT | REPAY_DEBT) mirrorsBudgetFundingRequest.operationso any per-rowfundBudgetmutation is also expressible in bulk; the action determines which payload fields are required.New schemas (all additive)
BudgetBulkFilter— mirrorslistBudgetsquery params (scope_prefix,unit,status,over_limit,has_debt,utilization_min/max,search).tenant_idis required (cross-tenant safety: no all-tenant fan-out from a single bulk call). Cascading reset across a scope subtree usesscope_prefix— the hierarchy is encoded in the scope path; no separatecascadeflag.BudgetBulkActionRequest—filter+action+amount(required for all current actions) + optionalspent(RESET_SPENT only) + optionalreasonfor audit trail +expected_countsafety gate +idempotency_key.BudgetBulkActionResponse— per-row outcome envelope reusingBulkActionRowOutcome(succeeded[]/failed[]/skipped[]).Safety semantics (mirrors tenant/webhook bulk-action)
LIMIT_EXCEEDEDexpected_countpreflight → HTTP 409COUNT_MISMATCHwith no writes on driftidempotency_keyreplay windowBUDGET_EXCEEDED(DEBIT would take remaining negative) andINVALID_TRANSITION(unit mismatch, ledger CLOSED) cover the common casesfundBudgetAudit log
One
AuditLogEntryper invocation (not per row),actor_type=ADMIN_ON_BEHALF_OF, embedding the full per-row outcome so security review can reconstruct exactly what changed without replaying the bulk request.Why one endpoint, not five
The earlier issue thread proposed a unified bulk-ops surface (vs. a dedicated
bulk-reset). Rationale, locked in here: one auth/audit/idempotency contract, the same envelope works for future asks ("credit all budgets in scope X", "repay debt across a subtree"), and matches the tenant/webhook bulk-action pattern already shipped in cycles-server-admin v0.1.25.26 (PR #109 there). Tradeoff acknowledged: slightly more validation surface (action-discriminated payload), mitigated by the action enum + per-action required-field rules called out in the schema descriptions.Why
scope_prefix, not acascadeflagThe scope hierarchy is already encoded in the canonical scope string (e.g.,
tenant:acme/workspace:eng). A prefix match ontenant:acme/workspace:engmatches that scope and all descendants — that is the cascade. Adding acascade: boolflag would be redundant and would invite the question "cascade from what root?" thatscope_prefixalready answers unambiguously.Why not async for 10k+ budgets
The existing 500-row hard cap (carried over from tenant/webhook bulk-action) sidesteps this entirely. Operators with > 500 budgets in a rollover batch partition by
scope_prefix(the natural partition for cascading resets) and issue multiple bulk requests. No async job runner needed in the spec; if 10k+ tenant scenarios become real, async can be added later as a separate*_asyncshape without breaking the sync contract.Backward compatibility
Purely additive — one new path, three new schemas. No existing endpoint or schema changes. No
ErrorCodeenum additions (BUDGET_EXCEEDED,INVALID_TRANSITION,COUNT_MISMATCH,LIMIT_EXCEEDEDalready present from v0.1.25.23).semantic_baseunchanged at0.1.25.9.Test plan
python scripts/merge_specs.py— admin merged regenerated; merge idempotent (verified via md5 snapshot)npx spectral lint cycles-governance-admin-v0.1.25.yaml— 0 errors (warnings only on pre-existing schemas, none in the new ones)npx spectral lint merged/cycles-openapi-admin-merged.yaml— 0 errorspython scripts/validate_changelogs.py— passes;info.version=0.1.25.26matches latest changelog headingBudgetBulkFilter,BudgetBulkActionRequest,BudgetBulkActionResponse) and the new path appear in the merged admin artifactbulkActionTenants/bulkActionWebhookscontroller pattern (per the comment from amavashev on issue build(deps): bump github/codeql-action from 4.35.5 to 4.36.0 #99)