fix: track ALL trajectories, detect new conversations, summary fallback per-traj

This commit is contained in:
2026-03-07 19:55:34 +09:00
parent 0c9664542e
commit 41f90b3b15
4 changed files with 142 additions and 109 deletions

Binary file not shown.

View File

@@ -282,13 +282,15 @@ function activate(context) {
}); });
} }
let pollFailCount = 0; let pollFailCount = 0;
let pollCount = 0;
async function pollConversations() { async function pollConversations() {
if (!lsPort) { if (!lsPort) {
return; return;
} }
if (pollFailCount > 3) { if (pollFailCount > 10) {
return; return;
} // stop after repeated failures } // stop after repeated failures
pollCount++;
try { try {
// Use getDiagnostics to get cascade-level conversation IDs // Use getDiagnostics to get cascade-level conversation IDs
const diag = await vscode.commands.executeCommand('antigravity.getDiagnostics'); const diag = await vscode.commands.executeCommand('antigravity.getDiagnostics');
@@ -302,64 +304,78 @@ function activate(context) {
} }
const isFirstPoll = Object.keys(lastStepIndex).length === 0; const isFirstPoll = Object.keys(lastStepIndex).length === 0;
if (isFirstPoll) { if (isFirstPoll) {
console.log(`Gravity Bridge: [LS] ${trajectories.length} recent trajectories from getDiagnostics`); console.log(`Gravity Bridge: [LS] ${trajectories.length} trajectories from getDiagnostics`);
const latest = trajectories[trajectories.length - 1];
console.log(`Gravity Bridge: [LS] latest: ${JSON.stringify(latest).substring(0, 400)}`);
} }
// Check the most recent trajectory for step count changes // Periodic debug every ~1 min (12 * 5s)
const latest = trajectories[trajectories.length - 1]; if (pollCount % 12 === 0) {
const agentId = latest.googleAgentId || ''; const summary = trajectories.map((t) => {
const trajId = latest.trajectoryId || ''; const id = (t.googleAgentId || '').substring(0, 8);
const stepIdx = latest.lastStepIndex ?? 0; return `${id}:s${t.lastStepIndex ?? '?'}`;
if (!agentId && !trajId) { }).join(', ');
return; console.log(`Gravity Bridge: [LS] poll#${pollCount}${trajectories.length} trajs: [${summary}]`);
} }
const key = agentId || trajId; // Check ALL trajectories for step count changes
const prev = lastStepIndex[key]; for (const traj of trajectories) {
if (prev === undefined) { const agentId = traj.googleAgentId || '';
// First poll — initialize const trajId = traj.trajectoryId || '';
lastStepIndex[key] = stepIdx; const stepIdx = traj.lastStepIndex ?? 0;
console.log(`Gravity Bridge: [LS] initialized ${key.substring(0, 8)} at step ${stepIdx}`); const summary = traj.summary || '';
return; if (!agentId && !trajId) {
} continue;
if (stepIdx > prev) {
// New steps detected! Try to fetch them
console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} new steps: ${prev}${stepIdx}`);
const attempts = [
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
{ method: 'GetCascadeTrajectorySteps', params: { conversationId: agentId, trajectoryId: trajId } },
];
let stepsResult = null;
for (const attempt of attempts) {
const res = await lsRPC(attempt.method, attempt.params);
if (res && !res.code && !res.message?.includes('not found')) {
stepsResult = res;
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`);
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`);
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`);
pollFailCount = 0;
break;
}
} }
if (stepsResult) { const key = agentId || trajId;
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || []; const prev = lastStepIndex[key];
if (Array.isArray(steps) && steps.length > 0) { if (prev === undefined) {
const newSteps = steps.slice(-(stepIdx - prev)); // First time seeing this trajectory — initialize
extractAndRelaySteps(newSteps); lastStepIndex[key] = stepIdx;
if (isFirstPoll) {
console.log(`Gravity Bridge: [LS] init ${key.substring(0, 8)} at step ${stepIdx} "${summary.substring(0, 30)}"`);
} }
} else {
else { // New trajectory appeared after first poll = new conversation!
// All attempts failed — try writing the summary as a fallback console.log(`Gravity Bridge: [LS] NEW trajectory ${key.substring(0, 8)} at step ${stepIdx} "${summary.substring(0, 40)}"`);
const summary = latest.summary || '';
if (summary && summary !== lastStepIndex[key + '_summary']) {
writeChatSnapshot(`[AI 대화 요약]\n\n${summary}\n\n(step ${prev}${stepIdx})`);
lastStepIndex[key + '_summary'] = summary;
console.log(`Gravity Bridge: [LS] relayed summary fallback: ${summary.substring(0, 100)}`);
} }
pollFailCount++; continue;
}
if (stepIdx > prev) {
// New steps detected!
console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} steps: ${prev}${stepIdx} "${summary.substring(0, 40)}"`);
// Try RPC to get full step text
const attempts = [
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
];
let stepsResult = null;
for (const attempt of attempts) {
const res = await lsRPC(attempt.method, attempt.params);
if (res && !res.code && !res.message?.includes('not found')) {
stepsResult = res;
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`);
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`);
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`);
pollFailCount = 0;
break;
}
}
if (stepsResult) {
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
if (Array.isArray(steps) && steps.length > 0) {
const newSteps = steps.slice(-(stepIdx - prev));
extractAndRelaySteps(newSteps);
}
}
else {
// Fallback: relay summary text
const summaryKey = key + '_summary';
if (summary && summary !== lastStepIndex[summaryKey]) {
writeChatSnapshot(`[AI 응답 감지]\n\n**${summary}**\n\n(step ${prev}${stepIdx})`);
lastStepIndex[summaryKey] = summary;
console.log(`Gravity Bridge: [LS] relayed summary: "${summary.substring(0, 80)}"`);
}
pollFailCount++;
}
lastStepIndex[key] = stepIdx;
} }
lastStepIndex[key] = stepIdx;
} }
} }
catch (e) { catch (e) {

File diff suppressed because one or more lines are too long

View File

@@ -264,10 +264,12 @@ export function activate(context: vscode.ExtensionContext) {
} }
let pollFailCount = 0; let pollFailCount = 0;
let pollCount = 0;
async function pollConversations() { async function pollConversations() {
if (!lsPort) { return; } if (!lsPort) { return; }
if (pollFailCount > 3) { return; } // stop after repeated failures if (pollFailCount > 10) { return; } // stop after repeated failures
pollCount++;
try { try {
// Use getDiagnostics to get cascade-level conversation IDs // Use getDiagnostics to get cascade-level conversation IDs
const diag: any = await vscode.commands.executeCommand('antigravity.getDiagnostics'); const diag: any = await vscode.commands.executeCommand('antigravity.getDiagnostics');
@@ -279,70 +281,84 @@ export function activate(context: vscode.ExtensionContext) {
const isFirstPoll = Object.keys(lastStepIndex).length === 0; const isFirstPoll = Object.keys(lastStepIndex).length === 0;
if (isFirstPoll) { if (isFirstPoll) {
console.log(`Gravity Bridge: [LS] ${trajectories.length} recent trajectories from getDiagnostics`); console.log(`Gravity Bridge: [LS] ${trajectories.length} trajectories from getDiagnostics`);
const latest = trajectories[trajectories.length - 1];
console.log(`Gravity Bridge: [LS] latest: ${JSON.stringify(latest).substring(0, 400)}`);
} }
// Check the most recent trajectory for step count changes // Periodic debug every ~1 min (12 * 5s)
const latest = trajectories[trajectories.length - 1]; if (pollCount % 12 === 0) {
const agentId = latest.googleAgentId || ''; const summary = trajectories.map((t: any) => {
const trajId = latest.trajectoryId || ''; const id = (t.googleAgentId || '').substring(0, 8);
const stepIdx = latest.lastStepIndex ?? 0; return `${id}:s${t.lastStepIndex ?? '?'}`;
}).join(', ');
if (!agentId && !trajId) { return; } console.log(`Gravity Bridge: [LS] poll#${pollCount}${trajectories.length} trajs: [${summary}]`);
const key = agentId || trajId;
const prev = lastStepIndex[key];
if (prev === undefined) {
// First poll — initialize
lastStepIndex[key] = stepIdx;
console.log(`Gravity Bridge: [LS] initialized ${key.substring(0, 8)} at step ${stepIdx}`);
return;
} }
if (stepIdx > prev) { // Check ALL trajectories for step count changes
// New steps detected! Try to fetch them for (const traj of trajectories) {
console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} new steps: ${prev}${stepIdx}`); const agentId = traj.googleAgentId || '';
const trajId = traj.trajectoryId || '';
const stepIdx = traj.lastStepIndex ?? 0;
const summary = traj.summary || '';
const attempts = [ if (!agentId && !trajId) { continue; }
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
{ method: 'GetCascadeTrajectorySteps', params: { conversationId: agentId, trajectoryId: trajId } },
];
let stepsResult: any = null; const key = agentId || trajId;
for (const attempt of attempts) { const prev = lastStepIndex[key];
const res = await lsRPC(attempt.method, attempt.params);
if (res && !res.code && !res.message?.includes('not found')) { if (prev === undefined) {
stepsResult = res; // First time seeing this trajectory — initialize
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`); lastStepIndex[key] = stepIdx;
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`); if (isFirstPoll) {
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`); console.log(`Gravity Bridge: [LS] init ${key.substring(0, 8)} at step ${stepIdx} "${summary.substring(0, 30)}"`);
pollFailCount = 0; } else {
break; // New trajectory appeared after first poll = new conversation!
console.log(`Gravity Bridge: [LS] NEW trajectory ${key.substring(0, 8)} at step ${stepIdx} "${summary.substring(0, 40)}"`);
} }
continue;
} }
if (stepsResult) { if (stepIdx > prev) {
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || []; // New steps detected!
if (Array.isArray(steps) && steps.length > 0) { console.log(`Gravity Bridge: [LS] ${key.substring(0, 8)} steps: ${prev}${stepIdx} "${summary.substring(0, 40)}"`);
const newSteps = steps.slice(-(stepIdx - prev));
extractAndRelaySteps(newSteps);
}
} else {
// All attempts failed — try writing the summary as a fallback
const summary = latest.summary || '';
if (summary && summary !== lastStepIndex[key + '_summary']) {
writeChatSnapshot(`[AI 대화 요약]\n\n${summary}\n\n(step ${prev}${stepIdx})`);
lastStepIndex[key + '_summary'] = summary;
console.log(`Gravity Bridge: [LS] relayed summary fallback: ${summary.substring(0, 100)}`);
}
pollFailCount++;
}
lastStepIndex[key] = stepIdx; // Try RPC to get full step text
const attempts = [
{ method: 'GetCascadeTrajectorySteps', params: { googleAgentId: agentId, trajectoryId: trajId, startStepIndex: prev } },
{ method: 'GetCascadeTrajectory', params: { googleAgentId: agentId, trajectoryId: trajId } },
];
let stepsResult: any = null;
for (const attempt of attempts) {
const res = await lsRPC(attempt.method, attempt.params);
if (res && !res.code && !res.message?.includes('not found')) {
stepsResult = res;
console.log(`Gravity Bridge: [LS] ✅ ${attempt.method} worked!`);
console.log(`Gravity Bridge: [LS] keys: ${Object.keys(res).join(', ')}`);
console.log(`Gravity Bridge: [LS] sample: ${JSON.stringify(res).substring(0, 800)}`);
pollFailCount = 0;
break;
}
}
if (stepsResult) {
const steps = stepsResult.steps || stepsResult.cortexSteps || stepsResult.cortex_steps || [];
if (Array.isArray(steps) && steps.length > 0) {
const newSteps = steps.slice(-(stepIdx - prev));
extractAndRelaySteps(newSteps);
}
} else {
// Fallback: relay summary text
const summaryKey = key + '_summary';
if (summary && summary !== lastStepIndex[summaryKey]) {
writeChatSnapshot(`[AI 응답 감지]\n\n**${summary}**\n\n(step ${prev}${stepIdx})`);
lastStepIndex[summaryKey] = summary;
console.log(`Gravity Bridge: [LS] relayed summary: "${summary.substring(0, 80)}"`);
}
pollFailCount++;
}
lastStepIndex[key] = stepIdx;
}
} }
} catch (e) { } catch (e) {
console.log(`Gravity Bridge: [LS poll] error: ${e}`); console.log(`Gravity Bridge: [LS poll] error: ${e}`);
@@ -351,6 +367,7 @@ export function activate(context: vscode.ExtensionContext) {
function extractAndRelaySteps(steps: any[]) { function extractAndRelaySteps(steps: any[]) {
const messages: string[] = []; const messages: string[] = [];