feat(coding-agent/eval): tracked and forwarded session id and working directory

- Added `sessionId` and `cwd` tracking to JS evaluator session instances.
- Updated `acquireSession` in the JS context manager to update existing session identity and directory metadata on reuse.
- Forwarded the current working directory from `executePerCall` and `executeOnSession` callers to the underlying Python kernel tasks.
This commit is contained in:
can1357
2026-06-18 00:59:56 +02:00
parent 6bcba1c730
commit dc915dfef1
2 changed files with 19 additions and 4 deletions
@@ -44,6 +44,8 @@ interface PendingRun {
interface JsSession {
sessionKey: string;
sessionId: string;
cwd: string;
worker: WorkerHandle;
state: "alive" | "dead";
pending: Map<string, PendingRun>;
@@ -151,7 +153,14 @@ export async function disposeAllVmContexts(): Promise<void> {
*/
export async function smokeTestJsEvalWorker(): Promise<void> {
const worker = spawnJsWorker();
const session: JsSession = { sessionKey: "smoke", worker, state: "alive", pending: new Map() };
const session: JsSession = {
sessionKey: "smoke",
sessionId: "smoke",
cwd: process.cwd(),
worker,
state: "alive",
pending: new Map(),
};
try {
await initWorker(session, { cwd: process.cwd(), sessionId: "smoke" }, WORKER_INIT_TIMEOUT_MS);
if (worker.mode !== "worker") {
@@ -219,7 +228,11 @@ async function runOnce(
async function acquireSession(sessionKey: string, snapshot: SessionSnapshot, timeoutMs?: number): Promise<JsSession> {
const existing = sessions.get(sessionKey);
if (existing && existing.state === "alive") return existing;
if (existing && existing.state === "alive") {
existing.sessionId = snapshot.sessionId;
existing.cwd = snapshot.cwd;
return existing;
}
const starting = startingSessions.get(sessionKey);
if (starting) return await starting;
@@ -231,6 +244,8 @@ async function acquireSession(sessionKey: string, snapshot: SessionSnapshot, tim
const worker = spawnJsWorker();
const session: JsSession = {
sessionKey,
sessionId: snapshot.sessionId,
cwd: snapshot.cwd,
worker,
state: "alive",
pending: new Map(),
@@ -632,7 +632,7 @@ async function executePerCall(code: string, cwd: string, options: PythonExecutor
}
const kernel = await startKernel(cwd, options);
try {
return await executeWithKernel(kernel, code, { ...options, cwd: undefined });
return await executeWithKernel(kernel, code, { ...options, cwd });
} finally {
await kernel.shutdown().catch(() => undefined);
}
@@ -682,7 +682,7 @@ async function executeOnSession(code: string, cwd: string, options: PythonExecut
throw new PythonExecutionCancelledError(false);
}
}
const runOptions = { ...options, cwd: undefined };
const runOptions = { ...options, cwd };
try {
return await executeWithKernel(session.kernel, code, runOptions);
} catch (err) {