Skip to content

Add kernel execution support for custom nodes#336

Open
Edwardvaneechoud wants to merge 4 commits intofeauture/kernel-implementationfrom
claude/custom-kernel-node-designer-osuks
Open

Add kernel execution support for custom nodes#336
Edwardvaneechoud wants to merge 4 commits intofeauture/kernel-implementationfrom
claude/custom-kernel-node-designer-osuks

Conversation

@Edwardvaneechoud
Copy link
Owner

Summary

This PR adds support for executing custom nodes inside Docker containers (kernels) with configurable package dependencies, while maintaining backward compatibility with the existing lazy-plan execution model.

Key Changes

Frontend

  • Node Designer: Added kernel execution toggle and required packages configuration UI

    • New "Execute in Kernel" checkbox to enable kernel mode
    • Input field for comma-separated list of required packages
    • Automatic code template switching between process method and kernel code
  • Custom Node Component: Implemented kernel selection UI with real-time status monitoring

    • Dropdown to select available kernels with state indicators (idle, executing, starting, stopped, error)
    • Visual indicators for kernel state and missing packages
    • Link to Kernel Manager for managing kernels
    • Warning messages when no kernel is selected or kernel is not in idle state
    • Polling mechanism (5-second intervals) to keep kernel status up-to-date
  • Code Editor: Updated to support both execution modes

    • Dynamic header and hints based on execution mode
    • Validation rules adapted for kernel vs. lazy execution
  • Constants & Types: Added kernel-specific defaults and type definitions

    • defaultKernelCode template with flowfile.read_input() and flowfile.publish_output()
    • Extended NodeMetadata and NodeUserDefined types with kernel fields

Backend

  • Flow Graph: Implemented dual execution paths for custom nodes

    • _add_user_defined_node_lazy(): Standard lazy-plan execution (existing behavior)
    • _add_user_defined_node_kernel(): New kernel-based execution with:
      • Automatic input materialization to Parquet files
      • Code injection of settings as Python variables
      • Kernel communication via ExecuteRequest
      • Output reading from Parquet back into LazyFrame
      • Proper logging and error handling
  • Custom Node Base: Extended with kernel configuration fields

    • use_kernel: bool - Enable kernel execution mode
    • required_packages: list[str] - Docker packages to install
    • kernel_code: str - Python code to execute in kernel
  • Code Generation: Updated to generate appropriate node classes

    • Kernel mode: Stores kernel_code as triple-quoted string, stubs process() method
    • Lazy mode: Extracts and re-indents process() method body (existing behavior)
  • Node Designer API: Enhanced to parse and extract kernel metadata from custom node files

    • Parses use_kernel, kernel_code, and required_packages attributes
    • Routes to appropriate code extraction based on execution mode

Data Models

  • Extended UserDefinedNode schema with optional kernel_id field
  • Updated CustomNodeSchema interface with kernel configuration fields

Implementation Details

  • Kernel execution follows the same pattern as add_python_script: materialize inputs → send code to kernel → read outputs
  • Settings are injected as plain Python variables in the kernel code (no self.settings_schema access needed)
  • Kernel polling is automatically started when a kernel-backed node is loaded and stopped on component unmount
  • Backward compatible: existing custom nodes continue to use lazy execution by default

Add support for custom nodes to execute in kernel containers, enabling
use of arbitrary Python packages beyond what Polars provides. Custom nodes
can now declare required packages (spec), and at runtime users select a
kernel that satisfies those requirements.

Backend changes:
- Add use_kernel, required_packages, kernel_code fields to CustomNodeBase
- Add kernel_id to UserDefinedNode for runtime kernel selection
- Split add_user_defined_node() into lazy and kernel execution paths
- Add _add_user_defined_node_kernel() following add_python_script() pattern
- Add _build_kernel_code_for_custom_node() for settings injection
- Parse kernel fields (use_kernel, required_packages, kernel_code) in
  get_custom_node() route for Node Browser loading

Frontend changes:
- Add kernel execution toggle and required packages input to NodeDesigner
- Add kernel-mode code editor with flowfile API hints
- Implement dual-mode code generation (lazy vs kernel)
- Add kernel-mode validation rules (flowfile.publish_output check)
- Add runtime kernel selector with package matching to CustomNode.vue
- Update types: NodeMetadata, CustomNodeSchema, NodeUserDefined

https://claude.ai/code/session_01Sody7mJjQrzJvSrmF5HMVe
The required packages input now uses a text field + "+" button to add
packages one at a time, displayed as removable tags. This avoids the
issue where typing commas was consumed by the parser.

https://claude.ai/code/session_01Sody7mJjQrzJvSrmF5HMVe
In kernel mode, settings are injected as plain Python variables by the
runtime, so Insert Variable now emits a comment showing the variable
name and type instead of self.settings_schema references. The insertion
point also skips initial comments rather than searching for def process.

https://claude.ai/code/session_01Sody7mJjQrzJvSrmF5HMVe
Build a SimpleNamespace-based `self` object in the kernel code so
`self.settings_schema.section.field.value` works identically in both
kernel and lazy modes. Flat convenience variables are kept too.

The Insert Variable button now emits the same self.settings_schema
pattern for both modes (no indentation in kernel mode since there's
no enclosing def).

https://claude.ai/code/session_01Sody7mJjQrzJvSrmF5HMVe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants