Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(agent-runtime): show question in intervention summary (#19254)

Tsukib762bbdd7d7b
diff --git a/apps/server/src/services/heterogeneousAgent/HeterogeneousPersistenceHandler.ts b/apps/server/src/services/heterogeneousAgent/HeterogeneousPersistenceHandler.ts
index 1b5c7d35ddb..f59aad28cd1 100644
--- a/apps/server/src/services/heterogeneousAgent/HeterogeneousPersistenceHandler.ts
+++ b/apps/server/src/services/heterogeneousAgent/HeterogeneousPersistenceHandler.ts
@@ -202,12 +202,29 @@ interface StoredHeterogeneousIntervention {
}
const HETEROGENEOUS_INTERVENTION_STATE_KEY = 'heterogeneousIntervention';
+const MAX_INTERVENTION_SUMMARY_LENGTH = 160;
+
+const interventionSummary = (
+ request?: AgentInterventionRequestData,
+ reviewDetail?: Extract<
+ AgentInterventionReviewDetail,
+ { type: 'permission' | 'plan' | 'question' }
+ >,
+): string => {
+ if (reviewDetail?.type === 'question') {
+ const question = reviewDetail.questions[0]?.question.trim().replaceAll(/\s+/g, ' ');
+ if (question) {
+ const characters = [...question];
+ return characters.length > MAX_INTERVENTION_SUMMARY_LENGTH
+ ? `${characters.slice(0, MAX_INTERVENTION_SUMMARY_LENGTH - 1).join('')}…`
+ : question;
+ }
+ }
-const interventionSummary = (request?: AgentInterventionRequestData): string => {
const provider = request?.provider ?? 'heterogeneous-agent';
const kind = request?.interactionKind ?? 'question';
const apiName = request?.apiName || 'interaction';
- return `${provider} ${kind}: ${apiName}`.slice(0, 160);
+ return `${provider} ${kind}: ${apiName}`.slice(0, MAX_INTERVENTION_SUMMARY_LENGTH);
};
const buildHeterogeneousReviewDetail = (
@@ -1299,8 +1316,9 @@ export class HeterogeneousPersistenceHandler {
);
}
- const summary = interventionSummary(intent.request);
const reviewRequest = sanitizeAgentInterventionRequestForReview(intent.request);
+ const reviewDetail = reviewRequest ? buildHeterogeneousReviewDetail(reviewRequest) : undefined;
+ const summary = interventionSummary(intent.request, reviewDetail);
const transitionKey = `${state.operationId}:${intent.toolCallId}:${intent.transition}`;
const pendingTransitionKey = `${state.operationId}:${intent.toolCallId}:pending`;
const requiresPendingReviewNotification =
@@ -1309,7 +1327,7 @@ export class HeterogeneousPersistenceHandler {
!state.notifiedInterventionTransitions.has(pendingTransitionKey);
if (
requiresPendingReviewNotification &&
- (!reviewRequest?.interactionKind || !reviewRequest.provider)
+ (!reviewRequest?.interactionKind || !reviewRequest.provider || !reviewDetail)
) {
throw new Error(
`Unsafe heterogeneous intervention review payload toolCallId=${intent.toolCallId}`,
@@ -1336,7 +1354,7 @@ export class HeterogeneousPersistenceHandler {
if (!this.deps.userId || state.notifiedInterventionTransitions.has(transitionKey)) return;
if (!state.notifiedInterventionTransitions.has(pendingTransitionKey)) {
- if (!reviewRequest?.interactionKind || !reviewRequest.provider) {
+ if (!reviewRequest?.interactionKind || !reviewRequest.provider || !reviewDetail) {
throw new Error(
`Unsafe heterogeneous intervention review payload toolCallId=${intent.toolCallId}`,
);
@@ -1391,7 +1409,7 @@ export class HeterogeneousPersistenceHandler {
items: [
{
allowedActions,
- detail: buildHeterogeneousReviewDetail(reviewRequest),
+ detail: reviewDetail,
interactionKind: reviewRequest.interactionKind,
provider: reviewRequest.provider,
requestRevision: {
diff --git a/apps/server/src/services/heterogeneousAgent/__tests__/HeterogeneousPersistenceHandler.eventBranches.test.ts b/apps/server/src/services/heterogeneousAgent/__tests__/HeterogeneousPersistenceHandler.eventBranches.test.ts
index 8e057ed36ad..cae76f1cb7a 100644
--- a/apps/server/src/services/heterogeneousAgent/__tests__/HeterogeneousPersistenceHandler.eventBranches.test.ts
+++ b/apps/server/src/services/heterogeneousAgent/__tests__/HeterogeneousPersistenceHandler.eventBranches.test.ts
@@ -1059,33 +1059,39 @@ describe('HeterogeneousPersistenceHandler β€” event branch coverage', () => {
]);
expect(notifyAgentInterventionRequired).toHaveBeenCalledTimes(1);
- expect(notifyAgentInterventionRequired.mock.calls[0][0].items[0]).toMatchObject({
- detail: {
- questions: [
- {
- header: 'Producer ACK E2E',
- id: 'question_1',
- multiple: false,
- options: [
- {
- description: 'Proceed with validation.',
- id: 'Continue',
- label: 'Continue',
- },
+ expect(notifyAgentInterventionRequired.mock.calls[0][0]).toMatchObject({
+ items: [
+ {
+ detail: {
+ questions: [
{
- description: 'Halt validation.',
- id: 'Stop',
- label: 'Stop',
+ header: 'Producer ACK E2E',
+ id: 'question_1',
+ multiple: false,
+ options: [
+ {
+ description: 'Proceed with validation.',
+ id: 'Continue',
+ label: 'Continue',
+ },
+ {
+ description: 'Halt validation.',
+ id: 'Stop',
+ label: 'Stop',
+ },
+ ],
+ question: 'Continue read only validation?',
},
],
- question: 'Continue read only validation?',
+ title: 'Producer ACK E2E',
+ type: 'question',
},
- ],
- title: 'Producer ACK E2E',
- type: 'question',
- },
- interactionKind: 'question',
- provider: 'claude-code',
+ interactionKind: 'question',
+ provider: 'claude-code',
+ summary: 'Continue read only validation?',
+ },
+ ],
+ summary: 'Continue read only validation?',
});
expect(h.messageModel.updatePluginState).toHaveBeenCalledWith(
expect.any(String),
@@ -1098,6 +1104,106 @@ describe('HeterogeneousPersistenceHandler β€” event branch coverage', () => {
);
});
+ it('uses only the sanitized first question for a multi-question summary', async () => {
+ const h = createHarness({ topicAgentId: 'agent-test' });
+
+ await ingest(h, [
+ buildEvent('agent_intervention_request', 0, {
+ apiName: 'askUserQuestion',
+ arguments: JSON.stringify({
+ privateRawArgument: 'must not appear in the summary',
+ questions: [
+ {
+ header: 'Validation',
+ multiSelect: false,
+ options: [
+ {
+ description: 'Sensitive option detail',
+ label: 'Continue',
+ },
+ ],
+ question: 'Which validation path should I use?',
+ },
+ {
+ header: 'Follow-up',
+ multiSelect: false,
+ options: [{ label: 'Production' }],
+ question: 'Which environment should I target?',
+ },
+ ],
+ }),
+ deadline: 1_900_000_000_000,
+ identifier: 'claude-code',
+ interactionKind: 'question',
+ provider: 'claude-code',
+ toolCallId: 'claude-question-summary',
+ }),
+ ]);
+
+ const notification = notifyAgentInterventionRequired.mock.calls[0][0];
+ expect(notification.summary).toBe('Which validation path should I use?');
+ expect(notification.items[0].summary).toBe('Which validation path should I use?');
+ });
+
+ it('normalizes and safely truncates a long question summary', async () => {
+ const h = createHarness({ topicAgentId: 'agent-test' });
+ const longQuestion = ` Confirm\n\t${'πŸ˜€'.repeat(170)} now? `;
+
+ await ingest(h, [
+ buildEvent('agent_intervention_request', 0, {
+ apiName: 'askUserQuestion',
+ arguments: JSON.stringify({
+ questions: [
+ {
+ header: 'Long question',
+ multiSelect: false,
+ options: [{ label: 'Continue' }],
+ question: longQuestion,
+ },
+ ],
+ }),
+ deadline: 1_900_000_000_000,
+ identifier: 'claude-code',
+ interactionKind: 'question',
+ provider: 'claude-code',
+ toolCallId: 'claude-long-question-summary',
+ }),
+ ]);
+
+ const summary = notifyAgentInterventionRequired.mock.calls[0][0].summary;
+ expect(summary).toBe(`Confirm ${'πŸ˜€'.repeat(151)}…`);
+ expect([...summary]).toHaveLength(160);
+ });
+
+ it('keeps the technical fallback when the sanitized question has no visible text', async () => {
+ const h = createHarness({ topicAgentId: 'agent-test' });
+
+ await ingest(h, [
+ buildEvent('agent_intervention_request', 0, {
+ apiName: 'askUserQuestion',
+ arguments: JSON.stringify({
+ questions: [
+ {
+ header: 'Blank question',
+ multiSelect: false,
+ options: [{ label: 'Continue' }],
+ question: ' \n\t ',
+ },
+ ],
+ }),
+ deadline: 1_900_000_000_000,
+ identifier: 'claude-code',
+ interactionKind: 'question',
+ provider: 'claude-code',
+ toolCallId: 'claude-blank-question-summary',
+ }),
+ ]);
+
+ const notification = notifyAgentInterventionRequired.mock.calls[0][0];
+ expect(notification.summary).toBe('claude-code question: askUserQuestion');
+ expect(notification.items[0].summary).toBe('claude-code question: askUserQuestion');
+ });
+
it('notifies pending once, ignores the publish leg, and notifies terminal only on ACK', async () => {
const h = createHarness({ topicAgentId: 'agent-test' });
const requestId = '018fbd8e-7baf-7c6d-8000-000000000001';