Skip to content

feat(bootstrapper): record bootstrap stack state on each loop iteration#1159

Open
dhellmann wants to merge 1 commit into
python-wheel-build:mainfrom
dhellmann:worktree-bootstrap-stack-record
Open

feat(bootstrapper): record bootstrap stack state on each loop iteration#1159
dhellmann wants to merge 1 commit into
python-wheel-build:mainfrom
dhellmann:worktree-bootstrap-stack-record

Conversation

@dhellmann
Copy link
Copy Markdown
Member

Summary

Writes bootstrap-stack.json to the work directory before each iteration of the DFS loop in Bootstrapper.bootstrap(). The file is a JSON array where index 0 is the next item to be processed (stack[-1]), overwritten on each iteration. Each entry captures identity and accumulated state fields (req, req_type, phase, resolved_version, source_url, why, parent, dep sets); heavy build objects (build_env, paths, build_result) are intentionally excluded.

Enables debugging, progress inspection, and post-mortem analysis of interrupted runs.

🤖 Generated with Claude Code

Write `bootstrap-stack.json` to the work directory before each iteration
of the DFS loop, capturing the full stack as a JSON array (index 0 =
next item to pop). Enables debugging, progress inspection, and
post-mortem analysis of interrupted runs.

Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
@dhellmann dhellmann requested a review from a team as a code owner May 14, 2026 21:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds stack persistence to the bootstrap resolver. The Bootstrapper class now records the current pending work stack to bootstrap-stack.json on each iteration of the main DFS loop via a new _record_stack_state method. This method serializes WorkItem metadata (requirement, phase, resolved version, source URL, parent link, why_snapshot chain, and build dependency sets) in reverse order and overwrites the file each time. The test suite validates serialization semantics, deterministic ordering of dependency sets, file creation and overwriting behavior, and confirms bootstrap() invokes the recorder during execution.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding bootstrap stack state recording during each loop iteration in the bootstrapper.
Description check ✅ Passed The description clearly explains what the PR does, why it was added, and what fields are captured and excluded.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dhellmann dhellmann requested a review from rd4398 May 14, 2026 21:57
@mergify mergify Bot added the ci label May 14, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fromager/bootstrapper.py`:
- Around line 1305-1307: The current bootstrap() snapshot write using
open(self._stack_filename, "w") may truncate the file and abort bootstrap on
error; instead, serialize the reversed(stack) into records and write JSON
atomically by writing to a temporary file in the same directory (e.g., use
tempfile.NamedTemporaryFile or a .tmp path) and then atomically replace the
target with os.replace; catch and log any exceptions (use the existing logger on
the object, e.g., self._logger or fallback logger) as a non-fatal warning so
bootstrap() continues on failure, referencing the existing serialize() call and
self._stack_filename to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 876da36e-8403-4513-abee-eb324d8b2989

📥 Commits

Reviewing files that changed from the base of the PR and between bd86c56 and 27e56a7.

📒 Files selected for processing (2)
  • src/fromager/bootstrapper.py
  • tests/test_bootstrapper.py

Comment on lines +1305 to +1307
records = [serialize(item) for item in reversed(stack)]
with open(self._stack_filename, "w") as f:
json.dump(records, f, indent=2, default=str)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Make stack snapshot writes atomic and non-fatal.

A failed snapshot write currently aborts bootstrap(), and direct writes can leave a truncated JSON file if interrupted. For a diagnostics artifact, this should degrade gracefully and write atomically.

Suggested fix
         records = [serialize(item) for item in reversed(stack)]
-        with open(self._stack_filename, "w") as f:
-            json.dump(records, f, indent=2, default=str)
+        tmp_filename = self._stack_filename.with_suffix(".tmp")
+        try:
+            with open(tmp_filename, "w", encoding="utf-8") as f:
+                json.dump(records, f, indent=2, default=str)
+            os.replace(tmp_filename, self._stack_filename)
+        except OSError as err:
+            logger.warning(
+                "failed to write bootstrap stack state to %s: %s",
+                self._stack_filename,
+                err,
+            )
+            with contextlib.suppress(FileNotFoundError):
+                tmp_filename.unlink()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
records = [serialize(item) for item in reversed(stack)]
with open(self._stack_filename, "w") as f:
json.dump(records, f, indent=2, default=str)
records = [serialize(item) for item in reversed(stack)]
tmp_filename = self._stack_filename.with_suffix(".tmp")
try:
with open(tmp_filename, "w", encoding="utf-8") as f:
json.dump(records, f, indent=2, default=str)
os.replace(tmp_filename, self._stack_filename)
except OSError as err:
logger.warning(
"failed to write bootstrap stack state to %s: %s",
self._stack_filename,
err,
)
with contextlib.suppress(FileNotFoundError):
tmp_filename.unlink()
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fromager/bootstrapper.py` around lines 1305 - 1307, The current
bootstrap() snapshot write using open(self._stack_filename, "w") may truncate
the file and abort bootstrap on error; instead, serialize the reversed(stack)
into records and write JSON atomically by writing to a temporary file in the
same directory (e.g., use tempfile.NamedTemporaryFile or a .tmp path) and then
atomically replace the target with os.replace; catch and log any exceptions (use
the existing logger on the object, e.g., self._logger or fallback logger) as a
non-fatal warning so bootstrap() continues on failure, referencing the existing
serialize() call and self._stack_filename to locate the change.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant