From 6ae9e1e2760310474cec0e215919c1263a17350a Mon Sep 17 00:00:00 2001 From: aws-ajangg Date: Wed, 18 Feb 2026 23:04:53 -0800 Subject: [PATCH 1/3] add additional criteria for idle activity monitoring --- patches/sagemaker-idle-extension.patch | 61 ++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/patches/sagemaker-idle-extension.patch b/patches/sagemaker-idle-extension.patch index 049cce6c7..ab78ad104 100644 --- a/patches/sagemaker-idle-extension.patch +++ b/patches/sagemaker-idle-extension.patch @@ -5,7 +5,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/README.m @@ -0,0 +1,3 @@ +# Code Editor Idle Extension + -+The Code Editor Idle Extension tracks user activity and logs the last active timestamp (in UTC) to a local file. User activities monitored include file changes, text editor selection changes, and terminal interactions. Additionally, it provides an API endpoint `/api/idle` that returns the lastActiveTimestamp. ++The Code Editor Idle Extension tracks user activity and logs the last active timestamp (in UTC) to a local file. User activities monitored include file changes, text editor selection changes, terminal interactions, background processes, notebook kernel activity, and unsaved work. Additionally, it provides an API endpoint `/api/idle` that returns the lastActiveTimestamp. \ No newline at end of file Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/extension-browser.webpack.config.js =================================================================== @@ -153,13 +153,19 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte +import * as path from "path"; + +let idleFilePath: string; ++let checkInterval: NodeJS.Timeout; + +export function activate(context: vscode.ExtensionContext) { + initializeIdleFilePath(); + registerEventListeners(context); ++ startPeriodicChecks(); +} + -+export function deactivate() {} ++export function deactivate() { ++ if (checkInterval) { ++ clearInterval(checkInterval); ++ } ++} + +/** + * Initializes the file path where the idle timestamp will be stored. @@ -175,7 +181,8 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte + +/** + * Registers event listeners to monitor user activity within the VSCode editor. -+ * It listens to document changes, editor focus changes, text selection changes, and terminal events. ++ * It listens to document changes, editor focus changes, text selection changes, terminal events, ++ * task execution, and notebook kernel state changes. + * @param context - The context in which the extension is running. + */ +function registerEventListeners(context: vscode.ExtensionContext) { @@ -194,11 +201,59 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte + }), + vscode.window.onDidCloseTerminal((_) => { + updateLastActivityTimestamp(); ++ }), ++ vscode.tasks.onDidStartTask((_) => { ++ updateLastActivityTimestamp(); ++ }), ++ vscode.tasks.onDidEndTask((_) => { ++ updateLastActivityTimestamp(); ++ }), ++ vscode.workspace.onDidChangeNotebookDocument((_) => { ++ updateLastActivityTimestamp(); + }) + ); +} + +/** ++ * Starts periodic checks for background activity (running tasks, executing kernels, unsaved work). ++ */ ++function startPeriodicChecks() { ++ checkInterval = setInterval(() => { ++ if (hasBackgroundActivity()) { ++ updateLastActivityTimestamp(); ++ } ++ }, 60000); // Check every 60 seconds ++} ++ ++/** ++ * Checks if there is any background activity that should prevent idle state. ++ * @returns true if there are running tasks, executing notebook kernels, or unsaved work. ++ */ ++function hasBackgroundActivity(): boolean { ++ // Check for running tasks ++ if (vscode.tasks.taskExecutions.length > 0) { ++ return true; ++ } ++ ++ // Check for executing notebook kernels or unsaved work ++ for (const notebook of vscode.workspace.notebookDocuments) { ++ // Check if any cell is executing ++ for (const cell of notebook.getCells()) { ++ if (cell.executionSummary?.executionOrder !== undefined && ++ cell.executionSummary.timing?.endTime === undefined) { ++ return true; ++ } ++ } ++ // Check if notebook has unsaved changes ++ if (notebook.isDirty) { ++ return true; ++ } ++ } ++ ++ return vscode.workspace.textDocuments.some(doc => doc.isDirty && doc.uri.scheme === 'file'); ++} ++ ++/** + * Updates the last activity timestamp by recording the current timestamp in the idle file and + * refreshing the status bar. The timestamp should be in ISO 8601 format and set to the UTC timezone. + */ From f55e6e4a0868623cd97de2885b210876682c4830 Mon Sep 17 00:00:00 2001 From: aws-ajangg Date: Wed, 18 Feb 2026 23:59:05 -0800 Subject: [PATCH 2/3] update lines for idle patch --- patches/sagemaker-idle-extension.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/sagemaker-idle-extension.patch b/patches/sagemaker-idle-extension.patch index ab78ad104..574d0ef45 100644 --- a/patches/sagemaker-idle-extension.patch +++ b/patches/sagemaker-idle-extension.patch @@ -147,7 +147,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte =================================================================== --- /dev/null +++ sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/extension.ts -@@ -0,0 +1,58 @@ +@@ -0,0 +1,113 @@ +import * as vscode from "vscode"; +import * as fs from "fs"; +import * as path from "path"; From bc8f2a4c6d684b499e66fc494370d677dafc19a4 Mon Sep 17 00:00:00 2001 From: aws-ajangg Date: Wed, 25 Feb 2026 09:40:07 -0800 Subject: [PATCH 3/3] add console logs for debugging --- patches/sagemaker-idle-extension.patch | 35 ++++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/patches/sagemaker-idle-extension.patch b/patches/sagemaker-idle-extension.patch index 574d0ef45..5926fa353 100644 --- a/patches/sagemaker-idle-extension.patch +++ b/patches/sagemaker-idle-extension.patch @@ -188,27 +188,35 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte +function registerEventListeners(context: vscode.ExtensionContext) { + context.subscriptions.push( + vscode.workspace.onDidChangeTextDocument((_) => { ++ console.log('[IdleMonitor] Text document changed'); + updateLastActivityTimestamp(); + }), + vscode.window.onDidChangeActiveTextEditor((_) => { ++ console.log('[IdleMonitor] Active text editor changed'); + updateLastActivityTimestamp(); + }), + vscode.window.onDidChangeTextEditorSelection((_) => { ++ console.log('[IdleMonitor] Text editor selection changed'); + updateLastActivityTimestamp(); + }), + vscode.window.onDidOpenTerminal((_) => { ++ console.log('[IdleMonitor] Terminal opened'); + updateLastActivityTimestamp(); + }), + vscode.window.onDidCloseTerminal((_) => { ++ console.log('[IdleMonitor] Terminal closed'); + updateLastActivityTimestamp(); + }), + vscode.tasks.onDidStartTask((_) => { ++ console.log('[IdleMonitor] Task started'); + updateLastActivityTimestamp(); + }), + vscode.tasks.onDidEndTask((_) => { ++ console.log('[IdleMonitor] Task ended'); + updateLastActivityTimestamp(); + }), + vscode.workspace.onDidChangeNotebookDocument((_) => { ++ console.log('[IdleMonitor] Notebook document changed'); + updateLastActivityTimestamp(); + }) + ); @@ -219,7 +227,9 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte + */ +function startPeriodicChecks() { + checkInterval = setInterval(() => { -+ if (hasBackgroundActivity()) { ++ const activity = hasBackgroundActivity(); ++ console.log('[IdleMonitor] Periodic check - background activity:', activity); ++ if (activity) { + updateLastActivityTimestamp(); + } + }, 60000); // Check every 60 seconds @@ -231,9 +241,11 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte + */ +function hasBackgroundActivity(): boolean { + // Check for running tasks -+ if (vscode.tasks.taskExecutions.length > 0) { -+ return true; -+ } ++ const hasActiveTasks = vscode.tasks.taskExecutions.length > 0; ++ console.log('[IdleMonitor] Active tasks:', hasActiveTasks); ++ ++ let hasExecutingKernels = false; ++ let hasUnsavedNotebooks = false; + + // Check for executing notebook kernels or unsaved work + for (const notebook of vscode.workspace.notebookDocuments) { @@ -241,16 +253,21 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte + for (const cell of notebook.getCells()) { + if (cell.executionSummary?.executionOrder !== undefined && + cell.executionSummary.timing?.endTime === undefined) { -+ return true; ++ hasExecutingKernels = true; ++ break; + } + } + // Check if notebook has unsaved changes + if (notebook.isDirty) { -+ return true; ++ hasUnsavedNotebooks = true; + } + } + -+ return vscode.workspace.textDocuments.some(doc => doc.isDirty && doc.uri.scheme === 'file'); ++ const hasUnsavedText = vscode.workspace.textDocuments.some(doc => doc.isDirty && doc.uri.scheme === 'file'); ++ ++ console.log('[IdleMonitor] Executing kernels:', hasExecutingKernels, 'Unsaved notebooks:', hasUnsavedNotebooks, 'Unsaved text:', hasUnsavedText); ++ ++ return hasActiveTasks || hasExecutingKernels || hasUnsavedNotebooks || hasUnsavedText; +} + +/** @@ -259,6 +276,7 @@ Index: sagemaker-code-editor/vscode/extensions/sagemaker-idle-extension/src/exte + */ +function updateLastActivityTimestamp() { + const timestamp = new Date().toISOString(); ++ console.log('[IdleMonitor] Updating timestamp:', timestamp); + fs.writeFileSync(idleFilePath, timestamp); +} \ No newline at end of file @@ -333,11 +351,12 @@ Index: sagemaker-code-editor/vscode/src/vs/server/node/webClientServer.ts + return now.getTime() - mtime < CHECK_INTERVAL; + }); + ++ console.log('[IdleMonitor] Terminal activity detected:', activityDetected); + if (activityDetected) { + fs.writeFileSync(idleFilePath, now.toISOString()); + } + } catch (err) { -+ console.error('Error checking terminal activity:', err); ++ console.error('[IdleMonitor] Error checking terminal activity:', err); + } +} +