Skip to content

Commit 1ad643f

Browse files
committed
Cleanup ASYNC_AGENTS_ENABLED
1 parent 477017d commit 1ad643f

File tree

7 files changed

+9
-49
lines changed

7 files changed

+9
-49
lines changed

backend/src/live-user-inputs.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { ASYNC_AGENTS_ENABLED } from '@codebuff/common/old-constants'
2-
31
import { logger } from './util/logger'
42

53
let liveUserInputCheckEnabled = true
@@ -34,14 +32,6 @@ export function cancelUserInput(userId: string, userInputId: string): void {
3432
}
3533
}
3634

37-
export function endUserInput(userId: string, userInputId: string): void {
38-
if (ASYNC_AGENTS_ENABLED) {
39-
// Don't remove user input id, since it can still be triggered by async agents.
40-
} else {
41-
cancelUserInput(userId, userInputId)
42-
}
43-
}
44-
4535
export function checkLiveUserInput(
4636
userId: string | undefined,
4737
userInputId: string,

backend/src/run-agent-step.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { insertTrace } from '@codebuff/bigquery'
22
import { trackEvent } from '@codebuff/common/analytics'
33
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
44
import {
5-
ASYNC_AGENTS_ENABLED,
65
supportsCacheControl,
76
} from '@codebuff/common/old-constants'
87
import { TOOLS_WHICH_WONT_FORCE_NEXT_STEP } from '@codebuff/common/tools/constants'

backend/src/websockets/server.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { ASYNC_AGENTS_ENABLED } from '@codebuff/common/old-constants'
21
import { CLIENT_MESSAGE_SCHEMA } from '@codebuff/common/websockets/websocket-schema'
32
import { isError } from 'lodash'
43
import { WebSocketServer } from 'ws'

backend/src/websockets/websocket-action.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { trackEvent } from '@codebuff/common/analytics'
33
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
44
import db from '@codebuff/common/db/index'
55
import * as schema from '@codebuff/common/db/schema'
6-
import {
7-
ASYNC_AGENTS_ENABLED,
8-
toOptionalFile,
9-
} from '@codebuff/common/old-constants'
6+
import { toOptionalFile } from '@codebuff/common/old-constants'
107
import { getErrorObject } from '@codebuff/common/util/error'
118
import { ensureEndsWithNewline } from '@codebuff/common/util/file'
129
import { generateCompactId } from '@codebuff/common/util/string'
@@ -15,7 +12,6 @@ import { eq } from 'drizzle-orm'
1512
import {
1613
cancelUserInput,
1714
checkLiveUserInput,
18-
endUserInput,
1915
startUserInput,
2016
} from '../live-user-inputs'
2117
import { mainPrompt } from '../main-prompt'
@@ -177,7 +173,7 @@ const onPrompt = async (
177173
message: response,
178174
})
179175
} finally {
180-
endUserInput(userId, promptId)
176+
cancelUserInput(userId, promptId)
181177
const usageResponse = await genUsageResponse(
182178
fingerprintId,
183179
userId,

common/src/old-constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export const API_KEY_ENV_VAR = 'CODEBUFF_API_KEY'
1313
export const INVALID_AUTH_TOKEN_MESSAGE =
1414
'Invalid auth token. You may have been logged out from the web portal. Please log in again.'
1515

16-
// Enable async agents to run tool calls even when main user input is cancelled
17-
export const ASYNC_AGENTS_ENABLED = true
18-
1916
// Allowed model prefixes for validation
2017
export const ALLOWED_MODEL_PREFIXES = [
2118
'anthropic',

npm-app/src/cli.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import path, { basename, dirname, isAbsolute, parse } from 'path'
55
import * as readline from 'readline'
66

77
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
8-
import {
9-
API_KEY_ENV_VAR,
10-
ASYNC_AGENTS_ENABLED,
11-
} from '@codebuff/common/old-constants'
8+
import { API_KEY_ENV_VAR } from '@codebuff/common/old-constants'
129
import {
1310
getAllAgents,
1411
getAgentDisplayName,
@@ -718,9 +715,7 @@ export class CLI {
718715
const client = Client.getInstance()
719716
Spinner.get().stop()
720717
this.isReceivingResponse = false
721-
if (!ASYNC_AGENTS_ENABLED) {
722-
client.cancelCurrentInput()
723-
}
718+
client.cancelCurrentInput()
724719

725720
if (this.shouldReconnectWhenIdle) {
726721
client.reconnect()

npm-app/src/client.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
REQUEST_CREDIT_SHOW_THRESHOLD,
3131
SHOULD_ASK_CONFIG,
3232
UserState,
33-
ASYNC_AGENTS_ENABLED,
3433
API_KEY_ENV_VAR,
3534
} from '@codebuff/common/old-constants'
3635
import { getInitialSessionState } from '@codebuff/common/types/session-state'
@@ -209,7 +208,6 @@ export class Client {
209208
private costMode: CostMode
210209
private responseComplete: boolean = false
211210
private userInputId: string | undefined
212-
private nonCancelledUserInputIds: string[] = []
213211
private currentOnChunk: ((chunk: string | PrintModeEvent) => void) | undefined
214212

215213
public usageData: UsageData = {
@@ -808,17 +806,15 @@ export class Client {
808806
const { requestId, toolName, input, userInputId, mcpConfig } = action
809807

810808
// Check if the userInputId matches or is from a spawned agent
811-
const isValidUserInput = ASYNC_AGENTS_ENABLED
812-
? this.nonCancelledUserInputIds.some((id) => userInputId.startsWith(id))
813-
: this.userInputId && userInputId.startsWith(this.userInputId)
809+
const isValidUserInput =
810+
this.userInputId && userInputId.startsWith(this.userInputId)
814811

815812
if (!isValidUserInput) {
816813
logger.warn(
817814
{
818815
requestId,
819816
toolName,
820817
currentUserInputId: this.userInputId,
821-
nonCancelledUserInputIds: this.nonCancelledUserInputIds,
822818
receivedUserInputId: userInputId,
823819
},
824820
'User input ID mismatch - rejecting tool call request',
@@ -831,9 +827,7 @@ export class Client {
831827
{
832828
type: 'json',
833829
value: {
834-
errorMessage: ASYNC_AGENTS_ENABLED
835-
? `User input ID mismatch: expected one of ${this.nonCancelledUserInputIds.join(', ')}, got ${userInputId}. That user input id might have been cancelled by the user.`
836-
: `User input ID mismatch: expected ${this.userInputId}, got ${userInputId}. Most likely cancelled by user.`,
830+
errorMessage: `User input ID mismatch: expected ${this.userInputId}, got ${userInputId}. Most likely cancelled by user.`,
837831
},
838832
},
839833
],
@@ -1131,9 +1125,6 @@ export class Client {
11311125
loggerContext.clientRequestId = userInputId
11321126
const startTime = Date.now() // Capture start time
11331127

1134-
// Add to non-cancelled list
1135-
this.nonCancelledUserInputIds.push(userInputId)
1136-
11371128
const f = this.subscribeToResponse.bind(this)
11381129

11391130
const { responsePromise, stopResponse } = f(
@@ -1319,11 +1310,6 @@ export class Client {
13191310
return
13201311
}
13211312

1322-
// Remove the cancelled input ID from the non-cancelled list
1323-
this.nonCancelledUserInputIds = this.nonCancelledUserInputIds.filter(
1324-
(id) => id !== this.userInputId,
1325-
)
1326-
13271313
sendActionAndHandleError(this.webSocket, {
13281314
type: 'cancel-user-input',
13291315
authToken: this.user?.authToken,
@@ -1562,10 +1548,8 @@ Go to https://www.codebuff.com/config for more information.`) +
15621548
// Always cleanup xmlStreamParser to prevent memory leaks and MaxListenersExceededWarning
15631549
xmlStreamParser.end()
15641550

1565-
if (!ASYNC_AGENTS_ENABLED) {
1566-
unsubscribeChunks()
1567-
unsubscribeComplete()
1568-
}
1551+
unsubscribeChunks()
1552+
unsubscribeComplete()
15691553

15701554
// Clear the onChunk callback when response is complete
15711555
this.currentOnChunk = undefined

0 commit comments

Comments
 (0)