Skip to content

channels request logs#4471

Merged
stuartc merged 28 commits intochannelsfrom
4408-channels-logs
Mar 6, 2026
Merged

channels request logs#4471
stuartc merged 28 commits intochannelsfrom
4408-channels-logs

Conversation

@midigofrank
Copy link
Copy Markdown
Collaborator

@midigofrank midigofrank commented Feb 26, 2026

Description

Screenshot 2026-03-02 at 19 14 09

Closes #4408

Validation steps

  1. You can access the request logs page from the menu
  2. Try filtering by channel name

AI Usage

Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):

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

You can read more details in our
Responsible AI Policy

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.
    (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

Introduces Lightning.Channels.SearchParams, an embedded schema that
parses and validates channel request filter params from URL query strings.
Adds list_channel_requests/3 to the Channels context, returning a
paginated Scrivener.Page of ChannelRequest structs with :channel and
filtered :channel_events preloaded (source_received and error types only).
Adds a paginated Channel Requests page at /projects/:id/channels/requests
with a changeset-backed channel filter dropdown. The page uses
SearchParams and list_channel_requests/3 from the Channels context to
display request ID, path, channel name, started-at timestamp, status
badge, and error message.

Also adds a "Channel Requests" nav item in the sidebar (experimental
features only) and converts the Requests count and Last Activity cells
on the Channels CRUD page into links that navigate to the requests page
pre-filtered to that channel.
@github-project-automation github-project-automation Bot moved this to New Issues in Core Feb 26, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 91.93548% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.52%. Comparing base (1f0ea49) to head (15dff6b).
⚠️ Report is 28 commits behind head on channels.

Files with missing lines Patch % Lines
lib/lightning_web/live/channel_live/index.ex 90.22% 13 Missing ⚠️
lib/lightning_web/plugs/channel_proxy_plug.ex 88.54% 11 Missing ⚠️
lib/lightning/channels/handler.ex 83.63% 9 Missing ⚠️
...htning_web/live/run_live/channel_logs_component.ex 88.70% 7 Missing ⚠️
lib/lightning/channels.ex 91.04% 6 Missing ⚠️
lib/lightning_web/live/run_live/index.ex 33.33% 4 Missing ⚠️
lib/lightning/runs.ex 90.00% 2 Missing ⚠️
.../lightning_web/live/channel_live/form_component.ex 97.84% 2 Missing ⚠️
lib/lightning_web/live/channel_live/helpers.ex 94.44% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           channels    #4471      +/-   ##
============================================
+ Coverage     89.42%   89.52%   +0.09%     
============================================
  Files           425      441      +16     
  Lines         20221    20868     +647     
============================================
+ Hits          18083    18682     +599     
- Misses         2138     2186      +48     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@midigofrank midigofrank self-assigned this Mar 2, 2026
@midigofrank midigofrank requested a review from stuartc March 2, 2026 16:16
@midigofrank midigofrank marked this pull request as ready for review March 2, 2026 16:16
midigofrank and others added 6 commits March 3, 2026 08:17
Previously these env vars only took effect in production. In dev/test
the endpoint URL was hardcoded by config/*.exs, making it impossible to
configure via env vars in dev containers (e.g. dev-elixir.local:4000).

Move the unified URL config (host, port, scheme) before the prod block
so it applies in all environments, with sensible per-env defaults.
Previously, invalid credentials returned 404 while missing credentials
returned 401. This was inconsistent and leaked resource existence via
the 401 anyway. Simplify authenticate_source into a single function.
The events preload and helper were filtering for :source_received events
which are never created — the handler only writes :sink_response or
:error events. Also remove em dash fallbacks for empty values.
* support batched logs

* Introduce another event run:batch_logs for batch logs

* update changelog

* refactor to make credo happy

---------

Co-authored-by: Frank Midigo <midigofrank@gmail.com>
@theroinaochieng theroinaochieng self-requested a review March 4, 2026 13:36
lmac-1 and others added 12 commits March 5, 2026 09:19
* fix: store follow_run_id on message meta so logs reach Apollo (#4380)

follow_run_id was only stored in session meta during channel JOIN.
When a user created a session without a run selected and later picked
one, the backend silently dropped follow_run_id from new_message params,
so maybe_add_run_logs never found it and context.log was null.

Now follow_run_id is stored per-message on message meta (same pattern as
unsaved_job), and the Oban worker propagates it to the in-memory session
before enrichment.

* test: add regression tests for follow_run_id propagation (#4380)

Add tests to prevent regression of the bug where logs weren't sent
to Apollo when users selected a run mid-session. Tests verify that
follow_run_id is properly stored in message.meta and propagated
during message processing for log enrichment.

* updates changelog

* test: fix failing follow_run_id regression test (#4380)

The regression test added in 5a22a97 had three setup issues:
- Missing workflow and project in test context
- Missing required dataclip for run creation
- Message lookup found first user message instead of the specific
  message with follow_run_id

Fix by using workflow/project from context, creating a dataclip,
and finding the message by content to get the correct one.

---------

Co-authored-by: Elias W. BA <eliaswalyba@gmail.com>
The run claim polling generates heavy Ecto debug output in development.
Add a LOG_QUEUE_QUERIES env var (default: false) that controls whether
queue claim queries are logged, threading the value through all SQL
calls in Runs.Queue.
- source_event_path now queries :sink_response events (not :source_received)
- Dash placeholder test updated since template renders nil instead of em-dashes
AI assistant tests were leaking error-level log messages into unrelated
test output during concurrent async execution. The MessageProcessor Oban
worker and AiAssistant module log errors when AI queries fail (e.g.
"AI query failed for session", "[MessageProcessor] Failed to process
message"), and with Oban configured as `testing: :inline`, these jobs
execute synchronously within the test process.

While many individual tests had `@tag :capture_log`, this only captures
logs from the tagged test's own process. Logs from spawned processes or
PubSub callbacks could escape capture and appear in the output of
completely unrelated tests running concurrently — such as channel request
LiveView tests that have nothing to do with AI.

Adding `@moduletag :capture_log` at the module level ensures all logs
from every test in these files are captured, preventing cross-test log
contamination. Only ai_assistant_test.exs already had this tag.
Move the inline tab switcher styling into a new TabBar component
(LightningWeb.Components.TabBar) with a pill_tabs/1 function component.
Matches the React Tabs.tsx visual style with slate background and
indigo active state. Includes unit tests for rendering, active state
styling, patch paths, and multi-tab support.
channel_snapshots.channel_id used on_delete: :restrict which blocked
project purging when channels had snapshots. Changed to :delete_all
to match the workflow_snapshots pattern.
Move channel request logs from a standalone page to a tab within the
History page. Adds ChannelLogsComponent as a live_component with
filtering and pagination, a new /history/channels route, and updates
links in the channel index to point to the new location.
Remove the separate ChannelRequestLive page and its nav menu item, now
that channel request logs are accessible via the History page tab.
- Add @moduledoc to TabBar component
- Reorder import before alias in ChannelLive modules
- Remove obsolete foreign_key_constraint on channel_snapshots
- Replace snapshot deletion error test with cascade delete assertion
The list_channel_requests query correctly filters to :sink_response and
:error, but the docstring and test referenced :source_received. Since
:source_received and :sink_request are never emitted by production code,
remove them from the migration enum, Ecto schema, and test factory.
stuartc added 5 commits March 5, 2026 15:10
…T LOCAL

Replace string interpolation in SET LOCAL work_mem with PostgreSQL's
set_config() function and a bind parameter. SET LOCAL doesn't support
$1 placeholders, but set_config('work_mem', $1, true) is equivalent
and eliminates the SQL injection surface.
Guard update/2 to only re-fetch channel requests when params have
actually changed. Use assign_new for the channels list so it's only
fetched once per component lifecycle.
Split state_pill into a shared base_pill (outer styling) and
domain-specific components. Add channel_state_pill with correct
mappings for channel request states — notably :pending displays as
"In Progress" (blue) instead of "Enqueued" (gray).
Replace the blanket handle_info(_event, socket) with a clause that
explicitly matches the four known PubSub events (RunCreated,
RunUpdated, WorkOrderCreated, WorkOrderUpdated) on the channel_logs
tab, preventing silent swallowing of unexpected messages.
Place CORSPlug before Plug.Telemetry so CORS preflight (OPTIONS)
requests are halted before the telemetry span opens, keeping them
out of endpoint duration metrics. Channel proxy and webhook requests
remain fully captured within the span.
@stuartc stuartc merged commit 874d166 into channels Mar 6, 2026
7 checks passed
@stuartc stuartc deleted the 4408-channels-logs branch March 6, 2026 09:29
@github-project-automation github-project-automation Bot moved this from New Issues to Done in Core Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants