Skip to content

fix: [Bug] Close the app when Opening (issue #8487)#8522

Closed
ipezygj wants to merge 13 commits intoAppFlowy-IO:mainfrom
ipezygj:fix-opus-8487-1771841480
Closed

fix: [Bug] Close the app when Opening (issue #8487)#8522
ipezygj wants to merge 13 commits intoAppFlowy-IO:mainfrom
ipezygj:fix-opus-8487-1771841480

Conversation

@ipezygj
Copy link

@ipezygj ipezygj commented Feb 23, 2026

🧙‍♂️ Gandalf AI (Claude 4.5 Opus) fix for #8487

Summary by Sourcery

Improve collaborative document initialization robustness and add an experimental automation script.

Bug Fixes:

  • Prevent app crashes when building a collab instance fails by handling blocking task join errors more gracefully.
  • Avoid closing the app when acquiring a collab write lock fails by returning the existing collab instead of propagating the error.

Enhancements:

  • Add structured logging around collab initialization and lock acquisition failures to aid debugging.

Chores:

  • Introduce a Gandalf AI helper script for automating issue-based fixes and PR creation.
  • Add a placeholder contributing guide file and minor README/test comment updates.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 23, 2026

Reviewer's Guide

Improves robustness of collab building and locking in Rust by handling spawn_blocking join errors and write-lock acquisition failures more gracefully, but also introduces unrelated AI-automation scaffolding, comments, and files that should likely be excluded from this bugfix PR.

Sequence diagram for robust collab building with spawn_blocking

sequenceDiagram
    participant AppFlowyCollabBuilder as AppFlowyCollabBuilder
    participant Tokio as TokioRuntime
    participant Blocker as BlockingThread
    participant CollabBuilder as CollabBuilder
    participant Collab as Collab
    participant Logger as Logger

    AppFlowyCollabBuilder->>Tokio: spawn_blocking(closure)
    Tokio-->>Blocker: run closure on blocking thread
    Blocker->>CollabBuilder: new(object_uid, object_id, data_source)
    CollabBuilder-->>Blocker: builder
    Blocker->>CollabBuilder: with_device_id(device_id)
    CollabBuilder-->>Blocker: builder
    Blocker->>CollabBuilder: build()
    CollabBuilder-->>Blocker: Result<Collab, Error>
    Blocker->>Collab: add_plugin(db_plugin)
    Blocker-->>Tokio: Ok(Result<Collab, Error>)
    Tokio-->>AppFlowyCollabBuilder: JoinHandle result (collab_result)

    alt join ok and build ok
        AppFlowyCollabBuilder->>AppFlowyCollabBuilder: match collab_result
        AppFlowyCollabBuilder-->>AppFlowyCollabBuilder: Ok(collab)
    else join ok but build error
        AppFlowyCollabBuilder->>AppFlowyCollabBuilder: match collab_result
        AppFlowyCollabBuilder-->>AppFlowyCollabBuilder: Err(e)
    else join error
        AppFlowyCollabBuilder->>Logger: error(Failed to spawn blocking task...)
        AppFlowyCollabBuilder-->>AppFlowyCollabBuilder: Err(anyhow!(task join error))
    end
Loading

Sequence diagram for finalize write-lock acquisition with graceful failure

sequenceDiagram
    participant AppFlowyCollabBuilder as AppFlowyCollabBuilder
    participant Collab as Collab
    participant Logger as Logger

    AppFlowyCollabBuilder->>Collab: try_write()
    alt write lock acquired
        Collab-->>AppFlowyCollabBuilder: Ok(write_guard)
        AppFlowyCollabBuilder->>AppFlowyCollabBuilder: check has_cloud_plugin()
        alt has_cloud_plugin
            AppFlowyCollabBuilder->>AppFlowyCollabBuilder: drop(write_guard)
            AppFlowyCollabBuilder-->>AppFlowyCollabBuilder: continue finalize with cloud plugin
        else no cloud plugin
            AppFlowyCollabBuilder-->>AppFlowyCollabBuilder: continue finalize without cloud plugin
        end
    else write lock error
        Collab-->>AppFlowyCollabBuilder: Err(e)
        AppFlowyCollabBuilder->>Logger: warn(Failed to acquire write lock...)
        AppFlowyCollabBuilder-->>AppFlowyCollabBuilder: return Ok(collab) (unchanged)
    end
Loading

Class diagram for updated AppFlowyCollabBuilder collab lifecycle

classDiagram
    class AppFlowyCollabBuilder {
        +build_collab() Result~Collab, Error~
        +finalize(collab: ArcRwLockCollab) Result~ArcRwLockCollab, Error~
    }

    class CollabBuilder {
        +new(uid: Uuid, object_id: String, data_source: DataSource) CollabBuilder
        +with_device_id(device_id: String) CollabBuilder
        +build() Result~Collab, Error~
    }

    class Collab {
        +add_plugin(plugin: BoxPlugin)
        +has_cloud_plugin() bool
    }

    class ArcRwLockCollab {
        +try_write() Result~WriteGuard, LockError~
    }

    class WriteGuard {
        +borrow() CollabRef
    }

    class CollabRef {
        +has_cloud_plugin() bool
    }

    AppFlowyCollabBuilder ..> CollabBuilder : uses to build
    AppFlowyCollabBuilder ..> ArcRwLockCollab : manages finalize
    ArcRwLockCollab o--> Collab : wraps
    WriteGuard o--> CollabRef : borrows
    CollabRef ..> Collab : references
Loading

File-Level Changes

Change Details Files
Handle collab builder spawn_blocking and lock acquisition errors without crashing the app.
  • Wrap the blocking collab construction task in a variable and await it once, capturing the JoinHandle result instead of using the previous double-? pattern.
  • On successful task completion, return the built collab as before; if the inner builder returns an error, propagate it unchanged.
  • If the blocking task itself panics or is cancelled, log an error and return an anyhow error describing the join failure instead of letting the panic propagate.
  • Replace direct collab.try_write()? usage with explicit pattern matching; on lock acquisition failure, log a warning and return the original collab without applying further mutations.
frontend/rust-lib/collab-integrate/src/collab_builder.rs
Adds AI-related scaffolding and comments that appear unrelated to the stated bugfix and production codebase.
  • Introduce a new gandalf_botti.py script that automates forking the repo, creating branches, modifying Rust files via AI, running git commands, and opening PRs via the GitHub CLI, including storing a GitHub token in the environment for commands.
  • Add multiple Gandalf/AI-related comment stubs in various Rust integration test and test files referencing unrelated issues and feature requests.
  • Create an essentially empty CONTRIBUTING.md file and append blank lines to README.md, which do not contribute to the fix and may clutter the repo history.
gandalf_botti.py
frontend/rust-lib/event-integration-test/src/chat_event.rs
frontend/rust-lib/dart-ffi/src/appflowy_yaml.rs
frontend/rust-lib/event-integration-test/src/database_event.rs
frontend/rust-lib/flowy-document/tests/file_storage.rs
CONTRIBUTING.md
README.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 security issues, and left some high level feedback:

Security issues:

  • Detected subprocess function 'check_output' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'. (link)
  • Found 'subprocess' function 'check_output' with 'shell=True'. This is dangerous because this call will spawn the command using a shell process. Doing so propagates current shell settings and variables, which makes it much easier for a malicious actor to execute commands. Use 'shell=False' instead. (link)

General comments:

  • The new gandalf_botti.py automation script and the empty CONTRIBUTING.md file don’t appear related to the crash bug being fixed and should be removed from this PR to keep it focused on the runtime issue.
  • The added AI-related comments in various Rust test files and the extra blank lines in README.md introduce noise without functional benefit; consider reverting those hunks to avoid cluttering the codebase.
  • In finalize, swallowing try_write errors by logging a warning and returning Ok(collab) changes the locking semantics silently; it would be better either to propagate the error or handle it in a way that makes the degraded behavior explicit to callers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `gandalf_botti.py` automation script and the empty `CONTRIBUTING.md` file don’t appear related to the crash bug being fixed and should be removed from this PR to keep it focused on the runtime issue.
- The added AI-related comments in various Rust test files and the extra blank lines in `README.md` introduce noise without functional benefit; consider reverting those hunks to avoid cluttering the codebase.
- In `finalize`, swallowing `try_write` errors by logging a warning and returning `Ok(collab)` changes the locking semantics silently; it would be better either to propagate the error or handle it in a way that makes the degraded behavior explicit to callers.

## Individual Comments

### Comment 1
<location> `gandalf_botti.py:9` </location>
<code_context>
        return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, env=env).decode('utf-8')
</code_context>

<issue_to_address>
**security (python.lang.security.audit.dangerous-subprocess-use-audit):** Detected subprocess function 'check_output' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

*Source: opengrep*
</issue_to_address>

### Comment 2
<location> `gandalf_botti.py:9` </location>
<code_context>
        return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, env=env).decode('utf-8')
</code_context>

<issue_to_address>
**security (python.lang.security.audit.subprocess-shell-true):** Found 'subprocess' function 'check_output' with 'shell=True'. This is dangerous because this call will spawn the command using a shell process. Doing so propagates current shell settings and variables, which makes it much easier for a malicious actor to execute commands. Use 'shell=False' instead.

```suggestion
        return subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT, env=env).decode('utf-8')
```

*Source: opengrep*
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

token = subprocess.getoutput("gh auth token").strip()
env["GITHUB_TOKEN"] = token
try:
return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, env=env).decode('utf-8')
Copy link
Contributor

Choose a reason for hiding this comment

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

security (python.lang.security.audit.dangerous-subprocess-use-audit): Detected subprocess function 'check_output' without a static string. If this data can be controlled by a malicious actor, it may be an instance of command injection. Audit the use of this call to ensure it is not controllable by an external resource. You may consider using 'shlex.escape()'.

Source: opengrep

token = subprocess.getoutput("gh auth token").strip()
env["GITHUB_TOKEN"] = token
try:
return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, env=env).decode('utf-8')
Copy link
Contributor

Choose a reason for hiding this comment

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

security (python.lang.security.audit.subprocess-shell-true): Found 'subprocess' function 'check_output' with 'shell=True'. This is dangerous because this call will spawn the command using a shell process. Doing so propagates current shell settings and variables, which makes it much easier for a malicious actor to execute commands. Use 'shell=False' instead.

Suggested change
return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, env=env).decode('utf-8')
return subprocess.check_output(cmd, shell=False, stderr=subprocess.STDOUT, env=env).decode('utf-8')

Source: opengrep

@LucasXu0 LucasXu0 closed this Feb 23, 2026
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ipezygj seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

3 participants