Skip to content

Add schema, handler, and proxy infrastructure for channel request details (#4541)#4610

Draft
stuartc wants to merge 9 commits intomainfrom
4541-channel-request-details-page
Draft

Add schema, handler, and proxy infrastructure for channel request details (#4541)#4610
stuartc wants to merge 9 commits intomainfrom
4541-channel-request-details-page

Conversation

@stuartc
Copy link
Copy Markdown
Member

@stuartc stuartc commented Apr 9, 2026

Description

This PR adds the backend infrastructure needed for the channel request detail page. It extends the data model and proxy pipeline to capture richer request/response metadata that was previously discarded.

Schema changes:

  • New columns on channel_events: request_query_string, request_body_size, response_body_size, request_send_us, response_duration_us
  • Migrate request_headers and response_headers from text to native jsonb (with USING clause for in-place data conversion, handling NULL and malformed JSON)
  • New columns on channel_requests: client_webhook_auth_method_id (FK with nilify_all) and client_auth_type (denormalized snapshot that survives auth method deletion)

Handler + proxy plug changes:

  • Adapt handler to Philter 0.3.0 timing structure (result.timing.total_us replaces result.duration_us)
  • Persist per-direction durations (send_us, recv_us) and body sizes from Philter observations
  • Pass collect_timing: true to Philter for per-phase timing breakdown
  • Pass conn.query_string through handler state to persist on events
  • Identify which client auth method matched (not just pass/fail) and persist the method ID and type on the channel request
  • Stop JSON-encoding headers — store as native jsonb arrays

Closes #4541

Validation steps

  1. mix test test/lightning/channels/ — 75 tests, 0 failures
  2. mix test test/lightning_web/plugs/channel_proxy_plug_test.exs — 49 tests, 0 failures
  3. mix verify — 4713 tests, 0 failures

Additional notes for the reviewer

  1. The headers jsonb migration (20260409100002) uses a CASE/USING clause to convert existing text data in-place. NULL values stay NULL; malformed JSON falls back to NULL.
  2. empty_values: [] was added to the ChannelEvent changeset because request_query_string needs to preserve empty strings ("" means "no query params"). Since all ChannelEvent fields are machine-written by the handler, not user input, this is safe.
  3. authenticate_client was refactored from boolean pass/fail to identifying the specific matched method, reusing Auth.valid_key?/Auth.valid_user? per-method to preserve constant-time comparison.

TODO

  • Migration: new columns on channel_events (body sizes, durations, query string)
  • Migration: convert request_headers and response_headers from text to jsonb
  • Migration: add client_webhook_auth_method_id and client_auth_type to channel_requests
  • Update ChannelEvent schema and changeset for new fields + jsonb headers
  • Update ChannelRequest schema with client auth method association
  • Adapt handler to Philter 0.3.0 timing structure
  • Handler persists body sizes, per-direction durations, and query string
  • Handler stores headers as native jsonb (no more Jason.encode!)
  • Proxy plug passes collect_timing: true to Philter
  • Proxy plug passes conn.query_string into handler state
  • Proxy plug identifies matched client auth method and passes ID + type into handler state
  • Test contracts for all schema, handler, and proxy plug changes
  • All existing tests pass (4713 tests, 0 failures)
  • Detail LiveView page (ChannelRequestLive.Show) with summary card, request/response sections, timing visualization, and context section
  • Error message humanization module (transport + credential error codes → human-readable messages)
  • Navigation wiring: link from channel logs table, breadcrumbs, route + feature gate
  • Context function Channels.get_channel_request_for_project/2 with project-scoped query

AI Usage

  • I have used Claude Code
  • I have used another model
  • I have not used AI

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review with Claude Code)
  • I have implemented and tested all related authorization policies.
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

@github-project-automation github-project-automation bot moved this to New Issues in Core Apr 9, 2026
@stuartc stuartc self-assigned this Apr 9, 2026
stuartc added 9 commits April 10, 2026 17:00
Define the target interface for schema, handler, and proxy plug changes
needed by the channel request detail page. These tests fail until
Phase 1b implements the backing code.

Test contracts cover:
- ChannelEvent new fields: request_query_string, request_body_size,
  response_body_size, request_send_us, response_duration_us
- ChannelEvent headers as native jsonb (round-trip without Jason.decode!)
- ChannelRequest auth tracking: client_webhook_auth_method_id (FK with
  on_delete nilify_all) and client_auth_type (denormalized snapshot)
- Handler persist_completion adapted to Philter 0.3.0: timing.total_us,
  timing.send_us, timing.recv_us, observation sizes
- Proxy plug: query string and client auth method pass-through
…ge (#4541)

Add new columns to channel_events (body sizes, per-direction durations,
query string), migrate headers from text to native jsonb, add client auth
tracking to channel_requests, adapt handler to Philter 0.3.0 timing
structure, and pass collect_timing/query_string/auth method through the
proxy plug pipeline.
Define failing test contracts for the detail LiveView, error
humanization helpers, and get_channel_request_for_project context
function. Enrich channel_event/channel_error_event factories and
migrate hand-rolled Repo.insert! calls across channel tests.
Implement the detail LiveView, context function, error humanization,
route, and navigation wiring to make all Phase 3a test contracts pass.
Store Finch telemetry values as-is in microseconds instead of truncating
to milliseconds in the handler. Adds queue_us, connect_us, and
reused_connection columns for full Finch phase visibility.
… UI polish (#4541)

Reorder layout (summary → timing → request/response side-by-side → context),
implement nested timeline showing Finch phases within proxy overhead using
crosshatch pattern, add foldable disclosure sections for headers/body,
improve body viewer with content-type badges and no-body indicators.
…4541)

Split the 1158-line show.ex into four focused files to improve
maintainability: helpers.ex (shared pure functions), components.ex
(reusable display components), timing.ex (timing visualization),
and show.ex (LiveView lifecycle + section composition).
@stuartc stuartc force-pushed the 4541-channel-request-details-page branch from 3b1045c to 0d65edd Compare April 10, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New Issues

Development

Successfully merging this pull request may close these issues.

Enable Debugging via a Channel Request Details Page

1 participant