Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

feat(meetings): let a term correction keep the AI summary for one save

Guido Boyke087f765ad2bb
diff --git a/app/models/meeting.rb b/app/models/meeting.rb
index 88f8435..883a1b4 100644
--- a/app/models/meeting.rb
+++ b/app/models/meeting.rb
@@ -222,6 +222,19 @@ class Meeting < ApplicationRecord
project_id == authorized_project_id
end
+ # The ONE exception to invalidate_stale_summary (K4b, plan §5.4, E4/E5): a
+ # term correction (Actors::CorrectMeetingTerm) changes the transcript and
+ # keeps the AI summary, with the same replacement on "everywhere", untouched
+ # on "only here". It asks Actors::SaveMeeting for it (keep_summary: true),
+ # which sets this on its own instance right before it saves; the next save
+ # takes it and clears it, whatever it changes, so it holds for that one save.
+ # Nothing else sets it (guard: spec/architecture/meeting_summary_exception_guard_spec.rb).
+ # Not "write generated_summary along": a summary without the word would be
+ # unchanged and dropped all the same.
+ def keep_summary_for_next_save!
+ @keep_summary_for_next_save = true
+ end
+
# The live summary stream names the project: after a move (Actors::MoveMeeting)
# a page still open in the old project hears nothing of what is written in
# the new one. The view subscribes through the same method.
@@ -301,10 +314,14 @@ class Meeting < ApplicationRecord
# Clears the summary trio remnants when transcript or notes change. Skipped when
# generated_summary is written in the same save — the service persisting a fresh
- # summary never touches the source. Known race, accepted: a job finishing AFTER
+ # summary never touches the source — and for the one save a term correction
+ # asked for (keep_summary_for_next_save!). Known race, accepted: a job finishing AFTER
# a source edit re-writes a summary of the old source; the next edit clears it
# again (review #235).
def invalidate_stale_summary
+ kept = @keep_summary_for_next_save
+ @keep_summary_for_next_save = false
+ return if kept
return if new_record?
return if will_save_change_to_attribute?(:generated_summary)
return unless will_save_change_to_attribute?(:transcript) || will_save_change_to_attribute?(:notes)
diff --git a/app/services/actors/save_meeting.rb b/app/services/actors/save_meeting.rb
index f25a05c..1916e9e 100644
--- a/app/services/actors/save_meeting.rb
+++ b/app/services/actors/save_meeting.rb
@@ -17,9 +17,14 @@ module Actors
# participant_links: normalized name => person_id, for a caller that has
# resolved people through the directory itself (Meetings::Intake). Separate
# from `params` on purpose: a payload never names a person_id.
- def initialize(project:, params:, current_user:, id: nil, participant_links: {})
+ # keep_summary: the AI summary survives this one save of a changed
+ # transcript (Meeting#keep_summary_for_next_save!). Only a term correction
+ # asks for it (Actors::CorrectMeetingTerm, K4b; guard:
+ # spec/architecture/meeting_summary_exception_guard_spec.rb).
+ def initialize(project:, params:, current_user:, id: nil, participant_links: {}, keep_summary: false)
super()
@participant_links = participant_links
+ @keep_summary = keep_summary
# Extract BEFORE find_meeting: a new record does project.meetings.build(params),
# which would choke on a :participants key that is not a Meeting column.
@participants_payload = extract_participants(params)
@@ -38,6 +43,7 @@ module Actors
if @meeting.id.present?
guard_still_in_project!
+ @meeting.keep_summary_for_next_save! if @keep_summary
@meeting.update!(@meeting_params)
else
@meeting.creator = @current_user
diff --git a/spec/models/meeting_spec.rb b/spec/models/meeting_spec.rb
index dd2c68d..196c13f 100644
--- a/spec/models/meeting_spec.rb
+++ b/spec/models/meeting_spec.rb
@@ -516,6 +516,42 @@ RSpec.describe Meeting, type: :model do
meeting.update!(notes: 'neu', generated_summary: 'Frische Zusammenfassung')
expect(meeting.generated_summary).to eq('Frische Zusammenfassung')
end
+
+ # The one exception (K4b, E4/E5): a term correction keeps the summary, for
+ # the one save of its corrected transcript. Only Actors::SaveMeeting sets it,
+ # when Actors::CorrectMeetingTerm asks (meeting_summary_exception_guard_spec).
+ describe 'the exception of a term correction' do
+ it 'keeps summary and error for the next save of the transcript' do
+ meeting.keep_summary_for_next_save!
+ meeting.update!(transcript: 'Transkript korrigiert')
+
+ expect(meeting.reload.generated_summary).to eq('Alte Zusammenfassung')
+ expect(meeting.summary_creation_error).to eq('alter Fehler')
+ end
+
+ it 'holds for that one save only' do
+ meeting.keep_summary_for_next_save!
+ meeting.update!(transcript: 'Transkript korrigiert')
+ meeting.update!(transcript: 'Transkript bearbeitet')
+
+ expect(meeting.reload.generated_summary).to eq('')
+ end
+
+ it 'is used up by the next save, whatever it changes' do
+ meeting.keep_summary_for_next_save!
+ meeting.update!(title: 'Umbenannt')
+ meeting.update!(notes: 'bearbeitet')
+
+ expect(meeting.reload.generated_summary).to eq('')
+ end
+
+ it 'belongs to the one instance it was set on' do
+ meeting.keep_summary_for_next_save!
+ Meeting.find(meeting.id).update!(notes: 'bearbeitet')
+
+ expect(meeting.reload.generated_summary).to eq('')
+ end
+ end
end
# Pure function: transcripts pasted from AI tools carry a leading YAML frontmatter
diff --git a/spec/services/actors/save_meeting_spec.rb b/spec/services/actors/save_meeting_spec.rb
index 23d8cf0..198c09a 100644
--- a/spec/services/actors/save_meeting_spec.rb
+++ b/spec/services/actors/save_meeting_spec.rb
@@ -74,6 +74,30 @@ RSpec.describe Actors::SaveMeeting do
end
end
+ # A term correction (Actors::CorrectMeetingTerm, K4b) keeps the AI summary
+ # for its one save; any other save of the transcript drops it as before.
+ describe 'keep_summary' do
+ let!(:meeting) do
+ create(:meeting, project: project, organisation: organisation, creator: user, transcript: 'Lalabeis hier',
+ generated_summary: 'Zusammenfassung zu Lalabeis')
+ end
+
+ it 'drops the summary of a changed transcript by default' do
+ described_class.call(project: project, params: { transcript: 'Lalabase hier' }, id: meeting.id, current_user: user)
+
+ expect(meeting.reload.generated_summary).to eq('')
+ end
+
+ it 'keeps it when asked, for that save' do
+ result = described_class.call(project: project, params: { transcript: 'Lalabase hier' }, id: meeting.id,
+ current_user: user, keep_summary: true)
+
+ expect(result).to be_success
+ expect(meeting.reload.transcript).to eq('Lalabase hier')
+ expect(meeting.generated_summary).to eq('Zusammenfassung zu Lalabeis')
+ end
+ end
+
describe 'participant sync' do
def org_member(_name = nil)
u = create(:user)