You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(storage): serve storage from a configured adapter - #1462
Stacked on the gateway layer. Until this layer the controller refused any storage binding other than embedded SQLite at startup (RequireEmbeddedSQLite returned AdapterTransportUnavailable), so a configured adapter could never be used. This layer dials the adapter and serves both contracts from it. It is the layer that lets Orka run on an out-of-tree PostgreSQL adapter.
Base is stack/512/29-gateway-wire; the diff below is this layer only. The regenerated wire provider and staging chart are in their own commit.
What changes
internal/storageclient/remote connects to an adapter. remote.Open:
dials a control connection and a bulk connection with wire.Dial: TLS 1.3 with the resolved CA bundle and server name, which for a serviceRef defaults to <service>.<namespace>.svc;
sends per-call credentials that require transport security. StaticToken holds a resolved bearer token; FileToken reads the projected ServiceAccount token on every call, so rotation needs no restart. A token that can't be read fails the call before it is sent. A ServiceAccount token is only ever sent to the serviceRef target;
calls DescribeServer, then builds wire.NewClient bound to the described dataset, the server's protocol revision, the families the server declares, the bulk connection and the provider's limits.
Stable startup reasons, checked in order: AdapterUnavailable (no answer before --storage-adapter-connect-timeout, two minutes by default, retried with backoff), AdapterTLSFailed, AdapterAuthRefused, AdapterIncompatible (contract version or revision, protocol revision, dataset, or no declared families), AdapterContractMissing and AdapterWireIncomplete (a required family the adapter doesn't implement, or an incomplete wire without the flag). Only AdapterUnavailable is retried. A TLS alert from the adapter, such as one that refuses TLS 1.3, is AdapterTLSFailed, not AdapterUnavailable. AdapterTransportUnavailable is gone.
wire.Provider in pkg/storage serves both contracts from one connection. It embeds *wire.Client, and wiregen now writes zz_generated.provider.go with a stub for every contract method that has no RPC yet, returning wire.UnservedFamilyError, which matches ErrIncompatible so callers never requeue it as temporary. A client bound to an older server refuses a method newer than the server's revision the same way. Wiring a family removes its stubs on the next generation, and a stale stub is a compile error. It lives in pkg/storage because that is the module wiregen writes into.
Declared families: the protocol revision says which families the wire carries, not which ones an adapter implements, so an adapter on the current revision that stubs whole families used to pass startup and fail on the first call. Describe now carries ServerInfo.families, the families whose methods the server's providers all implement. wire.NewServer derives it: a provider that stubs methods implements wire.PartialProvider, whose UnimplementedMethods names them, and one stubbed method withholds its whole family. adapterkit.Serve passes its providers straight to NewServer, so an adapter names the methods it stubs and never keeps a family list; a name that isn't a contract method fails NewServer. The controller treats as unserved the union of the families newer than the server's revision and the families the server doesn't declare, and the client refuses a method of an undeclared family without sending it.
Required families: every family on the wire is required (remote.RequiredFamilies) except the gateway's delivery and cleanup families (remote.OptionalFamilies), which only --gateway-enabled uses. That covers what the Task and Session paths always touch, such as outbox projections for ACP dispatch, Task data fences, session turns, sealed execution snapshots and usage. GatewayEventStore is required because every Task read looks up the Task's gateway identity. RepositoryMonitorStore is required because the RepositoryMonitor reconciler always runs and no flag turns it off. A family added to the wire later is required until it is listed as optional and mapped to the flag that uses it, and a test fails if an optional family belongs to no feature flag.
An adapter that declares nothing is refused with AdapterIncompatible. Such a server was built before the declaration existed, so the controller can't tell what it stubs, and reading silence as "implements everything" would bring back the call-time failures the declaration exists to prevent. Failing closed breaks no released adapter: the only released wire library, pkg/storage/v0.4.0, serves protocol revision 2, which the controller already refuses. An adapter built against an earlier head of this stack needs a rebuild.
Partial wire, off by default: --storage-allow-partial-wire (Helm: storage.experimental.allowPartialWire) lets the controller start on an adapter that serves only some families, and logs a warning. Families not yet on the wire (AHP, auth sessions, memory, connectors, security) and optional families the adapter doesn't declare then answer UnservedFamilyError. Startup still refuses each enabled feature whose families aren't served, for example --enable-ahp-api, --github-sign-in-enabled, --connectors-enabled and --gateway-enabled. Required families are never waived. Without the flag, any unserved family stops startup with AdapterWireIncomplete.
Startup on an adapter (cmd/storage_adapter.go): storageconfig.Plan() replaces RequireEmbeddedSQLite and picks embedded SQLite or one adapter; contracts on different backends stop with SplitBindingUnsupported. On an adapter the controller loads the snapshot key, minting one only for a dataset the adapter created empty and hasn't finished bootstrapping, activates it, completes the dataset bootstrap over the wire, and runs the connection as a runnable that reports orka_storage_adapter_up{contract,backend} and closes both connections on shutdown. The embedded SQLite path is unchanged.
Server description: by default the server still describes its provider before every read, so a read for a dataset the provider no longer serves is refused before it reaches the provider. An adapter whose dataset can't change while it serves can set adapterkit.Config.DescriptionMaxAge (ServerConfig.DescriptionMaxAge in the wire library). A read that names the dataset the server last described then reuses that description while it is younger than the age, so an out-of-tree adapter whose Describe takes several database round trips no longer pays for one on every read. A failed description is never reused, and Refresh (which adapterkit runs on its readiness interval) and every Describe renew it. A read is refused as unavailable when a description that started after its own failed, even if the dataset ID didn't change. Within the age, a read after a dataset switch can reach the new dataset; storage-contracts.md documents that window, and it is why the age is opt-in. A server whose two contract parts share one provider describes it once. Writes stay fenced by their envelope's dataset, and administrative calls still describe every time. When the client has gone before the response headers can be sent, the server reports the call as cancelled rather than logging a provider error.
API: storageHTTPError is the one mapping from storage errors. ErrNotReady and ErrUnavailable answer 503 with Retry-After, ErrOutcomeUnknown answers 409, and UnservedFamilyError answers 501 naming the family. About 90 handler sites now use it. Where a handler fails after it has already committed a write (a monitor command's workflow action, a security finding, patch proposal or scan status after its Task), a temporary error answers 500 without retry advice, because a retry would repeat the committed write.
Helm gains storage.experimental.allowPartialWire and the token path wiring for the dial; docs cover the operator side in configuration.md and troubleshooting.md, and the dial and declared families in storage-contracts.md ("Connecting to an adapter").
Orka doesn't call BindDataset yet. A dataset's owning installation comes from AdvanceControllerEpoch, which records the installation on an unbound dataset and refuses any other with ErrFenced; a test proves a second installation is refused.
Testing
go test ./internal/storageclient/remote/...:
TestStateProviderConformanceThroughAdapter and TestArtifactProviderConformanceThroughAdapter: the SQLite provider passes the whole storagetest suite through remote.Open and wire.Provider over TLS, the path production uses.
TestOpenFailureReasons covers every startup reason, including an adapter that only speaks TLS 1.2, an older protocol revision on a partial wire, an adapter that declares no families, and an adapter that stubs one method of a required family (EnqueueOutboxProjectionRecord), which is refused with AdapterWireIncomplete naming OutboxPersistenceStore. TestOpenGivesUpOnAnUnreachableAdapter, TestOpenRetriesUntilTheAdapterAnswers, TestOpenReportsAnUnreadableToken and TestOpenRefusesAnIncompleteWireWithoutTheFlag cover the rest.
TestOpenAcceptsAStubbedOptionalFamilyOnlyOnAPartialWire: a stubbed gateway delivery method is refused without the flag; with it the family is unserved and the client refuses its methods without sending them. TestRequiredFamiliesCoverEveryWiredFamilyButTheOptionalOnes pins the split.
TestFileTokenIsReadForEveryCall, TestConnectionReportsHealthAndClosesOnShutdown, TestASecondInstallationCannotAdvanceTheDataset and TestSnapshotKeyActivationSkipsUnservedFamiliesOnlyOnAPartialWire.
go test ./cmd/...: the snapshot key bootstrap matrix (mint for a new empty dataset, refuse a non-empty dataset without a key, activate an existing key), the startup refusals for an incomplete wire and for features with unserved families, TestControllerAdapterStartupRefusesTheGatewayWhenTheAdapterStubsItsFamilies (refused with the gateway on, starts with it off), and TestEveryOptionalFamilyBelongsToAFeature. The expected refusals come from wire.UnservedFamilies, so they stay right as families are wired.
go -C pkg/storage test ./...: TestProviderRefusesFamiliesWithoutRPCs, TestProviderRefusesFamiliesNewerThanTheServer, TestModelListsUnservedFamilies, TestServerDeclaresTheFamiliesItsProvidersImplement, TestServerRefusesAnUnknownUnimplementedMethod, TestClientRefusesFamiliesTheServerDoesNotDeclare, TestEveryWiredMethodIsAContractMethod, TestServerInfoFamiliesAreSortedBoundedAndClean, TestServerRechecksTheDatasetBeforeEachReadByDefault, TestServeDescribesBeforeEveryReadUnlessGivenADescriptionAge, TestServerChecksReadsAgainstAFreshDescription, TestServerDescribesAgainOnceTheDescriptionIsOld, TestServerKeepsADescriptionThatFailedLaterStale, TestServerRefusesAReadWhoseDescriptionAFailedRefreshSuperseded, TestAFreshDescriptionVouchesOnlyForItsOwnDataset, TestAReadAdmittedOnAFreshDescriptionAnswersForThatDescriptionsDataset and TestServerReportsACallTheClientAbandonedAsCancelled.
go test ./internal/api/...: TestStorageFailureMapsAdapterErrors, the retry-hint tests, TestStorageFailureAfterCommitNeverAsksForARetry, TestGenerateSecurityPatchDoesNotAskForARetryOnceTheProposalExists and TestRepositoryMonitorCommandDoesNotAskForARetryOnceTheCommandExists.
make test, full golangci-lint on the root and pkg/storage modules, go test ./internal/storageconfig/... ./cmd/build/helmify/..., make verify-generated, go test ./hack/repocheck, go build ./... and go vet: pass.
Enables Orka to serve both storage contracts through a configured external adapter, advancing #512 while preserving embedded SQLite as the default. Adapter use remains experimental until all contract families are available over the wire.
Changes:
Adds authenticated TLS connections, startup compatibility checks, snapshot-key bootstrap, and adapter health reporting.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The default validation gap can allow records from the wrong dataset to be accepted, while partially committed scan admission can incorrectly advertise a safe retry.
Avoid retryable responses after partially committed scan admission
internal/api/security_handlers.go:458
CreateScanRun has already committed, and CreateInitialScanTask can also create the Task before validation fails. If validation and cancellation both return ErrUnavailable, this mapping sends 503 with Retry-After even though the run and Task remain. Use storageFailureAfterCommit here unless rollback is confirmed, so partially committed admission does not advertise a safe retry.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The handler can return a retryable 503 after scan effects are committed without confirmed rollback, encouraging callers to repeat a POST and duplicate those effects.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Avoid retrying POST after scan task creation has committed
internal/api/security_handlers.go:458
The scan run has already committed here, and CreateInitialScanTask can also create the Task before its final storage-backed validation fails. If that validation and cancellation encounter ErrUnavailable, this returns 503 with Retry-After and explicitly asks the caller to repeat a POST whose effects already exist. Use the post-commit mapping here unless rollback is confirmed, as the later status-update failure already does.
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
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.
Stacked on the gateway layer. Until this layer the controller refused any storage binding other than embedded SQLite at startup (
RequireEmbeddedSQLitereturnedAdapterTransportUnavailable), so a configured adapter could never be used. This layer dials the adapter and serves both contracts from it. It is the layer that lets Orka run on an out-of-tree PostgreSQL adapter.Base is
stack/512/29-gateway-wire; the diff below is this layer only. The regenerated wire provider and staging chart are in their own commit.What changes
internal/storageclient/remoteconnects to an adapter.remote.Open:wire.Dial: TLS 1.3 with the resolved CA bundle and server name, which for aserviceRefdefaults to<service>.<namespace>.svc;StaticTokenholds a resolved bearer token;FileTokenreads the projected ServiceAccount token on every call, so rotation needs no restart. A token that can't be read fails the call before it is sent. A ServiceAccount token is only ever sent to theserviceReftarget;DescribeServer, then buildswire.NewClientbound to the described dataset, the server's protocol revision, the families the server declares, the bulk connection and the provider's limits.AdapterUnavailable(no answer before--storage-adapter-connect-timeout, two minutes by default, retried with backoff),AdapterTLSFailed,AdapterAuthRefused,AdapterIncompatible(contract version or revision, protocol revision, dataset, or no declared families),AdapterContractMissingandAdapterWireIncomplete(a required family the adapter doesn't implement, or an incomplete wire without the flag). OnlyAdapterUnavailableis retried. A TLS alert from the adapter, such as one that refuses TLS 1.3, isAdapterTLSFailed, notAdapterUnavailable.AdapterTransportUnavailableis gone.wire.Providerinpkg/storageserves both contracts from one connection. It embeds*wire.Client, and wiregen now writeszz_generated.provider.gowith a stub for every contract method that has no RPC yet, returningwire.UnservedFamilyError, which matchesErrIncompatibleso callers never requeue it as temporary. A client bound to an older server refuses a method newer than the server's revision the same way. Wiring a family removes its stubs on the next generation, and a stale stub is a compile error. It lives inpkg/storagebecause that is the module wiregen writes into.Describenow carriesServerInfo.families, the families whose methods the server's providers all implement.wire.NewServerderives it: a provider that stubs methods implementswire.PartialProvider, whoseUnimplementedMethodsnames them, and one stubbed method withholds its whole family.adapterkit.Servepasses its providers straight toNewServer, so an adapter names the methods it stubs and never keeps a family list; a name that isn't a contract method failsNewServer. The controller treats as unserved the union of the families newer than the server's revision and the families the server doesn't declare, and the client refuses a method of an undeclared family without sending it.remote.RequiredFamilies) except the gateway's delivery and cleanup families (remote.OptionalFamilies), which only--gateway-enableduses. That covers what the Task and Session paths always touch, such as outbox projections for ACP dispatch, Task data fences, session turns, sealed execution snapshots and usage.GatewayEventStoreis required because every Task read looks up the Task's gateway identity.RepositoryMonitorStoreis required because the RepositoryMonitor reconciler always runs and no flag turns it off. A family added to the wire later is required until it is listed as optional and mapped to the flag that uses it, and a test fails if an optional family belongs to no feature flag.AdapterIncompatible. Such a server was built before the declaration existed, so the controller can't tell what it stubs, and reading silence as "implements everything" would bring back the call-time failures the declaration exists to prevent. Failing closed breaks no released adapter: the only released wire library,pkg/storage/v0.4.0, serves protocol revision 2, which the controller already refuses. An adapter built against an earlier head of this stack needs a rebuild.--storage-allow-partial-wire(Helm:storage.experimental.allowPartialWire) lets the controller start on an adapter that serves only some families, and logs a warning. Families not yet on the wire (AHP, auth sessions, memory, connectors, security) and optional families the adapter doesn't declare then answerUnservedFamilyError. Startup still refuses each enabled feature whose families aren't served, for example--enable-ahp-api,--github-sign-in-enabled,--connectors-enabledand--gateway-enabled. Required families are never waived. Without the flag, any unserved family stops startup withAdapterWireIncomplete.cmd/storage_adapter.go):storageconfig.Plan()replacesRequireEmbeddedSQLiteand picks embedded SQLite or one adapter; contracts on different backends stop withSplitBindingUnsupported. On an adapter the controller loads the snapshot key, minting one only for a dataset the adapter created empty and hasn't finished bootstrapping, activates it, completes the dataset bootstrap over the wire, and runs the connection as a runnable that reportsorka_storage_adapter_up{contract,backend}and closes both connections on shutdown. The embedded SQLite path is unchanged.adapterkit.Config.DescriptionMaxAge(ServerConfig.DescriptionMaxAgein the wire library). A read that names the dataset the server last described then reuses that description while it is younger than the age, so an out-of-tree adapter whoseDescribetakes several database round trips no longer pays for one on every read. A failed description is never reused, andRefresh(whichadapterkitruns on its readiness interval) and everyDescriberenew it. A read is refused as unavailable when a description that started after its own failed, even if the dataset ID didn't change. Within the age, a read after a dataset switch can reach the new dataset;storage-contracts.mddocuments that window, and it is why the age is opt-in. A server whose two contract parts share one provider describes it once. Writes stay fenced by their envelope's dataset, and administrative calls still describe every time. When the client has gone before the response headers can be sent, the server reports the call as cancelled rather than logging a provider error.storageHTTPErroris the one mapping from storage errors.ErrNotReadyandErrUnavailableanswer503withRetry-After,ErrOutcomeUnknownanswers409, andUnservedFamilyErroranswers501naming the family. About 90 handler sites now use it. Where a handler fails after it has already committed a write (a monitor command's workflow action, a security finding, patch proposal or scan status after its Task), a temporary error answers500without retry advice, because a retry would repeat the committed write.storage.experimental.allowPartialWireand the token path wiring for the dial; docs cover the operator side inconfiguration.mdandtroubleshooting.md, and the dial and declared families instorage-contracts.md("Connecting to an adapter").Orka doesn't call
BindDatasetyet. A dataset's owning installation comes fromAdvanceControllerEpoch, which records the installation on an unbound dataset and refuses any other withErrFenced; a test proves a second installation is refused.Testing
go test ./internal/storageclient/remote/...:TestStateProviderConformanceThroughAdapterandTestArtifactProviderConformanceThroughAdapter: the SQLite provider passes the whole storagetest suite throughremote.Openandwire.Providerover TLS, the path production uses.TestOpenFailureReasonscovers every startup reason, including an adapter that only speaks TLS 1.2, an older protocol revision on a partial wire, an adapter that declares no families, and an adapter that stubs one method of a required family (EnqueueOutboxProjectionRecord), which is refused withAdapterWireIncompletenamingOutboxPersistenceStore.TestOpenGivesUpOnAnUnreachableAdapter,TestOpenRetriesUntilTheAdapterAnswers,TestOpenReportsAnUnreadableTokenandTestOpenRefusesAnIncompleteWireWithoutTheFlagcover the rest.TestOpenAcceptsAStubbedOptionalFamilyOnlyOnAPartialWire: a stubbed gateway delivery method is refused without the flag; with it the family is unserved and the client refuses its methods without sending them.TestRequiredFamiliesCoverEveryWiredFamilyButTheOptionalOnespins the split.TestFileTokenIsReadForEveryCall,TestConnectionReportsHealthAndClosesOnShutdown,TestASecondInstallationCannotAdvanceTheDatasetandTestSnapshotKeyActivationSkipsUnservedFamiliesOnlyOnAPartialWire.go test ./cmd/...: the snapshot key bootstrap matrix (mint for a new empty dataset, refuse a non-empty dataset without a key, activate an existing key), the startup refusals for an incomplete wire and for features with unserved families,TestControllerAdapterStartupRefusesTheGatewayWhenTheAdapterStubsItsFamilies(refused with the gateway on, starts with it off), andTestEveryOptionalFamilyBelongsToAFeature. The expected refusals come fromwire.UnservedFamilies, so they stay right as families are wired.go -C pkg/storage test ./...:TestProviderRefusesFamiliesWithoutRPCs,TestProviderRefusesFamiliesNewerThanTheServer,TestModelListsUnservedFamilies,TestServerDeclaresTheFamiliesItsProvidersImplement,TestServerRefusesAnUnknownUnimplementedMethod,TestClientRefusesFamiliesTheServerDoesNotDeclare,TestEveryWiredMethodIsAContractMethod,TestServerInfoFamiliesAreSortedBoundedAndClean,TestServerRechecksTheDatasetBeforeEachReadByDefault,TestServeDescribesBeforeEveryReadUnlessGivenADescriptionAge,TestServerChecksReadsAgainstAFreshDescription,TestServerDescribesAgainOnceTheDescriptionIsOld,TestServerKeepsADescriptionThatFailedLaterStale,TestServerRefusesAReadWhoseDescriptionAFailedRefreshSuperseded,TestAFreshDescriptionVouchesOnlyForItsOwnDataset,TestAReadAdmittedOnAFreshDescriptionAnswersForThatDescriptionsDatasetandTestServerReportsACallTheClientAbandonedAsCancelled.go test ./internal/api/...:TestStorageFailureMapsAdapterErrors, the retry-hint tests,TestStorageFailureAfterCommitNeverAsksForARetry,TestGenerateSecurityPatchDoesNotAskForARetryOnceTheProposalExistsandTestRepositoryMonitorCommandDoesNotAskForARetryOnceTheCommandExists.make test, fullgolangci-linton the root andpkg/storagemodules,go test ./internal/storageconfig/... ./cmd/build/helmify/...,make verify-generated,go test ./hack/repocheck,go build ./...andgo vet: pass.Part of #512.