Skip to content

feat: night mode - #48

Merged
keyldev merged 1 commit into
masterfrom
feat/night-mode
Nov 25, 2026
Merged

keyldev merged 1 commit into
masterfrom
feat/night-mode

Conversation

@keyldev

@keyldev keyldev commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Control majestic motion detection and night mode from the cloud

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Enable majestic’s motion detector through a coordinator command so cloud-triggered detection can
 work.
• Switch majestic between night and day mode using the configured snapshot origin and credentials.
• Add command tests, document the behavior, and bump the version to 0.3.4.
Diagram

graph TD
  C["Cloud coordinator"] --> A["Cerberus agent"] --> D{"Directive type"}
  D -->|EnableMotion| CLI["majestic cli"] --> R["Restart or SIGHUP"] --> M["majestic"]
  D -->|NightModeOn or NightModeOff| H["HTTP client"] --> M
Loading
High-Level Assessment

The approach fits the existing agent: use majestic’s CLI rather than editing its configuration file, and reuse the snapshot URL and HTTP client rather than introducing separate credentials. Neither alternative offers a clear architectural advantage.

Files changed (4) +137 / -2

Enhancement (1) +81 / -1
cerberus.cDispatch majestic motion and night-mode commands +81/-1

Dispatch majestic motion and night-mode commands

• Adds EnableMotion to set majestic’s detector and plugin configuration, then restart or reload it. Adds NightModeOn and NightModeOff calls to the snapshot origin with its existing credentials, logs outcomes without printing the URL, and bumps the version to 0.3.4.

src/cerberus.c

Tests (2) +40 / -1
fake_coordinator.pySimulate authenticated majestic night-mode endpoints +14/-1

Simulate authenticated majestic night-mode endpoints

• Extends the fake majestic server with /night/on and /night/off responses, including Basic-auth rejection for requests without the configured credentials.

tests/fake_coordinator.py

suite.shCover motion setup and night-mode directives +26/-0

Cover motion setup and night-mode directives

• Checks both motion configuration calls and the reload fallback. Verifies authenticated night-mode requests, password-free success logging, and guidance after an unauthorized request.

tests/suite.sh

Documentation (1) +16 / -0
CHANGELOG.mdDocument motion and night-mode commands +16/-0

Document motion and night-mode commands

• Adds 0.3.3 and 0.3.4 entries describing the new coordinator commands, authentication behavior, and operational limits.

CHANGELOG.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. A stalled night switch freezes monitoring 🐞 Bug ☼ Reliability
Description
night_mode() calls http_do() synchronously, and its socket read waits for the snapshot server to
close the connection without a timeout. If /night/on or /night/off leaves that connection open,
the heartbeat directive never returns, so subsequent watchdog checks and motion processing do not
run.
Code

src/cerberus.c[2170]

+    n = http_do(&rq, resp, sizeof resp, &status);
Evidence
The new call is made while processing a heartbeat directive. The HTTP reader waits for EOF without a
configured timeout, and the watch loop cannot reach its later work until directive processing
returns.

src/cerberus.c[2166-2173]
src/cerberus.c[904-916]
src/cerberus.c[1125-1129]
src/cerberus.c[2360-2383]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A night-mode request can wait indefinitely for the snapshot server to close its connection, blocking the agent’s main monitoring loop.
## Fix Focus Areas
- src/cerberus.c[2170-2170]
- src/cerberus.c[904-916]
- src/cerberus.c[1125-1129]
## Recommended Fix
Give night-mode HTTP operations a finite connection and read deadline, and return a logged failure when that deadline expires. Ensure a response that leaves the connection open cannot delay the next monitoring tick indefinitely.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Successful night switches can log failure 🐞 Bug ◔ Observability
Description
night_mode() passes a 512-byte response buffer to http_do(), which can return -1 without
parsing the status when a single read exceeds that buffer. If majestic returns a successful response
larger than 511 bytes in that read, the switch may have happened but the agent logs that majestic
did not answer.
Code

src/cerberus.c[2170]

+    n = http_do(&rq, resp, sizeof resp, &status);
Evidence
The receive loop rejects an oversized read before copying any response bytes; with fewer than 12
bytes buffered, http_do() returns -1. The new caller interprets that return value as no answer,
even if the server sent HTTP 200.

src/cerberus.c[2150-2150]
src/cerberus.c[1125-1141]
src/cerberus.c[2170-2179]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A successful night-mode response can be reported as a connection failure solely because its response exceeds the new 512-byte buffer.
## Fix Focus Areas
- src/cerberus.c[2150-2150]
- src/cerberus.c[2170-2179]
- src/cerberus.c[1125-1155]
## Recommended Fix
For night-mode requests, parse the HTTP status within a bounded response header and discard an unneeded body rather than requiring the entire response to fit in 512 bytes. Preserve a distinct warning for actual transport or malformed-response failures.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@keyldev keyldev changed the title Feat/night mode feat: night mode Nov 23, 2026
@keyldev
keyldev force-pushed the feat/night-mode branch 2 times, most recently from 4d4ec3f to 529e05f Compare November 25, 2026 01:19
The coordinator's new one-shot commands call majestic's own /night/on and
/night/off on the origin the snapshot comes from, so a majestic with a
password is reached with the one already in cerberus_snapshot_url; the log
names the path and never that address. As with every command nothing answers
the cloud, and majestic's automatic mode may switch back on its light sensor.
0.3.4.
@keyldev
keyldev merged commit 3eecc01 into master Nov 25, 2026
9 checks passed
@keyldev
keyldev deleted the feat/night-mode branch November 25, 2026 01:36
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.

1 participant