Part 91 inspection rules: limitations, annual as 100-hour, overrun, clock

- Inspection types say what overdue means: grounds the aircraft, no IFR
  (91.411), no transponder (91.413) or advisory. Overdue limitations show
  as a new LIMITED status ("VFR only", "No transponder") and don't block
  flights under airworthiness enforcement
- "Also counts as": an annual satisfies the 100-hour (91.409(b))
- Overrun allowance: a 100-hour done within 10 hrs of due counts the next
  one from when it was due; done early, from when it was done
- Per-aircraft maintenance clock (tach or Hobbs) for time in service; new
  records default to it (fixes the tach-offset mismatch)
- Status labels Current / Due soon / limitation / Grounded, with the
  91.7 pilot-in-command note
- Migration converts existing types by name; archives carry the new fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-07 10:04:46 -05:00
1 parent ef7cd2efba
commit a4b72cf2c1
28 files changed
+371 -63

No files matched your search

+3 -2
View File
@@ -119,7 +119,7 @@ module AircraftArchive
def aircraft_hash(a)
{ id: id(a), tail_number: a.tail_number, make: a.make, model: a.model, serial_number: a.serial_number,
description: a.description, purchased: a.purchased&.iso8601, status: a.status, tach_time: dec(a.tach_time),
description: a.description, purchased: a.purchased&.iso8601, status: a.status, time_basis: a.time_basis, tach_time: dec(a.tach_time),
tach_time_offset: dec(a.tach_time_offset), hobbs_time: dec(a.hobbs_time), hobbs_time_offset: dec(a.hobbs_time_offset),
picture: file(a.picture, "aircraft_pictures"), icao_type: a.icao_type }
end
@@ -150,7 +150,8 @@ module AircraftArchive
end
def inspection_type_hash(t, component_ids)
{ id: id(t), name: t.name, recurring: t.recurring, required: t.required, recurring_hours: dec(t.recurring_hours),
{ id: id(t), name: t.name, recurring: t.recurring, required: t.required, effect: t.effect,
hours_tolerance: dec(t.hours_tolerance), satisfies: t.satisfies_id && id(t.satisfies), recurring_hours: dec(t.recurring_hours),
recurring_days: t.recurring_days, recurring_months: t.recurring_months,
applicable_aircraft: t.aircraft_ids.include?(@aircraft.id) ? [ id(@aircraft) ] : [],
applicable_component: (t.component_ids & component_ids).map { id(_1) } }
+9 -1
View File
@@ -139,6 +139,7 @@ module AircraftArchive
tail_number: (@tail_number.presence || a["tail_number"]).to_s.strip.upcase,
make: a["make"].to_s, model: a["model"].to_s, serial_number: a["serial_number"].to_s, description: a["description"].to_s,
purchased: date(a["purchased"]), status: Aircraft::STATUSES.key?(a["status"]) ? a["status"] : "AVAILABLE",
time_basis: Aircraft::TIME_BASES.key?(a["time_basis"]) ? a["time_basis"] : "tach",
tach_time: num(a["tach_time"] || a["flight_time"]) || 0, tach_time_offset: num(a["tach_time_offset"]) || 0,
hobbs_time: num(a["hobbs_time"]) || 0, hobbs_time_offset: num(a["hobbs_time_offset"]) || 0,
icao_type: a["icao_type"].to_s.upcase.presence&.then { _1.match?(/\A[A-Z0-9]{1,4}\z/) ? _1 : nil }
@@ -256,7 +257,9 @@ module AircraftArchive
if type
warn("Inspection type “#{name}” already existed here and was reused.") if type.recurring != (data["recurring"] == true)
else
type = InspectionType.new(name: name, recurring: data["recurring"] == true, required: data["required"] != false,
effect = InspectionType::EFFECTS.key?(data["effect"]) ? data["effect"] : (data["required"] == false ? "advisory" : "grounds")
type = InspectionType.new(name: name, recurring: data["recurring"] == true, effect: effect,
required: effect != "advisory", hours_tolerance: num(data["hours_tolerance"]) || 0,
recurring_hours: num(data["recurring_hours"]), recurring_days: data["recurring_days"],
recurring_months: data["recurring_months"])
type.save!(validate: false)
@@ -265,6 +268,11 @@ module AircraftArchive
type.aircraft << @aircraft if Array(data["applicable_aircraft"]).any? && !type.aircraft.include?(@aircraft)
components(data["applicable_component"]).each { |c| type.components << c unless type.components.include?(c) }
@map[:inspection_type][data["id"].to_s] = type.id
(@satisfies ||= []) << [ type, data["satisfies"].to_s ] if data["satisfies"].present?
end
Array(@satisfies).each do |type, ref|
target = @map[:inspection_type][ref]
type.update_column(:satisfies_id, target) if target && type.satisfies_id.nil? && target != type.id
end
m("inspection_records").each do |data|
type_id = @map[:inspection_type][data["inspection_type_id"].to_s]
+49 -13
View File
@@ -1,22 +1,43 @@
# Computes RED / ORANGE / GREEN airworthiness for an aircraft. Checks (in order):
# AD compliance, grounding squawks, inspection recurrency, component replacement.
# Summarizes an aircraft's records: AD compliance, grounding squawks,
# inspection recurrency and component replacement.
#
# RED something that grounds the aircraft is overdue
# LIMITED it may fly with limitations (pitot-static overdue: VFR only;
# transponder check overdue: no transponder)
# ORANGE something is due soon
# GREEN nothing overdue or due soon
#
# This reflects only what's recorded here. Before each flight the pilot in
# command decides whether the aircraft is airworthy (14 CFR 91.7).
class Airworthiness
HOURS_WARNING = BigDecimal("10")
DAYS_WARNING = 30
RED = "RED"
LIMITED = "LIMITED"
ORANGE = "ORANGE"
GREEN = "GREEN"
DISCLAIMER = "Based on the records in this app. Before each flight the pilot in command decides whether the aircraft is airworthy (14 CFR 91.7)."
Issue = Struct.new(:category, :severity, :title, :description, :item, keyword_init: true)
Issue = Struct.new(:category, :severity, :title, :description, :item, :limitation, keyword_init: true)
Status = Struct.new(:status, :issues, keyword_init: true) do
def red? = status == RED
def limited? = status == LIMITED
def orange? = status == ORANGE
def green? = status == GREEN
def can_fly? = green?
def can_fly? = !red?
def red_issues = issues.select { |i| i.severity == RED }
def label = { RED => "Not Airworthy", ORANGE => "Attention Needed", GREEN => "Airworthy" }[status]
def limitations = issues.filter_map(&:limitation).uniq
def label
case status
when RED then "Grounded"
when LIMITED then limitations.join(" · ")
when ORANGE then "Due soon"
else "Current"
end
end
end
def initialize(aircraft, today: Date.current)
@@ -34,6 +55,7 @@ class Airworthiness
status =
if @issues.any? { _1.severity == RED } then RED
elsif @issues.any? { _1.severity == LIMITED } then LIMITED
elsif @issues.any? { _1.severity == ORANGE } then ORANGE
else GREEN
end
@@ -42,8 +64,8 @@ class Airworthiness
private
def add(category, severity, title, description, item)
@issues << Issue.new(category:, severity:, title:, description:, item:)
def add(category, severity, title, description, item, limitation: nil)
@issues << Issue.new(category:, severity:, title:, description:, item:, limitation:)
end
def check_ads
@@ -68,15 +90,16 @@ class Airworthiness
end
def check_inspections
@aircraft.applicable_inspection_types.where(required: true).find_each do |type|
last = type.inspection_records.for_aircraft(@aircraft).recent_first.first
res = Compliance.inspection_status(type, last, @hours, @today)
@aircraft.applicable_inspection_types.where.not(effect: "advisory").includes(:satisfied_by).find_each do |type|
records = type.records_for(@aircraft).to_a
res = Compliance.inspection_status(type, records, @hours, @today)
case res.rank
when Compliance::OVERDUE
if last
add("INSPECTION", RED, "#{type.name} - Overdue", "Inspection overdue.", type)
title = "#{type.name} - #{records.any? ? 'Overdue' : 'Never Completed'}"
if (limitation = type.limitation)
add("INSPECTION", LIMITED, title, "#{limitation} until it's done.", type, limitation: limitation)
else
add("INSPECTION", RED, "#{type.name} - Never Completed", "Required inspection has no completion record.", type)
add("INSPECTION", RED, title, overdue_description(type, records, res), type)
end
when Compliance::DUE_SOON
add("INSPECTION", ORANGE, "#{type.name} - Due Soon", "Inspection due soon.", type)
@@ -84,6 +107,19 @@ class Airworthiness
end
end
# The 100-hour may be overflown by up to its tolerance only to reach a
# place where it can be done (91.409(b)); say so while that's still open.
def overdue_description(type, records, res)
return "Required inspection has no completion record." if records.empty?
over = res.next_due_hours && @hours - res.next_due_hours
if over && type.hours_tolerance.positive? && over <= type.hours_tolerance
"Inspection overdue. It may be flown up to #{type.hours_tolerance.to_s.sub(/\.0\z/, '')} hrs past due only to reach " \
"a place where it can be done; that time counts toward the next interval (91.409(b))."
else
"Inspection overdue."
end
end
def check_components
@aircraft.components.in_use.where(replacement_critical: true).includes(:component_type).find_each do |c|
overdue = false
+29 -9
View File
@@ -65,7 +65,15 @@ module Compliance
result
end
def inspection_status(type, last_record, current_hours, today = Date.current)
# `records` are those that count for the type (InspectionType#records_for).
# Calendar intervals run from the latest one's date. Hour intervals run from
# the hours at the latest one, except that an inspection done late, within
# the type's hours_tolerance, is counted from when it was due (91.409(b):
# the 100-hour's 10-hour allowance counts toward the next 100 hours). Done
# early, there's no credit: the next is counted from when it was done.
def inspection_status(type, records, current_hours, today = Date.current)
records = records.to_a
last_record = records.max_by { [ _1.date, _1.created_at || Time.at(0) ] }
return Result.new(rank: OVERDUE) unless last_record
return Result.new(rank: COMPLIANT) unless type.recurring?
@@ -84,13 +92,11 @@ module Compliance
end
end
interval = type.recurring_hours.to_d
if interval > 0 && (hours_at = last_record.hours_at_inspection)
since = current_hours - hours_at
result.next_due_hours = hours_at + interval
if since >= interval
if (due_hours = next_due_hours(type, records))
result.next_due_hours = due_hours
if current_hours >= due_hours
rank = OVERDUE
elsif since + Airworthiness::HOURS_WARNING >= interval
elsif current_hours + Airworthiness::HOURS_WARNING >= due_hours
rank = [ rank, DUE_SOON ].max
end
end
@@ -99,6 +105,19 @@ module Compliance
result
end
def next_due_hours(type, records)
interval = type.recurring_hours.to_d
return unless interval.positive?
tolerance = type.hours_tolerance.to_d
due = nil
records.select(&:hours_at_inspection).sort_by { [ _1.date, _1.hours_at_inspection ] }.each do |r|
hours = r.hours_at_inspection.to_d
base = due && hours > due && hours - due <= tolerance ? due : hours
due = base + interval
end
due
end
# Rows for the ADs tab: every applicable AD with its latest compliance and status.
AdRow = Struct.new(:ad, :latest, :status, :next_due_date, :next_due_hours, keyword_init: true)
@@ -123,11 +142,12 @@ module Compliance
def inspection_rows(aircraft)
hours = aircraft.current_hours
aircraft.applicable_inspection_types.ordered.map do |type|
latest = type.inspection_records.for_aircraft(aircraft).recent_first.first
records = type.records_for(aircraft).to_a
latest = records.max_by { [ _1.date, _1.created_at || Time.at(0) ] }
if latest.nil?
InspectionRow.new(type: type, latest: nil, status: "never_completed")
else
res = inspection_status(type, latest, hours)
res = inspection_status(type, records, hours)
InspectionRow.new(type: type, latest: latest, status: res.label,
next_due_date: res.next_due_date, next_due_hours: res.next_due_hours)
end
+11 -7
View File
@@ -1,5 +1,6 @@
# Flight-activity writes: absolute hours updates and flight logs. Both cascade
# the tach delta to every IN-USE component.
# the time-in-service delta (tach or Hobbs, per the aircraft's maintenance
# clock) to every IN-USE component.
class HoursService
def initialize(aircraft, user: Current.user)
@aircraft = aircraft
@@ -17,19 +18,22 @@ class HoursService
def update_hours!(tach_time:, hobbs_time: nil)
enforce_airworthiness!
tach = BigDecimal(tach_time.to_s)
delta = tach - @aircraft.tach_time
hobbs = BigDecimal(hobbs_time.to_s) if hobbs_time.present?
old = @aircraft.tach_time
tach_delta = tach - old
# On Hobbs time, components follow the Hobbs change (when one is given).
delta = @aircraft.hobbs? && hobbs ? hobbs - @aircraft.hobbs_time : tach_delta
Aircraft.transaction do
@aircraft.tach_time = tach
@aircraft.hobbs_time = BigDecimal(hobbs_time.to_s) if hobbs_time.present?
@aircraft.hobbs_time = hobbs if hobbs
@aircraft.save!
cascade_to_components(delta, clamp: true)
@aircraft.log_event!("hours",
"Hours #{delta >= 0 ? 'updated' : 'corrected'} to #{tach}",
user: @user, notes: "Previous: #{old}, delta: #{delta >= 0 ? '+' : ''}#{delta}")
"Hours #{tach_delta >= 0 ? 'updated' : 'corrected'} to #{tach}",
user: @user, notes: "Previous: #{old}, delta: #{tach_delta >= 0 ? '+' : ''}#{tach_delta}")
end
delta
tach_delta
end
# Persist a flight log and apply its side effects atomically.
@@ -43,7 +47,7 @@ class HoursService
@aircraft.tach_time += flight.tach_time
@aircraft.hobbs_time += flight.hobbs_time if flight.hobbs_time
@aircraft.save!
cascade_to_components(flight.tach_time)
cascade_to_components(@aircraft.hobbs? && flight.hobbs_time ? flight.hobbs_time : flight.tach_time)
{ "oil" => [ flight.oil_added, flight.oil_level_after, flight.oil_added_type ],
"fuel" => [ flight.fuel_added, flight.fuel_level_after, flight.fuel_added_type ] }.each do |type, (qty, level, kind)|