From 43556e1603e87a6f05b6679261787743f9092192 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sat, 29 Aug 2026 12:00:04 +0300 Subject: [PATCH] GEN2-026: route household context through scoped Gen2 projection --- cmd/core-runtime/main.go | 2 +- dev/ACTIVE_TASK.json | 2 +- modules/interaction/domain/gen2_context.go | 17 +++++++++++++++++ modules/interaction/domain/gen2_context_test.go | 11 +++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cmd/core-runtime/main.go b/cmd/core-runtime/main.go index 034d962..4b0921e 100644 --- a/cmd/core-runtime/main.go +++ b/cmd/core-runtime/main.go @@ -533,7 +533,7 @@ func main() { log.Printf("interaction principal history loaded: %d utterances", len(recentUserHistory)) } conversationHistory = append(conversationHistory, recentUserHistory...) - gen2Context := interactiondomain.BuildGen2Context(conversationHistory) + gen2Context := interactiondomain.BuildScopedGen2Context(conversationHistory, string(session.PrincipalID)) if !creativeUserRequest && locationReply == "" { if continuation := interactiondomain.ContinueLocalSearch(effectiveTaskMessage, conversationHistory); continuation != "" { continuationMessage = continuation diff --git a/dev/ACTIVE_TASK.json b/dev/ACTIVE_TASK.json index 461db90..3fcf21f 100644 --- a/dev/ACTIVE_TASK.json +++ b/dev/ACTIVE_TASK.json @@ -1 +1 @@ -{"task_file":"dev/tasks/GEN2-025-multimodal-and-ambient-ingress-readiness-without-implementing-the-whole-.json","task_id":"GEN2-025","task_revision":1} +{"task_file":"dev/tasks/GEN2-026-migrate-household-behavior-to-gen2-context-memory-skills-with-local-degr.json","task_id":"GEN2-026","task_revision":1} diff --git a/modules/interaction/domain/gen2_context.go b/modules/interaction/domain/gen2_context.go index 4067750..21a6e50 100644 --- a/modules/interaction/domain/gen2_context.go +++ b/modules/interaction/domain/gen2_context.go @@ -11,6 +11,23 @@ type ContextProjection struct { // BuildGen2Context is a read-side projection over canonical utterance history. // PersonalMemory remains a compatibility fallback and is never written here. func BuildGen2Context(history []interaction.HumanUtterance) ContextProjection { + return BuildScopedGen2Context(history, "") +} + +// BuildScopedGen2Context is the Gen2 retrieval boundary for household +// context. The caller supplies already-authorized history; this defensive +// filter prevents accidental cross-principal projection when a mixed source +// is passed during degraded operation. +func BuildScopedGen2Context(history []interaction.HumanUtterance, principalID string) ContextProjection { + if principalID != "" { + scoped := make([]interaction.HumanUtterance, 0, len(history)) + for _, item := range history { + if item.PrincipalID == "" || string(item.PrincipalID) == principalID { + scoped = append(scoped, item) + } + } + history = scoped + } text := CompilePersonalMemory(history).ContextText() if text != "" { return ContextProjection{Text: text, Source: "retrieval:interaction-utterances"} diff --git a/modules/interaction/domain/gen2_context_test.go b/modules/interaction/domain/gen2_context_test.go index 1806281..0d37bf5 100644 --- a/modules/interaction/domain/gen2_context_test.go +++ b/modules/interaction/domain/gen2_context_test.go @@ -3,6 +3,7 @@ package domain_test import ( "git.cin.su/m/Assistant/contracts/interaction" "git.cin.su/m/Assistant/modules/interaction/domain" + "strings" "testing" ) @@ -16,3 +17,13 @@ func TestGen2ContextUsesRetrievalProjectionAndKeepsV1Fallback(t *testing.T) { t.Fatalf("fallback missing: %#v", empty) } } + +func TestGen2ContextDoesNotProjectAnotherPrincipal(t *testing.T) { + got := domain.BuildScopedGen2Context([]interaction.HumanUtterance{ + {ID: "mine", PrincipalID: "principal-1", Content: "Я сейчас в Москве", ReceivedAtUnixMillis: 2}, + {ID: "other", PrincipalID: "principal-2", Content: "Я сейчас в Казани", ReceivedAtUnixMillis: 3}, + }, "principal-1") + if got.Text == "" || strings.Contains(got.Text, "Казани") || !strings.Contains(got.Text, "Москве") { + t.Fatalf("scoped context=%#v", got) + } +}