Skip to content

ENT-14194: Run policy on event - #6362

Open
victormlg wants to merge 6 commits into
cfengine:masterfrom
victormlg:ENT-14463-part-3
Open

victormlg wants to merge 6 commits into
cfengine:masterfrom
victormlg:ENT-14463-part-3

Conversation

@victormlg

@victormlg victormlg commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@victormlg victormlg changed the title ENT-14463: Run policy on event ENT-14194: Run policy on event Sep 24, 2026
@victormlg
victormlg force-pushed the ENT-14463-part-3 branch 2 times, most recently from b7d8916 to 33ee80a Compare September 29, 2026 11:26
VarRefDestroy(ref);
}

static PromiseResult KeepAgentPromise(EvalContext *ctx, const Promise *pp, ARG_UNUSED void *param)
Comment thread cf-agent/agent_operations.c Fixed
Comment thread cf-agent/agent_operations.c Fixed
Comment thread cf-agent/agent_operations.c Fixed
Comment thread cf-agent/agent_operations.c Dismissed
Comment thread cf-agent/agent_operations.c Fixed
Comment thread cf-agent/agent_operations.c Fixed
Comment thread cf-agent/agent_operations.c Fixed
Comment thread cf-agent/agent_operations.c Fixed
Comment thread libpromises/eval_context.c Fixed
Comment thread cf-reactor/reactor_transform.c Fixed
Comment thread cf-reactor/reactor_transform.c Fixed
Comment thread cf-reactor/reactor_transform.c Fixed
@victormlg
victormlg force-pushed the ENT-14463-part-3 branch 3 times, most recently from f98bd05 to 36fa38f Compare September 30, 2026 15:11
Signed-off-by: Victor Moene <victor.moene@northern.tech>
@victormlg
victormlg marked this pull request as ready for review September 30, 2026 15:18
Comment thread cf-reactor/reactor_transform.c Fixed
Comment thread cf-reactor/reactor_transform.c Fixed
Comment thread cf-reactor/reactor_transform.c Fixed

@larsewi larsewi 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.

Please do a review with Claude. For me it found a few things that seem plausible:

  1. A remote copy_from in a then bundle crashes cf-reactor
  2. State builds up across repeated runs of the same bundle
  3. The EvalAborted branch is dead code

Comment thread cf-reactor/reactor_transform.c
Comment thread cf-reactor/reactor_transform.c Outdated
Comment thread cf-reactor/reactor_transform.c Outdated
@victormlg
victormlg force-pushed the ENT-14463-part-3 branch 2 times, most recently from 1bb39a3 to 5a8c477 Compare October 1, 2026 18:13
Comment thread cf-reactor/reactor_transform.c Fixed

@craigcomstock craigcomstock 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.

looks good generally

Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c Outdated
Comment thread cf-reactor/reactor_transform.c
Comment thread cf-reactor/reactor_transform.c Outdated
Comment thread cf-reactor/reactor_transform.c Outdated
Comment thread cf-reactor/watcher.c Outdated
Comment thread cf-reactor/reactor_transform.c Outdated
Comment thread tests/asan-check/Makefile Outdated
Comment thread cf-reactor/reactor_transform.c Outdated
Comment thread libpromises/attributes.c Outdated
@victormlg
victormlg force-pushed the ENT-14463-part-3 branch 2 times, most recently from 58f4f25 to d02b0bb Compare October 5, 2026 10:45
@olehermanse

Copy link
Copy Markdown
Member

@cf-bottom jenkins, please

@olehermanse
olehermanse self-requested a review October 5, 2026 12:37
@cf-bottom

Copy link
Copy Markdown

@victormlg

victormlg commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Sure, I triggered a build:

Build Status

Jenkins: https://ci.cfengine.com/job/pr-pipeline/14750/

Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14750/

Added a fix for the windows failure in enterprise. Restarted it Build Status

@craigcomstock

Copy link
Copy Markdown
Contributor

@victormlg for a rebuild in jenkins, it would be nice if we updated the PR with the links... so here I will do it manually:

Build Status

Jenkins: https://ci.cfengine.com/job/pr-pipeline/14753/

Packages: http://buildcache.cfengine.com/packages/testing-pr/jenkins-pr-pipeline-14753/

Comment thread cf-agent/agent_operations.c Outdated
Comment thread cf-agent/agent_operations.c Outdated
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c Outdated
Comment thread cf-agent/agent_operations.c Outdated
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c Outdated

@craigcomstock craigcomstock 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.

a bit more, will continue later today

Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c

@craigcomstock craigcomstock 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.

here's the last of my comments on the refactored-code-as-new-code... I would say my intention was mostly to have you add comments where needed in a separate commit and create tickets/todos for things I mention that you feel are valid.

Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c
Comment thread cf-agent/agent_operations.c Outdated
Comment thread cf-agent/agent_operations.c
Comment thread libpromises/attributes.c Outdated
Comment thread cf-reactor/reactor_transform.c
…ions.c

Linked TODOs to new tickets to fix old bugs/TODOs that were already in cf-agent
before moving the code.

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Better concurrency for cf-reactor static state
- No need for map anymore, since watcher keeps track of the promise
- No need to keep key as variable anymore, since we do not use a map
- No need to run bundle inside watcher.c
- No risk of running a bundle from a wrong key between policy reads

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Promises are skipped to prevent running them several times. However, on event, we want to run them every single time:
- we clear the promise lock cache
- we set the default if_elapsed time for bundles run from an events promise to be 0, so it doesn't skip the promises.

Fixed also connection cache and custom promise prologue and epilogue. Clear function cache before "then" bundle run

Signed-off-by: Victor Moene <victor.moene@northern.tech>
Signed-off-by: Victor Moene <victor.moene@northern.tech>
- Moved mod_methods.c's MethodsParseTreeCheck implementation to PromiseCheckBundleCallArity
in policy.c, and made it more generic
- Now, MethodsParseTreeCheck and EventsParseTreeCheck both call this new function when calling bundles

Signed-off-by: Victor Moene <victor.moene@northern.tech>

@craigcomstock craigcomstock 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.

thanks!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants