Skip to content

feat: Use supervisor when running tedge-agent/tedge-mapper#4244

Merged
jarhodes314 merged 2 commits into
thin-edge:mainfrom
jarhodes314:feat/standalone-supervisor
Jul 13, 2026
Merged

feat: Use supervisor when running tedge-agent/tedge-mapper#4244
jarhodes314 merged 2 commits into
thin-edge:mainfrom
jarhodes314:feat/standalone-supervisor

Conversation

@jarhodes314

@jarhodes314 jarhodes314 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Use the supervisor for running a single-process tedge-agent/tedge-mapper. This means we get log reloading on SIGHUP.

For these processes, the supervisor doesn't attempt to restart the process on failure unlike in tedge run all, as we assume there is an init system in place to restart the process, and an internal restart will mask issues where the process is in a crash loop. We don't do anything on SIGUSR1 for these processes, unlike tedge run all where we restart the mappers.

When reviewing, you probably want to look at the second commit onwards. The first commit is merely renaming a file (to separate out the supervisor into its own crate), but github doesn't show it as that.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
953 0 7 953 100 2h49m47.753702999s

@Bravo555 Bravo555 self-requested a review July 9, 2026 08:57
@Bravo555 Bravo555 self-assigned this Jul 9, 2026
@reubenmiller reubenmiller added the refactoring Developer value label Jul 9, 2026
@Bravo555

Bravo555 commented Jul 9, 2026

Copy link
Copy Markdown
Member

@reubenmiller To me it seems to be a behaviour/feature change, not a refactoring (which ideally shouldn't change behaviour)

@reubenmiller

reubenmiller commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@reubenmiller To me it seems to be a behaviour/feature change, not a refactoring (which ideally shouldn't change behaviour)

yeah you're write, I just couldn't find a better label, so maybe we're missing something.

Update: I've created a new "theme:runtime" label

@reubenmiller reubenmiller added theme:runtime General features regarding either the actor runtime, how processes are started etc. and removed refactoring Developer value labels Jul 9, 2026

@Bravo555 Bravo555 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see there are some unit tests in the tedge_supervisor crate, to make sure its API works as expected, but I'd also like to see system tests to make sure that tedge-mapper and tedge-agent actually use the supervisor correctly and exhibit the new behaviour we expect, because if I understand correctly, currently we don't seem to be checking that.

@Bravo555 Bravo555 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All the changes seem correct, nothing to complain about, but I do believe some system tests would be necessary here.

And just some thoughts about specs: having scenarios and requirements in spec.mds would be really, really nice if there was some neat way to reference the specs in any test (unit or system test) and then you could find backlinks to that requirement so you could easily see from the spec document itself the tests that cover its requirements.

Comment thread crates/common/tedge_supervisor/src/lib.rs

- SIGUSR1 mapper restart for standalone processes — this signal is meaningful only when the agent and mapper share a process, where it allows restarting the mapper without restarting the agent. A standalone mapper has nothing to coordinate with.
- Changing the `build()` factory contract — standalone and `tedge run all` paths continue to share the same factory
- Replacing systemd restart semantics — the supervisor's crash recovery complements systemd, it does not replace it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thought: Yeah, I was curious about that - I see in the last section that when we run tedge-mapper/tedge-agent using the supervisor and as a systemd unit, the service can restart up to supervisor × systemd times, because systemd doesn't know about restarting the supervisor does, but it's ok because supervisor restarting is faster and loses less state.

Though now there's probably no reason to, we could always make them both aware of each other. The supervisor could check INVOCATION_ID, which is set by systemd when running as a unit and disable restarts if we wish to add that type of configuration, and similarly we could also potentially support systemctl reload command since we now handle SIGHUP to reload log levels. But that's outside the scope of this PR and for future consideration.

Comment thread Cargo.lock
[[package]]
name = "quinn-udp"
version = "0.5.12"
version = "0.5.14"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: seems unrelated

@Bravo555 Bravo555 removed their assignment Jul 9, 2026
@jarhodes314 jarhodes314 requested a review from a team as a code owner July 9, 2026 12:28
@jarhodes314

Copy link
Copy Markdown
Contributor Author

I see there are some unit tests in the tedge_supervisor crate, to make sure its API works as expected, but I'd also like to see system tests to make sure that tedge-mapper and tedge-agent actually use the supervisor correctly and exhibit the new behaviour we expect, because if I understand correctly, currently we don't seem to be checking that.

Added in 39aa1f1

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.69953% with 131 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/common/tedge_supervisor/src/lib.rs 91.56% 74 Missing and 9 partials ⚠️
crates/core/tedge_agent/src/lib.rs 0.00% 21 Missing ⚠️
crates/core/tedge_mapper/src/lib.rs 0.00% 15 Missing ⚠️
...s/common/tedge_config/src/system_toml/log_level.rs 81.25% 0 Missing and 6 partials ⚠️
crates/core/tedge/src/supervisor.rs 50.00% 5 Missing ⚠️
plugins/tedge_file_config_plugin/src/lib.rs 66.66% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Move the supervisor implementation from crates/core/tedge/src/supervisor.rs
to crates/common/tedge_supervisor/src/lib.rs so it can be reused by
tedge-agent and tedge-mapper as standalone processes.

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Extract the supervisor into its own tedge_supervisor crate and add
support for running tedge-agent and tedge-mapper as standalone
supervised processes, in addition to the existing multi-unit mode.

Signed-off-by: James Rhodes <jarhodes314@gmail.com>
@jarhodes314 jarhodes314 force-pushed the feat/standalone-supervisor branch from af36fa5 to 71c80e0 Compare July 10, 2026 10:10
@jarhodes314 jarhodes314 temporarily deployed to Test Pull Request July 10, 2026 10:11 — with GitHub Actions Inactive

@Bravo555 Bravo555 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see we also changed the crash of standalone components (i.e. only mapper or only agent) to not recover using supervisor but proceed to crash and be restarted by the init system; that is fine.
Tests were added, so approving.

@rina23q rina23q left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved, the system tests are convincing.

@jarhodes314 jarhodes314 added this pull request to the merge queue Jul 13, 2026
Merged via the queue into thin-edge:main with commit 221053b Jul 13, 2026
35 checks passed

@albinsuresh albinsuresh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Solid work. Well documented with extensive test coverage as well.

I just noticed one bug: The mapper mapper component is getting restarted by the systemctl kill --signal=SIGUSR1 tedge-mapper-c8y command, despite the specs hinting otherwise.

A supervised component that requires a restart (after a self-update, or an update
of its own configuration) SHALL cause the supervisor to drain every component and
exit the process with a non-zero code, since only re-executing the binary makes
such an update effective.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming we were forced to handle action = "restart-agent" this way due to the current contract of the await-agent-restart. For a self-update, this makes sense as the entire tedge binary is updated. But for a config_update that only affects the tedge-agent, this isn't ideal. We might have to rethink this in future where an agent restart can be handled as just the actor restart without affecting all other mappers.

# mapper fails fast on the lock, so this does not block.
Execute Command tedge-mapper c8y exp_exit_code=!0

A config update restarting the agent restarts the whole process

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We'll have to rethink the config_update workflow itself to not expect a service restart but only a reload once the single process mode becomes the norm and tedge.toml updates are also handled by it.

Service Log Should Not Contain tedge-agent EntityStoreServer: recv date_from=${after}
[Teardown] Remove Log Override


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about an additional test that validates that SIGUSR1 signal has no effect in the standalone mode?


- **WHEN** a standalone process is started with `--log-level`, `--debug`, or `RUST_LOG`
- **AND** the process receives SIGHUP
- **THEN** the signal is logged as ignored and log levels remain unchanged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I understand why the current impl gives precedence to the cli overrides over the value defined in the system.toml. But from a user's pov, it feels counterintuitive. Shouldn't a runtime update get precedence over settings that the process was started with? Since a runtime action implies explicit user intent to override the existing settings, irrespective of what was specified on startup? Otherwise there's no way to override the values passed in the cli, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:runtime General features regarding either the actor runtime, how processes are started etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants