Skip to content

Conversation

@ewowi
Copy link
Collaborator

@ewowi ewowi commented Nov 22, 2025

Back end

  • EthernetSettingsService: use .config (hidden)
  • d0 tuning
  • no MOONLIGHT tuning

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Adjusted HTTP daemon stack allocation for ESP32 D0 variants.
    • Modified task stack sizes and core affinity settings for improved resource management.
    • Updated Ethernet settings file path for configuration storage.
  • Chores

    • Removed unused ESP32 P4 and S3 environment variants from build system.
    • Updated firmware build configurations.

✏️ Tip: You can customize this high-level summary in your review settings.

Back end
========
- EthernetSettingsService: use .config (hidden)
- d0 tuning
- no MOONLIGHT tuning
@coderabbitai
Copy link

coderabbitai bot commented Nov 22, 2025

Walkthrough

This PR adjusts ESP32 firmware configurations, updates Ethernet settings file path, implements conditional asynchronous callback execution for a Moonlight feature behind the FT_MOONLIGHT macro, and modifies FreeRTOS task stack sizes with explicit core affinity assignments.

Changes

Cohort / File(s) Summary
ESP32 Build Configuration
firmware/esp32-d0.ini
Adds HTTPD_STACK_SIZE=6144 build flag to multiple ESP32 D0 environments to increase HTTP daemon stack allocation
ESP32 Environment Removal
firmware/esp32-p4.ini, firmware/esp32-s3.ini
Removes entire environment blocks: env:esp32-p4-8MB_troyhacks_personal from P4 config and env:esp32-s3-devkitc-1-n16r8vVD from S3 config with all associated settings
Ethernet Settings Path
lib/framework/EthernetSettingsService.h
Updates macro ETHERNET_SETTINGS_FILE path from "/config/ethernetSettings.json" to "/.config/ethernetSettings.json"
Moonlight Async Callback Implementation
src/MoonBase/Module.cpp
Introduces conditional asynchronous execution for onReOrderSwap and onUpdate callbacks via runInAppTask when FT_MOONLIGHT is defined, otherwise invokes directly
Moonlight Feature Declarations
src/MoonBase/Utilities.h, src/MoonBase/Utilities.cpp
Conditionally gates global declarations (runInAppTask vector and runInAppTask_mutex mutex) behind #if FT_MOONLIGHT preprocessor guards
FreeRTOS Task Configuration
src/main.cpp
Adjusts stack size allocations for effectTask (6→3 KB when PSRAM absent) and driverTask (3→4 KB when PSRAM absent); explicitly assigns both tasks to core 1 via xTaskCreateUniversal parameter

Sequence Diagram

sequenceDiagram
    participant Module as Module
    participant TaskQueue as TaskQueue<br/>(runInAppTask)
    participant AppTask as AppTask<br/>(FreeRTOS)

    rect rgb(230, 245, 255)
    Note over Module,AppTask: FT_MOONLIGHT Enabled
    Module->>TaskQueue: Enqueue callback<br/>(onReOrderSwap/onUpdate)
    TaskQueue->>AppTask: Process queued callback<br/>when idle
    AppTask->>AppTask: Execute callback
    end

    rect rgb(255, 245, 230)
    Note over Module,AppTask: FT_MOONLIGHT Disabled
    Module->>Module: Execute callback directly<br/>(synchronous)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Moonlight feature conditional logic across three files (Module.cpp, Utilities.h/cpp) requires verification that guards and macro usage are consistent and thread-safe
  • FreeRTOS stack size changes in main.cpp should be validated against memory constraints and actual stack usage patterns for both PSRAM and non-PSRAM scenarios
  • File path change (EthernetSettingsService.h) needs confirmation that the new path is correctly handled by the filesystem layer and configuration initialization
  • Configuration file deletions in ESP32 INI files should be verified to not break any active build pipelines

Poem

🐰 New configs dance and old ones fade,
Stack sizes tuned with care displayed,
Async tasks on core one rest,
Moonlight features put to test,
Settings files in new homes made!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The PR title 'd0 tuning' is too vague and does not clearly convey the scope of changes, which include Ethernet config path updates, stack size adjustments, and core affinity changes across multiple files. Consider a more descriptive title that captures the main changes, such as 'ESP32 D0 tuning and Ethernet config updates' or 'Tune D0 stack sizes and move Ethernet config to hidden directory'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d59bdaa and 2220856.

📒 Files selected for processing (8)
  • firmware/esp32-d0.ini (2 hunks)
  • firmware/esp32-p4.ini (0 hunks)
  • firmware/esp32-s3.ini (0 hunks)
  • lib/framework/EthernetSettingsService.h (1 hunks)
  • src/MoonBase/Module.cpp (2 hunks)
  • src/MoonBase/Utilities.cpp (1 hunks)
  • src/MoonBase/Utilities.h (1 hunks)
  • src/main.cpp (2 hunks)
💤 Files with no reviewable changes (2)
  • firmware/esp32-p4.ini
  • firmware/esp32-s3.ini
🧰 Additional context used
🧬 Code graph analysis (1)
src/MoonBase/Module.cpp (1)
src/MoonBase/NodeManager.h (2)
  • onReOrderSwap (287-298)
  • onUpdate (134-285)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (8)
firmware/esp32-d0.ini (1)

89-89: LGTM: Consistent HTTPD stack sizing across D0 environments.

The HTTPD_STACK_SIZE of 6144 bytes is now consistent across all esp32-d0 environments. The reasoning that MoonBase-only builds need more HTTPD stack due to lack of app tasks is documented and sound.

Also applies to: 107-107

src/main.cpp (2)

299-299: Good: Explicit core affinity improves predictability.

Both tasks are now explicitly pinned to core 1, which makes the threading behavior more predictable and easier to reason about.

Also applies to: 308-308


304-304: Stack reallocation between tasks needs verification.

The driverTask stack size for non-PSRAM boards increased from 3KB to 4KB, which mirrors the 1KB reduction in effectTask. While this maintains total stack allocation, ensure this redistribution aligns with actual runtime requirements of each task.

lib/framework/EthernetSettingsService.h (1)

36-36: Directory creation is handled automatically; confirm breaking change intent.

The /.config/ directory is created automatically by FSPersistence::mkdirs() during the first write operation (lib/framework/FSPersistence.h:160–170), so explicit directory creation logic is not required.

However, migration logic is not present: there are no references to the old /config/ethernetSettings.json path in the codebase. This represents an intentional breaking change—existing deployments using /config/ethernetSettings.json will lose their settings and start fresh with the new path.

All code references correctly use the ETHERNET_SETTINGS_FILE macro (EthernetSettingsService.cpp:24), consistent with other services (WiFi, MQTT, NTP, Security, AP).

Verify that this breaking change is acceptable for your deployment scenario.

src/MoonBase/Utilities.h (1)

383-387: LGTM - Conditional compilation of task queue globals.

The extern declarations are now properly guarded behind FT_MOONLIGHT, making these globals optional. This aligns with the changes in Utilities.cpp where the actual definitions are similarly guarded.

src/MoonBase/Utilities.cpp (1)

166-170: LGTM - Conditional compilation matches header declarations.

The definitions are properly guarded behind FT_MOONLIGHT, consistent with the extern declarations in Utilities.h.

src/MoonBase/Module.cpp (2)

138-148: Same lifetime and macro concerns as checkReOrderSwap.

The same two concerns apply here:

  1. Macro inconsistency: Uses #if FT_ENABLED(FT_MOONLIGHT) instead of #if FT_MOONLIGHT used in Utilities files.

  2. Lambda lifetime: Captures this by reference while updatedItem is captured by value. The mutable keyword is appropriate since onUpdate may modify the captured copy, but the reference to this creates a potential use-after-free if the Module is destroyed before task execution.

Note: The comment on line 142 states "mutable as updatedItem is called by reference (&)" which is slightly misleading—mutable is needed because onUpdate takes a non-const reference and may modify the captured copy.


107-115: Lambda lifetime concern is invalid; Module objects are global with guaranteed lifetime.

The review comment's concerns do not hold upon verification:

  1. Lambda lifetime is safe: Module subclass instances (ModuleDevices, ModuleIO, ModuleEffects, etc.) are created as global objects in src/main.cpp (lines 93–113), not dynamically allocated. Global objects persist for the entire program execution. Since runInAppTask lambdas are processed in the continuous loopTask, the Module objects are guaranteed to exist when lambdas execute. There is no use-after-free risk.

  2. Macro consistency is a non-issue: FT_ENABLED(FT_MOONLIGHT) expands to FT_MOONLIGHT (FT_ENABLED is a passthrough macro defined in lib/framework/Features.h:18). Both forms are functionally identical. While the codebase predominantly uses #if FT_MOONLIGHT directly, the wrapper form in Module.cpp is merely a style variation, not a correctness problem.

Likely an incorrect or invalid review comment.

xTaskCreateUniversal(effectTask, // task function
"AppEffectTask", // name
(psramFound() ? 6 : 4) * 1024, // d0-tuning... stack size (without livescripts we can do with 12...). updated from 4 to 6 to support preset loop
(psramFound() ? 6 : 3) * 1024, // d0-tuning... stack size (without livescripts we can do with 12...). updated from 4 to 6 to support preset loop
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

Verify stack sufficiency and update misleading comment.

The effectTask stack size for non-PSRAM boards has been reduced from 4KB to 3KB (25% reduction). The inline comment states "updated from 4 to 6 to support preset loop," which appears to contradict the actual change.

Concerns:

  1. The 1KB reduction could lead to stack overflow if the task requires the full 4KB
  2. The comment is confusing and doesn't accurately describe the change

Please verify that 3KB is sufficient for effectTask on non-PSRAM ESP32-D0 boards, and update the comment to accurately reflect the stack size changes.


🏁 Script executed:

#!/bin/bash
# Search for any stack overflow detection or watermark checks
rg -nP --type=cpp 'uxTaskGetStackHighWaterMark|Stack.*overflow|stack.*remain' -A 2

Length of output: 2731



🏁 Script executed:

#!/bin/bash
# Get context around line 295 in src/main.cpp to see task creation
sed -n '280,310p' src/main.cpp

Length of output: 1610


🏁 Script executed:

#!/bin/bash
# Search for effectTask definition and its operations
rg -nP --type=cpp 'effectTask|void.*effect' -A 5 | head -100

Length of output: 2173


🏁 Script executed:

#!/bin/bash
# Look for any stack-related warnings or past issues with this task
rg -nP --type=cpp 'effect.*stack|effectTask.*size' -B 2 -A 2

Length of output: 0



🏁 Script executed:

#!/bin/bash
# Get full effectTask implementation
sed -n '121,145p' src/main.cpp

Length of output: 753


🏁 Script executed:

#!/bin/bash
# Search for layerP.step() to understand call depth
rg -nP --type=cpp 'layerP\.step|void step\(' -A 3 | head -80

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Search for any comments mentioning stack tuning or the "4 to 6" or "4 to 3" change
rg -nP --type=cpp 'tuning|preset.*loop|stack.*size' -B 1 -A 1

Length of output: 1185



🏁 Script executed:

#!/bin/bash
# Find layerP.loop implementation - likely in layer-related files
find src -name "*.h" -o -name "*.cpp" | xargs grep -l "layerP" | head -5

Length of output: 146


🏁 Script executed:

#!/bin/bash
# Search for loop() method definition in layer files
rg -nP --type=cpp 'void loop\(\)|void loop20ms\(\)' -B 2 -A 8 | head -100

Length of output: 7897


🏁 Script executed:

#!/bin/bash
# Check git log/blame for this line to see what was actually changed
git log -p --all -S "updated from 4 to" -- src/main.cpp 2>/dev/null | head -100

Length of output: 59


Fix misleading comment and verify 3KB stack is sufficient.

The effectTask stack size was reduced from 4KB to 3KB for non-PSRAM boards (25% reduction). The inline comment stating "updated from 4 to 6" is incorrect—the actual change is 4→3 for non-PSRAM (PSRAM remains 6KB unchanged).

Concerns:

  1. Comment contradicts the code change and must be corrected
  2. The 1KB reduction on non-PSRAM requires validation that 3KB suffices for effectTask's layerP.loop() call chain

Update the comment to accurately reflect: "reduced from 4 to 3 for non-PSRAM to..." and verify the stack is adequate or document the tradeoffs made.

🤖 Prompt for AI Agents
In src/main.cpp around line 295, the inline comment next to the effectTask stack
size is incorrect and misleading (it currently says "updated from 4 to 6" while
the code uses 6KB for PSRAM and 3KB for non-PSRAM); update the comment to
accurately state that non-PSRAM boards were reduced from 4KB to 3KB while PSRAM
remains 6KB, and explain the reason/tradeoff (e.g., to save RAM while accepting
tighter stack headroom). Then verify 3KB is sufficient by exercising
effectTask's call chain (specifically layerP.loop() and its callees) under
worst-case conditions (deep recursion, large local buffers, debug builds) using
an instrumented run or stack high-water mark check; if stack overflows or margin
is too small, either increase the non-PSRAM stack back to 4KB or refactor to
reduce stack usage, and document the chosen outcome in the comment.

@ewowi ewowi merged commit aec9b19 into main Nov 29, 2025
2 checks passed
This was referenced Dec 3, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 26, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jan 7, 2026
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