forked from sting8k/pi-vcc
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstress-debug.ts
More file actions
202 lines (178 loc) · 7.94 KB
/
Copy pathstress-debug.ts
File metadata and controls
202 lines (178 loc) · 7.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { compile } from "./src/core/summarize";
const FILES = [
"src/auth.ts", "src/users.ts", "src/api.ts", "src/db.ts",
"src/utils.ts", "src/config.ts", "src/routes.ts", "src/middleware.ts",
"src/models.ts", "src/services.ts", "src/handlers.ts", "src/types.ts",
"src/errors.ts", "src/validators.ts", "src/cache.ts", "src/logger.ts",
"src/session.ts", "src/token.ts", "src/oauth.ts", "src/crypto.ts",
];
const GOALS = [
"Build an authentication system",
"Add user management endpoints",
"Create the REST API layer",
"Set up the database connection pool",
"Implement utility functions",
"Load configuration from environment",
"Define route handlers",
"Add authentication middleware",
"Create data models",
"Build the service layer",
"Implement request handlers",
"Add TypeScript type definitions",
"Create error handling utilities",
"Build input validators",
"Add caching layer",
"Set up structured logging",
"Implement session management",
"Add JWT token handling",
"Build OAuth2 integration",
"Add cryptographic utilities",
"Refactor auth to support SSO",
"Add rate limiting to API",
"Migrate database to PostgreSQL",
"Add integration tests",
"Set up CI pipeline",
];
const makeRound = (roundIdx: number): any[] => {
const file1 = FILES[roundIdx % FILES.length];
const file2 = FILES[(roundIdx + 7) % FILES.length];
const goal = GOALS[roundIdx % GOALS.length];
const id1 = `r${roundIdx}-1`;
const id2 = `r${roundIdx}-2`;
const id3 = `r${roundIdx}-3`;
const msgs: any[] = [
{ role: "user", content: goal },
{ role: "assistant", content: [{ type: "toolCall", name: "Edit", id: id1, arguments: { file_path: file1, oldText: "// placeholder", newText: `export function fn${roundIdx}() { return ${roundIdx}; }` } }] },
{ role: "toolResult", toolCallId: id1, toolName: "Edit", content: "OK" },
{ role: "assistant", content: `Edited ${file1} with function fn${roundIdx}.` },
{ role: "assistant", content: [{ type: "toolCall", name: "read", id: id2, arguments: { file_path: file2 } }] },
{ role: "toolResult", toolCallId: id2, toolName: "read", content: `// ${file2}\nexport const DATA = ${roundIdx};` },
{ role: "assistant", content: `Read ${file2} to understand the interface.` },
];
if (roundIdx % 3 === 0) {
msgs.push(
{ role: "assistant", content: [{ type: "toolCall", name: "bash", id: id3, arguments: { command: `git commit -m "feat: ${goal.toLowerCase()}" ` } }] },
{ role: "toolResult", toolCallId: id3, toolName: "bash", content: `[main abc${String(roundIdx).padStart(4, "0")}] feat: ${goal.toLowerCase()}` },
{ role: "assistant", content: `Committed: feat: ${goal.toLowerCase()}.` },
);
}
return msgs;
};
let prev = "";
const goalRecovery = new Map<string, {
rounds: number[];
recoveredByRound: boolean[];
directMention: boolean[];
breadcrumbOnly: boolean[];
firstLostRound: number | null;
}>();
for (let round = 0; round < 100; round++) {
const goal = GOALS[round % GOALS.length];
const msgs = makeRound(round);
const result = compile({ messages: msgs, previousSummary: prev || undefined });
prev = result;
if (!goalRecovery.has(goal)) {
goalRecovery.set(goal, { rounds: [], recoveredByRound: [], directMention: [], breadcrumbOnly: [], firstLostRound: null });
}
const entry = goalRecovery.get(goal)!;
entry.rounds.push(round + 1);
const directInGoals = result.includes(goal);
let breadcrumbHit = false;
const keywords = goal.split(/\s+/).filter(w => w.length > 3).slice(0, 3);
for (const line of result.split("\n")) {
if (line.startsWith("- ...recall:")) {
if (keywords.every(kw => line.toLowerCase().includes(kw.toLowerCase()))) breadcrumbHit = true;
}
}
const recoverable = directInGoals || breadcrumbHit;
entry.recoveredByRound.push(recoverable);
entry.directMention.push(directInGoals);
entry.breadcrumbOnly.push(breadcrumbHit && !directInGoals);
if (!recoverable && entry.firstLostRound === null) {
entry.firstLostRound = round + 1;
}
}
console.log("=== GOAL RECOVERY ANALYSIS (100 compactions) ===\n");
const alwaysPresent: string[] = [];
const sometimesLost: any[] = [];
const alwaysLost: any[] = [];
for (const [goal, entry] of goalRecovery) {
const total = entry.rounds.length;
const recovered = entry.recoveredByRound.filter(Boolean).length;
const directCount = entry.directMention.filter(Boolean).length;
const breadcrumbOnlyCount = entry.breadcrumbOnly.filter(Boolean).length;
const rate = recovered / total;
if (rate === 1) alwaysPresent.push(goal);
else if (rate === 0) alwaysLost.push({ goal, total, directCount, breadcrumbOnlyCount, firstLost: entry.firstLostRound });
else sometimesLost.push({ goal, total, recovered, rate, directCount, breadcrumbOnlyCount, firstLost: entry.firstLostRound });
}
console.log(`UNIQUE GOALS: ${goalRecovery.size}`);
console.log(`Always recoverable: ${alwaysPresent.length}`);
console.log(`Sometimes lost: ${sometimesLost.length}`);
console.log(`Always lost: ${alwaysLost.length}\n`);
if (alwaysPresent.length > 0) {
console.log("--- ALWAYS RECOVERABLE ---");
for (const g of alwaysPresent) console.log(` ${g}`);
console.log();
}
if (sometimesLost.length > 0) {
console.log("--- SOMETIMES LOST ---");
for (const g of sometimesLost) console.log(` ${(g.rate * 100).toFixed(0).padStart(3)}% recovery | lost first at round ${g.firstLost} | ${g.directCount} direct, ${g.breadcrumbOnlyCount} bc-only | ${g.goal}`);
console.log();
}
if (alwaysLost.length > 0) {
console.log("--- ALWAYS LOST (0% recovery) ---");
for (const g of alwaysLost) console.log(` lost first at round ${g.firstLost} | direct:${g.directCount} bc:${g.breadcrumbOnlyCount} | ${g.goal}`);
console.log();
}
// Show the actual sections at round 100
console.log("=== SESSION GOAL SECTION AT ROUND 100 ===");
const goalIdx = prev.indexOf("[Session Goal]");
const goalEnd = prev.indexOf("\n\n[", goalIdx + 1);
console.log(prev.slice(goalIdx, goalEnd > 0 ? goalEnd : prev.indexOf("\n\n---\n\n", goalIdx)));
console.log("\n=== EARLIER TURNS SECTION AT ROUND 100 ===");
const turnsIdx = prev.indexOf("[Earlier Turns]");
const turnsEnd = prev.indexOf("\n\n---\n\n", turnsIdx);
console.log(prev.slice(turnsIdx, turnsEnd > 0 ? turnsEnd : undefined));
console.log("\n=== FILES AND CHANGES AT ROUND 100 ===");
const filesIdx = prev.indexOf("[Files And Changes]");
const filesEnd = prev.indexOf("\n\n[", filesIdx + 1);
console.log(prev.slice(filesIdx, filesEnd > 0 ? filesEnd : prev.indexOf("\n\n---\n\n", filesIdx)));
// Breadcrumb collision analysis
console.log("\n=== BREADCRUMB COLLISION ANALYSIS ===");
const crumbs = new Map<string, string[]>();
for (const line of prev.split("\n")) {
if (line.startsWith("- ...recall:")) {
const content = line.slice("- ...recall: ".length);
for (const part of content.split(", ")) {
if (!crumbs.has(part)) crumbs.set(part, []);
crumbs.get(part)!.push(content);
}
}
}
const collisions = [...crumbs.entries()].filter(([k, v]) => v.length > 1);
if (collisions.length > 0) {
console.log(`Segments appearing in multiple breadcrumb lines (collisions):`);
for (const [segment, lines] of collisions) {
console.log(` "${segment}" appears in ${lines.length} breadcrumb lines`);
}
} else {
console.log("No segment collisions detected.");
}
// What extractBreadcrumb produces for each goal
console.log("\n=== BREADCRUMB EXTRACTION FOR EACH GOAL ===");
const extractBreadcrumb = (line: string): string => {
const text = line.replace(/^\s*-\s*/, "").trim();
if (!text) return "";
const fileMatch = text.match(/(?:edited |read |wrote |created |deleted )?(\S+\.\w{1,12})/);
if (fileMatch) return fileMatch[1];
const beforeArrow = text.split("\u2192")[0].trim();
const words = beforeArrow.split(/\s+/).filter(w => w.length > 2).slice(0, 3);
if (words.length > 0) return words.join(" ");
const first = text.split(/\s+/).find(w => w.length > 2);
return first ?? "";
};
for (const g of GOALS) {
const bc = extractBreadcrumb(g);
console.log(` "${g}" -> "${bc}"`);
}