Skip to content

Git designed for AI agents.

graft: server review minors: final pass, error codes, dead code, comments, storage-core proposals

Federico Eliad89e0c72137e
diff --git a/doc/graft/PLAN10.md b/doc/graft/PLAN10.md
index 9d852f6..53cadea 100644
--- a/doc/graft/PLAN10.md
+++ b/doc/graft/PLAN10.md
@@ -1678,7 +1678,7 @@ point that the evidence supports, the gates that were tried, and the reading.
*The judges.* The strict judge calls an answer right when it equals the human's file after normalization (line endings,
trailing whitespace): about a fifth of the answers it calls wrong are valid (whitespace, order, an equivalent
phrasing, or a different resolution that a reviewer would accept). Judge A is the reference-based rubric of
-ConflictAgent (Shen 2026, MIT) adapted (Appendix A), run by a small model (glm-5.3-flash); a second judge
+ConflictAgent (Shen 2026, MIT) adapted (the text is in Appendix B), run by a small model (glm-5.3-flash); a second judge
(qwen3.8-flash, with 37 of 107 calls failed, counted as not acceptable) agrees with it on 91% of the answers and
accepts fewer (187 against 205 of 270), so "judge A" below is one cheap judge and "both judges" is the
conservative reading. For the gates on the held-out sets a stronger second judge was added, `openai/gpt-6.1-sol` (effort
@@ -1876,3 +1876,26 @@ rust and a ts file) that costs at most a few cents and stops a model whose calls
half of the calls failing, or a real spend above what the budget booked, or a projection above its cap. It judges
the model *in this configuration* (effort low, `max_tokens` 8000, `call_timeout` 120 s), which a model that reasons
for minutes does not fit.
+
+### Appendix B: the judge rubric of section 15
+
+Judge A (15.12) is a reference-based LLM judge, used offline for measurement only: nothing of it is in the product. It is
+adapted from the resolution-acceptability criteria of ConflictAgent (`evaluation/metrics.py`, `RESOLUTION_ACCEPTABILITY_CRITERIA`,
+commit d3ab8cc of https://github.com/UBOWENVT/ConflictAgent; MIT licence, Copyright (c) 2026 Bowen Shen). It is asked directly
+for a binary verdict (no DeepEval scoring), it sees a unified diff of the candidate against the developer's file instead of the
+conflict block, and the same text goes to every judge model (glm-5.3-flash for judge 1, gpt-6.1-sol for judge 2,
+mistral-large-4-0 for judge 3). A verdict that is missing or not parsable counts as not acceptable. The answers that equal the
+developer's file after normalization (line endings, trailing whitespace, trailing blank lines) are accepted without a call.
+The text, as it is sent:
+
+> Decide whether the CANDIDATE (a merge-conflict resolution) is an ACCEPTABLE resolution relative to the DEVELOPER's actual
+> resolution of the SAME conflict: would a careful reviewer accept it as resolving the conflict the way the developer intended -
+> same behavior and same essential content - even if not character-identical? These differences alone do NOT make it
+> unacceptable: whitespace, indentation, formatting, or comments; the ordering of imports, fields, or methods; a different but
+> behaviorally equivalent phrasing of the same logic; a different set of import statements, as long as the actual code is
+> consistent. Treat it as NOT acceptable if the candidate: still contains conflict markers or is otherwise an unresolved /
+> partial merge; has different program logic or behavior; uses different literal values that matter (version numbers,
+> constants, configuration values); is missing or adds FUNCTIONAL code (statements, methods, conditions - not imports); or
+> chooses a different side's behavior than the developer did.
+
+The script (`judge.py`, with the corpus builders and the analysis scripts) is in `c1-work/scripts/` next to the data of Appendix A.
diff --git a/internal/git/housekeeping/manager/manager.go b/internal/git/housekeeping/manager/manager.go
index a142ae4..fc5427e 100644
--- a/internal/git/housekeeping/manager/manager.go
+++ b/internal/git/housekeeping/manager/manager.go
@@ -1,10 +1,9 @@
package manager
import (
- "time"
-
"context"
"sync"
+ "time"
"github.com/feder-cr/git-ai/internal/git/housekeeping"
"github.com/feder-cr/git-ai/internal/git/housekeeping/config"
diff --git a/internal/git/housekeeping/manager/optimize_repository.go b/internal/git/housekeeping/manager/optimize_repository.go
index 4659e37..a95440b 100644
--- a/internal/git/housekeeping/manager/optimize_repository.go
+++ b/internal/git/housekeeping/manager/optimize_repository.go
@@ -5,9 +5,6 @@ import (
"context"
"errors"
"fmt"
- "github.com/feder-cr/git-ai/internal/graft/proposals"
- "github.com/prometheus/client_golang/prometheus"
- "github.com/prometheus/client_golang/prometheus/promauto"
"os"
"time"
@@ -19,9 +16,12 @@ import (
"github.com/feder-cr/git-ai/internal/git/mvcc"
"github.com/feder-cr/git-ai/internal/git/stats"
"github.com/feder-cr/git-ai/internal/gitaly/storage"
+ "github.com/feder-cr/git-ai/internal/graft/proposals"
"github.com/feder-cr/git-ai/internal/structerr"
"github.com/feder-cr/git-ai/internal/tracing"
"github.com/feder-cr/git-ai/proto/go/gitalypb"
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/labkit/correlation"
"google.golang.org/grpc/codes"
diff --git a/internal/gitaly/config/config_graft.go b/internal/gitaly/config/config_graft.go
index 10e4857..0b4adc8 100644
--- a/internal/gitaly/config/config_graft.go
+++ b/internal/gitaly/config/config_graft.go
@@ -349,8 +349,9 @@ type GraftResolver struct {
// DefaultGraftResolverResolveConcurrency.
ResolveConcurrency int `json:"resolve_concurrency" toml:"resolve_concurrency,omitempty"`
// VerifyConcurrency bounds the verifications that run at once on this server out of the lane
- // (PLAN10 15.9): the operator's verify.command on the exact tree of a model's resolution, which
- // lands only if it passes. It is a pool of its own, as the command takes minutes. Zero means
+ // (PLAN10 15.9): the operator's verify.command on the exact tree of every resolution that needs it
+ // (a model's always, a rule's or an agent's whenever a verification is configured), which lands
+ // only if it passes. It is a pool of its own, as the command takes minutes. Zero means
// DefaultGraftResolverVerifyConcurrency.
VerifyConcurrency int `json:"verify_concurrency" toml:"verify_concurrency,omitempty"`
// VerifyPerRepository bounds the verifications that run at once for one repository, inside
diff --git a/internal/gitaly/service/operations/land_final_pass_test.go b/internal/gitaly/service/operations/land_final_pass_test.go
new file mode 100644
index 0000000..e5ee8fb
--- /dev/null
+++ b/internal/gitaly/service/operations/land_final_pass_test.go
@@ -0,0 +1,85 @@
+package operations
+
+import (
+ "fmt"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "google.golang.org/grpc/codes"
+ "google.golang.org/grpc/status"
+
+ "github.com/feder-cr/git-ai/internal/git"
+ "github.com/feder-cr/git-ai/internal/gitaly/config"
+ "github.com/feder-cr/git-ai/proto/go/gitalypb"
+)
+
+// TestUserLand_finalPass_aTreeThatPassedStillLands: the land has run out of time (the final pass),
+// but the tree it would land passed verify.command in an earlier round, so the verification is not
+// needed again and the land lands, without running the command once more.
+func TestUserLand_finalPass_aTreeThatPassedStillLands(t *testing.T) {
+ t.Parallel()
+
+ rdir, rargv := resolverScript(t, "")
+ writeAnswer(t, rdir, modelAnswer())
+ vdir, vargv := countingVerify(t, "exit 0")
+ rcfg := withVerify(enabledResolver(rargv), vargv, "")
+ var s *Server
+ operationServerHooks.Store(t.Name(), func(served *Server) { s = served })
+ fx := newResolveFixture(t, rcfg)
+ require.NotNil(t, s, "the service's own Server")
+
+ pre := newLandPreResolution()
+ pre.verifyAll = true
+ require.NoError(t, s.landPreResolve(fx.ctx, fx.request("Land"), fx.committer(), pre))
+ require.Equal(t, 1, verifyRuns(t, vdir))
+
+ resp, err := s.landFinalPass(fx.ctx, fx.request("Land"), fx.committer(), pre, "the time ran out")
+ require.NoError(t, err, "a tree that passed is landed, not proposed")
+ requireBranchAt(t, fx.cfg, fx.repoPath, git.DefaultBranch, git.ObjectID(resp.GetLandedCommitId()))
+ require.Equal(t, 1, verifyRuns(t, vdir), "the command did not run again")
+}
+
+// TestLandPrecheckResolution_aServerFaultIsInternal: a verification that cannot run because of the
+// server (here its directory cannot be made) is Internal on the precheck path, as on the resolve
+// path, not Unknown.
+func TestLandPrecheckResolution_aServerFaultIsInternal(t *testing.T) {
+ t.Parallel()
+
+ vdir, vargv := countingVerify(t, "exit 0")
+ rcfg := withVerify(config.GraftResolver{}, vargv, "")
+ fx := newResolveFixture(t, rcfg)
+ s := fx.server(t, rcfg)
+ s.verifyTmpDir = t.TempDir() + "/no/such/directory"
+ in := fx.request("Land")
+ in.Resolution = resolutionOf(fx, "agent-a\n", "agent-b\n")
+
+ pc, err := s.landPrecheckResolution(fx.ctx, in, fx.repo)
+ require.Nil(t, pc)
+ require.Equal(t, codes.Internal, status.Code(err), "err = %v", err)
+ require.Contains(t, err.Error(), "verification directory")
+ require.Equal(t, 0, verifyRuns(t, vdir))
+}
+
+// TestLandFinalPass_givingUpIsTheKeptMovingError: a land that loses every pass of the final pass ends
+// as any land that lost the race: the retryable FailedPrecondition "kept moving", with the
+// ReferenceUpdate detail (landKeptMovingError), not a bare error.
+func TestLandFinalPass_givingUpIsTheKeptMovingError(t *testing.T) {
+ t.Parallel()
+
+ in := &gitalypb.UserLandRequest{Branch: []byte(git.DefaultBranch), CommitId: "c"}
+ err := landFinalPassGaveUp(in, &landNeedsResolution{tip: "1111111111111111111111111111111111111111"}, landFinalPasses)
+ require.Equal(t, codes.FailedPrecondition, status.Code(err), "err = %v", err)
+ require.Contains(t, err.Error(), fmt.Sprintf("kept moving, giving up after %d attempts", landFinalPasses))
+
+ var detail *gitalypb.UserLandError
+ for _, d := range status.Convert(err).Details() {
+ if e, ok := d.(*gitalypb.UserLandError); ok {
+ detail = e
+ }
+ }
+ require.NotNil(t, detail, "the UserLandError detail of the kept-moving error")
+ update := detail.GetReferenceUpdate()
+ require.NotNil(t, update, "the ReferenceUpdate detail")
+ require.Equal(t, "refs/heads/"+git.DefaultBranch, string(update.GetReferenceName()))
+ require.Equal(t, "1111111111111111111111111111111111111111", update.GetOldOid())
+}
diff --git a/internal/gitaly/service/operations/land_preresolve.go b/internal/gitaly/service/operations/land_preresolve.go
index 1f0d969..4330286 100644
--- a/internal/gitaly/service/operations/land_preresolve.go
+++ b/internal/gitaly/service/operations/land_preresolve.go
@@ -242,12 +242,12 @@ func (s *Server) landPreResolve(ctx context.Context, in *gitalypb.UserLandReques
func (s *Server) landResolving(ctx context.Context, in *gitalypb.UserLandRequest, committer git.Signature) (*gitalypb.UserLandResponse, error) {
timeout, err := s.resolveCfg.TimeoutOrDefault()
if err != nil {
- return nil, fmt.Errorf("resolver timeout: %w", err)
+ return nil, structerr.NewInternal("resolver timeout: %w", err)
}
if s.resolveCfg.Verify.Enabled {
verifyTimeout, err := s.resolveCfg.Verify.TimeoutOrDefault()
if err != nil {
- return nil, fmt.Errorf("verify timeout: %w", err)
+ return nil, structerr.NewInternal("verify timeout: %w", err)
}
timeout += verifyTimeout
}
@@ -359,7 +359,20 @@ func (s *Server) landFinalPass(
return resp, err
}
if pass >= landFinalPasses {
- return nil, structerr.NewFailedPrecondition("branch %q kept moving while the land was being ended, giving up after %d passes", string(in.GetBranch()), pass)
+ return nil, landFinalPassGaveUp(in, needs, pass)
}
}
}
+
+// landFinalPassGaveUp is the error of a land that lost every pass of the final pass: as any land
+// that lost the race, the retryable "kept moving" FailedPrecondition with the ReferenceUpdate detail
+// (landKeptMovingError). needs is the lane's last handing back, whose tip is the one the branch is
+// at; the package of a conflict is not what it is about.
+func landFinalPassGaveUp(in *gitalypb.UserLandRequest, needs *landNeedsResolution, passes int) error {
+ return landKeptMovingError(in, landConflict{
+ reference: git.NewReferenceNameFromBranchName(string(in.GetBranch())),
+ oldOID: needs.tip,
+ newOID: needs.tip,
+ cause: errors.New("the branch kept moving while the land was being ended"),
+ }, passes)
+}
diff --git a/internal/gitaly/service/operations/land_reland.go b/internal/gitaly/service/operations/land_reland.go
index 71b0b9b..9475696 100644
--- a/internal/gitaly/service/operations/land_reland.go
+++ b/internal/gitaly/service/operations/land_reland.go
@@ -328,7 +328,9 @@ func (s *Server) landPrecheckVerify(caller, budgetCtx context.Context, budget ti
if caller.Err() != nil {
return landCallerGaveUp(caller, err)
}
- return err
+ // A fault of the server (the file system, the read-back of the checkout, the verification
+ // directory, a git command), as on the resolve path: Internal, not Unknown.
+ return structerr.NewInternal("verifying the resolution: %w", err)
}
return nil
}
diff --git a/internal/gitaly/service/operations/land_resolve.go b/internal/gitaly/service/operations/land_resolve.go
index 8d91a66..69fab4d 100644
--- a/internal/gitaly/service/operations/land_resolve.go
+++ b/internal/gitaly/service/operations/land_resolve.go
@@ -80,8 +80,9 @@ type landFileConflict struct {
// pre yet (PLAN10 15.8). It runs out of the lane: the policy first (an agent that may not
// update the branch gets nothing resolved), the listing, the classification of every file, one
// resolver request for the files to resolve, taken with a resolve slot, and the validation; then,
-// for an answer that holds a model's resolution, the verification of the exact tree that would
-// land (15.9), with a verify slot; then decideLand over every file, the verdicts reused included.
+// for every resolution that needs it (a model's always, any when a verification is configured),
+// the verification of the exact tree that would land (15.9), with a verify slot; then decideLand
+// over every file, the verdicts reused included.
// A request carries only what a file's verdict may depend on: the sides, the path and modes, the
// change's message, the configuration; not the tip, its merge base or its message, so that a
// verdict can be reused at another tip (15.8). When the land is landable, the new verdicts are
@@ -230,6 +231,18 @@ func (s *Server) landResolveAt(
// A file is held back: the land cannot land, so the tree is not verified (that would hold
// the repository's verify slot for nothing). The files say why in their reasons.
case pre.unverifiable != "":
+ // The land has run out of time to verify. A tree that passed in an earlier round needs no
+ // verification, and lands (the lane only compares): check it before giving up.
+ if verifyRequired && landAllAnswered(files) {
+ var err error
+ if tree, err = s.landResolvedTree(ctx, repo, l.mergedTree, combined); err != nil {
+ return l, nil, err
+ }
+ if pre.isVerified(tree) {
+ verified = tree
+ break
+ }
+ }
landAnnotateUnverified(files, combined, pre.unverifiable)
case !verifyRequired && len(s.resolveCfg.Verify.Command) > 0:
landAnnotateProposed(files, landVerifyDisabledReason)
diff --git a/internal/gitaly/service/operations/land_verify.go b/internal/gitaly/service/operations/land_verify.go
index 66e23d8..540f93b 100644
--- a/internal/gitaly/service/operations/land_verify.go
+++ b/internal/gitaly/service/operations/land_verify.go
@@ -34,7 +34,7 @@ import (
// merged tree, the resolution included. A failure or a timeout rejects the resolution, and the
// conflict package says why. It applies to resolver answers and agents' resolutions alike.
//
-// The checkout is the tree byte for byte (landCheckoutTree): what the operator's command sees is
+// The checkout is the tree byte for byte (landCheckoutTreeThen): what the operator's command sees is
// what lands. git-archive(1) is not used, since it honours the attributes of the tree itself
// (export-ignore hides a file, export-subst changes its content), and a .gitattributes written by
// an agent or by a model would decide what the verification sees.
@@ -182,7 +182,7 @@ func landVerifyRepoKey(repository *gitalypb.Repository) string {
return repository.GetStorageName() + "\x00" + repository.GetRelativePath()
}
-// landVerifyOutOfLane runs the verification of a model's resolution out of the lane (PLAN10 15.9),
+// landVerifyOutOfLane runs the verification of a resolution out of the lane (PLAN10 15.9), whoever made it,
// with a slot of the verify pool. It returns a *landVerifyError when the command fails or times
// out, a *landVerifyUnfinishedError when ctx ended first, and another error when the verification
// could not be run.
@@ -305,7 +305,7 @@ func landRefuse(format string, args ...any) error {
return &landCheckoutRefusal{reason: fmt.Sprintf(format, args...)}
}
-// landCheckoutTree writes the tree under dir byte for byte: the entries of git-ls-tree(1) -r and the
+// landCheckoutTreeThen writes the tree under dir byte for byte: the entries of git-ls-tree(1) -r and the
// contents of git-cat-file(1) --batch, which apply no attribute (no export-ignore, export-subst,
// eol, filter or smudge), with the modes (a file is executable or not), the symbolic links as links,
// and the gitlinks as empty directories. It then reads the directory back and compares it with the
@@ -316,12 +316,9 @@ func landRefuse(format string, args ...any) error {
// The listing and the blobs are streamed, one entry at a time, so the memory it takes is that of the
// entries (which limits bounds) and not of the tree. A tree beyond the limits, or with a path that is
// not safe to write, is a *landCheckoutRefusal.
-func landCheckoutTree(ctx context.Context, repo *localrepo.Repo, tree git.ObjectID, dir string, limits landCheckoutLimits) error {
- return landCheckoutTreeThen(ctx, repo, tree, dir, limits, nil)
-}
-
-// landCheckoutTreeThen is landCheckoutTree with a function that runs between the writing and the
-// check; only tests give one, to damage the checkout and see that the check notices.
+//
+// afterWrite, when given, runs between the writing and the check; only tests give one, to damage the
+// checkout and see that the check notices.
func landCheckoutTreeThen(ctx context.Context, repo *localrepo.Repo, tree git.ObjectID, dir string, limits landCheckoutLimits, afterWrite func()) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
@@ -451,24 +448,6 @@ func landReadRecord(r *bufio.Reader) (string, error) {
}
}
-// landParseTreeListing parses the output of git-ls-tree(1) -r -z: "<mode> <type> <object>\t<path>"
-// entries ended by NUL (with -l, "<mode> <type> <object> <size>\t<path>"). A tree holds files, links
-// and gitlinks once listed recursively.
-func landParseTreeListing(raw []byte) ([]landTreeEntry, error) {
- var entries []landTreeEntry
- for _, record := range strings.Split(string(raw), "\x00") {
- if record == "" {
- continue
- }
- e, err := landParseTreeRecord(record)
- if err != nil {
- return nil, err
- }
- entries = append(entries, e)
- }
- return entries, nil
-}
-
// landParseTreeRecord parses one entry of the listing.
func landParseTreeRecord(record string) (landTreeEntry, error) {
meta, name, ok := strings.Cut(record, "\t")
diff --git a/internal/gitaly/service/operations/land_verify_test.go b/internal/gitaly/service/operations/land_verify_test.go
index 688f303..cef3a63 100644
--- a/internal/gitaly/service/operations/land_verify_test.go
+++ b/internal/gitaly/service/operations/land_verify_test.go
@@ -984,3 +984,26 @@ func TestLandVerify_aDeadlineAfterTheCheckoutIsTheTimeoutOfTheVerdict(t *testing
require.Contains(t, verifyErr.reason, "did not finish within 200ms")
require.Equal(t, 0, verifyRuns(t, vdir))
}
+
+// landCheckoutTree writes the tree under dir (landCheckoutTreeThen with nothing between the writing
+// and the check).
+func landCheckoutTree(ctx context.Context, repo *localrepo.Repo, tree git.ObjectID, dir string, limits landCheckoutLimits) error {
+ return landCheckoutTreeThen(ctx, repo, tree, dir, limits, nil)
+}
+
+// landParseTreeListing parses the output of git-ls-tree(1) -r -z: "<mode> <type> <object>\t<path>"
+// entries ended by NUL (with -l, "<mode> <type> <object> <size>\t<path>").
+func landParseTreeListing(raw []byte) ([]landTreeEntry, error) {
+ var entries []landTreeEntry
+ for _, record := range strings.Split(string(raw), "\x00") {
+ if record == "" {
+ continue
+ }
+ e, err := landParseTreeRecord(record)
+ if err != nil {
+ return nil, err
+ }
+ entries = append(entries, e)
+ }
+ return entries, nil
+}
diff --git a/internal/gitaly/service/operations/server.go b/internal/gitaly/service/operations/server.go
index a43cb82..89fbbdb 100644
--- a/internal/gitaly/service/operations/server.go
+++ b/internal/gitaly/service/operations/server.go
@@ -62,7 +62,7 @@ type Server struct {
verifyPool *resolver.VerifyPool
// conflictResolver answers the resolve requests of UserLand. Nil when resolution is disabled,
// or when the configured resolver cannot be built: then resolverErr says why, and every land
- // that needs the resolver fails closed with it (resolveLandConflicts, landWithResolution).
+ // that needs the resolver fails closed with it (landResolveAt, landWithResolution).
conflictResolver *resolver.Client
resolverErr error
// landLanes batches the UserLand requests of a branch. Nil disables batching, and every
diff --git a/internal/graft/e2e/proposals_agree_test.go b/internal/graft/e2e/proposals_agree_test.go
new file mode 100644
index 0000000..ab8101f
--- /dev/null
+++ b/internal/graft/e2e/proposals_agree_test.go
@@ -0,0 +1,201 @@
+package e2e
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+
+ "github.com/feder-cr/git-ai/internal/gitaly/config"
+ "github.com/feder-cr/git-ai/internal/graft/corestore"
+ "github.com/feder-cr/git-ai/internal/graft/corestore/sqlstore"
+ "github.com/feder-cr/git-ai/proto/go/gitalypb"
+ "github.com/feder-cr/git-ai/sdk"
+)
+
+// otherModel is a second model for the agree_with table: it answers like fakeModel, except that it
+// changes the contested line, so that it disagrees with the first one.
+const otherModel = `import json, re, sys
+req = json.load(sys.stdin)
+m = re.search(r"===== BEGIN CODE ([0-9a-f]+) =====\n(.*?)===== END CODE ([0-9a-f]+) =====", req["prompt"], re.S)
+n, code = m.group(1), m.group(2)
+code = code.replace("line of", "LINE of")
+sys.stdout.write("===== BEGIN PATCHED CODE %s =====\n%s===== END PATCHED CODE %s =====\n" % (n, code, n))
+`
+
+// agreeResolverConfig writes a resolve.toml with the llm strategy of fakeModel and an agree_with model
+// (second, the source of a model), and returns the graft configuration that uses the real
+// graft-resolve with it and a verification that always passes.
+func agreeResolverConfig(t *testing.T, second string) exampleConfig {
+ t.Helper()
+
+ dir := t.TempDir()
+ first := filepath.Join(dir, "model.py")
+ require.NoError(t, os.WriteFile(first, []byte(fakeModel), 0o600))
+ other := filepath.Join(dir, "other.py")
+ require.NoError(t, os.WriteFile(other, []byte(second), 0o600))
+ resolveConfig := filepath.Join(dir, "resolve.toml")
+ require.NoError(t, os.WriteFile(resolveConfig, []byte(`[[strategy]]
+name = "model"
+type = "llm"
+paths = ["shared-log.txt"]
+
+[strategy.llm]
+type = "command"
+command = ["python3", "-I", "`+first+`"]
+model = "fake-a"
+
+[strategy.llm.agree_with]
+type = "command"
+command = ["python3", "-I", "`+other+`"]
+model = "fake-b"
+`), 0o600))
+
+ ex := loadExample(t)
+ ex.graft.Land.Resolver = config.GraftResolver{
+ Enabled: true,
+ Command: []string{buildAgentsTool(t, "./cmd/graft-resolve"), "--config", resolveConfig},
+ Verify: config.GraftResolverVerify{Enabled: true, Command: []string{"/bin/true"}},
+ }
+ return ex
+}
+
+// TestAgreeWithTheModelsThatAgreeLandThroughVerify and ...ThatDisagreeAreHeld are the agreement gate
+// end to end (PLAN10 15.13): the real graft-resolve with two models in its llm strategy, the server
+// with a verification that always passes. Two models that give the same file land through the
+// verification; when the second differs, the same land is a merge conflict whose package holds the
+// first model's proposal with the hold, the branch does not move, and the command never runs.
+func TestAgreeWithTheModelsThatAgreeLandThroughVerify(t *testing.T) {
+ t.Parallel()
+
+ ex := agreeResolverConfig(t, fakeModel)
+ s := startGitaly(t, ex.graft, ex.sharedToken)
+ repo := s.repoAs(t, exampleTokens["planner"])
+ ctx := s.ctx
+
+ base := writeMain(t, s, map[string]string{sharedLogPath: sharedLogHeader})
+ const branch = "agree"
+ _, err := landAs(ctx, repo, "planner", branch, base)
+ require.NoError(t, err)
+ first, err := sharedChange(ctx, repo, "agent", base, 1, true)
+ require.NoError(t, err)
+ _, err = landOn(ctx, repo, branch, first, true)
+ require.NoError(t, err)
+ second, err := sharedChange(ctx, repo, "agent", base, 2, true)
+ require.NoError(t, err)
+ res, err := landOn(ctx, repo, branch, second, true)
+ require.NoError(t, err, "two models that agree, and a verification that passes: the resolution lands")
+ msg := s.git(t, "log", "-1", "--format=%B", res.LandedCommitID)
+ require.Contains(t, msg, "Graft-Resolved-By: graft-resolve/model")
+ require.Contains(t, msg, "Graft-Checked-By: verify:true")
+}
+
+func TestAgreeWithTheModelsThatDisagreeAreHeld(t *testing.T) {
+ t.Parallel()
+
+ ex := agreeResolverConfig(t, otherModel)
+ s := startGitaly(t, ex.graft, ex.sharedToken)
+ repo := s.repoAs(t, exampleTokens["planner"])
+ ctx := s.ctx
+
+ base := writeMain(t, s, map[string]string{sharedLogPath: sharedLogHeader})
+ const branch = "held"
+ _, err := landAs(ctx, repo, "planner", branch, base)
+ require.NoError(t, err)
+ first, err := sharedChange(ctx, repo, "agent", base, 1, true)
+ require.NoError(t, err)
+ _, err = landOn(ctx, repo, branch, first, true)
+ require.NoError(t, err)
+ tip := s.git(t, "rev-parse", branch)
+
+ second, err := sharedChange(ctx, repo, "agent", base, 2, true)
+ require.NoError(t, err)
+ _, err = landOn(ctx, repo, branch, second, true)
+ require.True(t, sdk.IsMergeConflict(err), "a held resolution must not land: %v", err)
+ require.Equal(t, tip, s.git(t, "rev-parse", branch), "the branch did not move")
+ pkg, ok := sdk.LandConflict(err)
+ require.True(t, ok)
+ require.Len(t, pkg.GetFiles(), 1)
+ f := pkg.GetFiles()[0]
+ require.Equal(t, gitalypb.LandConflictFile_OUTCOME_PROPOSED, f.GetOutcome())
+ require.Contains(t, f.GetReason(), "held back by the resolver")
+ require.Contains(t, f.GetReason(), "fake-b")
+ require.NotNil(t, f.GetProposal(), "the first model's proposal is kept for the agent")
+ require.Contains(t, f.GetProposal().GetExplanation(), "the second model disagreed")
+}
+
+// TestStorageProposalsInAuthoritativeMode: the references of the proposals are written and pruned
+// through the reference transaction, so in authoritative storage-core mode they are in the database
+// as well as on disk, and the node is consistent after a proposal is written and after the change
+// that it was made for has landed (which drops it).
+func TestStorageProposalsInAuthoritativeMode(t *testing.T) {
+ t.Parallel()
+
+ dir := t.TempDir()
+ model := filepath.Join(dir, "model.py")
+ require.NoError(t, os.WriteFile(model, []byte(fakeModel), 0o600))
+ resolveConfig := filepath.Join(dir, "resolve.toml")
+ require.NoError(t, os.WriteFile(resolveConfig, []byte(`[[strategy]]
+name = "model"
+type = "llm"
+paths = ["shared-log.txt"]
+
+[strategy.llm]
+type = "command"
+command = ["python3", "-I", "`+model+`"]
+model = "fake"
+`), 0o600))
+
+ graft, tokens := workerGraft(1)
+ graft.Land.Resolver = config.GraftResolver{
+ Enabled: true,
+ Command: []string{buildAgentsTool(t, "./cmd/graft-resolve"), "--config", resolveConfig},
+ }
+ cluster := newStorageCluster(t, sqlstore.SQLite, corestore.ModeAuthoritative, unbatched(graft))
+ node := cluster.addNode(t)
+ rel := node.createRepository(t).GetRelativePath()
+ who := workerName(0)
+ repo := node.agent(t, rel, tokens[who])
+ ctx := node.ctx
+
+ base, err := commitFile(ctx, repo, who, "main", "", sharedLogPath, sharedLogHeader)
+ require.NoError(t, err)
+ const branch = "propose"
+ _, err = landAs(ctx, repo, who, branch, base)
+ require.NoError(t, err)
+ first, err := sharedChange(ctx, repo, who, base, 1, true)
+ require.NoError(t, err)
+ _, err = landOn(ctx, repo, branch, first, true)
+ require.NoError(t, err)
+
+ second, err := sharedChange(ctx, repo, who, base, 2, true)
+ require.NoError(t, err)
+ _, err = landOn(ctx, repo, branch, second, true)
+ require.True(t, sdk.IsMergeConflict(err), "a model's resolution must not land: %v", err)
+ pkg, ok := sdk.LandConflict(err)
+ require.True(t, ok)
+ ref := pkg.GetProposalRef()
+ require.NotEmpty(t, ref)
+
+ // The proposal reference went through the voter: it is in the database and on disk.
+ require.Contains(t, node.dbRefs(t, rel), ref, "the proposal reference is in the database")
+ require.Contains(t, node.localRefs(t, rel), ref, "and on disk")
+ node.requireConsistent(t, rel)
+
+ // The agent lands the proposal as its own resolution: the proposal of the change is dropped, again
+ // through the voter, and the node stays consistent.
+ sides, err := repo.ConflictSides(ctx, pkg)
+ require.NoError(t, err)
+ _, err = repo.Land(ctx, sdk.LandOptions{
+ Branch: branch,
+ Commit: second,
+ User: sdk.User{Name: who, Email: who + "@example.com"},
+ Strategy: sdk.LandMerge,
+ Resolution: sdk.ResolutionFromProposals(pkg, sides),
+ })
+ require.NoError(t, err)
+ require.NotContains(t, node.dbRefs(t, rel), ref, "the proposal of the change that landed is gone from the database")
+ require.NotContains(t, node.localRefs(t, rel), ref, "and from the disk")
+ node.requireConsistent(t, rel)
+}
diff --git a/internal/graft/e2e/proposals_test.go b/internal/graft/e2e/proposals_test.go
old mode 100755
new mode 100644
index acef3eb..aa5d810
--- a/internal/graft/e2e/proposals_test.go
+++ b/internal/graft/e2e/proposals_test.go
@@ -24,8 +24,9 @@ sys.stdout.write("===== BEGIN PATCHED CODE %s =====\n%s===== END PATCHED CODE %s
// TestPhase2ModelResolutionIsProposedThenLandedByTheAgent is decision 1 of PLAN10 14 end to end:
// the real graft-resolve answers with its llm strategy, the server lands nothing and proposes the
// answer in the conflict package, the SDK reads the proposal, and the agent lands it as its own.
-// The strategy is named "model", not "llm": the server's fallback on the resolver's name cannot
-// catch it, so the proposal flag that graft-resolve sets is what makes it a proposal.
+// The strategy is named "model", not "llm": the server never reads the resolver's name, so the
+// origin that graft-resolve sets on the file (and that a file without one defaults to) is what
+// makes it a model's resolution.
func TestPhase2ModelResolutionIsProposedThenLandedByTheAgent(t *testing.T) {
t.Parallel()
diff --git a/internal/graft/resolver/check.go b/internal/graft/resolver/check.go
index cc135a7..f2ee760 100644
--- a/internal/graft/resolver/check.go
+++ b/internal/graft/resolver/check.go
@@ -132,7 +132,7 @@ func (s *ResolveSlot) Resolve(ctx context.Context, req Request) (*Response, erro
// verifySlotWait is the time the verifications waited for a verify slot.
var verifySlotWait = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "graft_resolver_verify_slot_wait_seconds",
- Help: "Time a verification of a model's resolution waited for one of the resolver's verify slots.",
+ Help: "Time a verification of a resolution waited for one of the resolver's verify slots.",
Buckets: prometheus.ExponentialBuckets(0.01, 4, 8),
})
@@ -170,7 +170,7 @@ type repoVerifySlots struct {
// VerifySlot is the right to run one verification at a time: the client runs at most
// verify_concurrency of them at once, and at most verify_per_repository for one repository
-// (AcquireVerifySlot), in a pool apart from the checks' and the resolutions'. Release it when the
+// (VerifyPool.Acquire), in a pool apart from the checks' and the resolutions'. Release it when the
// verification is done.
type VerifySlot struct {
p *VerifyPool
@@ -178,18 +178,10 @@ type VerifySlot struct {
released bool
}
-// AcquireVerifySlot waits for a verify slot of repo (a key of the repository: its storage and
-// relative path) and then for one of the pool. The wait counts against the deadline of ctx: when ctx
-// ends first, it fails, and the land cannot be verified in time. The slot of the repository is taken
-// first, so that a land that waits for its repository holds nothing of the pool.
-func (c *Client) AcquireVerifySlot(ctx context.Context, repo string) (*VerifySlot, error) {
- if c == nil {
- return nil, ErrDisabled
- }
- return c.verify.Acquire(ctx, repo)
-}
-
-// Acquire waits for a verify slot of repo and then for one of the pool; see Client.AcquireVerifySlot.
+// Acquire waits for a verify slot of repo (a key of the repository: its storage and relative path)
+// and then for one of the pool. The wait counts against the deadline of ctx: when ctx ends first, it
+// fails, and the land cannot be verified in time. The slot of the repository is taken first, so that a
+// land that waits for its repository holds nothing of the pool.
func (p *VerifyPool) Acquire(ctx context.Context, repo string) (*VerifySlot, error) {
if p == nil {
return nil, ErrDisabled
diff --git a/internal/graft/resolver/client.go b/internal/graft/resolver/client.go
index 4bc8b03..34940bb 100644
--- a/internal/graft/resolver/client.go
+++ b/internal/graft/resolver/client.go
@@ -102,10 +102,6 @@ type Client struct {
// the short checks (PLAN10 15.8).
checkSlots chan struct{}
resolveSlots chan struct{}
- // verify bounds the verifications that run at once (VerifySlot), a third pool, as the operator's
- // command takes minutes (PLAN10 15.9). Shared replaces it with the pool of the process, which
- // the verification of every land goes through, with or without an AI resolver.
- verify *VerifyPool
// sendRules decide the files that are never sent (SendRules).
sendRules *SendRules
}
@@ -163,7 +159,6 @@ func New(cfg config.GraftResolver) (*Client, error) {
sendRules: rules,
checkSlots: make(chan struct{}, cfg.CheckConcurrencyOrDefault()),
resolveSlots: make(chan struct{}, cfg.ResolveConcurrencyOrDefault()),
- verify: NewVerifyPool(cfg),
}
if cfg.URL != "" {
diff --git a/internal/graft/resolver/client_test.go b/internal/graft/resolver/client_test.go
index 2f7f50f..e640acb 100644
--- a/internal/graft/resolver/client_test.go
+++ b/internal/graft/resolver/client_test.go
@@ -770,12 +770,12 @@ func TestAcquireResolveSlot_boundsTheResolutionsAtOnce(t *testing.T) {
// timedOut reports whether acquiring a verify slot of repo gives up at once: the wait counts against
// the context, so a short one ends it.
-func timedOut(t *testing.T, client *Client, repo string) error {
+func timedOut(t *testing.T, pool *VerifyPool, repo string) error {
t.Helper()
ctx, cancel := context.WithTimeout(testhelper.Context(t), 50*time.Millisecond)
defer cancel()
- slot, err := client.AcquireVerifySlot(ctx, repo)
+ slot, err := pool.Acquire(ctx, repo)
if err == nil {
slot.Release()
}
@@ -791,15 +791,16 @@ func TestAcquireVerifySlot_boundsTheVerificationsAtOnce(t *testing.T) {
cfg.CheckConcurrency = 1
cfg.ResolveConcurrency = 1
client := newClient(t, cfg)
+ pool := NewVerifyPool(cfg)
ctx := testhelper.Context(t)
- a, err := client.AcquireVerifySlot(ctx, "a")
+ a, err := pool.Acquire(ctx, "a")
require.NoError(t, err)
- b, err := client.AcquireVerifySlot(ctx, "b")
+ b, err := pool.Acquire(ctx, "b")
require.NoError(t, err)
// Two repositories hold the two slots: a third waits until its deadline, then fails.
- err = timedOut(t, client, "c")
+ err = timedOut(t, pool, "c")
require.ErrorIs(t, err, context.DeadlineExceeded)
require.ErrorContains(t, err, "waiting for a verify slot of the resolver")
@@ -816,20 +817,20 @@ func TestAcquireVerifySlot_boundsTheVerificationsAtOnce(t *testing.T) {
// A slot released twice frees one place only.
a.Release()
a.Release()
- require.NoError(t, timedOut(t, client, "c"))
- c, err := client.AcquireVerifySlot(ctx, "c")
+ require.NoError(t, timedOut(t, pool, "c"))
+ c, err := pool.Acquire(ctx, "c")
require.NoError(t, err)
- require.ErrorIs(t, timedOut(t, client, "d"), context.DeadlineExceeded, "a second release must not free a second place")
+ require.ErrorIs(t, timedOut(t, pool, "d"), context.DeadlineExceeded, "a second release must not free a second place")
b.Release()
c.Release()
var none *VerifySlot
none.Release()
- var disabled *Client
- _, err = disabled.AcquireVerifySlot(ctx, "a")
+ var disabled *VerifyPool
+ _, err = disabled.Acquire(ctx, "a")
require.ErrorIs(t, err, ErrDisabled)
- require.Equal(t, config.DefaultGraftResolverVerifyConcurrency, cap(newClient(t, commandConfig([]string{"/bin/true"})).verify.slots))
+ require.Equal(t, config.DefaultGraftResolverVerifyConcurrency, cap(NewVerifyPool(commandConfig([]string{"/bin/true"})).slots))
}
// TestAcquireVerifySlot_oneRepositoryCannotTakeThePool: at most verify_per_repository verifications run
@@ -839,15 +840,15 @@ func TestAcquireVerifySlot_boundsTheVerificationsAtOnce(t *testing.T) {
func TestAcquireVerifySlot_oneRepositoryCannotTakeThePool(t *testing.T) {
cfg := commandConfig([]string{"/bin/true"})
cfg.VerifyConcurrency = 2
- client := newClient(t, cfg)
+ pool := NewVerifyPool(cfg)
ctx := testhelper.Context(t)
- require.Equal(t, config.DefaultGraftResolverVerifyPerRepository, client.verify.perRepo)
+ require.Equal(t, config.DefaultGraftResolverVerifyPerRepository, pool.perRepo)
- first, err := client.AcquireVerifySlot(ctx, "busy")
+ first, err := pool.Acquire(ctx, "busy")
require.NoError(t, err)
// A second verification of the same repository waits, though the pool has a free slot...
- err = timedOut(t, client, "busy")
+ err = timedOut(t, pool, "busy")
require.ErrorIs(t, err, context.DeadlineExceeded)
require.ErrorContains(t, err, "waiting for a verify slot of the repository")
@@ -855,18 +856,18 @@ func TestAcquireVerifySlot_oneRepositoryCannotTakeThePool(t *testing.T) {
// while a land waits for the busy one.
waiting := make(chan error, 1)
go func() {
- slot, err := client.AcquireVerifySlot(ctx, "busy")
+ slot, err := pool.Acquire(ctx, "busy")
if err == nil {
slot.Release()
}
waiting <- err
}()
require.Eventually(t, func() bool {
- client.verify.mu.Lock()
- defer client.verify.mu.Unlock()
- return client.verify.repos["busy"] != nil && client.verify.repos["busy"].users == 2
+ pool.mu.Lock()
+ defer pool.mu.Unlock()
+ return pool.repos["busy"] != nil && pool.repos["busy"].users == 2
}, 5*time.Second, 5*time.Millisecond, "the second land never waited")
- other, err := client.AcquireVerifySlot(ctx, "other")
+ other, err := pool.Acquire(ctx, "other")
require.NoError(t, err, "a land that waits for its repository holds nothing of the pool")
// The release of the first lets the waiter through.
@@ -874,26 +875,26 @@ func TestAcquireVerifySlot_oneRepositoryCannotTakeThePool(t *testing.T) {
require.NoError(t, <-waiting)
other.Release()
- client.verify.mu.Lock()
- require.Empty(t, client.verify.repos, "nothing is kept of a repository without holder or waiter")
- client.verify.mu.Unlock()
+ pool.mu.Lock()
+ require.Empty(t, pool.repos, "nothing is kept of a repository without holder or waiter")
+ pool.mu.Unlock()
// A waiter that gave up leaves no trace either.
- held, err := client.AcquireVerifySlot(ctx, "gone")
+ held, err := pool.Acquire(ctx, "gone")
require.NoError(t, err)
- require.Error(t, timedOut(t, client, "gone"))
+ require.Error(t, timedOut(t, pool, "gone"))
held.Release()
- client.verify.mu.Lock()
- require.Empty(t, client.verify.repos)
- client.verify.mu.Unlock()
+ pool.mu.Lock()
+ require.Empty(t, pool.repos)
+ pool.mu.Unlock()
// Configured, the cap is the number of verifications of one repository at once.
cfg.VerifyPerRepository = 2
cfg.VerifyConcurrency = 3
- wide := newClient(t, cfg)
- one, err := wide.AcquireVerifySlot(ctx, "r")
+ wide := NewVerifyPool(cfg)
+ one, err := wide.Acquire(ctx, "r")
require.NoError(t, err)
- two, err := wide.AcquireVerifySlot(ctx, "r")
+ two, err := wide.Acquire(ctx, "r")
require.NoError(t, err)
require.ErrorContains(t, timedOut(t, wide, "r"), "of the repository")
one.Release()
diff --git a/internal/graft/resolver/shared.go b/internal/graft/resolver/shared.go
index 7525ddf..c8bc241 100644
--- a/internal/graft/resolver/shared.go
+++ b/internal/graft/resolver/shared.go
@@ -26,8 +26,5 @@ func NewShared(cfg config.GraftResolver) *Shared {
if err != nil {
return &Shared{Err: err, Verify: pool}
}
- if client != nil && pool != nil {
- client.verify = pool
- }
return &Shared{Client: client, Verify: pool}
}