Repository navigation
fix(core): validate instruction entry keys outside HTTP - #56689
Open
kitlangton wants to merge 2 commits into
Open
kitlangton wants to merge 2 commits into
kitlangton wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
The fix works and I found nothing that should block a merge. I copied the new session-runner tests onto the base branch: put saved "Bad Key" instead of rejecting it, and load crashed in Instructions.Key.make. With this PR both cases behave as described. The nearby core, schema and protocol tests pass, and so do the core and server type checks.
Public API impact (experimental session instructions API, backwards compatible):
- OpenAPI:
InstructionEntry.KeygainsmaxLength: 128. Keys longer than 128 characters now get a 400 response; nothing else that was valid before is rejected. @opencode/schema/instruction-entrygainsMaxKeyLengthandInvalidKeyError(InstructionEntryInvalidKeyError).- In-process
InstructionEntry.Service.put/removecan now fail withInvalidKeyError. HTTP callers still get the sameInvalidRequestErroras before.
No concerns.
This branch has not been deployed
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.
Why
InstructionEntry.Key(/^[a-z0-9][a-z0-9._-]*$/u) was previously enforced by transport schemas and had no maximum length. Direct callers ofInstructionEntry.Service.putandremove(including Effect plugins via #56550) could write malformed keys like"Bad Key"or"a/b"directly intosession_instruction_entry. On the next step boundary,InstructionEntry.loadcalledInstructions.Key.make(\api/${entry.key}`), which either defected and broke every subsequent step of the session ("Bad Key") or admitted a key containing/("a/b"`) that could never be addressed or deleted over HTTP.What Changes
InstructionEntry.MaxKeyLength = 128andSchema.isMaxLength(128)toInstructionEntry.Keyin@opencode/schema/instruction-entry(propagated as"maxLength": 128inopenapi.json).InstructionEntry.InvalidKeyError(InstructionEntryInvalidKeyError) alongsideValueTooLargeErrorand decodesinput.keywithInstructionEntry.Keyat the start ofInstructionEntry.putandInstructionEntry.remove, failing with a typed error instead of persisting an invalid key or defecting later.InstructionEntryInvalidKeyErrortoInvalidRequestError(field: "key") inSessionHandlerso the HTTP error contract stays unchanged.InstructionEntry.loadto validate stored row keys withInstructionEntry.Keyand skip malformed rows withEffect.logWarningrather than defecting insideInstructions.Key.make, preventing pre-existing bad rows from bricking a session.keyInstructionEntry.put/remove"deploy-target"(1..128chars matching/^[a-z0-9][a-z0-9._-]*$/u)InstructionEntry.put/remove"","Bad Key","-leading","a/b"remove)InstructionEntry.InvalidKeyErrorInstructionEntry.put/remove"a".repeat(129)400 InvalidRequestErrorover HTTP;InstructionEntry.InvalidKeyErrorin-process)InstructionEntry.load"Bad Key"or"a/b""Bad Key"; admits unaddressableapi/a/bon"a/b"Scope
Validates instruction entry keys at the Core service boundary, bounds key length to 128 characters in Schema/OpenAPI, and guards
InstructionEntry.loadagainst pre-existing invalid rows. This hardens the core path that #56550 (plugin exposure) and the planned graduation of the session instructions API rely on.Verification
packages/schema/test/contract-hygiene.test.ts: 16 passed (restricts instruction entry keys to slash-free lowercase identifiers up to 128 characters).packages/protocol/test/openapi-patterns.test.ts: 1 passed (verifiesInstructionEntry.KeyemitsmaxLength: 128and pattern in OpenAPI).packages/core/test/session-runner.test.ts: 15 passed across 3 reruns (validates API instruction entry keys on put and removeandskips stored instruction entries with malformed keys when loading).bun run checkpassed with 0 errors.Added by the opencode bot (AI-generated).
Public API: adds maxLength 128 to InstructionEntry.Key and a new InstructionEntryInvalidKeyError from put/remove in process (backwards compatible apart from rejecting keys over 128 chars)