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.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Check every write action of the meeting controllers for the meeting lock
Guido Boyked7493373a81f
diff --git a/CLAUDE.md b/CLAUDE.mdindex 7370584..9dc35f2 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -220,15 +220,18 @@ from this project": refuse, or answer as if it were not found.actors that lock and then authorize again, under the lock, in the project the meeting is innow (`AcceptTicketSuggestion`, `StartTicketSuggestionRun`). It only shrinks, and every entrygives its reason.-* `WRITERS` pins the files of the seven writes that exist: the move, the edit, the delete, the- ticket link, the analysis publication, the booking and the start of a summary. Four review- rounds of the move found each of them landing in the old project after a move.-* ⚠️ **The guard checks files, not actions.** A second write in a listed file passes as soon- as one other write there takes the lock: `create_summary` sat next to the delete without- it until a fourth review round.-* ⚠️ **Not seen: a new write that takes no lock at all.** Writing a meeting's data (its- project, links, analyses, bookings) means calling the helper; the guard cannot know that a- file it has never heard of should.+* In a controller the lock is `with_meeting_in_project { ... }` (`MeetingInProject`): the+ block runs under the lock, a moved meeting answers 404. The guard asks **every write+ action** (each route but GET) of `MeetingsController` and `MeetingTicketLinksController`+ for that call or for an actor that locks itself (`LOCKING_ACTORS`). A check per file had+ passed `create_summary`, unlocked next to a delete that locked, until a fourth review round.+ The exception list (`NO_MEETING_YET`, a write before any meeting exists) only shrinks.+* `WRITERS` pins the services that lock: the move, the edit, the analysis publication, the+ booking, and the controller helper. Four review rounds of the move found each of these+ writes landing in the old project after a move.+* ⚠️ **Not seen: a write in a service or controller the guard does not name.** Writing a+ meeting's data (its project, links, analyses, bookings) elsewhere means calling the helper+ and adding the file to `WRITERS` or `CONTROLLERS`.* Lock order: the meeting before a booking or an analysis, never the other way round.---diff --git a/app/controllers/concerns/CLAUDE.md b/app/controllers/concerns/CLAUDE.mdindex b2bfc21..e30ad25 100644--- a/app/controllers/concerns/CLAUDE.md+++ b/app/controllers/concerns/CLAUDE.md@@ -1,4 +1,4 @@-# Karte: app/controllers/concerns (Stand: 2026-10-17)+# Karte: app/controllers/concerns (Stand: 2026-10-24)> Für die Ticket-**Domäne** (Attributsystem, Kanban, Actors, Fallen) gilt zusätzlich> `docs/architektur/tickets_lesepfad.md`. Diese Karte hier beschreibt nur den **Stack**.@@ -51,7 +51,10 @@ Lese-Reihenfolge, um eine Listen-Seite wirklich zu verstehen:`viewport_switchable.rb` (Mobile/Desktop-Umschaltung), `project_controller.rb`(Projekt-Scope-Basis, nutzt z. B. der MeetingsController), `ai_feature_gate.rb`(`ensure_ai_enabled`, org-Ebene; aus `project_controller.rb` extrahiert in S3a T2,- damit die projektlosen Assistant-Controller dasselbe Gate nutzen).+ damit die projektlosen Assistant-Controller dasselbe Gate nutzen),+ `meeting_in_project.rb` (24.10.2026: `with_meeting_in_project { ... }`, die Sperre eines+ Meeting-Schreibwegs im Controller, Abschnitt zu `Meeting#lock_in_project!` in der+ Wurzel-`CLAUDE.md`; der Wächter fragt jede schreibende Aktion der Meeting-Controller).Daneben liegen **Patches in Rails-eigene Controller**, die nicht per `include` im App-Controller,sondern über einen `to_prepare`-Initializer eingehängt werden: `direct_uploads_guard.rb` →diff --git a/app/controllers/concerns/meeting_in_project.rb b/app/controllers/concerns/meeting_in_project.rbnew file mode 100644index 0000000..ca19df8--- /dev/null+++ b/app/controllers/concerns/meeting_in_project.rb@@ -0,0 +1,21 @@+# frozen_string_literal: true++# THE lock for a meeting write in a controller action. The action was+# authorized against @project; a move (Actors::MoveMeeting) that committed+# meanwhile has taken the meeting into a project this request was never+# checked for. Such a meeting is gone from here: 404, as for a foreign one.+# The block runs inside the transaction that holds the meeting's row lock+# (Meeting#lock_in_project!). Guard: spec/architecture/meeting_lock_guard_spec.rb,+# which asks every write action of the meeting controllers for this call or+# for an actor that locks itself.+module MeetingInProject+ private++ def with_meeting_in_project(meeting = @meeting)+ Meeting.transaction do+ raise ActiveRecord::RecordNotFound unless meeting.lock_in_project!(@project.id)++ yield+ end+ end+enddiff --git a/app/controllers/organisations/meeting_ticket_links_controller.rb b/app/controllers/organisations/meeting_ticket_links_controller.rbindex 8267220..a44cb1d 100644--- a/app/controllers/organisations/meeting_ticket_links_controller.rb+++ b/app/controllers/organisations/meeting_ticket_links_controller.rb@@ -15,6 +15,7 @@module Organisationsclass MeetingTicketLinksController < Organisations::BaseControllerinclude ProjectController+ include MeetingInProjectbefore_action :set_meeting@@ -37,9 +38,7 @@ module Organisations# A move that committed while this waited has taken the meeting into# another project, and the ticket of this one may not follow it there# (404, as for a foreign meeting).- Meeting.transaction do- raise ActiveRecord::RecordNotFound unless @meeting.lock_in_project!(@project.id)-+ with_meeting_in_project do@meeting.outgoing_references.create!(organisation: @current_organisation,target: ticket,@@ -57,7 +56,8 @@ module Organisationsauthorize @meeting, :update?# Scoped to this meeting's outgoing references: a foreign reference id is 404.- @meeting.outgoing_references.find(params[:id]).destroy+ # Under the lock like every meeting write here (MeetingInProject).+ with_meeting_in_project { @meeting.outgoing_references.find(params[:id]).destroy }respond_link_result(:notice, 'flash.meeting_ticket_links.removed')enddiff --git a/app/controllers/organisations/meetings_controller.rb b/app/controllers/organisations/meetings_controller.rbindex a7b28e0..3bc4825 100644--- a/app/controllers/organisations/meetings_controller.rb+++ b/app/controllers/organisations/meetings_controller.rb@@ -12,6 +12,7 @@ module Organisationsinclude AdHocFilterableinclude Pageableinclude MeetingList+ include MeetingInProject# edit/update included so the detail-frame re-render after a save keeps the right# viewport: the edit link + form carry viewport so the round-trip preserves it.@@ -183,7 +184,9 @@ module Organisationsdef destroyauthorize @meeting, :destroy?- if destroy_in_project+ # The delete was authorized against this project: a meeting that moved+ # meanwhile is gone from here, as a deleted one would be.+ if with_meeting_in_project { @meeting.destroy }respond_to do |format|format.turbo_stream do# closeLane (application.js): the meeting is gone, so is its lane and@@ -230,13 +233,9 @@ module Organisations# Pending flag → the section shows "wird erstellt…"; the job clears it on# completion and the after_update_commit broadcast pushes the final state.- # Under the meeting's lock: a meeting that moved meanwhile is gone from- # here, and its summary is not started from a project it left.- Meeting.transaction do- raise ActiveRecord::RecordNotFound unless @meeting.lock_in_project!(@project.id)-- @meeting.update!(summary_creation_flag: true, summary_creation_error: '')- end+ # A meeting that moved meanwhile is gone from here; its summary is not+ # started from a project it left.+ with_meeting_in_project { @meeting.update!(summary_creation_flag: true, summary_creation_error: '') }Meetings::SummaryJob.perform_later(meeting_id: @meeting.id)respond_to do |format|@@ -480,16 +479,6 @@ module Organisationsorganisation_project_meetings_path(@current_organisation, target, meeting_id: @meeting.id)end- # The delete was authorized against this project: a meeting that moved- # meanwhile is gone from here, as a deleted one would be.- def destroy_in_project- Meeting.transaction do- raise ActiveRecord::RecordNotFound unless @meeting.lock_in_project!(@project.id)-- @meeting.destroy- end- end-def set_meeting# Scoped to @project.meetings: a foreign-project (or foreign-tenant) id is# simply not found → 404, which rejects cross-project/tenant access.diff --git a/spec/architecture/meeting_lock_guard_spec.rb b/spec/architecture/meeting_lock_guard_spec.rbindex 79d2b29..0d7ea87 100644--- a/spec/architecture/meeting_lock_guard_spec.rb+++ b/spec/architecture/meeting_lock_guard_spec.rb@@ -11,8 +11,13 @@ require 'rails_helper'# a delete, a ticket link, a booking, an analysis publication, a second move.# Each had been fixed by hand with "lock, then compare the project". A rule# that has to be remembered at every write is not a rule.-# Not seen: a write that takes no lock at all. WRITERS pins the ones that exist;-# a new write on a meeting is for the person who reads the diff.+# The controllers lock through MeetingInProject#with_meeting_in_project, and+# every write action of the meeting controllers is asked for it one by one:+# a fourth round found create_summary unlocked in a file whose delete locked,+# which a check per file had passed.+# Not seen: a write in a service or a controller this guard does not name.+# WRITERS and CONTROLLERS pin the ones that exist; a new one is for the+# person who reads the diff.module MeetingLockGuardROOTS = %w[app lib].freezeMODEL = 'app/models/meeting.rb'@@ -37,14 +42,58 @@ module MeetingLockGuardapp/services/actors/save_meeting.rbapp/services/actors/save_meeting_analysis.rbapp/services/actors/save_time_session.rb- app/controllers/organisations/meeting_ticket_links_controller.rb- app/controllers/organisations/meetings_controller.rb+ app/controllers/concerns/meeting_in_project.rb].freeze+ # The write actions (every route but GET) of these controllers each run under+ # with_meeting_in_project, or hand the write to an actor that locks itself,+ # or write no meeting that exists.+ CONTROLLERS = {+ 'organisations/meetings' => 'app/controllers/organisations/meetings_controller.rb',+ 'organisations/meeting_ticket_links' => 'app/controllers/organisations/meeting_ticket_links_controller.rb'+ }.freeze++ CONTROLLER_LOCK = 'with_meeting_in_project'++ # Each one is in WRITERS (checked below).+ LOCKING_ACTORS = %w[Actors::SaveMeeting Actors::MoveMeeting].freeze++ # Only shrinks; every entry gives its reason.+ NO_MEETING_YET = {+ 'organisations/meetings#detect_participants' =>+ 'reads a transcript from the form before any meeting is saved'+ }.freeze++ def self.write_actions(controller)+ actions = Rails.application.routes.routes.filter_map do |route|+ route.defaults[:action] if route.defaults[:controller] == controller && route.verb.present? && route.verb != 'GET'+ end+ actions.uniq!+ actions.sort!+ end++ # The lines of `def action` up to its own `end`, by indentation.+ def self.action_body(source, action)+ lines = source.lines+ start = lines.index { |line| line.match?(/^\s*def #{Regexp.escape(action)}\b/) }+ return unless start++ indent = lines[start][/^\s*/]+ finish = lines[(start + 1)..].index { |line| line.rstrip == "#{indent}end" }+ lines[start..(start + 1 + finish.to_i)].join+ end++ def self.locked?(body)+ body.include?(CONTROLLER_LOCK) || LOCKING_ACTORS.any? { |actor| body.include?(actor) }+ end+def self.files- ROOTS.flat_map { |root| Dir[Rails.root.join(root, '**', '*.{rb,erb}')] }- .map { |path| Pathname(path).relative_path_from(Rails.root).to_s }- .reject { |path| path == MODEL }+ ROOTS.each_with_object([]) do |root, files|+ Dir[Rails.root.join(root, '**', '*.{rb,erb}')].each do |path|+ relative = Pathname(path).relative_path_from(Rails.root).to_s+ files << relative unless relative == MODEL+ end+ endenddef self.bare_locks(source)@@ -85,6 +134,69 @@ RSpec.describe 'Meeting locks go through Meeting#lock_in_project!', type: :archiexpect(missing).to be_empty, "These writers no longer take the lock: #{missing.join(', ')}"end+ describe 'the write actions of the meeting controllers' do+ it 'runs each of them under the lock' do+ unlocked = MeetingLockGuard::CONTROLLERS.flat_map do |controller, file|+ source = File.read(Rails.root.join(file))+ MeetingLockGuard.write_actions(controller).filter_map do |action|+ key = "#{controller}##{action}"+ next if MeetingLockGuard::NO_MEETING_YET.key?(key)++ body = MeetingLockGuard.action_body(source, action)+ next "#{key} (not defined in #{file})" unless body++ key unless MeetingLockGuard.locked?(body)+ end+ end++ expect(unlocked).to be_empty,+ "These write actions take no meeting lock: #{unlocked.join(', ')}\n" \+ 'Wrap the write in with_meeting_in_project { ... } (MeetingInProject), ' \+ 'or hand it to an actor in LOCKING_ACTORS.'+ end++ it 'finds write actions at all' do+ expect(MeetingLockGuard.write_actions('organisations/meetings')).to include('destroy', 'create_summary')+ expect(MeetingLockGuard.write_actions('organisations/meeting_ticket_links')).to eq(%w[create destroy])+ end++ it 'keeps the exception list to write actions that exist and take no lock' do+ MeetingLockGuard::NO_MEETING_YET.each_key do |key|+ controller, action = key.split('#')+ body = MeetingLockGuard.action_body(File.read(Rails.root.join(MeetingLockGuard::CONTROLLERS.fetch(controller))),+ action)++ expect(MeetingLockGuard.write_actions(controller)).to include(action), "#{key} is no write action any more"+ expect(MeetingLockGuard.locked?(body)).to be(false), "#{key} locks now: remove it from NO_MEETING_YET"+ end+ end++ it 'names only actors that lock themselves' do+ MeetingLockGuard::LOCKING_ACTORS.each do |actor|+ expect(MeetingLockGuard::WRITERS).to include("app/services/#{actor.underscore}.rb"), actor+ end+ end++ it 'reads an action up to its own end' do+ source = <<~RUBY+ class Example+ def create_summary+ if ready?+ with_meeting_in_project { write }+ end+ end++ def destroy+ @meeting.destroy+ end+ end+ RUBY++ expect(MeetingLockGuard.locked?(MeetingLockGuard.action_body(source, 'create_summary'))).to be(true)+ expect(MeetingLockGuard.locked?(MeetingLockGuard.action_body(source, 'destroy'))).to be(false)+ end+ end+describe 'the matcher' doit 'sees the forms a direct lock takes' do['@meeting.lock!', '@time_session.meeting&.lock!', 'meeting.lock!',