Skip to content

EnableMotion: switch majestic's motion detector on from the cloud - #47

Merged
keyldev merged 1 commit into
masterfrom
feat/enable-motion
Nov 23, 2026
Merged

keyldev merged 1 commit into
masterfrom
feat/enable-motion

Conversation

@keyldev

@keyldev keyldev commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

The coordinator's new one-shot command turns on .motionDetect.enabled and .system.plugins through cli and restarts majestic (init script, or SIGHUP where there is none). Without it the cloud's detection switch did nothing on a camera whose detector had not been enabled by hand. 0.3.3.

The coordinator's new one-shot command turns on .motionDetect.enabled and
.system.plugins through cli and restarts majestic (init script, or SIGHUP
where there is none). Without it the cloud's detection switch did nothing
on a camera whose detector had not been enabled by hand. 0.3.3.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Enable majestic motion detection from a coordinator command

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Handle EnableMotion so cloud detection works without manually enabling majestic’s detector.
• Restart majestic after changing its settings, falling back to SIGHUP when needed.
• Add command coverage and document the behavior in the 0.3.3 release notes.
Diagram

graph TD
  coordinator["Coordinator"] --> directive["Directive handler"] --> enable["EnableMotion"] --> cli["Majestic CLI"] --> restart{"Init restart succeeds?"}
  restart -- "Yes" --> majestic["Majestic detector"] --> hook["Motion hook"]
  restart -- "No" --> sighup["SIGHUP fallback"] --> majestic
Loading
High-Level Assessment

Using majestic’s CLI preserves its ownership of the configuration format, and the init-script/SIGHUP fallback accommodates firmware without that script. Directly editing majestic’s configuration was considered but offers no clear advantage.

Files changed (3) +54 / -1

Bug fix (1) +33 / -1
cerberus.cHandle EnableMotion and advance the version to 0.3.3 +33/-1

Handle EnableMotion and advance the version to 0.3.3

• Dispatches the new coordinator command to set both majestic configuration keys through 'cli', then attempts an init-script restart with a SIGHUP fallback. Logs configuration or restart failures and notes when agent motion events are disabled.

src/cerberus.c

Tests (1) +13 / -0
suite.shExercise EnableMotion through the heartbeat back-channel +13/-0

Exercise EnableMotion through the heartbeat back-channel

• Adds stub 'cli' and 'killall' commands and verifies both configuration writes, the SIGHUP fallback, and the success log.

tests/suite.sh

Documentation (1) +8 / -0
CHANGELOG.mdDocument the 0.3.3 motion-enablement behavior +8/-0

Document the 0.3.3 motion-enablement behavior

• Adds release notes explaining the new cloud command, majestic restart fallback, and continued use of the camera web interface to switch detection off.

CHANGELOG.md

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

qodo-free-for-open-source-projects Bot commented Nov 12, 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


Remediation recommended

1. A failed plugin update leaves motion half-enabled 🐞 Bug ☼ Reliability
Description
enable_motion() writes .motionDetect.enabled before .system.plugins, then returns without
reloading Majestic if the second write fails. Because the two cli calls are independent, that
failure leaves the first setting changed but unapplied, with no rollback or attempt to complete the
configuration.
Code

src/cerberus.c[R2125-2127]

+    if (run(detector, NULL, 0) != 0 || run(plugins, NULL, 0) != 0) {
+        warn_("EnableMotion: `cli -s` failed — is majestic on this firmware?");
+        return;
Evidence
The first write precedes the second; the failure branch returns before the only restart path, while
run() executes each command separately.

src/cerberus.c[2120-2133]
src/cerberus.c[552-590]

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

## Issue description
If the plugin write fails after the detector write succeeds, the function returns with a partially changed configuration and does not reload Majestic.
## Fix Focus Areas
- src/cerberus.c[2120-2133]
## Recommended Fix
Handle the two write results separately. If the second write fails, restore the first setting or retain a retryable incomplete state, and make the restart decision reflect any settings that were successfully changed.

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


2. A transient failure loses the cloud command 🐞 Bug ☼ Reliability
Description
enable_motion() logs a failed configuration write or restart and returns without retaining work
for another attempt. When the coordinator delivers EnableMotion as a one-shot heartbeat command,
either transient failure leaves this agent with no automatic retry, so motion may remain disabled
until another command is issued.
Code

src/cerberus.c[R2129-2133]

+    if (run(restart, NULL, 0) != 0 && run(reload, NULL, 0) != 0) {
+        warn_("EnableMotion: the detector is on in majestic's config, but majestic could not be restarted"
+              " — it takes effect on majestic's next start");
+        return;
+    }
Evidence
Both failure branches return without scheduling another attempt. The watch loop applies the command
only from a heartbeat response, and the repository’s coordinator fixture clears its queued command
when delivering that response.

src/cerberus.c[2125-2135]
src/cerberus.c[2311-2331]
tests/fake_coordinator.py[219-228]

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 one-shot EnableMotion directive is lost when a configuration write or Majestic restart fails transiently.
## Fix Focus Areas
- src/cerberus.c[2125-2135]
- src/cerberus.c[2311-2331]
## Recommended Fix
Retain a pending enablement state after either failure and retry the incomplete operation from the watch loop until the settings have been applied and Majestic has restarted or reloaded.

ⓘ 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 keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@keyldev
keyldev merged commit b3cab47 into master Nov 23, 2026
7 of 9 checks passed
@keyldev
keyldev deleted the feat/enable-motion branch November 23, 2026 23:17
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