Skip to content

ENG-9646: Reflex Init --agents#6620

Open
amsraman wants to merge 1 commit into
mainfrom
aditya/init-agentsmd
Open

ENG-9646: Reflex Init --agents#6620
amsraman wants to merge 1 commit into
mainfrom
aditya/init-agentsmd

Conversation

@amsraman

@amsraman amsraman commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

b. Describe your changes.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

@linear-code

linear-code Bot commented Jun 5, 2026

Copy link
Copy Markdown

ENG-9646

@amsraman amsraman marked this pull request as ready for review June 5, 2026 21:58
@amsraman amsraman requested review from a team and Alek99 as code owners June 5, 2026 21:58
@greptile-apps

greptile-apps Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a --agents flag to reflex init that downloads a starter AGENTS.md from the canonical reflex-dev/agent-skills repo and writes it to the project root, while never overwriting an existing file. It also adds an AI-agent-oriented info block to the installation docs.

  • initialize_agents_md() in frontend_skeleton.py performs an HTTP fetch, guards against overwrites, and aborts on failure — but the exception handler only catches httpx.HTTPError, missing all httpx.RequestError subclasses (connection errors, timeouts), so network failures produce an unhandled traceback rather than the intended clean SystemExit(1). The same gap causes the bundled test_initialize_agents_md_aborts_on_fetch_failure test to fail since it raises httpx.ConnectError.
  • Constants and CLI wiring follow the existing project patterns cleanly.

Confidence Score: 3/5

The new --agents path has a real defect in its error handling that would produce an unhandled traceback on any network failure and would also break the bundled test verifying that behaviour.

The exception handler in initialize_agents_md catches only httpx.HTTPError, which does not cover httpx.RequestError subclasses (ConnectError, TimeoutException, etc.). Any network-level failure escapes as an unhandled exception, and the accompanying test that exercises exactly this failure mode would itself fail for the same reason. The rest of the change is straightforward and follows existing patterns.

reflex/utils/frontend_skeleton.py and tests/units/utils/test_utils.py need attention for the exception-handling gap.

Important Files Changed

Filename Overview
reflex/utils/frontend_skeleton.py Adds initialize_agents_md(); exception handler only catches httpx.HTTPError, missing RequestError subclasses (ConnectError, TimeoutException) so network failures escape unhandled.
tests/units/utils/test_utils.py Adds three tests for initialize_agents_md; test_initialize_agents_md_aborts_on_fetch_failure patches net.get to raise ConnectError but the production code won't catch it, so the test itself would fail.
packages/reflex-base/src/reflex_base/constants/config.py Adds AgentsMd SimpleNamespace with FILE and CANONICAL_URL constants; clean and follows existing patterns.
packages/reflex-base/src/reflex_base/constants/init.py Exports AgentsMd from constants; correctly added to both import and all.
reflex/reflex.py Adds --agents CLI flag wired to _init; correctly placed after gitignore init and before template messaging.
docs/ai_builder/integrations/agents_md.md Documentation updated to describe reflex init --agents; clear and accurate.
docs/getting_started/installation.md Adds an AI-agent-facing info block and starter rules file to the installation page; no functional impact.

Reviews (1): Last reviewed commit: "change source" | Re-trigger Greptile

Comment on lines +69 to +71
except httpx.HTTPError as e:
console.error(f"Failed to fetch AGENTS.md from {url} due to {e}.")
raise SystemExit(1) from None

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.

P1 httpx.HTTPError only covers HTTP-protocol-level errors (like HTTPStatusError for non-2xx responses). Network-level errors — httpx.ConnectError, httpx.TimeoutException, httpx.ReadTimeout, etc. — are subclasses of httpx.RequestError, which is not a subclass of httpx.HTTPError. If the GitHub raw URL is unreachable (DNS failure, timeout, firewall), the exception escapes unhandled and the user sees a raw traceback instead of the clean error message. The companion test test_initialize_agents_md_aborts_on_fetch_failure patches net.get to raise httpx.ConnectError and asserts SystemExit, but with the current catch clause that test will also fail at runtime because ConnectError is not caught.

Suggested change
except httpx.HTTPError as e:
console.error(f"Failed to fetch AGENTS.md from {url} due to {e}.")
raise SystemExit(1) from None
except (httpx.HTTPError, httpx.RequestError) as e:
console.error(f"Failed to fetch AGENTS.md from {url} due to {e}.")
raise SystemExit(1) from None

@codspeed-hq

codspeed-hq Bot commented Jun 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.37%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 24 untouched benchmarks
⏩ 8 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_from_event_type[lambda_event_spec] 53.8 µs 55.8 µs -3.42%
test_from_event_type[event_spec] 51.9 µs 53.7 µs -3.31%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing aditya/init-agentsmd (9f89e0b) with main (31f785e)

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.

- Use the [Reflex MCP server](/docs/ai-builder/integrations/mcp-overview) (`https://build.reflex.dev/mcp`) for live component/prop lookup so you don't hallucinate APIs. *(MCP access is an enterprise feature.)*
- Run `uv run reflex --version` and trust the live docs for that version over memory.

**Drop a rules file in the project root** (`AGENTS.md`, or `CLAUDE.md`/`.cursorrules` for your tool) so these conventions persist across your session — a starter is below.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

did you test the efficacy of this line

raise SystemExit(1) from None

console.debug(f"Creating {agents_file}")
agents_file.write_text(response.text)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should have a starter marker and finish marker so one can add other things in AGENTS.md

Comment thread reflex/reflex.py
Comment on lines +130 to +134
@click.option(
"--agents",
is_flag=True,
help="Write a sample AGENTS.md to guide AI coding agents working in the app.",
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i thought we wanted this be turned on by default?

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.

2 participants