Files
bellsystems-cp/backend/alembic/versions/c9d0e1f2a3b4_boot_event_crash_detail.py
bonaminandClaude Opus 5.5 963516ece0 feat(mqtt): store F-070 crash detail and group crashes fleet-wide
Firmware F-070 adds a fuller `crash` object (backtrace, backtrace_corrupted,
elf_sha256) and a new `pre_crash` snapshot (uptime, heap stats, optional
abort_msg) to boot_report and to telemetry.get_boot_history entries.

- Migration c9d0e1f2a3b4: device_boot_events gains crash / pre_crash JSONB,
  stored verbatim so later additive fields need no migration. The legacy
  crash_* columns are still filled; old rows and old firmware are unchanged.
  JSON is bound as CAST(CAST(:x AS TEXT) AS JSONB): a bare JSONB cast makes
  asyncpg JSON-encode the already-encoded string a second time.
- boot_report ingestion passes both objects through.
- telemetry.get_boot_history replies (control/ack) are merged into boot
  history whoever sent the command: an entry matches an existing row on
  boot_count + reset_reason + time within 30 min (boot_count alone is not
  unique - the counter gets reset), and only fills crash/pre_crash the row
  lacks; unmatched entries are boots we never saw live and are inserted at
  the device's timestamp; entries without ts are skipped.
- GET /api/mqtt/crash-groups: fault boots grouped by abort_msg with hex
  addresses stripped, else task + exception cause, else reset reason. When
  abort_msg is present, pc/exc_cause describe abort() itself and are
  ignored for grouping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:28:40 +03:00

33 lines
1.2 KiB
Python

"""boot event crash detail (firmware F-070)
Firmware F-070 enriches boot_report (and telemetry.get_boot_history entries)
with a fuller `crash` object (backtrace, backtrace_corrupted, elf_sha256) and a
new, independent `pre_crash` object (uptime/heap snapshot + optional
abort_msg). Both are stored verbatim as JSONB so future additive fields don't
need another migration. The existing flat crash_* columns stay and are still
filled, so older rows and older firmware keep working unchanged.
Revision ID: c9d0e1f2a3b4
Revises: b8c9d0e1f2a3
Create Date: 2026-09-30 00:00:00.000000
"""
from typing import Sequence, Union
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
from alembic import op
revision: str = "c9d0e1f2a3b4"
down_revision: Union[str, None] = "b8c9d0e1f2a3"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column("device_boot_events", sa.Column("crash", postgresql.JSONB(), nullable=True))
op.add_column("device_boot_events", sa.Column("pre_crash", postgresql.JSONB(), nullable=True))
def downgrade() -> None:
op.drop_column("device_boot_events", "pre_crash")
op.drop_column("device_boot_events", "crash")