Repository navigation
feat: add on-demand checkpoint/restore API for external orchestrators - #65
Merged
Merged
Conversation
カーネル起動/停止時だけでなく、外部オーケストレーターから任意タイミングで チェックポイントの保存/復元を発火できるようにする。発火は明示指示のみで、 ノートブックユーザーには透過(マジック不要・user_ns を汚さない)。 - kernel.py: 保存/復元ロジックを _save_checkpoint / _restore_checkpoint に共通化 (do_shutdown / __init__ からも再利用)。control チャネルにカスタムメッセージ ハンドラ (elastic_checkpoint_request / elastic_restore_request) を登録。実処理は メイン io_loop へ marshal して走行中セルとの user_ns 競合を回避。 - serverextension.py: Jupyter Server 拡張。POST /elastic_kernel/checkpoint・/restore を提供し、kernel_id 指定でカーネルの control チャネルへ橋渡し、reply を JSON で中継。 - command.py: `elastic-kernel install --server` で拡張を有効化 (toggle_server_extension_python)。 - pyproject.toml: optional-dependencies に server extra (jupyter_server) を追加。 - tests: 保存/復元・control ハンドラ・拡張登録のユニットテストを追加。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
その機能用のドキュメントをどこかに書いておいてほしいです. |
機能の使い方を docs/CHECKPOINT_API.md にまとめ、README.md / README.ja.md の ドキュメントセクションからリンクして辿れるようにする。有効化方法・REST エンドポイント・レスポンス・curl 例・control チャネル直送の代替手段を記載。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
Author
|
ドキュメントを追加しました 📝(commit 3239260)
|
MRyutaro
commented
Jun 17, 2026
…aling) レビュー指摘を受け、_run_on_main_loop が何をしているのかを具体化。control スレッドと メイン shell io_loop の住み分け、なぜ user_ns を直接触ると競合するのか、add_callback と call_soon_threadsafe による橋渡しの手順をステップで説明。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
カーネルの起動/停止時だけだったチェックポイント保存/復元を、外部オーケストレーターから任意タイミングで発火できるようにする。発火は外部からの明示指示のみで、ノートブックのエンドユーザーには透過(マジックコマンド不要・
user_ns/%whoを汚さない)。動機
別途構築する外部オーケストレーションシステムが、稼働中の特定カーネルの状態を任意のタイミングでスナップショット/復元したい、というユースケースに対応する。
アーキテクチャ
user_nsにコードを走らせないため透過。user_ns競合を回避(一貫したスナップショット)。変更点
elastic_kernel/kernel.py: 保存/復元ロジックを_save_checkpoint/_restore_checkpointに共通化(do_shutdown/__init__からも再利用)。control チャネルにelastic_checkpoint_request/elastic_restore_requestハンドラを登録。_run_on_main_loopでメインループへ marshal。elastic_kernel/serverextension.py(新規): Jupyter Server 拡張。POST /elastic_kernel/checkpoint・/restoreを提供し、kernel_id指定でカーネルの control チャネルへ橋渡し、reply を JSON で中継。kernel.pyからはjupyter_serverを import しない(カーネルプロセスは非依存)。elastic_kernel/command.py:elastic-kernel install --serverで拡張を有効化(toggle_server_extension_python)。jupyter_server未導入なら extras を案内。pyproject.toml:optional-dependenciesにserver = ["jupyter_server"]を追加。切り分け(インストール)
REST API はオプトイン。常時 ON の
jupyter_server_config.dJSON は同梱せず、有効化はコマンド経由:elastic-kernel installelastic-kernel install --serverOFF に戻す:
jupyter server extension disable elastic_kernel.serverextension使い方(外部オーケストレーター側)
レスポンス: 成功
200 ok:true/ 不可409(plain_kernel_mode・no_checkpoint_file・exception)/kernel_id不正404・欠落400・無認証403・タイムアウト504。テスト
tests/test_checkpoint_control.py):_save_checkpoint/_restore_checkpoint(成功・plain-kernel・例外・ファイル無し)、control ハンドラの reply 送信、サーバー拡張の登録。全 79 passed / 16 skipped。jupyter_clientで起動 → セル実行 → control にelastic_checkpoint_request送信 →ok:true・checkpoint.pickle書き込み・restore も成功。jupyter server起動 → セッション作成 →POST /elastic_kernel/checkpointで200 ok:true・ファイル書き込み確認、/restoreも成功、ネガティブ(400/404/403)も期待通り。black/isort/flake8/mypy全て clean。補足(スコープ外の既存バグ)
E2E 中、
JPY_SESSION_NAME未設定で API 起動した場合に__setup_file_pathがロガー設定前にself.loggerを参照してクラッシュする既存バグを確認(通常の JupyterLab 利用ではJPY_SESSION_NAMEが設定されるため踏まない)。本 PR のスコープ外として別途対応を推奨。🤖 Generated with Claude Code