Skip to content

Commit b10a54d

Browse files
phenomenon0claude
andcommitted
fix: streaming validator — surface limit errors, reject unknown args
- Go: append error to v.errors before setting StateError on buffer/field limit hit - Go/JS/Rust: record error on unknown argument instead of silent return - Matches Python reference behavior for cross-runtime parity Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b3fd01f commit b10a54d

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

go/glyph/stream_validator.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,18 @@ func (v *StreamingValidator) PushToken(token string) *StreamValidationResult {
308308
func (v *StreamingValidator) processChar(char rune) {
309309
// Check hard limits before processing
310310
if v.buffer.Len() >= v.maxBufferSize {
311+
v.errors = append(v.errors, StreamValidationError{
312+
Code: ErrCodeLimitExceeded,
313+
Message: "Buffer size limit exceeded",
314+
})
311315
v.state = StateError
312316
return
313317
}
314318
if len(v.parsedFields) >= v.maxFieldCount {
319+
v.errors = append(v.errors, StreamValidationError{
320+
Code: ErrCodeLimitExceeded,
321+
Message: "Field count limit exceeded",
322+
})
315323
v.state = StateError
316324
return
317325
}
@@ -470,6 +478,11 @@ func (v *StreamingValidator) validateField(key string, value interface{}) {
470478

471479
argSchema, exists := schema.Args[key]
472480
if !exists {
481+
v.errors = append(v.errors, StreamValidationError{
482+
Code: ErrCodeUnknownTool,
483+
Message: fmt.Sprintf("Unknown argument: %s", key),
484+
Field: key,
485+
})
473486
return
474487
}
475488

js/src/stream_validator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ export class StreamingValidator {
524524

525525
const argSchema = hasOwn(schema.args, key) ? schema.args[key] : undefined;
526526
if (!argSchema) {
527+
this.addError(ErrorCode.UnknownTool, `Unknown argument: ${key}`, key);
527528
return;
528529
}
529530

rust/glyph-codec/src/stream_validator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,13 @@ impl StreamingValidator {
608608

609609
let arg_schema = match schema.args.get(key).cloned() {
610610
Some(s) => s,
611-
None => return,
611+
None => {
612+
self.add_error(
613+
ValidationError::new(ErrorCode::UnknownTool, &format!("Unknown argument: {}", key))
614+
.with_field(key),
615+
);
616+
return;
617+
}
612618
};
613619

614620
if !Self::type_matches(&arg_schema, value) {

0 commit comments

Comments
 (0)