Skip to content

Commit c3a3c88

Browse files
springai/multimodel: capture previous response before signaling
Same bug pattern that RagApplication had: the polling loop compared against an empty-string baseline, so the very first poll could return the stale prior response and print it as if it were the new one. Capture previousResponse before sending the chat signal and wait until getLastResponse() differs from that pre-signal baseline. Also drop the redundant initial Thread.sleep(100) — the loop's own sleep handles backoff, and reading immediately is fine when we're comparing against the pre-signal baseline. Addresses Copilot review on PR #775. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4d32397 commit c3a3c88

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

springai/multimodel/src/main/java/io/temporal/samples/springai/multimodel/MultiModelApplication.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,17 @@ public void run(String... args) throws Exception {
117117
continue;
118118
}
119119

120+
// Capture current response BEFORE sending so we can detect the change against
121+
// the pre-signal baseline (not against an empty string — the workflow may already
122+
// hold the previous prompt's reply).
123+
String previousResponse = workflowStub.getLastResponse();
120124
System.out.println("[Sending to " + modelName + " model...]");
121-
122-
// Send the message via signal
123125
workflowStub.chat(modelName, message);
124126

125-
// Wait a moment for processing, then query for response
126-
Thread.sleep(100);
127-
128-
// Poll for response (in production, you'd use a more sophisticated approach)
129-
String lastResponse = "";
127+
// Poll until the response changes from the pre-signal baseline.
130128
for (int i = 0; i < 300; i++) { // Wait up to 30 seconds
131129
String response = workflowStub.getLastResponse();
132-
if (!response.isEmpty() && !response.equals(lastResponse)) {
130+
if (!response.equals(previousResponse)) {
133131
System.out.println(
134132
"\n[" + modelName.toUpperCase(java.util.Locale.ROOT) + "]: " + response + "\n");
135133
break;

0 commit comments

Comments
 (0)