Skip to content

Commit 0998916

Browse files
authored
fix: Deprecate isFinal overrides in AgentEmitter interrupted state me… (a2aproject#989)
fix: Deprecate isFinal overrides in AgentEmitter interrupted state methods
1 parent 305c127 commit 0998916

2 files changed

Lines changed: 34 additions & 33 deletions

File tree

‎server-common/src/main/java/org/a2aproject/sdk/server/tasks/AgentEmitter.java‎

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -115,28 +115,14 @@ public AgentEmitter(RequestContext context, EventQueue eventQueue) {
115115
this.contextId = context.getContextId();
116116
}
117117

118-
private void updateStatus(TaskState taskState) {
119-
updateStatus(taskState, null, taskState.isFinal());
120-
}
121-
122118
/**
123119
* Updates the task status to the given state with an optional message.
124120
*
125121
* @param taskState the new task state
126122
* @param message optional message to include with the status update
127123
*/
128124
public void updateStatus(TaskState taskState, @Nullable Message message) {
129-
updateStatus(taskState, message, taskState.isFinal());
130-
}
131-
132-
/**
133-
* Updates the task status to the given state with an optional message and finality flag.
134-
*
135-
* @param state the new task state
136-
* @param message optional message to include with the status update
137-
* @param isFinal whether this is a final status (prevents further updates)
138-
*/
139-
private void updateStatus(TaskState state, @Nullable Message message, boolean isFinal) {
125+
boolean isFinal = taskState.isFinal();
140126
// Check terminal state first (fail fast)
141127
if (terminalStateReached.get()) {
142128
throw new IllegalStateException("Cannot update task status - terminal state already reached");
@@ -152,7 +138,7 @@ private void updateStatus(TaskState state, @Nullable Message message, boolean is
152138
TaskStatusUpdateEvent event = TaskStatusUpdateEvent.builder()
153139
.taskId(taskId)
154140
.contextId(contextId)
155-
.status(new TaskStatus(state, message, null))
141+
.status(new TaskStatus(taskState, message, null))
156142
.build();
157143
eventQueue.enqueueEvent(event);
158144
}
@@ -371,7 +357,7 @@ public void reject(@Nullable Message message) {
371357
* Marks the task as INPUT_REQUIRED, indicating the agent needs user input to continue.
372358
*/
373359
public void requiresInput() {
374-
requiresInput(null, false);
360+
requiresInput(null);
375361
}
376362

377363
/**
@@ -380,33 +366,39 @@ public void requiresInput() {
380366
* @param message optional message to include
381367
*/
382368
public void requiresInput(@Nullable Message message) {
383-
requiresInput(message, false);
369+
updateStatus(TaskState.TASK_STATE_INPUT_REQUIRED, message);
384370
}
385371

386372
/**
387-
* Marks the task as INPUT_REQUIRED with a finality flag.
373+
* Marks the task as INPUT_REQUIRED.
388374
*
389-
* @param isFinal whether this is a final status (prevents further updates)
375+
* @param isFinal ignored — interrupted states are not final per the A2A specification.
376+
* Use {@link #requiresInput()} instead.
377+
* @deprecated The {@code isFinal} parameter has no effect. Use {@link #requiresInput()} instead.
390378
*/
379+
@Deprecated(forRemoval = true)
391380
public void requiresInput(boolean isFinal) {
392-
requiresInput(null, isFinal);
381+
requiresInput();
393382
}
394383

395384
/**
396-
* Marks the task as INPUT_REQUIRED with an optional message and finality flag.
385+
* Marks the task as INPUT_REQUIRED with an optional message.
397386
*
398387
* @param message optional message to include
399-
* @param isFinal whether this is a final status (prevents further updates)
388+
* @param isFinal ignored — interrupted states are not final per the A2A specification.
389+
* Use {@link #requiresInput(Message)} instead.
390+
* @deprecated The {@code isFinal} parameter has no effect. Use {@link #requiresInput(Message)} instead.
400391
*/
392+
@Deprecated(forRemoval = true)
401393
public void requiresInput(@Nullable Message message, boolean isFinal) {
402-
updateStatus(TaskState.TASK_STATE_INPUT_REQUIRED, message, isFinal);
394+
requiresInput(message);
403395
}
404396

405397
/**
406398
* Marks the task as AUTH_REQUIRED, indicating the agent needs authentication to continue.
407399
*/
408400
public void requiresAuth() {
409-
requiresAuth(null, false);
401+
requiresAuth(null);
410402
}
411403

412404
/**
@@ -415,26 +407,32 @@ public void requiresAuth() {
415407
* @param message optional message to include
416408
*/
417409
public void requiresAuth(@Nullable Message message) {
418-
requiresAuth(message, false);
410+
updateStatus(TaskState.TASK_STATE_AUTH_REQUIRED, message);
419411
}
420412

421413
/**
422-
* Marks the task as AUTH_REQUIRED with a finality flag.
414+
* Marks the task as AUTH_REQUIRED.
423415
*
424-
* @param isFinal whether this is a final status (prevents further updates)
416+
* @param isFinal ignored — interrupted states are not final per the A2A specification.
417+
* Use {@link #requiresAuth()} instead.
418+
* @deprecated The {@code isFinal} parameter has no effect. Use {@link #requiresAuth()} instead.
425419
*/
420+
@Deprecated(forRemoval = true)
426421
public void requiresAuth(boolean isFinal) {
427-
requiresAuth(null, isFinal);
422+
requiresAuth();
428423
}
429424

430425
/**
431-
* Marks the task as AUTH_REQUIRED with an optional message and finality flag.
426+
* Marks the task as AUTH_REQUIRED with an optional message.
432427
*
433428
* @param message optional message to include
434-
* @param isFinal whether this is a final status (prevents further updates)
429+
* @param isFinal ignored — interrupted states are not final per the A2A specification.
430+
* Use {@link #requiresAuth(Message)} instead.
431+
* @deprecated The {@code isFinal} parameter has no effect. Use {@link #requiresAuth(Message)} instead.
435432
*/
433+
@Deprecated(forRemoval = true)
436434
public void requiresAuth(@Nullable Message message, boolean isFinal) {
437-
updateStatus(TaskState.TASK_STATE_AUTH_REQUIRED, message, isFinal);
435+
requiresAuth(message);
438436
}
439437

440438
/**
@@ -569,7 +567,6 @@ public void addTask(Task task) {
569567
* .taskId(context.getTaskId())
570568
* .contextId(context.getContextId())
571569
* .status(new TaskStatus(TaskState.WORKING))
572-
* .isFinal(false)
573570
* .build();
574571
* emitter.emitEvent(event);
575572
* }

‎server-common/src/test/java/org/a2aproject/sdk/server/tasks/AgentEmitterTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,14 @@ public void testRequiresInputWithMessage() throws Exception {
184184
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_INPUT_REQUIRED, SAMPLE_MESSAGE);
185185
}
186186

187+
@SuppressWarnings("deprecation")
187188
@Test
188189
public void testRequiresInputWithFinalTrue() throws Exception {
189190
agentEmitter.requiresInput(true);
190191
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_INPUT_REQUIRED, null);
191192
}
192193

194+
@SuppressWarnings("deprecation")
193195
@Test
194196
public void testRequiresInputWithMessageAndFinalTrue() throws Exception {
195197
agentEmitter.requiresInput(SAMPLE_MESSAGE, true);
@@ -208,12 +210,14 @@ public void testRequiresAuthWithMessage() throws Exception {
208210
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_AUTH_REQUIRED, SAMPLE_MESSAGE);
209211
}
210212

213+
@SuppressWarnings("deprecation")
211214
@Test
212215
public void testRequiresAuthWithFinalTrue() throws Exception {
213216
agentEmitter.requiresAuth(true);
214217
checkTaskStatusUpdateEventOnQueue(false, TaskState.TASK_STATE_AUTH_REQUIRED, null);
215218
}
216219

220+
@SuppressWarnings("deprecation")
217221
@Test
218222
public void testRequiresAuthWithMessageAndFinalTrue() throws Exception {
219223
agentEmitter.requiresAuth(SAMPLE_MESSAGE, true);

0 commit comments

Comments
 (0)