Skip to content

Commit 848b80a

Browse files
authored
Add log for "invalid value reference" (#248959)
Add log for "invalid value reference" (#248767) microsoft/vscode-copilot-release#7402
1 parent d197ffb commit 848b80a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/vs/workbench/api/common/extHostChatAgents2.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Iterable } from '../../../base/common/iterator.js';
1313
import { Disposable, DisposableMap, DisposableStore, toDisposable } from '../../../base/common/lifecycle.js';
1414
import { revive } from '../../../base/common/marshalling.js';
1515
import { StopWatch } from '../../../base/common/stopwatch.js';
16-
import { assertType } from '../../../base/common/types.js';
16+
import { assertType, isDefined } from '../../../base/common/types.js';
1717
import { URI } from '../../../base/common/uri.js';
1818
import { generateUuid } from '../../../base/common/uuid.js';
1919
import { Location } from '../../../editor/common/languages.js';
@@ -410,7 +410,15 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
410410
const { request, location, history } = await this._createRequest(requestDto, context, detector.extension);
411411

412412
const model = await this.getModelForRequest(request, detector.extension);
413-
const extRequest = typeConvert.ChatAgentRequest.to(request, location, model, this.getDiagnosticsWhenEnabled(detector.extension), this.getToolsForRequest(detector.extension, request), this.getTools2ForRequest(detector.extension, request), detector.extension);
413+
const extRequest = typeConvert.ChatAgentRequest.to(
414+
request,
415+
location,
416+
model,
417+
this.getDiagnosticsWhenEnabled(detector.extension),
418+
this.getToolsForRequest(detector.extension, request),
419+
this.getTools2ForRequest(detector.extension, request),
420+
detector.extension,
421+
this._logService);
414422

415423
return detector.provider.provideParticipantDetection(
416424
extRequest,
@@ -501,7 +509,8 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
501509
this.getDiagnosticsWhenEnabled(agent.extension),
502510
this.getToolsForRequest(agent.extension, request),
503511
this.getTools2ForRequest(agent.extension, request),
504-
agent.extension
512+
agent.extension,
513+
this._logService
505514
);
506515
inFlightRequest = { requestId: requestDto.requestId, extRequest };
507516
this._inFlightRequests.add(inFlightRequest);
@@ -598,7 +607,8 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
598607
// REQUEST turn
599608
const varsWithoutTools = h.request.variables.variables
600609
.filter(v => v.kind !== 'tool')
601-
.map(v => typeConvert.ChatPromptReference.to(v, this.getDiagnosticsWhenEnabled(extension)));
610+
.map(v => typeConvert.ChatPromptReference.to(v, this.getDiagnosticsWhenEnabled(extension), this._logService))
611+
.filter(isDefined);
602612
const toolReferences = h.request.variables.variables
603613
.filter(v => v.kind === 'tool')
604614
.map(typeConvert.ChatLanguageModelToolReference.to);

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import { LanguageModelDataPart, LanguageModelPromptTsxPart, LanguageModelTextPar
6565
import { ChatAgentLocation } from '../../contrib/chat/common/constants.js';
6666
import { AiSettingsSearchResult, AiSettingsSearchResultKind } from '../../services/aiSettingsSearch/common/aiSettingsSearch.js';
6767
import { McpServerLaunch, McpServerTransportType } from '../../contrib/mcp/common/mcpTypes.js';
68+
import { ILogService } from '../../../platform/log/common/log.js';
6869

6970
export namespace Command {
7071

@@ -2903,7 +2904,7 @@ export namespace ChatResponsePart {
29032904
}
29042905

29052906
export namespace ChatAgentRequest {
2906-
export function to(request: IChatAgentRequest, location2: vscode.ChatRequestEditorData | vscode.ChatRequestNotebookData | undefined, model: vscode.LanguageModelChat, diagnostics: readonly [vscode.Uri, readonly vscode.Diagnostic[]][], toolSelection: vscode.ChatRequestToolSelection | undefined, tools: Map<string, boolean>, extension: IRelaxedExtensionDescription): vscode.ChatRequest {
2907+
export function to(request: IChatAgentRequest, location2: vscode.ChatRequestEditorData | vscode.ChatRequestNotebookData | undefined, model: vscode.LanguageModelChat, diagnostics: readonly [vscode.Uri, readonly vscode.Diagnostic[]][], toolSelection: vscode.ChatRequestToolSelection | undefined, tools: Map<string, boolean>, extension: IRelaxedExtensionDescription, logService: ILogService): vscode.ChatRequest {
29072908
const toolReferences = request.variables.variables.filter(v => v.kind === 'tool');
29082909
const variableReferences = request.variables.variables.filter(v => v.kind !== 'tool');
29092910
const requestWithAllProps: vscode.ChatRequest = {
@@ -2913,7 +2914,9 @@ export namespace ChatAgentRequest {
29132914
attempt: request.attempt ?? 0,
29142915
enableCommandDetection: request.enableCommandDetection ?? true,
29152916
isParticipantDetected: request.isParticipantDetected ?? false,
2916-
references: variableReferences.map(v => ChatPromptReference.to(v, diagnostics)),
2917+
references: variableReferences
2918+
.map(v => ChatPromptReference.to(v, diagnostics, logService))
2919+
.filter(isDefined),
29172920
toolReferences: toolReferences.map(ChatLanguageModelToolReference.to),
29182921
location: ChatLocation.to(request.location),
29192922
acceptedConfirmationData: request.acceptedConfirmationData,
@@ -2977,10 +2980,18 @@ export namespace ChatLocation {
29772980
}
29782981

29792982
export namespace ChatPromptReference {
2980-
export function to(variable: IChatRequestVariableEntry, diagnostics: readonly [vscode.Uri, readonly vscode.Diagnostic[]][]): vscode.ChatPromptReference {
2983+
export function to(variable: IChatRequestVariableEntry, diagnostics: readonly [vscode.Uri, readonly vscode.Diagnostic[]][], logService: ILogService): vscode.ChatPromptReference | undefined {
29812984
let value: vscode.ChatPromptReference['value'] = variable.value;
29822985
if (!value) {
2983-
throw new Error('Invalid value reference');
2986+
let varStr: string;
2987+
try {
2988+
varStr = JSON.stringify(variable);
2989+
} catch {
2990+
varStr = `kind=${variable.kind}, id=${variable.id}, name=${variable.name}`;
2991+
}
2992+
2993+
logService.error(`[ChatPromptReference] Ignoring invalid reference in variable: ${varStr}`);
2994+
return undefined;
29842995
}
29852996

29862997
if (isUriComponents(value)) {

0 commit comments

Comments
 (0)