Part 39: Session 42 — Consolidation and Quality Pass
Date: 2026-03-04 to 2026-03-05 | Version: v0.1.18-alpha
Overview
Consolidation session. No new features. Goal: production-grade code hygiene, architectural correctness, and full license compliance across all 47 source files. Every task was purely structural with identical object code and zero functional changes. Build green, device stable, zero printf in production.
Task 1: smp_handshake.c Debug Cleanup
main/protocol/smp_handshake.c reduced from 1281 to 1207 lines (74 lines removed). Removed 9 printf blocks (Layer dumps L0-L6, SKEY response hex, error-path hex dumps, A_MSG hex+ASCII). Auth-key-prefix log removed (security: would have leaked Ed25519 key bytes to serial). Plaintext message log removed (privacy: would have leaked cleartext to serial). 8 verbose pipeline LOGIs downgraded to LOGD. All session/task reference comments removed. German inline comments translated to English.
Result: Zero printf in production code. Verified across entire codebase.
Bugfix on-the-fly: smp_storage.c had an implicit declaration for mbedtls_platform_zeroize due to missing #include "mbedtls/platform_util.h". One line added.
Commits: refactor(handshake): remove debug logging and cleanup comments, fix(storage): add missing mbedtls/platform_util.h include
Task 2: smp_globals.c Dissolved
11 files affected. main/state/smp_globals.c was an architectural anomaly: a container for global definitions that belonged to specific owning modules. All 7 symbols migrated to their natural homes:
| Symbol | Moved to | Header |
|---|---|---|
ED25519_SPKI_HEADER[12] | smp_contacts.c | smp_contacts.h |
X25519_SPKI_HEADER[12] | smp_contacts.c | smp_contacts.h |
contacts_db | smp_contacts.c | smp_contacts.h |
base64url_chars[] | smp_utils.c | smp_utils.h |
pending_peer | smp_peer.c | smp_peer.h |
peer_conn | smp_peer.c | smp_peer.h |
wifi_connected | wifi_manager.c | wifi_manager.h |
smp_types.h now contains only type definitions (typedef struct, typedef enum, #define constants), no object declarations. This is the core architectural fix establishing a clear ownership model.
Additional cleanup: local extern declarations removed from smp_peer.c, ui_settings_info.c, smp_handshake.c (all now use proper header includes). Three follow-up build errors fixed: smp_queue.c, reply_queue.c, smp_parser.c were missing #include "smp_contacts.h".
smp_globals.c deleted. CMakeLists.txt uses SRC_DIRS so no explicit removal needed.
Commit: refactor(globals): dissolve smp_globals.c into owning modules
Task 3: extern TODO Markers Resolved
Grep scan for // TODO: move to header returned zero results (markers already cleaned during Task 2). One remaining case identified manually: extern bool peer_send_hello(contact_t *contact) in smp_tasks.c line 35. Declaration added to main/include/smp_peer.h, local extern removed.
Commit: refactor(tasks): move peer_send_hello declaration to smp_peer.h
Task 4: Re-delivery Log Level (Verified Correct)
Scan of smp_ratchet.c confirmed the re-delivery log was already ESP_LOGW. No changes needed. Task closed as verified.
Task 5: smp_app_run() Refactored
main/core/smp_tasks.c function smp_app_run() reduced from ~530 lines to 118 lines. Five static helper functions extracted, placed directly before smp_app_run(). No new headers, no logic changes, identical object code.
| Function | Responsibility |
|---|---|
app_init_run() | Initialization, parse buffer alloc, initial subscribe + wildcard ACK |
app_process_deferred_work() | Three deferred-save blocks: contacts NVS, RQ NVS, history load |
app_process_keyboard_queue() | Keyboard send with delivery status, history append |
app_handle_reply_queue_msg() | Full Reply Queue MSG path: E2E decrypt, agent process, 42d post-confirmation, ACK |
app_handle_contact_queue_msg() | Full Contact Queue MSG path: SMP decrypt, parse_agent_message, ACK |
The goto skip_42d_app label remains inside app_handle_reply_queue_msg(), functionally identical.
Commit: refactor(tasks): split smp_app_run into focused static helpers
Task 6: License Header Audit
47 source files across main/ now carry a standardized AGPL-3.0 header:
/**
* SimpleGo - filename.c
* Brief description
*
* Copyright (c) 2025-2026 Sascha Daemgen, IT and More Systems
* SPDX-License-Identifier: AGPL-3.0
*/
Excluded: lv_conf.h, generated font files (simplego_umlauts_*.c). Processed in 9 rounds of 5 files each. Side effect: 7 files contained UTF-8 BOM characters (primarily UI files), cleaned up during the license pass. UTF-8 BOM in ESP-IDF projects can cause subtle compiler warnings.
Commits: 9 commits (one per round)
Additional Fix
fix: ui_contacts.c TAG + reply_queue.c restore -- build-impacting fix discovered during license pass.
Architectural Decisions
smp_types.h scope: Strictly type definitions only. No object declarations. Any module needing a global object includes the header of the owning module.
Ownership model established:
| Module | Owns |
|---|---|
| smp_contacts.c | contacts_db, SPKI headers |
| smp_peer.c | pending_peer, peer_conn |
| wifi_manager.c | wifi_connected |
| smp_utils.c | base64url_chars |
Known Non-Errors (Unchanged)
E HISTORY: GCM decrypt failed for msg 0: -0x0012 is a corrupted first slot from early development, not a runtime error. W SMP_RATCH: Re-delivery is normal behavior (error code -10 is a skip code, correctly logged as LOGW).
Open Items for Session 43
Security cleanup: 5 logging categories with security-relevant data identified but not yet fixed (contact links, SUB hex dumps, response hex dumps, block header dumps, parser byte dumps). Must be resolved before Kickstarter release.
Documentation restructure: docs/ directory (150+ files) has grown organically with significant duplication. Decision: complete restructure from scratch with Docusaurus 3 at wiki.simplego.dev, deployed via GitHub Actions to GitHub Pages.
README rewrite: current README references criminal encrypted phone networks in inappropriate context for public-facing documentation. New README must be positive, professional, focused on what SimpleGo is.
Lessons Learned
L226 (HIGH): Global state containers (smp_globals.c) are architectural debt. Every global symbol should live in the module that logically owns it, with extern declared in that module's header. smp_types.h is for types only, never object declarations.
L227: smp_app_run() at 530 lines was unmaintainable. Five static helpers with clear responsibility boundaries (init, deferred work, keyboard, reply queue, contact queue) reduce the main loop to 118 lines with identical object code.
L228: UTF-8 BOM characters in C source files cause subtle compiler warnings in ESP-IDF. Clean during any file-wide pass (license headers, comment cleanup). Primarily affects files created or edited in Windows editors.
L229: License header standardization across 47 files requires batch processing (9 rounds of 5) to maintain build-green verification between rounds. Never apply to all files in one commit without intermediate builds.
Part 39 - Session 42 Consolidation and Quality Pass SimpleGo Protocol Analysis Date: March 4-5, 2026 Bugs: 71 total (69 FIXED, 1 identified for SPI3, 1 temp fix) Lessons: 229 total Milestone 18: Production Code Quality