From 7fd393492d73937cb5d1adee410ff5a02a3c3f84 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 12:48:38 +1000 Subject: [PATCH 1/2] fix(curator): populate PassInput.Since with the prior pass time WIRE: docs/prds/session-memory-curator.md specifies that each pass finds "sessions with activity since the last pass", and its effectiveSince rule treats a zero Since as "the runtime declining to name a horizon" (24h fallback for the first pass). The runtime is the only production constructor of PassInput and already carries lastPass, so it must name the horizon at the producer by setting Since to the prior pass time. Previously Since was never set, so the session curator fell back to now-24h on every pass and re-read the same window each chat turn. --- internal/domain/curator/runtime.go | 2 +- internal/domain/curator/runtime_test.go | 35 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/internal/domain/curator/runtime.go b/internal/domain/curator/runtime.go index f30f94640..13940afdf 100644 --- a/internal/domain/curator/runtime.go +++ b/internal/domain/curator/runtime.go @@ -214,7 +214,7 @@ func (rt *Runtime) runLoop(ctx context.Context, name string, c CuratorEngine) { return // shutting down while waiting for a pass slot } passCtx, cancel := context.WithTimeout(ctx, rt.cfg.PassTimeout) - result, perr := rt.safePass(passCtx, c, PassInput{Reason: reason, LastPass: lastPass}) + result, perr := rt.safePass(passCtx, c, PassInput{Reason: reason, Since: lastPass, LastPass: lastPass}) cancel() rt.release() diff --git a/internal/domain/curator/runtime_test.go b/internal/domain/curator/runtime_test.go index dbb914884..79b09b88d 100644 --- a/internal/domain/curator/runtime_test.go +++ b/internal/domain/curator/runtime_test.go @@ -453,3 +453,38 @@ func TestRuntimePassInputRecordsReasonAndLastPass(t *testing.T) { t.Error("second pass LastPass is zero; want the previous pass time") } } + +func TestRuntimePassInputSetsSinceToPriorPass(t *testing.T) { + t.Parallel() + + clock := newFakeClock(time.Unix(0, 0)) + c := newFake("c", Manifest{Interval: testInterval, OnInput: true}) + c.checkResult = true + _, rt, _ := newRuntimeTestEnv(t, clock, RuntimeConfig{}, c) + + if err := rt.Start(context.Background()); err != nil { + t.Fatalf("Start() = %v, want nil", err) + } + t.Cleanup(func() { _ = rt.Stop(context.Background()) }) + + waitFor(t, 2*time.Second, "first pass", func() bool { return c.passCalls.Load() == 1 }) + + rt.Nudge("c") + waitFor(t, 2*time.Second, "nudged pass", func() bool { return c.passCalls.Load() == 2 }) + + c.inputMu.Lock() + inputs := slices.Clone(c.inputs) + c.inputMu.Unlock() + if len(inputs) != 2 { + t.Fatalf("pass inputs = %d, want 2", len(inputs)) + } + if !inputs[0].Since.IsZero() { + t.Errorf("first pass Since = %v, want zero so the curator applies its own first-pass lookback", inputs[0].Since) + } + if inputs[1].Since.IsZero() { + t.Error("second pass Since is zero; want the previous pass time so a pass reads only activity since the last pass") + } + if !inputs[1].Since.Equal(inputs[1].LastPass) { + t.Errorf("second pass Since = %v, want %v (the previous pass time also carried in LastPass)", inputs[1].Since, inputs[1].LastPass) + } +} From 42adee2f87e717e5ed785fdddbee5944a70599f9 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Tue, 15 Sep 2026 12:50:57 +1000 Subject: [PATCH 2/2] fix(staterpc): preserve marshal_error marker in eventDataJSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WIRE: docs/prds/state-store-contract.md §11 requires the remote wire and the local adapter to behave identically. The local adapter (internal/store/events.go) records a {"marshal_error":%q} marker when json.Marshal of event Data fails, while eventDataJSON silently returned "" on the same failure, emptying the event's Data on the wire. Carry the same marker so an unmarshalable Data value survives the hop with the local adapter's fidelity. --- internal/infrastructure/staterpc/values.go | 2 +- .../infrastructure/staterpc/values_test.go | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 internal/infrastructure/staterpc/values_test.go diff --git a/internal/infrastructure/staterpc/values.go b/internal/infrastructure/staterpc/values.go index 6c3fa3332..3573f98fd 100644 --- a/internal/infrastructure/staterpc/values.go +++ b/internal/infrastructure/staterpc/values.go @@ -84,7 +84,7 @@ func eventDataJSON(data map[string]any) string { } b, err := json.Marshal(data) if err != nil { - return "" + return fmt.Sprintf(`{"marshal_error":%q}`, err.Error()) } return string(b) } diff --git a/internal/infrastructure/staterpc/values_test.go b/internal/infrastructure/staterpc/values_test.go new file mode 100644 index 000000000..8d06c201d --- /dev/null +++ b/internal/infrastructure/staterpc/values_test.go @@ -0,0 +1,38 @@ +package staterpc + +import ( + "encoding/json" + "fmt" + "testing" +) + +// TestEventDataJSONPreservesMarshalErrorMarker pins §11's conformance +// invariant: the local store (internal/store/events.go) records a +// {"marshal_error":%q} marker when json.Marshal of event Data fails, so the +// remote wire must carry the same marker rather than silently emptying the +// Data on the hop. +func TestEventDataJSONPreservesMarshalErrorMarker(t *testing.T) { + data := map[string]any{"channel": make(chan int)} + + got := eventDataJSON(data) + if got == "" { + t.Fatal(`eventDataJSON = "", want the local adapter's marshal_error marker`) + } + + _, err := json.Marshal(data) + if err == nil { + t.Fatal("test input must fail json.Marshal") + } + want := fmt.Sprintf(`{"marshal_error":%q}`, err.Error()) + if got != want { + t.Fatalf("eventDataJSON = %q, want %q (local-adapter fidelity)", got, want) + } + + // The server side rehydrates the marker back into a Data map, exactly + // as the local store's scanEvents rehydrates its on-disk column. + round := eventDataValue(got) + message, ok := round["marshal_error"].(string) + if !ok || message == "" { + t.Fatalf("eventDataValue = %#v, want a non-empty marshal_error string", round) + } +}