Repository navigation
fix(core): keep history sampling off the execution lease #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
543609c
fix(core): isolate history sampling from the execution lease
49bb8b5
fix(core): publish ownership checks in authoritative order
e4fa9c6
docs: update translated sampling ownership rules
16b0dd5
docs: preserve sampling ownership heading anchor across locales
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/MiniMax-AI/OpenAgentCore/services/core/internal/execution" | ||
| ) | ||
|
|
||
| // runtimeHistoryOwnership implements the sampler's read-only ownership check. | ||
| // The execution worker performs authoritative database checks. Sampling observes | ||
| // their result without putting its short-lived contexts on the leased connection. | ||
| type runtimeHistoryOwnership struct { | ||
| snapshot func() execution.WorkerMetrics | ||
| } | ||
|
|
||
| func (o runtimeHistoryOwnership) CheckOwnership(ctx context.Context) error { | ||
| if err := ctx.Err(); err != nil { | ||
| return err | ||
| } | ||
| snapshot := o.snapshot() | ||
| if snapshot.ExecutionOwner == nil || !*snapshot.ExecutionOwner || snapshot.Scheduler.Status == "stopped" || snapshot.Scheduler.Status == "failing" { | ||
| return errors.New("execution ownership is not observed") | ||
| } | ||
| return nil | ||
| } |
41 changes: 41 additions & 0 deletions
41
services/core/cmd/server/runtime_history_ownership_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/MiniMax-AI/OpenAgentCore/services/core/internal/execution" | ||
| ) | ||
|
|
||
| func TestHistoryOwnershipObservesWorkerWithoutDatabaseChecks(t *testing.T) { | ||
| owned, notOwned := true, false | ||
| for _, tt := range []struct { | ||
| name string | ||
| owner *bool | ||
| status string | ||
| available bool | ||
| }{ | ||
| {"unobserved", nil, "unknown", false}, {"owned", &owned, "ok", true}, | ||
| {"acquired before first poll", &owned, "unknown", true}, {"released", ¬Owned, "stopped", false}, | ||
| {"draining", &owned, "stopped", false}, {"failed", &owned, "failing", false}, | ||
| } { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| calls := 0 | ||
| owner := runtimeHistoryOwnership{snapshot: func() execution.WorkerMetrics { | ||
| calls++ | ||
| return execution.WorkerMetrics{ExecutionOwner: tt.owner, Scheduler: execution.WorkerJobMetrics{Status: tt.status}} | ||
| }} | ||
| if got := owner.CheckOwnership(t.Context()) == nil; got != tt.available { | ||
| t.Fatalf("ownership availability = %v", got) | ||
| } | ||
| if calls != 1 { | ||
| t.Fatal("snapshot was not read once") | ||
| } | ||
| ctx, cancel := context.WithCancel(t.Context()) | ||
| cancel() | ||
| if owner.CheckOwnership(ctx) == nil || calls != 1 { | ||
| t.Fatal("cancelled sampling touched the owner") | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package execution | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| obslog "github.com/MiniMax-AI/OpenAgentCore/internal/obs/log" | ||
| ) | ||
|
|
||
| func observeWorkerFailure(ctx context.Context, stage string, err error) { | ||
| obslog.Ctx(ctx).Error("execution worker stopped", "stage", stage, "error_type", fmt.Sprintf("%T", err)) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package execution | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "errors" | ||
| "log/slog" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestWorkerFailureLogPreservesCompletionStageWithoutErrorText(t *testing.T) { | ||
| var output bytes.Buffer | ||
| previous := slog.Default() | ||
| slog.SetDefault(slog.New(slog.NewJSONHandler(&output, nil))) | ||
| t.Cleanup(func() { slog.SetDefault(previous) }) | ||
| observeWorkerFailure(t.Context(), "execution_completion", errors.New("confidential-query-canary")) | ||
| var event map[string]any | ||
| if err := json.Unmarshal(output.Bytes(), &event); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if event["stage"] != "execution_completion" || event["error_type"] == nil || strings.Contains(output.String(), "confidential-query-canary") { | ||
| t.Fatal("completion failure lost provenance or leaked error text", output.String()) | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This paragraph says periodic sampling only reads the Worker's observed ownership state, but the same document still promises that collection runs under the database lease, checks that lease every 100 ms (lines 88–90), and performs node-history copying after a lease check (line 106); the Chinese mirror retains the same conflicting claims at lines 90–92 and 108. Since the implementation now consults
runtimeHistoryOwnershiprather than the lease, update those existing paragraphs instead of leaving contradictory operational semantics.AGENTS.md reference: AGENTS.md:L58-L58
Useful? React with 👍 / 👎.