Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mahler v4 release #70

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

Mahler v4 release #70

wants to merge 9 commits into from

Conversation

pipex
Copy link
Collaborator

@pipex pipex commented May 24, 2024

  • Refactor sensor interface to return Operation instances
  • Update agent runtime to report changes via Operation to the observer
  • Fix state rollback for parallel branches in the plan
  • Modify agent interface to receive a single trace logger, move human logging to mahler/utils
  • Abort planning stage if it takes over some time (configurable)

Closes: #68

Release Notes

Breaking changes

Simplified Sensor interface

The ouput of a Sensor is now a Subscribable instance that emits Operation values. The sensor no longer modifies the agent state but only returns changes that are applied by the Agent runtime.

This makes state management more robust as state is only modified by the agent runtime, preventing non-determinism on state reporting because of concurrency.

Removed logger option when constructing an Agent

The option has been replaced by a single trace option, which expects a void function that will be called for each agent runtime event. The function can be used to generate human readable logs or to log agent progress on disk. The agent runtime events relate to each other according to the following diagram.
Agent runtime state machine

Note that this also means that the Agent runtime no longer produces human readable logs by default. In order to get a readable log a readableTrace function has now be added on mahler/utils. The function accepts a Logger instance.

import { readableTrace } from 'mahler/utils';

const agent = Agent.from({
	initial: 0,
	tasks: [/* task list */],
	// readableTrace requires a Logger instance
	opts: { trace: readableTrace(console) },
});

Minor improvements

  • Improved state management on the Agent runtime. Previously, the internal agent state could be modified by different operations within the runtime lifecycle, action execution, rollbacks, sensors, etc. While the generated plans ensure that two actions cannot modify the same part of the state at the same time, the Agent state could still be affected by concurrency, because of the need to clone the state for some of these operations. With this new version, state changes are propagated using Operation events, limiting the number of places where state changes are allowed. This reduces the need for state cloning and ensures the state remains consistent event if some actions of the plan fail.
  • A new plannerMaxWaitMs configuration option has been added to the Agent constructor. This value defaults to 60 seconds and allows the agent to interrupt planning if it's taking too long. A long planning time usually means that there is some scenario not being considered and that a Method should be added to the task knowledge databased to help prune the search tree. A planning timeout is reported to the trace function with the event name plan-timeout.

Other improvements

Other changes include refactoring, better linting, improved types and some updated dev dependencies.

Simplifies the default operation type, removing the unnecessary source
property for the general case.

Change-type: patch
@pipex pipex marked this pull request as draft May 24, 2024 17:25
This updates the sensor interface to no longer require a state reference
as input, but simply return a subscribable for changes on a specific
path. This makes the interface simpler and moves the responsibility of
updating the state to sensor subscribers.

This is however a breaking change, even though the contructor interface
does not changes.

Change-type: major
@pipex pipex force-pushed the v4 branch 7 times, most recently from 99c7e27 to 7596476 Compare May 27, 2024 14:53
@pipex pipex force-pushed the v4 branch 10 times, most recently from 6e99131 to b88e6f2 Compare July 19, 2024 03:58
@pipex pipex changed the title Mahler v4 Version 4.0.0 Jul 19, 2024
@pipex pipex changed the title Version 4.0.0 v4 Jul 19, 2024
@pipex pipex force-pushed the v4 branch 2 times, most recently from 6203ed2 to 58c35b2 Compare July 19, 2024 18:55
@pipex pipex changed the title v4 Mahler v4 release Jul 19, 2024
pipex and others added 5 commits July 19, 2024 17:13
This updates the agent runtime and observer to report on changes
rather than the full state. Changes are now aggregated in the Agent
to communicate to subscribers.

Change-type: patch
The `observe` module would observe changes on a state and revert to the
previous state if an error occurred, however this had a flaw as the
rollback would revert the whole state object, causing problems if
concurrent changes were performed in parallel branches of the plan. This
moves the reversal to the Agent runtime, where the path information can
be used to revert, limiting the reverted changes only to the path that
the action modifies.

Change-type: patch
The property has been replaced by a `trace` property, receiving
an `AgentRuntimeEvent`. The property can be used to implement any type of
logging behaviour based on the agent runtime state machine.

The previous `Logger` interface has been moved to `mahler/utils` and a
basic human readable tracer has been provided under the same path with
the name `readableTrace`.

This also exports a diff function in utils to be potentially used for
state comparison in traces.

Change-type: major
This also re-lints the code to comply with the latest balena-lint
improvements
The Pointer type has been updated to reflect the result of Pointer.from,
returning never if the type does not exist, or undefined if the parent
exists.

Change-type: minor
This prevents a large task database from searching forever without
finding a suitable plan and without making progress. If that happens
that means the knowledge database should be optimized using some
additional methods

Change-type: minor
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.

Next major version changes
1 participant