[RTOP-69] implement base code to commands#9
Conversation
…ment-command-compile/status
…mplement-command-compile/status
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Note 🎁 Summarized by CodeRabbit FreeYour organization has reached its limit of developer seats under the Pro Plan. For new users, CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please add seats to your subscription by visiting https://app.coderabbit.ai/login.If you believe this is a mistake and have available seats, please assign one to the pull request author through the subscription management page using the link above. Comment |
…ask/RTOP-69-Implement-command-compile/status
There was a problem hiding this comment.
Pull Request Overview
Implements base code for PLC program management commands including compilation, file upload handling, and runtime process management. This replaces the legacy openplc.py system with a more robust architecture.
- Introduces
RuntimeManagerclass for managing PLC runtime processes with auto-restart capability - Implements secure ZIP file upload with safety validation and compilation pipeline
- Refactors command handling to use modern patterns with proper error handling
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| webserver/unixclient.py | Adds STATUS command support to the Unix socket client |
| webserver/runtimemanager.py | New runtime manager class for PLC process lifecycle management |
| webserver/plcapp_management.py | New module for secure ZIP file handling and compilation management |
| webserver/app.py | Refactors main application to use new runtime and compilation systems |
| webserver/openplc.py | Removes legacy OpenPLC runtime implementation |
| webserver/credentials.py | Removes default parameters from certificate generation method |
| test_api.py | Removes existing API tests |
| conftest.py | Removes test configuration file |
| scripts/compile.sh | Moves cleanup operations to separate script |
| scripts/compile-clean.sh | New cleanup script for post-compilation operations |
| install.sh | Adds PLC application build step to installation |
| core/src/plc_app/utils/log.c | Fixes socket logging implementation |
| core/src/plc_app/unix_socket.c | Improves command handling and adds proper STATUS implementation |
| .pre-commit-config.yaml | Adds comment explaining clang-format configuration |
Comments suppressed due to low confidence (2)
webserver/plcapp_management.py:1
- Variable
clientis not defined in this function scope. Therun_compilefunction expects aSyncUnixClientparameter but no client is available here.
from dataclasses import dataclass, field
webserver/plcapp_management.py:1
- The
analyze_zipfunction expects a file path string butzip_fileis aFileStorageobject from Flask. Should save the file first and pass the path toanalyze_zip.
from dataclasses import dataclass, field
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Fix #2: Guard buffer mutex release after crash with a volatile flag (holding_buffer_mutex) to avoid undefined behavior when unlocking a mutex not owned by the calling thread - Fix #3: Reset plc_crash_signal to 0 at the start of plc_cycle_thread so stale values don't persist after successful recovery - Fix #4: Add plc_force_error_state() function for the watchdog to transition to ERROR state through the mutex instead of writing plc_state directly. Remove extern PLCState from watchdog.c - Fix #5: Skip watchdog heartbeat check when already in ERROR state to prevent repeated error log spam every 2 seconds. Move heartbeat reset to the non-RUNNING branch so it happens once on ERROR entry - Fix #6: Add trailing newline to plc_state_manager.h - Fix #8: Add threading.Lock to protect _crash_times and _safe_mode in RuntimeManager against concurrent access from the monitor and compilation threads - Fix #9: Rename _should_enter_safe_mode to _record_crash_and_check_safe_mode to make the side effect explicit Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Compiles a program and manages the entire build process.
What it does:
Starts compilation: Executes a bash script (compile.sh)
Monitors progress: Shows real-time output and error messages
Manages build state: Tracks compiling/success/failed status
Handles system restart: Stops and starts the PLC controller after compilation
Performs cleanup: Runs a cleanup script (compile-clean.sh)
Step-by-step flow:
Sets status to "COMPILING"
Starts the compilation script
Creates threads to monitor process output
Waits for compilation to complete
If successful: stops PLC, runs cleanup, restarts PLC
If failed: shows error message
Receives a ZIP file, validates it, and extracts contents.
What it does:
Validations: Checks file safety (prevents zip bombs)
Preparation: Cleans old directory and extracts new ZIP
Initiates compilation: Calls compilation function in separate thread
Validation checks:
✅ Verifies no active compilation is running
✅ Confirms file exists in request
✅ Checks file size limits
✅ Analyzes ZIP safety
✅ Extracts only valid files
Complete Flow:
Upload ZIP → Validate → Clean folder → Extract → Compile → Stop PLC → Move file → Start PLC