diff --git a/changelog.d/changed-app-signed-commits-docs.md b/changelog.d/changed-app-signed-commits-docs.md new file mode 100644 index 0000000000..abc5a7a904 --- /dev/null +++ b/changelog.d/changed-app-signed-commits-docs.md @@ -0,0 +1 @@ +- Docs: `github.app_signed_commits` now has an operator-reference row (default off, App-only, what it rewrites, fallbacks, Settings location) and the level-6 checklist and `github-app-setup.md` point at its dashboard switch (Settings → Forge App → "Re-author agent PRs as GitHub-signed commits") instead of calling it YAML-only. diff --git a/changelog.d/changed-crux-streamtail.md b/changelog.d/changed-crux-streamtail.md new file mode 100644 index 0000000000..3743f6b0d1 --- /dev/null +++ b/changelog.d/changed-crux-streamtail.md @@ -0,0 +1 @@ +- crux: the follow-stream overlap rule shared by the CLI and the serve layer now lives in one `internal/streamtail` package instead of two copies. diff --git a/changelog.d/fixed-16654-navigation-label.md b/changelog.d/fixed-16654-navigation-label.md new file mode 100644 index 0000000000..d32f536cd1 --- /dev/null +++ b/changelog.d/fixed-16654-navigation-label.md @@ -0,0 +1 @@ +- Label the narrow dashboard's navigation drawer button so operators can find sidebar sections and version details without guessing what the menu icon does (#16654). diff --git a/changelog.d/fixed-16685.md b/changelog.d/fixed-16685.md new file mode 100644 index 0000000000..d7752470be --- /dev/null +++ b/changelog.d/fixed-16685.md @@ -0,0 +1 @@ +- In-place DCO repair no longer appends the App's Signed-off-by to a collaborator's unsigned commit on a hive-authored PR: only commits GitHub links to the App bot or a hive identity are re-signed, and a hive-authored PR carrying anyone else's unsigned commit waits for a person instead ([#16685](https://github.com/hivecommons/hive/issues/16685)). diff --git a/changelog.d/fixed-16707.md b/changelog.d/fixed-16707.md new file mode 100644 index 0000000000..97449a01cd --- /dev/null +++ b/changelog.d/fixed-16707.md @@ -0,0 +1 @@ +- A DCO split cached while no `project.ai_author` was configured is no longer treated as computed with the hive identity, so configuring it later re-reads the commits for in-flight heads ([#16707](https://github.com/hivecommons/hive/issues/16707)). diff --git a/changelog.d/fixed-16710.md b/changelog.d/fixed-16710.md new file mode 100644 index 0000000000..b3a82301a4 --- /dev/null +++ b/changelog.d/fixed-16710.md @@ -0,0 +1 @@ +- A stale hive-identity DCO marker is now cleared when a new head is cached App-only, so re-adding `ai_author` after removing it re-reads the commit check instead of serving the App-only split ([#16710](https://github.com/hivecommons/hive/issues/16710)). diff --git a/changelog.d/fixed-16721.md b/changelog.d/fixed-16721.md new file mode 100644 index 0000000000..d87d18044e --- /dev/null +++ b/changelog.d/fixed-16721.md @@ -0,0 +1 @@ +- Decouple the crux sidecar probe deadline from the poll interval so a fast test ticker no longer reports a live `crux serve` as unreachable (#16721). diff --git a/changelog.d/fixed-dco-hive-ownership-consistency.md b/changelog.d/fixed-dco-hive-ownership-consistency.md new file mode 100644 index 0000000000..104339ea77 --- /dev/null +++ b/changelog.d/fixed-dco-hive-ownership-consistency.md @@ -0,0 +1 @@ +- DCO checks now treat commits linked to `project.ai_author` as the hive's in both the unsigned split and the squash-unsafe count, and a split cached before hive identities counted is read again once, so an in-flight hive-authored PR is re-signed instead of waiting for a person ([#16701](https://github.com/hivecommons/hive/issues/16701), [#16703](https://github.com/hivecommons/hive/issues/16703)). The docs now state that this login linkage comes from the commit email and is trusted only because the in-place path needs base-repo push access ([#16702](https://github.com/hivecommons/hive/issues/16702)). diff --git a/changelog.d/fixed-stage-label-reopen-warn-dedupe.md b/changelog.d/fixed-stage-label-reopen-warn-dedupe.md new file mode 100644 index 0000000000..42044d4780 --- /dev/null +++ b/changelog.d/fixed-stage-label-reopen-warn-dedupe.md @@ -0,0 +1 @@ +- The stage-label reconciler now warns once per PR head and refusal reason when the write-back gate refuses reopening a hive-closed superseded PR, instead of on every tick. diff --git a/src/Dockerfile b/src/Dockerfile index 48379c25a1..e7da4b0237 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -383,10 +383,10 @@ RUN ARCH="${TARGETARCH:-$(dpkg --print-architecture)}" && \ # complete the interactive OAuth flow itself). This enables a self-hosted Hive # controller to use its configured agy fallback rung without pretending that # generic contributor containers can bootstrap Google login. -ARG AGY_VERSION=1.4.0 -ARG AGY_BUILD=5281842794987520 -ARG AGY_SHA512_AMD64=6c4b298c2a69b6bd0f58567031cc56d8097a32be54c4b633aa80ad395871b389618ab3860d4ba0a12599831b8226b51b03e258ee2ec7fae105a45b8e0fce2188 -ARG AGY_SHA512_ARM64=64dfb2a9665ebd19b6e9d687c094673b61ca9f5ffdebc81391cea8e3858773e1c88154f088e8a8691208561d946a7aea9acbec7a3bdca9e5d8a48fa197b0a308 +ARG AGY_VERSION=1.5.0 +ARG AGY_BUILD=5269980577660928 +ARG AGY_SHA512_AMD64=e6031f850929210705d8c2393a5665b82b8c3b19684a6d3c556cafa31f26f77acbf164dfee96ca84a5ae7670ac0cc238a974c981c517b269194bdccff271cbd5 +ARG AGY_SHA512_ARM64=509518b2820945db2bea5e013ca43a49df5c78927c3ac341a1115287d52627356e1e9506ac0d2040fb467915fba4dde90061d091fddbddf8ddc212637ae40150 RUN ARCH="${TARGETARCH:-$(dpkg --print-architecture)}" && \ case "$ARCH" in \ amd64|x86_64) AGY_URL_ARCH=x64; AGY_FILE_ARCH=x64; AGY_SHA512="$AGY_SHA512_AMD64" ;; \ diff --git a/src/Dockerfile.contributor b/src/Dockerfile.contributor index 4b98cfff4d..74df8ac5a0 100644 --- a/src/Dockerfile.contributor +++ b/src/Dockerfile.contributor @@ -433,9 +433,9 @@ RUN ARCH="${TARGETARCH:-$(dpkg --print-architecture)}" \ # API-key mode, so a fresh container still needs an operator to sign in # inside it (or a future credential-mount fix, see Justfile's `agy)` staging # case) before it can do unattended work. -ARG AGY_VERSION=1.4.0-5281842794987520 -ARG AGY_SHA256_AMD64=fd96967583c1eed94733c039638fa59b71ddbd823c75ebc8dd0e677463565aad -ARG AGY_SHA256_ARM64=cf953adcc69f87d00d71f97c3f35dc723a8669a350accf9a199df781f0523f56 +ARG AGY_VERSION=1.5.0-5269980577660928 +ARG AGY_SHA256_AMD64=f65e365a67be49abdaf92f5669c3157bd4b9c569f6b9f448340b00ca261b0f01 +ARG AGY_SHA256_ARM64=87e73a5ab4ecb3a9668660d259dafd13f5443149da0113664d59129a21a62ba4 RUN ARCH="${TARGETARCH:-$(dpkg --print-architecture)}" \ && case "$ARCH" in \ amd64) AGY_PLATFORM=linux-x64; AGY_TARBALL=cli_linux_x64.tar.gz; AGY_SHA256="$AGY_SHA256_AMD64" ;; \ diff --git a/src/cmd/hive/agent_runtime_supervise.go b/src/cmd/hive/agent_runtime_supervise.go index 7aad99df44..ef136dd808 100644 --- a/src/cmd/hive/agent_runtime_supervise.go +++ b/src/cmd/hive/agent_runtime_supervise.go @@ -52,9 +52,12 @@ type cruxRuntimeSupervision struct { prober runtimeProber supervisor *cruxruntime.Supervisor logger *slog.Logger - interval time.Duration - observe func(class, key, message, diagnostics string) - clear func(class, key string) + // interval is the poll-loop period; probeTimeout is the per-probe HTTP + // deadline. They are decoupled so a fast test ticker cannot starve the probe. + interval time.Duration + probeTimeout time.Duration + observe func(class, key, message, diagnostics string) + clear func(class, key string) } // newCruxRuntimeSupervision prepares supervision for rt under cfg. It @@ -76,7 +79,7 @@ func newCruxRuntimeSupervision(cfg cruxconfig.RuntimeConfig, rt crux.Runtime, lo return nil } } - s := &cruxRuntimeSupervision{cfg: cfg, prober: p, logger: logger, interval: cruxRuntimeProbeInterval, observe: fleetreport.Observe, clear: fleetreport.Clear} + s := &cruxRuntimeSupervision{cfg: cfg, prober: p, logger: logger, interval: cruxRuntimeProbeInterval, probeTimeout: cruxRuntimeProbeInterval, observe: fleetreport.Observe, clear: fleetreport.Clear} if cfg.Supervise == cruxconfig.SuperviseChild { s.supervisor = &cruxruntime.Supervisor{Config: cfg, Logger: logger} } @@ -121,7 +124,7 @@ func (s *cruxRuntimeSupervision) watch(ctx context.Context) { // probe makes one health call so the client's Status reflects the socket // even when no agent traffic has exercised it. func (s *cruxRuntimeSupervision) probe(ctx context.Context) { - pctx, cancel := context.WithTimeout(ctx, s.interval) + pctx, cancel := context.WithTimeout(ctx, s.probeTimeout) defer cancel() _, _ = s.prober.Client().Health(pctx) } diff --git a/src/cmd/hive/agent_runtime_supervise_test.go b/src/cmd/hive/agent_runtime_supervise_test.go index b0805cbdf8..fb1d7e5c6e 100644 --- a/src/cmd/hive/agent_runtime_supervise_test.go +++ b/src/cmd/hive/agent_runtime_supervise_test.go @@ -116,6 +116,20 @@ func TestCruxRuntimeSupervision_NilOutsideSidecar(t *testing.T) { } } +func TestCruxRuntimeSupervision_ProbeDeadlineIndependentOfInterval(t *testing.T) { + _, ts := liveServe(t) + s, _, _ := newSupervisionFor(t, ts.URL, cruxconfig.SuperviseExternal) + s.interval = time.Nanosecond + + s.probe(context.Background()) + if down := s.reconcile(false); down { + t.Fatal("live server reported down with a tiny poll interval") + } + if !s.prober.Status().Reachable { + t.Fatal("prober unreachable with a tiny poll interval") + } +} + func TestCruxRuntimeSupervision_ConditionFollowsReachability(t *testing.T) { _, ts := liveServe(t) s, cl, log := newSupervisionFor(t, ts.URL, cruxconfig.SuperviseExternal) diff --git a/src/crux/cli/cli_test.go b/src/crux/cli/cli_test.go index 4c01be43e8..d5acdcf260 100644 --- a/src/crux/cli/cli_test.go +++ b/src/crux/cli/cli_test.go @@ -444,25 +444,6 @@ func TestRunStopErrorAndOutputError(t *testing.T) { } } -func TestNewTail(t *testing.T) { - cases := []struct { - prev, cur, want []string - }{ - {nil, []string{"a", "b"}, []string{"a", "b"}}, - {[]string{"a", "b"}, []string{"a", "b"}, nil}, - {[]string{"a", "b"}, []string{"a", "b", "c"}, []string{"c"}}, - {[]string{"a", "b", "c"}, []string{"b", "c", "d", "e"}, []string{"d", "e"}}, - {[]string{"a", "b"}, []string{"x", "y"}, []string{"x", "y"}}, - {[]string{"a", "b"}, []string{"b"}, nil}, - } - for _, c := range cases { - got := newTail(c.prev, c.cur) - if strings.Join(got, ",") != strings.Join(c.want, ",") { - t.Errorf("newTail(%v, %v) = %v, want %v", c.prev, c.cur, got, c.want) - } - } -} - func hiveYAML(t *testing.T) string { t.Helper() dir := t.TempDir() diff --git a/src/crux/cli/commands.go b/src/crux/cli/commands.go index 02def517c5..5571a6f106 100644 --- a/src/crux/cli/commands.go +++ b/src/crux/cli/commands.go @@ -13,6 +13,7 @@ import ( "time" "github.com/hivecommons/hive/crux" + "github.com/hivecommons/hive/crux/internal/streamtail" ) // subFlags builds a subcommand flag set that reports to stderr and never @@ -130,7 +131,7 @@ func (e *Env) stream(ctx context.Context, rt crux.Runtime, name string, interval fmt.Fprintf(e.Stderr, "crux: output %s: %v\n", name, err) return } - for _, line := range newTail(prev, cur) { + for _, line := range streamtail.Fresh(prev, cur) { fmt.Fprintln(e.Stdout, line) } prev = cur @@ -138,34 +139,6 @@ func (e *Env) stream(ctx context.Context, rt crux.Runtime, name string, interval } } -// newTail returns the lines of cur that were not already printed from prev, -// treating both as windows onto the same append-only buffer: the longest -// suffix of prev that is a prefix of cur is the overlap. -func newTail(prev, cur []string) []string { - max := len(prev) - if len(cur) < max { - max = len(cur) - } - for k := max; k > 0; k-- { - if equalLines(prev[len(prev)-k:], cur[:k]) { - return cur[k:] - } - } - return cur -} - -func equalLines(a, b []string) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true -} - // processRow is the ps projection of a crux.Process: the columns an operator // reads at a glance, and the JSON shape --json emits. type processRow struct { diff --git a/src/crux/cline/provider_file_test.go b/src/crux/cline/provider_file_test.go index 7f8c20421b..fc931bd1d4 100644 --- a/src/crux/cline/provider_file_test.go +++ b/src/crux/cline/provider_file_test.go @@ -195,3 +195,70 @@ func TestProviderStagingRootAndRedactionFailures(t *testing.T) { t.Fatal("nested or overlapping secret redaction failed") } } + +func TestMountedProviderWorkerDenials(t *testing.T) { + root, workspace := t.TempDir(), t.TempDir() + t.Setenv("HOME", root) + t.Setenv("HIVE_CLINE_CONFIG_DIR", "") + source := filepath.Join(root, "source") + credentials(t, source, providerConfig) + p, err := StageProviderFile(source, "openrouter/test", workspace) + if err != nil { + t.Fatal(err) + } + defer p.Close() + mounted, err := p.MountFile(workspace) + if err != nil { + t.Fatal(err) + } + narrowed, err := os.ReadFile(mounted) + if err != nil { + t.Fatal(err) + } + // A denied provider file must never reach inference: the stub leaves a + // marker when launched, and none of the cases below may create it. + launched := filepath.Join(root, "launched") + binary := fakeCLI(t, "touch "+launched+`; cat >/dev/null; echo '{"type":"run_result","finishReason":"completed","text":"done"}'`) + write := func(path string, body []byte) string { + t.Helper() + if err := os.WriteFile(path, body, 0o600); err != nil { + t.Fatal(err) + } + return path + } + inWorkspace := write(filepath.Join(workspace, "providers.json"), narrowed) + viaSymlink := filepath.Join(root, "outside-link") + if err := os.Symlink(inWorkspace, viaSymlink); err != nil { + t.Fatal(err) + } + unreadable := filepath.Join(root, "directory-not-file") + if err := os.Mkdir(unreadable, 0o700); err != nil { + t.Fatal(err) + } + cases := []struct { + name, file, want string + }{ + {"inside workspace", inWorkspace, "outside the Git workspace"}, + {"symlink into workspace", viaSymlink, "outside the Git workspace"}, + {"missing", filepath.Join(root, "missing"), "cannot resolve"}, + {"unreadable", unreadable, "cannot read the mounted selected Cline provider"}, + {"unsupported schema", write(filepath.Join(root, "schema.json"), []byte(`{"version":2}`)), "unsupported Cline providers.json schema"}, + {"other provider only", write(filepath.Join(root, "other.json"), []byte(`{"version":1,"providers":{"other":{"settings":{"apiKey":"test-key"}}}}`)), "not configured"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + var out, errOut bytes.Buffer + code := Run([]string{"--cline", binary, "--model", "openrouter/test", "--provider-file", tc.file, + "--cwd", workspace, "--state-dir", filepath.Join(root, "state")}, strings.NewReader("bounded task"), &out, &errOut) + if code != 1 || !strings.Contains(errOut.String(), tc.want) { + t.Fatalf("code %d, stderr %q", code, &errOut) + } + if strings.Contains(errOut.String(), "test-key") || strings.Contains(out.String(), "test-key") { + t.Fatal("denial leaked the provider credential") + } + if _, err := os.Stat(launched); !os.IsNotExist(err) { + t.Fatal("denied provider file still launched the Cline CLI") + } + }) + } +} diff --git a/src/crux/internal/streamtail/streamtail.go b/src/crux/internal/streamtail/streamtail.go new file mode 100644 index 0000000000..afdbd9059d --- /dev/null +++ b/src/crux/internal/streamtail/streamtail.go @@ -0,0 +1,30 @@ +// Package streamtail computes the unseen part of a polled output window. +package streamtail + +// Fresh returns the lines of cur that were not already seen in prev, treating +// both as windows onto the same append-only buffer: the longest suffix of prev +// that is a prefix of cur is the overlap. +func Fresh(prev, cur []string) []string { + max := len(prev) + if len(cur) < max { + max = len(cur) + } + for k := max; k > 0; k-- { + if equalLines(prev[len(prev)-k:], cur[:k]) { + return cur[k:] + } + } + return cur +} + +func equalLines(a, b []string) bool { + if len(a) != len(b) { + return false + } + for i := range a { + if a[i] != b[i] { + return false + } + } + return true +} diff --git a/src/crux/internal/streamtail/streamtail_test.go b/src/crux/internal/streamtail/streamtail_test.go new file mode 100644 index 0000000000..76a9872ab7 --- /dev/null +++ b/src/crux/internal/streamtail/streamtail_test.go @@ -0,0 +1,25 @@ +package streamtail + +import ( + "strings" + "testing" +) + +func TestFresh(t *testing.T) { + cases := []struct { + prev, cur, want []string + }{ + {nil, []string{"a", "b"}, []string{"a", "b"}}, + {[]string{"a", "b"}, []string{"a", "b"}, nil}, + {[]string{"a", "b"}, []string{"a", "b", "c"}, []string{"c"}}, + {[]string{"a", "b", "c"}, []string{"b", "c", "d", "e"}, []string{"d", "e"}}, + {[]string{"a", "b"}, []string{"x", "y"}, []string{"x", "y"}}, + {[]string{"a", "b"}, []string{"b"}, nil}, + {[]string{"a", "b", "c"}, []string{"c"}, nil}, + } + for _, c := range cases { + if got := Fresh(c.prev, c.cur); strings.Join(got, ",") != strings.Join(c.want, ",") { + t.Errorf("Fresh(%v, %v) = %v, want %v", c.prev, c.cur, got, c.want) + } + } +} diff --git a/src/crux/serve/log_tail.go b/src/crux/serve/log_tail.go deleted file mode 100644 index b7b6ea2785..0000000000 --- a/src/crux/serve/log_tail.go +++ /dev/null @@ -1,30 +0,0 @@ -package serve - -// newTail returns the lines of cur that were not already seen in prev, -// treating both as windows onto the same append-only buffer: the longest -// suffix of prev that is a prefix of cur is the overlap. It is the CLI's -// stream rule (crux/cli.newTail) applied server side. -func newTail(prev, cur []string) []string { - max := len(prev) - if len(cur) < max { - max = len(cur) - } - for k := max; k > 0; k-- { - if equalLines(prev[len(prev)-k:], cur[:k]) { - return cur[k:] - } - } - return cur -} - -func equalLines(a, b []string) bool { - if len(a) != len(b) { - return false - } - for i := range a { - if a[i] != b[i] { - return false - } - } - return true -} diff --git a/src/crux/serve/serve_follow.go b/src/crux/serve/serve_follow.go index b39f531c93..5c62b3cc3e 100644 --- a/src/crux/serve/serve_follow.go +++ b/src/crux/serve/serve_follow.go @@ -7,6 +7,7 @@ import ( "github.com/hivecommons/hive/crux" "github.com/hivecommons/hive/crux/api" + "github.com/hivecommons/hive/crux/internal/streamtail" ) // followWindow is how many ring-buffer lines each follow poll asks for when @@ -74,7 +75,7 @@ func (s *Server) followLogs(w http.ResponseWriter, r *http.Request, name string, flusher.Flush() return } - if fresh := newTail(prev, cur); len(fresh) > 0 { + if fresh := streamtail.Fresh(prev, cur); len(fresh) > 0 { if api.WriteEvent(w, api.EventLog, api.LogChunk{Agent: name, Lines: fresh}) != nil { return } diff --git a/src/crux/serve/serve_test.go b/src/crux/serve/serve_test.go index e256692c1c..dd6c8ac238 100644 --- a/src/crux/serve/serve_test.go +++ b/src/crux/serve/serve_test.go @@ -1221,7 +1221,7 @@ func TestWriteJSONLogsEncodeFailures(t *testing.T) { func slogTo(w io.Writer) *slog.Logger { return slog.New(slog.NewTextHandler(w, nil)) } -func TestIsTrueAndNewTail(t *testing.T) { +func TestIsTrue(t *testing.T) { for _, v := range []string{"1", "true", "YES", "on"} { if !isTrue(v) { t.Errorf("%q should be true", v) @@ -1232,16 +1232,4 @@ func TestIsTrueAndNewTail(t *testing.T) { t.Errorf("%q should be false", v) } } - cases := []struct{ prev, cur, want []string }{ - {nil, []string{"a"}, []string{"a"}}, - {[]string{"a", "b"}, []string{"a", "b"}, nil}, - {[]string{"a", "b"}, []string{"b", "c"}, []string{"c"}}, - {[]string{"a", "b"}, []string{"x", "y"}, []string{"x", "y"}}, - {[]string{"a", "b", "c"}, []string{"c"}, nil}, - } - for _, c := range cases { - if got := newTail(c.prev, c.cur); strings.Join(got, ",") != strings.Join(c.want, ",") { - t.Errorf("newTail(%v,%v) = %v, want %v", c.prev, c.cur, got, c.want) - } - } } diff --git a/src/docs/github-app-setup.md b/src/docs/github-app-setup.md index 81db0abb0c..32fc466ff8 100644 --- a/src/docs/github-app-setup.md +++ b/src/docs/github-app-setup.md @@ -209,6 +209,8 @@ github: app_signed_commits: true # opt-in; needs an installed App ``` +In the dashboard the same switch is **Settings → Forge App → Re-author agent PRs as GitHub-signed commits** (Owner role required to save). + With it on, the PR-request watcher (the choke point every `hive-open-pr` request passes through) re-authors the head branch before it opens the PR: it reads the `base...head` diff, builds one commit through the mutation with the App installation token — same tree, the agents' original commit messages and DCO trailers as the message — force-updates the branch to it, and then opens the PR. The PR arrives with a single commit, signed by GitHub, authored by `[bot]`, that a `required_signatures` rule accepts. **DCO.** The mutation takes no author: GitHub stamps its own bot account on the commit (`[bot] `). That is fine for the DCO checks - probot-dco exempts a commit whose GitHub author resolves to a Bot account, and Prow's `dco` plugin only requires a `Signed-off-by` line to be present. The `Signed-off-by` trailers copied from the agents' commits are what the hive controls, and they are re-addressed to the bracket-free form the pane identity uses since #6276: a `[bot]@users.noreply.github.com` sign-off (with or without GitHub's numeric prefix) becomes `@hive.kubestellar.io` (`HIVE_GIT_BOT_EMAIL_DOMAIN`), because probot-dco rejects the bracketed local-part as "not a valid email address" wherever it does validate it (#6251). Every other sign-off address, a human's or the legacy `hive-bot@kubestellar.io`, is copied unchanged. diff --git a/src/docs/labels-and-control-signals/stage-labels.md b/src/docs/labels-and-control-signals/stage-labels.md index 7c70b15b32..e595f9dc16 100644 --- a/src/docs/labels-and-control-signals/stage-labels.md +++ b/src/docs/labels-and-control-signals/stage-labels.md @@ -1217,12 +1217,20 @@ When a contributor-agent PR goes red the hive does not just relabel it (a human- If an adopted head is DCO-red, an empty signed commit is never enough. "Hive-authored" is decided the same way as head attribution above: an unsigned commit is the hive's own only when GitHub links its author or - committer to the App bot; git author/committer names and emails — even a - lane-looking `@` address — are - contributor-controlled and never count. The stage pass caches that split - with the commit check (`dco_unsigned_hive`), so the decision does not - depend on which labels the PR currently carries. When every unsigned - commit is App-linked and the head lives in the **base repo**, an in-place + committer to the App bot, or its author to one of the hive's identities + (`project.ai_author`); git author/committer names — even a lane-looking + `@` address — never count on their own. + GitHub derives that login linkage from the commit email and agents push + unsigned commits, so it is not proof of origin: anyone who can push to a + base-repo branch can author a commit as `project.ai_author` and have it + re-signed. Only collaborators with push access reach the in-place path, + so the hive trusts them not to do that + ([#16702](https://github.com/hivecommons/hive/issues/16702)). The stage + pass caches that split with the commit check (`dco_unsigned_hive`), so + the decision does not depend on which labels the PR currently carries; a + split cached before hive identities counted is read again once + (`dco_split_hive_identity`). When every unsigned commit is the hive's + and the head lives in the **base repo**, an in-place adoption stays in place and the stage engine itself re-signs the branch once per head (`reason=dco-rehomed`): it replays the PR's commits through the git-data API, keeping each author, message, tree and parents (merge diff --git a/src/docs/operator-reference/README.md b/src/docs/operator-reference/README.md index c8eec88283..c71e2a70b6 100644 --- a/src/docs/operator-reference/README.md +++ b/src/docs/operator-reference/README.md @@ -252,6 +252,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through | `github.pr_detail_ttl_s` | `1800` seconds. `HIVE_GITHUB_PR_DETAIL_TTL` overrides for tests/experiments. | Reuses `GET /pulls/{number}` detail responses while the cheap PR list still reports the same `head.sha` and `updated_at`, and GitHub has resolved `mergeable_state`. | | `github.graphql_pr_batch` | `true` | Uses one paginated GraphQL query per repository scan to populate the PR detail cache and CI rollup cache, replacing most per-PR `GET /pulls/{number}` and `check-runs` reads. Set `false` to return to the REST-only scan path. | | `github.graphql_pr_batch_page_size` | `50` | Page size for the GraphQL `pullRequests(first:)` batch. Values above GitHub's `100` maximum are rejected. | +| `github.app_signed_commits` | Unset (off). App-authenticated hives only; PAT-authenticated hives ignore it. Settings → Forge App → **Re-author agent PRs as GitHub-signed commits** (Owner role). | Opt-in for repositories whose ruleset requires signed commits (`required_signatures`). Agents commit with plain `git` in their pane and cannot sign, so without it every agent PR is unmergeable there however many approvals it has. With it on, the PR-request watcher re-authors the head branch before the PR opens as one commit created through the GraphQL `createCommitOnBranch` mutation with the App installation token — same tree, the agents' messages and DCO trailers as the message — which GitHub signs and shows as **Verified**, authored by `[bot]`. A reconcile pass (at most once a minute) re-signs the hive's own unsigned follow-up pushes on open App-authored PRs the same way. Falls back to the plain unsigned push (PR still opens; `signed_skipped` in the request's `.result.json` and a WARN in the hive log) for changes the mutation cannot express (executable bits, symlinks, submodule pointers), more than 20 MiB of content or 300 files, a head that moved mid-rewrite, or a head that already has an open PR. A person's commit or a merge commit in the range stops the reconcile with one `hive:signed-commits-blocked` comment. See [github-app-setup.md](../github-app-setup.md#signed-commits-on-agent-prs-app_signed_commits). | | `governor.logging.kick_log_source` | `scrollback`. Also `transcript` or `auto`; unknown values mean `scrollback`. `HIVE_KICK_LOG_SOURCE` (when set to a valid value) wins over this key. | What per-kick logs (archives and the live full log) are built from: the tmux scrollback, the backend CLI's own transcript (Copilot CLI, Claude Code), or the transcript when a reader exists else the scrollback. Editable under **Settings → Logging → Kick log source**; applies to the next kick without a restart, and each log's header `source:` line (and the kick history page) shows which was used. See [agent-logging.md](../agent-logging.md#per-kick-log-history). | | `governor.logging.read_scan_max_mb` | Unset: `64` MiB per read. | Lowers how many megabytes of log (counting decompressed bytes of compressed history) one `GET /api/logs/read` / admin MCP `log_read` call may scan; it can only lower the built-in 64 MiB bound, never raise it. A read that reaches the bound stops early, says so in `coverage` (`complete: false`, `stopped_reason`) and returns a `next_cursor` that resumes where it stopped. See [design/admin-mcp.md](../design/admin-mcp.md#log-read). | | `governor.labels.automerge` | Defaults to `lgtm`. | Label applied when a merger/owner queues a PR for Hive auto-merge-on-green. With Prow's commit binding (prow-github-actions v3), Hive binds `lgtm` by also setting the `prow/lgtm` commit status (needs the App's `statuses: write` permission); alternatively choose a distinct label such as `hive/auto-merge`. Distinct from the [App self-merge sweep](#app-self-merge-sweep-auto_merge), which needs no label and no human queuer. | diff --git a/src/docs/running-at-level-6.md b/src/docs/running-at-level-6.md index 3eb879cb7f..6c719e8473 100644 --- a/src/docs/running-at-level-6.md +++ b/src/docs/running-at-level-6.md @@ -174,7 +174,7 @@ For hosted and self-hosted hives alike, GitHub repository/organization administr | **G5. Require an up-to-date base.** Enable strict required checks/"Require branches to be up to date before merging" on each protected branch. | Green on an older base does not establish green after integration. Verify a PR becomes blocked after a base push until updated/retested. The sweep attempts updates for `behind`; see [sweep](../pkg/github/automerge/automerge_sweep.go). On a personal-account repository without GitHub's merge queue, `merge_strategy: hive-serialized` serializes merges per branch; keep this rule on there too — the lane panel shows "server-enforced" when it is, and without it a one-API-call window remains that Hive only detects and alerts on after the merge. The rule costs one CI run per merge, since the lane updates only the front pull request. The lane panel shows no enforcement badge (server-enforced / Hive-checked / unknown) until a PR has entered the lane, so before the first merge confirm the up-to-date rule in the ruleset itself (Settings → Rules → Rulesets). If you keep the ruleset as code (for example `.github/rulesets/*.json` plus a note that the live rules match the file), update that file whenever you change the live ruleset here. See [merge strategy](operator-reference.md#per-repo-merge-strategy-merge_strategy). | | **G6. Allow the merge methods actually used.** Settings → General → Pull Requests: allow squash; also allow merge commits if managing release-line forward merges. | The ordinary method is squash; recognized forward merges use merge commits to preserve ancestry. Disallowed methods cause merge refusals. Verify landing method in a test PR and ancestry for a sync PR. See `mergeMethodFor` in [sweep](../pkg/github/automerge/automerge_sweep.go) and [pull requests](../pkg/github/pullrequest.go). | | **G7. Keep fork-run approval deliberate.** Settings → Actions → General → Approval for running fork pull request workflows: choose the trust policy your maintainers can service. **JUDGMENT CALL:** require approval for untrusted fork authors rather than relaxing it to drain a queue. | Unapproved runs are `action_required`, not successful CI. Have a maintainer inspect the workflow/diff then approve runs; verify check evidence appears at the PR head. See `forkRunApprovalReason` in [CI gate](../pkg/github/merge_ci_gate.go). | -| **G8. Test signed-commit requirements end to end.** If your ruleset requires signatures, enable `github.app_signed_commits` in Hive runtime YAML (not a dashboard switch) and test follow-up commits too. | An unsigned follow-up can strand an otherwise green PR. Hive reconciles its own commits, not people's work. Verify GitHub's Verified badge at the latest head and branch-rule acceptance. See [signed reconciliation](../pkg/github/pr_signed_reconcile.go). | +| **G8. Test signed-commit requirements end to end.** If your ruleset requires signatures, enable `github.app_signed_commits` (Settings → Forge App → **Re-author agent PRs as GitHub-signed commits**, Owner role; or in Hive runtime YAML) and test follow-up commits too. | An unsigned follow-up can strand an otherwise green PR. Hive reconciles its own commits, not people's work. Verify GitHub's Verified badge at the latest head and branch-rule acceptance. See [signed reconciliation](../pkg/github/pr_signed_reconcile.go). | ### Test coverage of 90% or better diff --git a/src/pkg/dashboard/static-src/html/topbar.html b/src/pkg/dashboard/static-src/html/topbar.html index 579f6885af..968ccaffd2 100644 --- a/src/pkg/dashboard/static-src/html/topbar.html +++ b/src/pkg/dashboard/static-src/html/topbar.html @@ -1,9 +1,9 @@
- + title="Open navigation">Navigation diff --git a/src/pkg/dashboard/static-src/js/chat.js b/src/pkg/dashboard/static-src/js/chat.js index d625115364..8dc10e77b0 100644 --- a/src/pkg/dashboard/static-src/js/chat.js +++ b/src/pkg/dashboard/static-src/js/chat.js @@ -572,7 +572,8 @@ sidebar.classList.toggle('open', open); backdrop.classList.toggle('open', open); toggle.setAttribute('aria-expanded', open ? 'true' : 'false'); - toggle.setAttribute('aria-label', open ? 'Close menu' : 'Open menu'); + toggle.setAttribute('aria-label', open ? 'Close navigation' : 'Open navigation'); + toggle.title = open ? 'Close navigation' : 'Open navigation'; } function closeDrawer() { if (isOpen()) setOpen(false); } diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index ca979f1c1a..65454948af 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -8274,9 +8274,9 @@

🐝 Getting Started
- + title="Open navigation">Navigation @@ -70946,7 +70946,8 @@

${model.editIndex === null ? 'Add Event trigger' : 'Edit Event trigger'}

1 { @@ -71,12 +79,12 @@ func dcoCommitStatsForSquashAuthor(commits []*gh.RepositoryCommit, appLogin, prA msg := rc.GetCommit().GetMessage() if !signedOffByRE.MatchString(msg) { stats.unsigned++ - if dcoCommitByHive(rc, appLogin) { + if dcoCommitOwnedByHive(rc, appLogin, isHive) { stats.unsignedHive++ } else { stats.unsignedOther++ } - } else if !selfSquash && dcoCommitByHive(rc, appLogin) && !messageHasPRAuthorSignoff(msg, prAuthor) { + } else if !selfSquash && dcoCommitOwnedByHive(rc, appLogin, isHive) && !messageHasPRAuthorSignoff(msg, prAuthor) { stats.squashUnsafeHive++ } } @@ -92,6 +100,34 @@ func dcoCommitByHive(commit *gh.RepositoryCommit, appLogin string) bool { return commitByApp(commit, appLogin) } +// dcoCommitOwnedByHive is dcoCommitByHive that also counts a commit GitHub +// links (by author login) to one of the hive's own identities (isHive: +// project.ai_author, the login the hive's agents push as). Only GitHub's +// linkage counts here too, never the git author name, so a collaborator's +// unsigned commit under their own email stays "other" and is never signed by +// the App (hivecommons/hive#16685). +// +// Trust assumption (hivecommons/hive#16702): GitHub derives the login from +// the git author email and the hive's agents push plain, unsigned git +// commits (app_signed_commits re-authors only the PR's opening head), so +// neither Commit.Verification nor the committer can tell an agent's commit +// from one a pusher authored with project.ai_author's email. Requiring +// either would stop the hive re-signing its own fix commits. The in-place +// path that acts on this split needs a base-repo head the App can push +// (adoptionDCORepairMode), so only collaborators with push access can +// present such a commit, and they are trusted not to. commitByApp has the +// same property for the App bot login. +func dcoCommitOwnedByHive(commit *gh.RepositoryCommit, appLogin string, isHive func(login string) bool) bool { + if dcoCommitByHive(commit, appLogin) { + return true + } + if commit == nil || isHive == nil { + return false + } + login := strings.TrimSpace(commit.GetAuthor().GetLogin()) + return login != "" && isHive(login) +} + // stageDCO returns the commit check for the observation's head, reading the // commits only when the store has no result for this head (the caller // caches the result, including how many unsigned commits are the App's own, @@ -104,7 +140,10 @@ func (c *Engine) stageDCO(ctx context.Context, store *stagelabels.Store, key str } appLogin := c.transport.AppBotLogin() selfSquash := botSquashAuthor(obs.Author) || hiveAuthoredPR(obs, policy, appLogin) - if rec, ok := store.Get(key); ok { + // A split cached before hive identities counted (hivecommons/hive#16701) filed + // project.ai_author commits as "other"; read the commits once more so + // a hive-authored head is re-signed rather than left waiting. + if rec, ok := store.Get(key); ok && (policy.HiveAuthor == nil || rec.DCOSplitHiveIdentity) { if t, u, cached := rec.DCOFor(obs.HeadSHA); cached { // Records cached before the ownership split existed carry // none; an in-place adoption decides repair-vs-rehome on it, @@ -123,7 +162,7 @@ func (c *Engine) stageDCO(ctx context.Context, store *stagelabels.Store, key str if err != nil { return dcoStats{}, err } - return dcoCommitStatsForSquashAuthor(all, appLogin, obs.Author, selfSquash), nil + return dcoCommitStatsForHive(all, appLogin, obs.Author, selfSquash, policy.HiveAuthor), nil } // hiveAuthoredPR reports whether the PR is the hive's own: author/hive by diff --git a/src/pkg/github/automerge/automerge_stage_labels.go b/src/pkg/github/automerge/automerge_stage_labels.go index e53d3a1cae..486bba1560 100644 --- a/src/pkg/github/automerge/automerge_stage_labels.go +++ b/src/pkg/github/automerge/automerge_stage_labels.go @@ -1308,7 +1308,7 @@ func (c *Engine) ApplyStageLabels(ctx context.Context) (StageLabelResult, error) soakFirstGreen, _ := c.contributorSoak.FirstGreen(obs.Owner, obs.Repo, obs.Number, obs.HeadSHA) noteSoak(store, key, obs.Reason, obs.HeadSHA, pass.Route, c.currentContributorLanePolicy().Soak, soakFirstGreen, now) if dcoRead { - store.NoteDCO(key, obs.HeadSHA, obs.Detail.DCOTotal, obs.Detail.DCOUnsigned, obs.Detail.DCOUnsignedHive, obs.Detail.DCOSquashUnsafeHive) + store.NoteDCO(key, obs.HeadSHA, obs.Detail.DCOTotal, obs.Detail.DCOUnsigned, obs.Detail.DCOUnsignedHive, obs.Detail.DCOSquashUnsafeHive, policy.HiveAuthor != nil) } if verdict.Stage != stagelabels.ReturnedToContributor && verdict.Stage != stagelabels.NeedsAuthor { c.resolveNudge(ctx, prevRec, hadPrev, obs) diff --git a/src/pkg/github/automerge/automerge_stage_labels_test.go b/src/pkg/github/automerge/automerge_stage_labels_test.go index b3c34ac9fa..ee4c870ba9 100644 --- a/src/pkg/github/automerge/automerge_stage_labels_test.go +++ b/src/pkg/github/automerge/automerge_stage_labels_test.go @@ -8,6 +8,7 @@ import ( "log/slog" "net/http" "net/http/httptest" + "os" "path/filepath" "reflect" "slices" @@ -2450,6 +2451,87 @@ func TestDCOCommitStatsSkipsMerges(t *testing.T) { } } +// hivecommons/hive#16685: an unsigned commit GitHub links to one of the +// hive's identities (project.ai_author) is the hive's to sign; a +// collaborator's unsigned commit is not, whatever its git author name says. +func TestDCOCommitStatsForHiveCountsHiveIdentities(t *testing.T) { + commits := []*gh.RepositoryCommit{ + {Author: &gh.User{Login: gh.Ptr("thatguywob")}, Commit: &gh.Commit{Message: gh.Ptr("hive fix")}, Parents: []*gh.Commit{{}}}, + {Author: &gh.User{Login: gh.Ptr("collaborator")}, Commit: &gh.Commit{Message: gh.Ptr("drive-by"), Author: &gh.CommitAuthor{Name: gh.Ptr("thatguywob")}}, Parents: []*gh.Commit{{}}}, + {Author: &gh.User{Login: gh.Ptr(testHiveAppBotLogin)}, Commit: &gh.Commit{Message: gh.Ptr("app fix")}, Parents: []*gh.Commit{{}}}, + } + isHive := func(login string) bool { return strings.EqualFold(login, "thatguywob") } + stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "thatguywob", true, isHive) + if stats.unsigned != 3 || stats.unsignedHive != 2 || stats.unsignedOther != 1 { + t.Fatalf("with hive identities: %+v, want unsigned=3 hive=2 other=1", stats) + } + stats = dcoCommitStatsForHive(commits, testHiveAppBotLogin, "thatguywob", true, nil) + if stats.unsigned != 3 || stats.unsignedHive != 1 || stats.unsignedOther != 2 { + t.Fatalf("nil predicate: %+v, want unsigned=3 hive=1 other=2", stats) + } + if old := dcoCommitStatsForSquashAuthor(commits, testHiveAppBotLogin, "thatguywob", true); old != stats { + t.Fatalf("dcoCommitStatsForSquashAuthor=%+v, want App-only split %+v", old, stats) + } +} + +// hivecommons/hive#16703: the squash-unsafe count uses the same ownership +// rule as the unsigned split, so a signed commit GitHub links to a hive +// identity is the hive's to misattribute on a PR a squash would credit to +// someone else. +func TestDCOCommitStatsForHiveSquashUnsafeCountsHiveIdentities(t *testing.T) { + commits := []*gh.RepositoryCommit{ + {Author: &gh.User{Login: gh.Ptr("thatguywob")}, Commit: &gh.Commit{Message: gh.Ptr("hive fix\n\nSigned-off-by: Hive ")}, Parents: []*gh.Commit{{}}}, + {Author: &gh.User{Login: gh.Ptr("collaborator")}, Commit: &gh.Commit{Message: gh.Ptr("drive-by\n\nSigned-off-by: C ")}, Parents: []*gh.Commit{{}}}, + } + isHive := func(login string) bool { return strings.EqualFold(login, "thatguywob") } + if stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "person", false, isHive); stats.unsigned != 0 || stats.squashUnsafeHive != 1 { + t.Fatalf("with hive identities: %+v, want squashUnsafeHive=1", stats) + } + if stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "person", true, isHive); stats.squashUnsafeHive != 0 { + t.Fatalf("self squash: %+v, want squashUnsafeHive=0", stats) + } + if stats := dcoCommitStatsForHive(commits, testHiveAppBotLogin, "person", false, nil); stats.squashUnsafeHive != 0 { + t.Fatalf("nil predicate: %+v, want App-only squashUnsafeHive=0", stats) + } +} + +// hivecommons/hive#16701: a split cached before hive identities counted filed +// a project.ai_author commit as "other"; stageDCO reads that head's commits +// once more so the hive's own commit can be re-signed, then trusts the +// refreshed cache. +func TestStageDCORereadsSplitCachedBeforeHiveIdentities(t *testing.T) { + api := &stageAPI{labels: map[string]string{}, commitDetails: map[int][]stageCommitFixture{ + 42: {{message: "hive fix", authorLogin: "thatguywob"}}, + }} + srv := newStageAPI(t, api) + defer srv.Close() + e, _, _ := newStageEngine(t, srv.URL, &contributorLaneClock{at: time.Now()}) + key := stageKey("acme", "widget", 42) + path := filepath.Join(t.TempDir(), "legacy.json") + data, err := json.Marshal(map[string]stagelabels.Record{key: {DCOHead: "aaa", DCOTotal: 1, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true}}) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, data, 0o644); err != nil { + t.Fatal(err) + } + store := stagelabels.NewStore(path, nil) + if err := store.Load(); err != nil { + t.Fatal(err) + } + policy := StageLabelPolicy{HiveAuthor: func(login string) bool { return strings.EqualFold(login, "thatguywob") }} + obs := stageObservation{Owner: "acme", Repo: "widget", Number: 42, HeadSHA: "aaa", Author: "thatguywob"} + got, err := e.stageDCO(context.Background(), store, key, obs, policy) + if err != nil || got.unsigned != 1 || got.unsignedHive != 1 || got.unsignedOther != 0 || api.commitReads != 1 { + t.Fatalf("legacy split: %+v, %v, reads=%d; want hive=1 other=0 after one read", got, err, api.commitReads) + } + store.NoteDCO(key, obs.HeadSHA, got.total, got.unsigned, got.unsignedHive, got.squashUnsafeHive, true) + got, err = e.stageDCO(context.Background(), store, key, obs, policy) + if err != nil || got.unsignedHive != 1 || got.unsignedOther != 0 || api.commitReads != 1 { + t.Fatalf("refreshed split: %+v, %v, reads=%d; want the cache served", got, err, api.commitReads) + } +} + // hivecommons/hive#12557: a gate flapping between merge-queue and a pending // stage on one unchanged head used to post a stage-regressed comment every // sweep, because each recover re-armed the dedupe. One comment per head. diff --git a/src/pkg/github/automerge/shared_ci_attribution_test.go b/src/pkg/github/automerge/shared_ci_attribution_test.go index 1e20a6a6d3..0716ff0aee 100644 --- a/src/pkg/github/automerge/shared_ci_attribution_test.go +++ b/src/pkg/github/automerge/shared_ci_attribution_test.go @@ -42,7 +42,7 @@ func TestStageDCONormalizesCachedBotAttributionWithoutChangingSignoffs(t *testin e, _, store := newStageEngine(t, srv.URL, &contributorLaneClock{at: time.Now()}) key := stageKey("acme", "widget", 42) store.Observe(key, stagelabels.Fixing, stagelabels.LaneReasonHiveSignoffAttribution) - store.NoteDCO(key, "aaa", 3, 0, 0, 1) + store.NoteDCO(key, "aaa", 3, 0, 0, 1, true) got, err := e.stageDCO(context.Background(), store, key, stageObservation{ Owner: "acme", Repo: "widget", Number: 42, HeadSHA: "aaa", Author: "dependabot[bot]", }, StageLabelPolicy{}) diff --git a/src/pkg/github/webhook_ci_evidence_test.go b/src/pkg/github/webhook_ci_evidence_test.go index acd2b946ee..d36229b62f 100644 --- a/src/pkg/github/webhook_ci_evidence_test.go +++ b/src/pkg/github/webhook_ci_evidence_test.go @@ -221,6 +221,12 @@ func TestWebhookCIRefetchListsHeadOnceAndRecordsListing(t *testing.T) { t.Cleanup(resetPRDetailCacheForTest(clock.Now, 0)) t.Cleanup(resetWebhookTrackerForTest(clock.Now)) t.Cleanup(ResetCIEvidenceForTest(clock.Now)) + // refetchHeadCI refuses to list while the process-wide REST budget is + // critical or the pacing window is engaged; isolate both from whatever + // earlier tests left behind. + resetRESTAccountingForTest(t, clock.now) + ResetRateLimitPacingForTest() + t.Cleanup(ResetRateLimitPacingForTest) listings := 0 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/repos/org/repo/commits/sha-9/check-runs" { diff --git a/src/pkg/stagelabels/stagelabels_test.go b/src/pkg/stagelabels/stagelabels_test.go index 7af7ea3037..4dfc923447 100644 --- a/src/pkg/stagelabels/stagelabels_test.go +++ b/src/pkg/stagelabels/stagelabels_test.go @@ -998,18 +998,18 @@ func TestStoreNoteDCOSplitAndAdoptReason(t *testing.T) { now := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC) s := NewStore("", func() time.Time { return now }) key := Key("acme/widget", 7) - s.NoteDCO(key, "a", 3, 2, 1, 0) + s.NoteDCO(key, "a", 3, 2, 1, 0, true) s.NoteAdoptReason(key, "dco-rehome") if _, ok := s.Get(key); ok { t.Fatal("NoteDCO/NoteAdoptReason created a record") } s.Observe(key, ReturnedToContributor, "check-failing:dco") - s.NoteDCO(key, "a", 3, 2, 1, 0) + s.NoteDCO(key, "a", 3, 2, 1, 0, true) r, _ := s.Get(key) if t0, u, ok := r.DCOFor("a"); !ok || t0 != 3 || u != 2 || r.DCOUnsignedHive != 1 || r.DCOUnsignedOther != 1 || !r.DCOSplitKnown("a") || r.DCOSplitKnown("b") { t.Fatalf("cached split: %+v", r) } - s.NoteDCO(key, "a", 3, 2, 2, 0) + s.NoteDCO(key, "a", 3, 2, 2, 0, true) if r, _ = s.Get(key); r.DCOUnsignedHive != 2 || r.DCOUnsignedOther != 0 || !r.DCOSplitKnown("a") { t.Fatalf("hive share not updated: %+v", r) } @@ -1027,6 +1027,51 @@ func TestStoreNoteDCOSplitAndAdoptReason(t *testing.T) { } } +// hivecommons/hive#16701: NoteDCO marks the split as computed with hive +// identities, including on a legacy record whose counts are unchanged. +func TestStoreNoteDCOMarksHiveIdentitySplit(t *testing.T) { + s := NewStore("", nil) + key := Key("acme/widget", 8) + s.items[key] = Record{DCOHead: "a", DCOTotal: 2, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true} + s.NoteDCO(key, "a", 2, 1, 0, 0, true) + if r, _ := s.Get(key); !r.DCOSplitHiveIdentity || r.DCOUnsignedOther != 1 { + t.Fatalf("legacy record not marked: %+v", r) + } +} + +// hivecommons/hive#16707: an App-only split (no hive identity configured) +// must not be marked, so configuring one later triggers the re-read. +func TestStoreNoteDCOAppOnlySplitNotMarked(t *testing.T) { + s := NewStore("", nil) + key := Key("acme/widget", 9) + s.items[key] = Record{DCOHead: "a", DCOTotal: 2, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true} + s.NoteDCO(key, "a", 2, 1, 1, 0, false) + if r, _ := s.Get(key); r.DCOSplitHiveIdentity || r.DCOUnsignedHive != 1 { + t.Fatalf("app-only split marked or not stored: %+v", r) + } + s.NoteDCO(key, "a", 2, 1, 1, 0, true) + if r, _ := s.Get(key); !r.DCOSplitHiveIdentity { + t.Fatalf("hive-identity split not marked: %+v", r) + } +} + +// hivecommons/hive#16710: a new head cached App-only must clear a stale +// hive-identity marker; a same-head App-only refresh must keep it. +func TestStoreNoteDCONewHeadClearsHiveIdentityMarker(t *testing.T) { + s := NewStore("", nil) + key := Key("acme/widget", 10) + s.items[key] = Record{DCOHead: "a", DCOTotal: 2, DCOUnsigned: 1, DCOUnsignedOther: 1, DCOSquashUnsafeKnown: true} + s.NoteDCO(key, "a", 2, 1, 0, 0, true) + s.NoteDCO(key, "a", 2, 1, 0, 0, false) + if r, _ := s.Get(key); !r.DCOSplitHiveIdentity { + t.Fatalf("same-head App-only refresh cleared the marker: %+v", r) + } + s.NoteDCO(key, "b", 2, 1, 1, 0, false) + if r, _ := s.Get(key); r.DCOSplitHiveIdentity || r.DCOHead != "b" { + t.Fatalf("stale marker survived a new App-only head: %+v", r) + } +} + func TestStoreAdoptInPlaceAndYield(t *testing.T) { now := time.Date(2026, 10, 16, 12, 0, 0, 0, time.UTC) s := NewStore("", func() time.Time { return now }) diff --git a/src/pkg/stagelabels/store.go b/src/pkg/stagelabels/store.go index 4b6ed68b08..ad009fc857 100644 --- a/src/pkg/stagelabels/store.go +++ b/src/pkg/stagelabels/store.go @@ -159,6 +159,10 @@ type Record struct { DCOUnsignedOther int `json:"dco_unsigned_other,omitempty"` DCOSquashUnsafeHive int `json:"dco_squash_unsafe_hive,omitempty"` DCOSquashUnsafeKnown bool `json:"dco_squash_unsafe_known,omitempty"` + // DCOSplitHiveIdentity marks a split computed with the hive's own + // identities (project.ai_author) counted as the hive's; records cached + // before that (hivecommons/hive#16701) lack it and are read again once. + DCOSplitHiveIdentity bool `json:"dco_split_hive_identity,omitempty"` // EntryCommented records that the stage's entry comment (085 "needs a // decision", 090 "ready for a human merge") was posted for the current // stage visit; reset on every stage change so each transition explains @@ -2617,9 +2621,11 @@ func (s *Store) NoteHold(key string, hold *HoldProvenance) { func (s *Store) ClearHold(key string) { s.NoteHold(key, nil) } // NoteDCO caches the commit check for head on an existing record: -// unsignedHive is the App-linked share of the unsigned commits, the rest -// is recorded as other. -func (s *Store) NoteDCO(key, head string, total, unsigned, unsignedHive, squashUnsafeHive int) { +// unsignedHive is the hive's share of the unsigned commits (App bot or a +// hive identity), the rest is recorded as other. hiveIdentity says the split +// was computed with a hive identity configured; an App-only split leaves the +// marker unset so configuring one later triggers the one-time re-read. +func (s *Store) NoteDCO(key, head string, total, unsigned, unsignedHive, squashUnsafeHive int, hiveIdentity bool) { if head == "" { return } @@ -2629,11 +2635,15 @@ func (s *Store) NoteDCO(key, head string, total, unsigned, unsignedHive, squashU s.mu.Lock() defer s.mu.Unlock() r, ok := s.items[key] - if !ok || (r.DCOHead == head && r.DCOTotal == total && r.DCOUnsigned == unsigned && r.DCOUnsignedHive == unsignedHive && r.DCOUnsignedOther == other && r.DCOSquashUnsafeHive == squashUnsafeHive && r.DCOSquashUnsafeKnown) { + if !ok || (r.DCOHead == head && r.DCOTotal == total && r.DCOUnsigned == unsigned && r.DCOUnsignedHive == unsignedHive && r.DCOUnsignedOther == other && r.DCOSquashUnsafeHive == squashUnsafeHive && r.DCOSquashUnsafeKnown && (r.DCOSplitHiveIdentity || !hiveIdentity)) { return } + headChanged := r.DCOHead != head r.DCOHead, r.DCOTotal, r.DCOUnsigned, r.DCOUnsignedHive, r.DCOUnsignedOther, r.DCOSquashUnsafeHive = head, total, unsigned, unsignedHive, other, squashUnsafeHive r.DCOSquashUnsafeKnown = true + if headChanged || hiveIdentity { + r.DCOSplitHiveIdentity = hiveIdentity + } s.items[key] = r s.dirty = true }