Repository navigation
feat(runtime): add idempotent wrapper lifecycle - #10
Merged
Merged
Conversation
yusufozmis
approved these changes
Aug 5, 2026
Base automatically changed from
feat/flexible-deployment-phase-1
to
development
August 5, 2026 16:05
korayakpinar
force-pushed
the
feat/flexible-deployment-phase-2
branch
from
August 5, 2026 16:05
37ae5f5 to
ded291d
Compare
korayakpinar
force-pushed
the
feat/flexible-deployment-phase-2
branch
from
August 5, 2026 16:42
ded291d to
1a712d0
Compare
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.
Summary
This PR replaces the separate first-boot and restart commands with one idempotent runtime lifecycle:
The command classifies the actual LevelDB state, initializes a fresh deployment or resumes a valid existing deployment, rejects unsafe persisted state before external side effects, and shuts down all runtime resources through one bounded ownership path.
This PR builds on the explicit configuration and transport contract introduced in #9.
Motivation
The previous
startandproceedsplit required operators or shell scripts to infer wrapper state from filesystem paths. Path existence is not a reliable representation of application state and creates race-prone first-boot/restart behavior.Container orchestration needs one long-running command that behaves correctly with both a fresh volume and a persisted volume. It also needs deterministic failures for mismatched, incomplete, corrupt, or concurrently opened state.
Idempotent
runCommandThe long-running command surface is now:
The legacy
start,proceed, andstop --socket-pathinterfaces have been removed because the software has not been deployed and does not require a compatibility migration.runuses the same command and startup path for both first boot and restart.LevelDB Deployment State
LevelDB initialization now returns an explicit state:
The zero value is not treated as a valid state.
Fresh database
When the application keyspace is empty, the wrapper validates and stores deployment metadata containing:
The cursor is not fabricated during initialization. It is created only after the indexer completes a successful reconciliation.
Initialized database
When metadata already exists, the wrapper verifies that it exactly matches the requested deployment and validates any persisted cursor before starting PostgreSQL or gRPC resources.
A metadata-only database is valid because the deployment may still be waiting for its first finalized block.
Invalid database states
The runtime distinguishes:
Persisted block records are validated when read, including protobuf validity, action validity, and record-key consistency. Startup deliberately avoids an
O(N)scan of all historical records.Startup Ordering
The runtime validates all local prerequisites before opening external resources:
POSTGRES_URI.Missing secrets, invalid genesis, corrupt state, metadata mismatch, and database locks therefore fail before PostgreSQL or gRPC listeners are opened.
Bounded Shutdown
Signals, the control socket, fatal indexer failures, and fatal gRPC errors now converge on one cancellation path.
Shutdown performs the following ordered cleanup:
STOPPING.Normal
SIGINT,SIGTERM, andSTOPshutdowns return success. Runtime, worker, database, or cleanup failures return a failure exit code.Control Socket Ownership
The control listener is managed by a dedicated component with idempotent close and a completion signal for the accept loop.
The existing
PING/PONGandSTOPprotocol is preserved. Stale sockets can be removed safely, live owners are rejected, and an older listener cannot unlink a newer replacement socket.Logging and Process Bootstrap
Runtime logs now go to
stderrby default, which matches container logging expectations.When
ARCHIVE_WRAPPER_LOG_PATHis explicitly configured, logs are written to bothstderrand the selected file. New files are created with mode0600.The binary no longer loads
.envautomatically. Environment loading is now the responsibility of the shell, Compose, or another process supervisor.Process startup is exposed through a testable
runMain(args, stderr)function, whilemainonly converts its result into the process exit code.Tests
The expanded tests cover:
Stack
feat/flexible-deployment-phase-1