feat: record module execution history incrementally#72
Draft
jahkeup wants to merge 1 commit into
Draft
Conversation
Previously, module results were only written to the history file after all modules completed. If the process crashed or was killed mid-run, no history was persisted and modules would re-execute on the next boot. Introduce HistoryRecorder which flushes to disk after each module completes. This uses a mutex for goroutine safety within priority groups and atomic file writes (via temp + rename) for crash safety. Via: git.commit.create (mcp-server-go-git/v0.1.0-8-gb11cc3f)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
n/a
Description of changes:
Module execution history is currently written to disk only after all modules finish. If the process crashes, is killed, or the instance is interrupted mid-run, no history is persisted for modules that already completed successfully. On the next boot those modules re-execute — potentially re-running expensive or non-idempotent operations like userdata scripts.
This change introduces
HistoryRecorder, a concurrency-safe writer that flushes history to disk after each module completes. EachRecordcall appends the module result and atomically rewrites the history file (temp file + fsync + rename), so the on-disk state always reflects all modules that have finished so far. The old batchedWriteHistoryFile()call at the end ofrun()is removed (the method is retained onInitConfigfor backward compatibility).Files changed:
lib/ec2macosinit/instancehistory.go— newHistoryRecordertype withNewHistoryRecorderandRecordrun.go— instantiate recorder before the priority loop; callRecordin each module goroutine; remove end-of-runWriteHistoryFilecalllib/ec2macosinit/instancehistory_test.go— tests for single record, multiple records, concurrent writes, failed modules, and incremental persistenceHow to manually verify:
Build and deploy to an EC2 Mac instance:
Configure a slow module in
/usr/local/aws/ec2-macos-init/init.toml(two priority groups):Clean history and run:
While
slow-moduleis still running, check history in another terminal:fast-moduleshould already appear with"success": truebefore the run completes.Simulate a crash — kill the process while the second group runs:
Confirm
history.jsonhas results from priority group 1.Re-run after crash.
RunPerInstance/RunOncemodules that succeeded should be skipped (look for "Skipping module ... due to Run type setting" in logs).Let a full run complete normally and verify
history.jsoncontains all module results — no regression from prior behavior.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.