From 9c0ea938b8c4c2ae85360b45f2aa3e3dabc4c4b5 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sun, 22 Nov 2026 02:09:32 +1100 Subject: [PATCH] fix(chat): canonicalise a held action's stored input before comparing it (#2072, #2096) The binding is read back from a jsonb column with a space after every colon, so an unchanged approved action failed the byte comparison and never ran. --- modules/chat/binding.go | 3 +++ modules/chat/binding_test.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/modules/chat/binding.go b/modules/chat/binding.go index d48412f6c..c7585bc8e 100644 --- a/modules/chat/binding.go +++ b/modules/chat/binding.go @@ -158,6 +158,9 @@ func recorded(a store.Action) (Binding, string) { if sum, err := stored.Digest(); err != nil || sum != a.BindingDigest { return Binding{}, "its binding is incomplete or was altered" } + // The binding comes back from a jsonb column reformatted, so its input is + // canonicalised again before it is compared byte for byte. + stored.Input = connectors.Canonical(stored.Input) return stored, "" } diff --git a/modules/chat/binding_test.go b/modules/chat/binding_test.go index b1c72c684..8b648282c 100644 --- a/modules/chat/binding_test.go +++ b/modules/chat/binding_test.go @@ -6,6 +6,7 @@ import ( "encoding/json/jsontext" "errors" "log/slog" + "slices" "strings" "testing" "time" @@ -236,6 +237,16 @@ func newApprovalFixture(t *testing.T) *approvalFixture { return f } +// reformatted returns raw with the whitespace jsonb puts back on output. +func reformatted(t *testing.T, raw []byte) []byte { + t.Helper() + v := jsontext.Value(slices.Clone(raw)) + if err := v.Indent(jsontext.WithIndent(" ")); err != nil { + t.Fatal(err) + } + return v +} + // TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce guards the dispatch-time // recheck: an approval is discarded, and nothing runs, when the owner has lost // access, when the target, effect, arguments or approvers changed, when the @@ -249,6 +260,16 @@ func TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce(t *testing.T) { wantDiscard string }{ {name: "an action that still matches runs", wantRuns: 1}, + { + // Postgres stores both columns as jsonb and hands them back + // reformatted, with a space after every colon. + name: "an action read back from jsonb still runs", + change: func(f *approvalFixture) { + f.action.Binding = reformatted(t, f.action.Binding) + f.action.Decision = reformatted(t, f.action.Decision) + }, + wantRuns: 1, + }, { name: "the owner's access revoked while pending", change: func(f *approvalFixture) { f.d.People = fakePeople{alice: person(alice, governance.RoleViewer)} },