feat(coding-agent): improved Python startup performance with prelude caching and shared gateway mode
- Added Python prelude caching to improve startup performance by caching helper functions and module discovery results. - Added OMP_DEBUG_STARTUP environment variable for detailed startup stage tracing across initialization pipeline. - Changed Python kernel initialization to require shared gateway mode, removing support for local kernel gateway startup. - Improved error handling in shared gateway acquisition with automatic retries on 5xx status codes. - Added repro-stuck.ts script for reproducing and debugging rare CLI hang issues with Chrome DevTools integration. - Added trace-loader.ts preload script for tracing module resolution during startup diagnostics.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Bun preload script that traces module resolution.
|
||||
* Usage: bun --preload ./scripts/trace-loader.ts <script>
|
||||
*/
|
||||
|
||||
const startTime = performance.now();
|
||||
const resolved = new Set<string>();
|
||||
|
||||
Bun.plugin({
|
||||
name: "trace-loader",
|
||||
setup(build) {
|
||||
// Trace module resolution (doesn't interfere with loading)
|
||||
build.onResolve({ filter: /.*/ }, (args) => {
|
||||
// Skip if already traced this path
|
||||
if (resolved.has(args.path)) {
|
||||
return undefined;
|
||||
}
|
||||
resolved.add(args.path);
|
||||
|
||||
const elapsed = (performance.now() - startTime).toFixed(1);
|
||||
// Only trace local/project files, not node_modules
|
||||
if (!args.path.includes("node_modules") && !args.path.startsWith("node:")) {
|
||||
const shortPath = args.path.replace(process.cwd(), ".");
|
||||
process.stderr.write(`[${elapsed}ms] resolve: ${shortPath}\n`);
|
||||
}
|
||||
|
||||
// Return undefined to let Bun handle resolution normally
|
||||
return undefined;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
process.stderr.write(`[trace-loader] preload active\n`);
|
||||
Reference in New Issue
Block a user