PatrickEifler opened a new issue, #1515: URL: https://github.com/apache/flink-agents/issues/1515
### Search before asking - [x] I searched in the [issues](https://github.com/apache/flink-agents/issues) and found nothing similar. ### Description Since #1505, a Java agent's declared output type (`toDataStream(TypeInformation)`, `toDataStream(Class)`, `toTable(TypeInformation)`, `toTable(Class)`) is applied directly to the agent operator. The operator promises that type to Flink, but it emits whatever the action put into the `OutputEvent` without checking it. If an action emits a payload of a different type, the job fails with a `ClassCastException` from the output serializer or a chained downstream operator. The error does not say which agent or event produced the value, or that the cause is a mismatch with the declared output type. Example: ```java public static class LengthAgent extends Agent { @Action(EventType.InputEvent) public static void handle(Event event, RunnerContext ctx) { String input = (String) InputEvent.fromEvent(event).getInput(); ctx.sendEvent(new OutputEvent(input.length())); // emits Integer } } agentsEnv.fromDataStream(input, v -> v) .apply(new LengthAgent()) .toDataStream(String.class); // declared as String ``` **Proposal** Check each Java output payload against the declared output class before the operator emits it. On a mismatch, fail with an `IllegalStateException` that names the agent, the event type, the emitted class and the declared class, and points to the fix (emit the declared type, or declare a matching type in `toDataStream(...)` / `toTable(...)`). - Subtypes of the declared class are accepted. - `null` payloads are left to the serializer, as today. - No check for an `Object` declared type (untyped `toDataStream()` / `toTable(Schema)`), or for Python pipelines, whose output is pickled bytes. - The declared type is captured through Flink's `setOutputType` hook on `ActionExecutionOperatorFactory`. No public API changes. Pipelines that emit matching payloads are unaffected. Pipelines with a mismatch already fail today; only the error changes. ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
