Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-journal-decision-throughput.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Record validated operator approvals before optional GitHub reporting, bound reporting waits, and keep mutation-journal readers responsive during ordered durable writes without weakening merge gates.
2 changes: 1 addition & 1 deletion src/docs/scale-envelope.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ones to:
2. **Truncation must preserve the prioritization signal, not cut an arbitrary slice.**
This holds today and is easy to assume backwards:
- Issues are sorted by actionable rank tier, then **oldest first** within each tier before any cap is applied
(`RankActionableIssues`, `src/pkg/github/client.go:5040-5050`, descending `AgeMinutes` within each tier).
(`RankActionableIssues`, `src/pkg/github/client.go:5058-5068`, descending `AgeMinutes` within each tier).
- PRs are sorted by **review class then oldest-first within class**
(`SortPullRequestsForReview`, `src/pkg/github/review_priority.go:334`;
fixes → refactors/docs → tests).
Expand Down
14 changes: 7 additions & 7 deletions src/pkg/convergence/mutation/boundary.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ func (b *Boundary) ExecuteJournaled(ctx context.Context, claim effects.Claim, ef
invoked := false
out, err := frozen.Execute(ctx, claim, func(ctx context.Context) (effects.Result, error) {
invoked = true
if err := frozen.Executor.Journal.syncPersistent(); err != nil {
if err := frozen.Executor.Journal.syncPersistentContext(ctx); err != nil {
return effects.Result{}, effects.NotApplied(fmt.Errorf("syncing mutation intent before effect: %w", err))
}
return effect(ctx)
})
if invoked || err == nil || out.Provenance != "" {
if syncErr := frozen.Executor.Journal.syncPersistent(); syncErr != nil {
if syncErr := frozen.Executor.Journal.syncPersistentContext(ctx); syncErr != nil {
return out, fmt.Errorf("mutation journal acknowledgement not synced: %w (execution: %v)", syncErr, err)
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ func (b *Boundary) Execute(ctx context.Context, claim effects.Claim, effect func
}
mutEffect := boundaryEffect(claim)
var out effects.Result
op, execErr := executor.Execute(mutEffect, entry.Epoch, holder, func() (string, error) {
op, execErr := executor.ExecuteContext(ctx, mutEffect, entry.Epoch, holder, func() (string, error) {
res, err := effect(ctx)
out = res
return res.Provenance, err
Expand Down Expand Up @@ -205,7 +205,7 @@ func (b *Boundary) noteResolved(logicalID string) {
// observation of external state (effects.Reconciler): Applied records the
// found effect without repeating it, !Applied authorizes the same logical
// operation to retry. Off mode journals nothing, so there is nothing to do.
func (b *Boundary) Reconcile(_ context.Context, claim effects.Claim, state effects.ExternalState) error {
func (b *Boundary) Reconcile(ctx context.Context, claim effects.Claim, state effects.ExternalState) error {
if b == nil {
return nil
}
Expand All @@ -222,7 +222,7 @@ func (b *Boundary) Reconcile(_ context.Context, claim effects.Claim, state effec
if executor.Journal == nil {
return fmt.Errorf("mutation boundary requires a journal when mode is enabled")
}
op, err := executor.Journal.Reconcile(boundaryEffect(claim).LogicalID(), ExternalState{
op, err := executor.Journal.ReconcileContext(ctx, boundaryEffect(claim).LogicalID(), ExternalState{
Known: true,
Applied: state.Applied,
Result: state.Provenance,
Expand All @@ -239,7 +239,7 @@ func (b *Boundary) Reconcile(_ context.Context, claim effects.Claim, state effec
// be attempted again. A Known external observation (Reconcile) is always
// preferred; this is for the case where none can be obtained and the entry
// would otherwise fence every retry forever. Off mode journals nothing.
func (b *Boundary) ExpireUnresolved(_ context.Context, claim effects.Claim, ttl time.Duration) (bool, error) {
func (b *Boundary) ExpireUnresolved(ctx context.Context, claim effects.Claim, ttl time.Duration) (bool, error) {
if b == nil || ttl <= 0 {
return false, nil
}
Expand All @@ -265,7 +265,7 @@ func (b *Boundary) ExpireUnresolved(_ context.Context, claim effects.Claim, ttl
if now.Sub(op.UpdatedAt) < ttl {
return false, nil
}
if _, err := executor.Journal.Reconcile(id, ExternalState{Known: true, Applied: false}, now); err != nil {
if _, err := executor.Journal.ReconcileContext(ctx, id, ExternalState{Known: true, Applied: false}, now); err != nil {
return false, err
}
if b.Logger != nil {
Expand Down
21 changes: 16 additions & 5 deletions src/pkg/convergence/mutation/executor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mutation

import (
"context"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -85,6 +86,10 @@ func (x Executor) now() time.Time {
// operation whose latest attempt is Unknown replays as ErrNeedsReconciliation,
// never as a success carrying an empty result.
func (x Executor) Execute(e Effect, epoch uint64, holder string, effect EffectFunc) (Operation, error) {
return x.ExecuteContext(context.Background(), e, epoch, holder, effect)
}

func (x Executor) ExecuteContext(ctx context.Context, e Effect, epoch uint64, holder string, effect EffectFunc) (Operation, error) {
if !JournalingEnabled(x.Mode) {
result, err := effect()
if err != nil {
Expand All @@ -107,7 +112,7 @@ func (x Executor) Execute(e Effect, epoch uint64, holder string, effect EffectFu
}

// Intent before effect, durably.
op, err := x.Journal.Begin(e, epoch, holder, now)
op, err := x.Journal.BeginContext(ctx, e, epoch, holder, now)
if err != nil {
if errors.Is(err, ErrAlreadyApplied) {
// Dedup replay: the journal already holds this logical operation
Expand All @@ -122,18 +127,24 @@ func (x Executor) Execute(e Effect, epoch uint64, holder string, effect EffectFu
return Operation{}, err
}

if err := ctx.Err(); err != nil {
// Physical persistence cannot be interrupted safely. If cancellation
// arrived during it, leave the durable intent for reconciliation,
// rather than starting an external call after the caller has gone.
return Operation{}, fmt.Errorf("mutation canceled after intent; reconciliation required: %w", err)
}
result, effectErr := effect()
after := x.now()

if effectErr != nil && errors.Is(effectErr, effects.ErrNotApplied) {
if _, recErr := x.Journal.RecordResult(op.LogicalID, epoch, StatusNotApplied, "", after); recErr != nil {
if _, recErr := x.Journal.RecordResultContext(ctx, op.LogicalID, epoch, StatusNotApplied, "", after); recErr != nil {
return Operation{}, fmt.Errorf("recording refused effect: %v (effect error: %w)", recErr, effectErr)
}
return Operation{}, effectErr
}
if effectErr != nil {
// Uncertain: the call failed but the effect may exist externally.
if _, recErr := x.Journal.RecordResult(op.LogicalID, epoch, StatusUnknown, "", after); recErr != nil {
if _, recErr := x.Journal.RecordResultContext(ctx, op.LogicalID, epoch, StatusUnknown, "", after); recErr != nil {
return Operation{}, fmt.Errorf("recording uncertain effect: %v (effect error: %w)", recErr, effectErr)
}
return Operation{}, fmt.Errorf("effect outcome uncertain, reconciliation required: %w", effectErr)
Expand All @@ -144,11 +155,11 @@ func (x Executor) Execute(e Effect, epoch uint64, holder string, effect EffectFu
// The effect happened but this owner may no longer speak for it:
// record Unknown so the CURRENT owner reconciles the same logical
// operation from authoritative external state — never a duplicate.
if _, recErr := x.Journal.RecordResult(op.LogicalID, epoch, StatusUnknown, "", after); recErr != nil {
if _, recErr := x.Journal.RecordResultContext(ctx, op.LogicalID, epoch, StatusUnknown, "", after); recErr != nil {
return Operation{}, fmt.Errorf("recording unacknowledgeable effect: %v (fence: %w)", recErr, err)
}
return Operation{}, fmt.Errorf("acknowledgment fenced, reconciliation required: %w", err)
}

return x.Journal.RecordResult(op.LogicalID, epoch, StatusApplied, result, after)
return x.Journal.RecordResultContext(ctx, op.LogicalID, epoch, StatusApplied, result, after)
}
Loading
Loading