Skip to content

ENG-10963 refactor(log): migrate the reflex CLI and runtime to logging (3/5) - #6865

Merged
FarhanAliRaza merged 5 commits into
mainfrom
farhan/eng-10963-log-3-migrate-core
Aug 19, 2026
Merged

ENG-10963 refactor(log): migrate the reflex CLI and runtime to logging (3/5)#6865
FarhanAliRaza merged 5 commits into
mainfrom
farhan/eng-10963-log-3-migrate-core

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Replaces the console helper call sites with per-module loggers across reflex/, and adds shared click log options in reflex.utils.cli_options including a new --json flag that switches output to JSON-lines records (REFLEX_LOG_JSON equivalent).

Keeps a temporary LogLevel conversion mapper for the hosting CLI boundary; it is removed in the next PR when the enums unify.

Stack (ENG-10963)

#6863#6864 → this → hosting CLI → deprecate.
Merge in order; each PR is based on the previous branch.

Review in cubic

@FarhanAliRaza
FarhanAliRaza requested a review from a team as a code owner August 10, 2026 20:36
@linear-code

linear-code Bot commented Aug 10, 2026

Copy link
Copy Markdown

ENG-10963

@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR migrates Reflex CLI and runtime output to per-module Python loggers and introduces shared logging options, including JSON-lines output.

  • Replaces console helper calls across CLI, compiler, runtime, state, and utility modules.
  • Centralizes Click logging options and adds --json support.
  • Updates logging-related tests and command integrations.

Confidence Score: 4/5

The PR is not yet safe to merge because JSON/no-rich compilation still writes non-JSON progress lines to stdout.

The prior reply states that the issue was fixed because PoorProgress.advance goes through console.print, but the current implementation calls built-in print, providing the concrete counterexample: reflex compile --json --no-rich still interleaves Progress: N/M text with JSON records.

Files Needing Attention: reflex/compiler/compiler.py and packages/reflex-base/src/reflex_base/utils/console.py

Important Files Changed

Filename Overview
reflex/compiler/compiler.py Migrates compiler messages and timings to logging and changes progress construction; the previously reported JSON/no-rich progress defect remains outstanding.
reflex/utils/cli_options.py Centralizes eager Click callbacks for log level, verbosity, and JSON mode.
reflex/reflex.py Applies shared logging options across the main CLI and enables managed logging at the root command.
reflex/custom_components/custom_components.py Migrates custom-component commands to module logging and shared CLI log options.
reflex/app.py Replaces runtime console calls with a module logger across exception, page, and socket handling.

Reviews (11): Last reviewed commit: "fix(istate): resolve the disk states dir..." | Re-trigger Greptile

Comment thread reflex/compiler/compiler.py
@codspeed-hq

codspeed-hq Bot commented Aug 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 27 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing farhan/eng-10963-log-3-migrate-core (89a637c) with main (d881ab2)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 29505c0626

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread reflex/reflex.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 39 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="reflex/reflex.py">

<violation number="1" location="reflex/reflex.py:96">
P2: The `login` command now exposes `--json` via `@log_options`, but it delegates to `reflex_cli.v2.cli.login()`, which prints through `reflex_cli.utils.console` (Rich's `_console.print`) and never checks the JSON log mode. Running `reflex login --json` will mix plain-text hosting CLI output with JSON-lines records, breaking JSON-lines consumers. Consider bridging/migrating the hosting console before exposing `--json` on hosting-backed commands, or withhold the option there until the hosting CLI is migrated.</violation>

<violation number="2" location="reflex/reflex.py:717">
P2: `reflex db` commands cannot accept the new `--json` flag, so their migrated log output is only JSON-capable through the environment variable. Apply `log_options` to the database subcommands (or provide equivalent group-level options) so CLI JSON output covers this command family.</violation>
</file>

<file name="tests/units/utils/test_utils.py">

<violation number="1" location="tests/units/utils/test_utils.py:790">
P2: This test no longer exercises the debug path it intends to. `output_system_info()` gates its body on `console.is_debug()` (`reflex_base.utils.console.is_debug`), which reads `console._LOG_LEVEL` — not `log._log_level`. The old test patched `reflex_base.utils.console._LOG_LEVEL` directly; the new one patches `reflex_base.utils.log._log_level`, which is a separate module global that only changes when `console.set_log_level()` is called. As a result `console.is_debug()` still returns `False` (default INFO), so `output_system_info()` returns early and the imports/iteration under the debug branch are no longer covered. The test still passes (its only assertion is that it doesn't crash), silently reducing coverage.</violation>
</file>

<file name="reflex/compiler/compiler.py">

<violation number="1" location="reflex/compiler/compiler.py:1191">
P2: When `reflex compile` is run with `--json --no-rich`, `console.PoorProgress()` is selected as the fallback progress renderer, and its `advance` method writes plain-text `Progress: N/M` lines directly to stdout. This mixes non-JSON text into the output stream expected to be JSON-lines, breaking machine parsing for `--json` consumers.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/reflex.py
Comment thread tests/units/utils/test_utils.py
Comment thread reflex/compiler/compiler.py
Comment thread reflex/reflex.py
Comment thread tests/units/test_app.py Outdated
Comment thread tests/units/test_state.py Outdated
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-10963-log-3-migrate-core branch from 29505c0 to b3d0c80 Compare August 12, 2026 10:37
masenf
masenf previously approved these changes Aug 18, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread tests/units/istate/manager/test_disk.py
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-10963-log-3-migrate-core branch from 2b2e21e to 3578b3d Compare August 18, 2026 22:03
masenf
masenf previously approved these changes Aug 18, 2026
Base automatically changed from farhan/eng-10963-log-2-migrate-base to main August 19, 2026 16:04
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-10963-log-3-migrate-core branch from 3578b3d to 2942cd0 Compare August 19, 2026 16:04
FarhanAliRaza and others added 5 commits August 19, 2026 21:55
Replace console.debug/info/warn/error call sites with per-module
loggers across reflex/, add shared click log options in
reflex.utils.cli_options including a new --json flag that switches
output to JSON-lines records (REFLEX_LOG_JSON equivalent).
- clear the deprecation dedupe set that console.deprecate actually uses in
  the legacy-token state manager test
- scope the app tests' caplog assertions to the reflex.app logger
- name the news fragment after the PR
…of the session

Invoking the real ``cli`` group runs its callback, which sets
REFLEX_MANAGED_LOGGING in os.environ and attaches the sinks for the whole
process. Snapshot the marker with monkeypatch and detach the sinks after
the invocation so later tests (and their subprocesses) start clean.
The default frontend/backend exception handlers now log through the
pipeline. Under AppHarness the backend runs in-process in library mode,
where records propagate to the root logger (pytest's caplog) and nothing
is written to stderr, so the capsys assertions could never match. The
React assertion also carried a line break from rich's console wrapping;
log records are unwrapped.
StateManagerDisk resolved the relative .states path on every call, so a
cwd change after startup (as AppHarness does) made every write-queue
cycle raise FileNotFoundError from _purge_expired_states. Resolve it to
an absolute path in the cached property. Log the expected closed-file
ValueError in AppHarness at debug instead of error.
@FarhanAliRaza
FarhanAliRaza force-pushed the farhan/eng-10963-log-3-migrate-core branch from 2942cd0 to 89a637c Compare August 19, 2026 16:55
@FarhanAliRaza
FarhanAliRaza merged commit d28be54 into main Aug 19, 2026
121 of 122 checks passed
@FarhanAliRaza
FarhanAliRaza deleted the farhan/eng-10963-log-3-migrate-core branch August 19, 2026 18:02
masenf pushed a commit that referenced this pull request Aug 28, 2026
client_error (#6827): mismatch scenarios produce actionable errors and
fatal sessions as designed; sanitization/truncation/rate-limits verified
via raw socket.io probing. Found: a no-argument client_error emit raises
an unhandled TypeError, bypassing the anti-abuse guards.

logging_cli (#6863/#6865/#6867/#6924): JSON-lines purity verified for
reflex-owned logs across init/export/run; deprecation shims and missing
hosting-cli fallbacks work. Found: REFLEX_ENABLE_FULL_LOGGING's worker
file handler is closed (records silently dropped, stdout JSON purity
broken) and granian's own lines break strict --json parsing at debug
level.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EMjBXPozsNeQNSBZecNH8x
masenf pushed a commit that referenced this pull request Aug 28, 2026
A ~29s 1920x1080 motion graphic covering the end-user-facing changes in
0.9.9, sourced from the 0.9.9a1 and 0.9.9a2 changelog entries across
reflex, reflex-base, the component packages and reflex-hosting-cli.

Nine beats: the dev-mode main-thread win (#6905), call-site
auto-memoization of @rx.memo (#6949), the move to React Router 8 (#6854),
DevTools component naming (#6945), stdlib logging with --json plus the
client_error report (#6863, #6865, #6827), the cloud CLI's whoami/token
and autoscaling flags (#6918, #6884, #6948), and a grid of the smaller
fixes a user would notice (#6786, #6593, #6944, #6971, #6790, #6920).

Styled to match reflex.dev by reusing its design system rather than
approximating it: the dark violet/slate scales, wave-line motif, radial
bloom and type scale come from reflex-site-shared, and the fonts are the
same @fontsource-variable Instrument Sans and JetBrains Mono files the
site serves.

Source only — the rendered mp4 is a build artifact, regenerated by
`npm run build` and ignored. Lives outside the packaged tree (hatch only
includes /reflex), so it does not affect the published wheel or sdist.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016arkVKmoogzUtZNfZZSvSo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants