Skip to content

CFE-3866: Allowed select_region to converge across passes#6072

Open
nickanderson wants to merge 2 commits intocfengine:masterfrom
nickanderson:CFE-3866/master
Open

CFE-3866: Allowed select_region to converge across passes#6072
nickanderson wants to merge 2 commits intocfengine:masterfrom
nickanderson:CFE-3866/master

Conversation

@nickanderson
Copy link
Copy Markdown
Member

Enable select_region to find regions created by earlier promises during
multi-pass convergence. Previously, if a promise inserted a section header
in pass 1, promises using select_region for that section would fail with
INTERRUPTED, preventing convergence.

This allows policies like set_variable_values_ini() to work without the
workarounds currently required in masterfiles.

Ticket: CFE-3866
Changelog: Title

@nickanderson
Copy link
Copy Markdown
Member Author

@cf-bottom jenkins please

@cf-bottom
Copy link
Copy Markdown

@nickanderson nickanderson marked this pull request as ready for review April 16, 2026 02:13
@nickanderson nickanderson requested a review from larsewi April 16, 2026 02:14
nickanderson added a commit to nickanderson/masterfiles that referenced this pull request Apr 16, 2026
…sing sections

This test demonstrates the bug where set_variable_values_ini() emits
'could not select an edit region' errors when called on a file where
the promised section doesn't exist yet.

The test creates an empty file and uses set_variable_values_ini() to
add a section with keys. Without the fix, this produces multiple errors
even though the section is created by the same bundle.

Together with cfengine/core#6072

Ticket: CFE-3866
Comment thread cf-agent/files_editline.c Outdated
Comment thread cf-agent/files_editline.c Outdated
Comment thread cf-agent/files_editline.c Outdated
Comment thread cf-agent/files_editline.c Outdated
Copy link
Copy Markdown
Contributor

@craigcomstock craigcomstock left a comment

Choose a reason for hiding this comment

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

looks reasonable to me. probably rework your commits to never include a libntech bump.

Comment thread cf-agent/files_editline.c Outdated
@nickanderson
Copy link
Copy Markdown
Member Author

@olehermanse I believe that the acceptance test failures are relating to the test set_variable_values_ini_missing_section.cf depends on plucked.cf.sub from the masterfiles repository. This test was added in the corresponding masterfiles PR #3128, which has now been merged to master. So I thik after mynext push that acceptance test might start passing. It was passing when I did together build before.

This test verifies that select_region can now find regions created by
earlier promises in the same agent run. Without the fix, this test
would fail with "could not select an edit region" errors even though
the region marker is inserted by the same bundle.

The test creates an INI-style file section and immediately edits it
within the same bundle, demonstrating multi-pass convergence.

Ticket: CFE-3866
Changelog: None
Modified edit_line operations to allow select_region to succeed across
multiple convergence passes. Previously, if a promise inserted a section
header in pass 1, promises using select_region for that section would
fail with INTERRUPTED in the same run, preventing convergence.

Changes:
- Added EDIT_CONTEXT_IS_FINAL_PASS macro to files_edit.h for checking
  if we're on the final convergence pass
- Extracted HandleSelectRegionFailure() to centralize error handling
  for SelectRegion failures across VerifyLineDeletions, VerifyColumnEdits,
  VerifyPatterns, and VerifyLineInsertions
- On non-final passes: log verbose message and return NOOP to allow retry
- On final pass: report error with detailed context
- Log messages now show remaining passes (e.g., "pass 1/2, 1 more pass to try")

This eliminates the need for workarounds in set_variable_values_ini()
and similar functions that create sections and immediately edit them.

Ticket: CFE-3866
Changelog: Title
@olehermanse
Copy link
Copy Markdown
Member

@olehermanse I believe that the acceptance test failures are relating to the test set_variable_values_ini_missing_section.cf depends on plucked.cf.sub from the masterfiles repository. This test was added in the corresponding cfengine/masterfiles#3128, which has now been merged to master. So I thik after mynext push that acceptance test might start passing. It was passing when I did together build before.

@nickanderson @craigcomstock sounds like, and looks like, acceptance tests job is missing a "together" step, while other workflows like valgrind_tests have it.

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.

5 participants