Enforce automation length caps at the CLI boundary, not on stored rows - #2219
Open
SawyerHood wants to merge 1 commit into
Open
Enforce automation length caps at the CLI boundary, not on stored rows#2219SawyerHood wants to merge 1 commit into
SawyerHood wants to merge 1 commit into
Conversation
`bb automation create/update` built agent and script executions from argv without the request-side Zod caps the RPC route applies, so an over-cap `--prompt` was persisted and only rejected when the stored row was re-parsed for the response. Because the same capped schema also parsed stored rows, every later `list`, `show`, and repairing `update` for that project failed with the same `too_big` issue. - Parse agent executions and partial agent updates in the CLI with the same request schemas the RPC route uses, and parse inline/file script content with the shared script cap, before anything is persisted. - Split request policy from the stored/response shape: the prompt, script, and scriptFile caps now live only on the request schemas, so rows that already exceed a cap stay readable and repairable. - Make `service.list` skip a malformed row with a warning, like overview. Fixes #2166 Co-Authored-By: Claude <noreply@anthropic.com>
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.
What was wrong
bb automation createandbb automation updatebuilt the agent and script execution payloads from argv and handed them straight to the service, skipping the request-side Zod length caps that theautomations_create/automations_updateRPC routes apply. An over-cap--prompt(8,039 chars against the 8,000 cap) was therefore persisted, and thetoo_bigerror the user saw came from re-parsing the stored row for the response. Because that same capped schema (automationAgentExecutionSchema) was also used to parse stored rows, every laterlist,show, and repairingupdatefor the project failed with the sametoo_bigissue, andlisttook the healthy automations in the project down with it. Report: https://get-bb.github.io/reports/issues/2166.htmlWhat changed
plugins/automationsonly; no wire change, no CLI flag or knob change.src/rpc-types.ts: separated request policy from the stored/response shape. The storedautomationAgentExecutionSchema/automationScriptExecutionSchemano longer carry.max()caps. New exportedautomationPromptRequestSchema,automationScriptRequestSchema, andautomationAgentExecutionRequestSchema, plus a script request variant, composeautomationExecutionRequestSchema(used bycreateAutomationInputSchema/updateAutomationInputSchema), so the RPC routes enforce exactly the caps they did before.agentExecutionUpdateSchemais now exported.src/cli.ts: the argv boundary parses with the same request schemas the RPC route uses before anything is persisted:automationAgentExecutionRequestSchemafor the agent branch of create/complete-update,agentExecutionUpdateSchemafor the partial agent update branch, andautomationScriptRequestSchemafor inline and--script-filecontent. The whole request is deliberately not parsed withupdateAutomationInputSchema: the CLI's script shape carries bothscript(content) andscriptFile(absolute source path), which the RPC-only "exactly one of script | scriptFile" refinement would reject.src/service.ts:listskips a malformed row with a warning, asoverviewalready did, instead of failing the whole project.Rows that already exceed a cap (the reporter's situation) now parse, so
list/showwork andupdate --prompt <short>repairs them.How you verified
describe("automation CLI length caps (#2166)")insrc/automations.test.ts(6 tests, in-memory SQLite, real service + CLI registration): over-cap--prompton update and create is rejected with nothing persisted and the project stays usable; over-cap inline--scripton create and update is rejected before the snapshot file is written; a seeded over-cap row stays listable, showable, and repairable;service.listskips a malformed row and warns; the RPC request schemas still reject over-cap prompt/script on create and update while the stored schema accepts an over-cap prompt. With the fix stashed, all 6 fail (6 failed | 78 passed); with it,84 passed.pnpm exec turbo run typecheck test --filter=bb-plugin-automations: green.scripts/bb-dev-app current,pnpm bb:dev): reran the report's scenario.update --prompt <8039 chars>exits 1 withtoo_bigand the stored prompt stays at 19 chars;createwith an over-cap prompt and with a 262,145-char--scriptboth exit 1 and create nothing;list/showkeep working. Then seeded the over-cap prompt directly into the row via sqlite to mimic a pre-fix victim:listshows both automations,showexits 0,update --prompt 'short again'exits 0 and the stored length becomes 11.Fixes #2166