Skip to content

fix: make custom server setup more resilient#1277

Merged
UladzislauK-Writer merged 1 commit intodevfrom
vlad/AB-950
Feb 3, 2026
Merged

fix: make custom server setup more resilient#1277
UladzislauK-Writer merged 1 commit intodevfrom
vlad/AB-950

Conversation

@UladzislauK-Writer
Copy link
Copy Markdown
Collaborator

@UladzislauK-Writer UladzislauK-Writer commented Feb 3, 2026

Summary by CodeRabbit

  • New Features
    • Server setup errors and informational messages are now captured and displayed to users during the app initialization process.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

The changes introduce error handling for custom server setup operations. A new AdditionalMail data model is added to capture and propagate setup errors, which are then collected during server initialization and passed through the session init flow to populate the session state.

Changes

Cohort / File(s) Summary
Error Handling Model
src/writer/ss_types.py
Introduced AdditionalMail data model with type, title, message, and optional code fields. Extended InitSessionRequestPayload to carry a list of these mail entries.
Server Setup Error Capture
src/writer/serve.py
Added traceback import and error handling logic. Wrapped server setup hook execution in try/except to capture errors and append them to custom_server_setup_mail list. Passed this list as additionalMail parameter during session initialization.
Session Mail Processing
src/writer/app_runner.py
Added logic in _handle_session_init to iterate over payload.additionalMail and add each mail entry to session state via add_log_entry().

Sequence Diagram(s)

sequenceDiagram
    participant Server Setup
    participant Error Handler
    participant Session Init
    participant Session State

    Server Setup->>Error Handler: Execute setup hook
    alt Setup fails
        Error Handler->>Error Handler: Catch exception
        Error Handler->>Error Handler: Create AdditionalMail entry
        Error Handler->>Session Init: Pass additionalMail list
    else Setup succeeds
        Error Handler->>Session Init: Pass empty additionalMail
    end
    
    Session Init->>Session State: Process each AdditionalMail
    Session State->>Session State: add_log_entry() for each mail
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 When setup stumbles, we now gracefully capture the fall,
Each error bundled in mail, delivered to one and all,
No silent crashes in the night—we log them with care,
A resilient dance of try and catch, beyond compare! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main purpose of the changes: making custom server setup more resilient by capturing and handling setup errors.
Linked Issues check ✅ Passed The linked issue AB-950 lacks detailed requirements; the changes implement error handling for server setup, which aligns with the objective to make it more resilient.
Out of Scope Changes check ✅ Passed All changes are focused on making server setup resilient by adding error capture, handling, and propagation mechanisms without introducing unrelated modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vlad/AB-950

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/writer/serve.py`:
- Line 16: The broad bare except in src/writer/serve.py (around the block
spanning lines 967–976) must log the exception so failures aren't silent: in the
except Exception handler, call logging.exception(...) to record the stacktrace
and error context, and append a "# noqa: BLE001" comment to the except line to
acknowledge the broad catch; update any local variable references in the log
message to provide context (e.g., session or request identifiers) and ensure the
logging module is imported at the top of the file if not already.
🧹 Nitpick comments (1)
src/writer/ss_types.py (1)

149-153: Avoid a mutable default for additionalMail.

Even if Pydantic handles mutable defaults safely, Field(default_factory=list) is the safer, idiomatic choice and prevents any cross-request state bleed if behavior changes.

♻️ Proposed change
-from pydantic import BaseModel
+from pydantic import BaseModel, Field
@@
-    additionalMail: list[AdditionalMail] = []
+    additionalMail: list[AdditionalMail] = Field(default_factory=list)

import tempfile
import textwrap
import time
import traceback
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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

find . -name "serve.py" -path "*/writer/*" | head -20

Repository: writer/writer-framework

Length of output: 88


🏁 Script executed:

wc -l src/writer/serve.py

Repository: writer/writer-framework

Length of output: 91


🏁 Script executed:

sed -n '10,25p' src/writer/serve.py

Repository: writer/writer-framework

Length of output: 365


🏁 Script executed:

sed -n '960,980p' src/writer/serve.py

Repository: writer/writer-framework

Length of output: 625


🏁 Script executed:

head -20 src/writer/serve.py

Repository: writer/writer-framework

Length of output: 429


🏁 Script executed:

sed -n '967,976p' src/writer/serve.py

Repository: writer/writer-framework

Length of output: 430


🏁 Script executed:

grep -n "except Exception" src/writer/serve.py

Repository: writer/writer-framework

Length of output: 312


🏁 Script executed:

grep -n "logging\." src/writer/serve.py | head -20

Repository: writer/writer-framework

Length of output: 373


🏁 Script executed:

sed -n '590,595p' src/writer/serve.py

Repository: writer/writer-framework

Length of output: 328


🏁 Script executed:

sed -n '787,805p' src/writer/serve.py

Repository: writer/writer-framework

Length of output: 1038


🏁 Script executed:

sed -n '14,18p' src/writer/serve.py

Repository: writer/writer-framework

Length of output: 178


Add logging to the exception handler to prevent silent failures.

The bare except Exception at line 969 should include explicit logging. Currently, if no session is created, the error remains invisible. Add logging.exception() and a # noqa: BLE001 comment to address the broad exception catch while making failures visible.

🛠️ Suggested adjustment
     if enable_server_setup is True:
         try:
             _execute_server_setup_hook(user_app_path)
-        except Exception as e:
+        except Exception as e:  # noqa: BLE001
+            logging.exception("Custom server setup failed")
             custom_server_setup_mail.append(
                 {
                     "type": "error",
                     "title": "Custom server setup error",
                     "message": str(e),
                     "code": traceback.format_exc()
                 }
             )

Also applies to: 967-976

🤖 Prompt for AI Agents
In `@src/writer/serve.py` at line 16, The broad bare except in src/writer/serve.py
(around the block spanning lines 967–976) must log the exception so failures
aren't silent: in the except Exception handler, call logging.exception(...) to
record the stacktrace and error context, and append a "# noqa: BLE001" comment
to the except line to acknowledge the broad catch; update any local variable
references in the log message to provide context (e.g., session or request
identifiers) and ensure the logging module is imported at the top of the file if
not already.

@pullrequest
Copy link
Copy Markdown

pullrequest bot commented Feb 3, 2026

HackerOne Code Security Review

🟢 Scan Complete: 2 Issue(s)
🟢 Validation Complete: Any Issues detected were validated by one of our engineers. None were determined to require immediate action.

Here's how the code changes were interpreted and info about the tools used for scanning.

📖 Summary of Changes The changes focus on enhancing mail entry handling during session initialization across multiple files. A new `AdditionalMail` class was introduced to support additional mail messages with type, title, and optional details. The modifications enable capturing and processing supplementary mail entries during server setup and session initialization, improving error handling and logging capabilities.
File Summary
src/writer/app_runner.py The code has been updated to add support for additional mail entries during session initialization. A new loop has been added in the _handle_session_init method to process additionalMail from the initialization payload, which allows adding log entries to the session state before further processing.
src/writer/serve.py The changes include adding error handling for the server setup hook by introducing a custom_server_setup_mail list to capture and pass any errors that occur during server setup, and modifying the init_session method to include this additional mail information.
src/writer/ss_types.py A new AdditionalMail class was added to the InitSessionRequestPayload class, introducing a list of additional mail messages with type, title, message, and optional code fields.
ℹ️ Issues Detected

NOTE: These may not require action!

Below are unvalidated results from the Analysis Tools that ran during the latest scan for transparency. We investigate each of these for accuracy and relevance before surfacing them as a potential problem.

How will I know if something is a problem?
When validation completes, any concerns that warrant attention prior to merge will be posted as inline comments. These will show up in 2 ways:

  • Expert review (most cases): Issues will be posted by experts who manually reviewed and validated them. These are real HackerOne engineers (not bots) reviewing through an integrated IDE-like tool. You can communicate with them like any other reviewer. They'll stay assigned and get notified with commit & comment updates.
  • Automatically: In cases where our validation checks have highest confidence the problem is legitimate and urgent. These will include a description of contextual reasoning why & actionable next steps.
File & Line Issue
src/writer/app_runner.py Line 175 The code adds log entries from user-controlled payload (additionalMail) without validation. The mail.model_dump() is called on each item in payload.additionalMail, but there's no verification that these entries are safe or sanitized before being added to the session state. If the additionalMail payload contains malicious content (e.g., XSS payloads in log messages), this could be stored and later rendered in the UI, potentially leading to stored XSS vulnerabilities. The add_log_entry method should validate and sanitize the input parameters before storing them.
src/writer/serve.py Line 975 Exception details including full traceback are being exposed to the client via the 'custom_server_setup_mail' mechanism. The traceback (line 975: traceback.format_exc()) can leak sensitive information about the application's internal structure, file paths, environment details, and potentially credentials or API keys that might be present in the stack trace. This information is then sent to the frontend via 'additionalMail' (line 357) during session initialization, making it accessible to any client that can initiate a session. Consider logging the full traceback server-side only and sending a sanitized error message to the client.
🧰 Analysis tools

⏱️ Latest scan covered changes up to commit b61e9c9 (latest)

@pullrequest
Copy link
Copy Markdown

pullrequest bot commented Feb 3, 2026

✅ Graham C reviewed all the included code changes and associated automation findings and determined that there were no immediately actionable security flaws. Note that they will continue to be notified of any new commits or comments and follow up as needed throughout the duration of this pull request's lifecycle.

Image of Graham C Graham C


Reviewed with ❤️ by PullRequest

@UladzislauK-Writer UladzislauK-Writer merged commit 29ea53e into dev Feb 3, 2026
16 checks passed
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.

1 participant