Skip to content

Add proper binary guards for authorize_refresh/1 - #3924

Open
michaeljguarino wants to merge 3 commits into
masterfrom
fix-jwt-length
Open

Add proper binary guards for authorize_refresh/1#3924
michaeljguarino wants to merge 3 commits into
masterfrom
fix-jwt-length

Conversation

@michaeljguarino

Copy link
Copy Markdown
Member

Trying to plug random conditions that htrow errors.

Test Plan

Test environment: https://console.your-env.onplural.sh/

Checklist

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have deployed the agent to a test environment and verified that it works as expected (required only when changing agent code).

Plural Flow: console

Trying to plug random conditions that htrow errors.
@michaeljguarino
michaeljguarino requested a review from a team July 28, 2026 21:37
@michaeljguarino michaeljguarino added the enhancement New feature or request label Jul 28, 2026
@soffi-ai

soffi-ai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Soffi AI Summary

This PR addresses two distinct stability and behavioral improvements in the chatbot/AI subsystem:

  1. Binary guard for authorize_refresh/1 — Adds a proper when is_binary(token) guard to the function and a fallback clause returning {:error, "no refresh token provided"}. This prevents runtime errors when nil or non-binary values are passed as refresh tokens, hardening the auth path against unexpected input.

  2. Improved chatbot reply behavior — Changes how follow-up messages (replies to prior chatbot messages in a thread) are handled. Previously, a reply would create a WorkbenchJobActivity directly and mark the job as :pending, which could conflict with an already-running job. Now, replies create a QueuedPrompt with an immediate dequeable_at timestamp, allowing the system to enqueue the follow-up safely regardless of the job's current status (running, successful, etc.). A dedicated EEx prompt template (chat_reply.md.eex) is introduced to render the follow-up context separately from new-message prompts, giving the agent clear instructions to continue the existing job thread. The parent_job/1 helper is also simplified to return the job regardless of its status, enabling replies even when the parent job is still active.

Commits

Commit Summary
39c25ca Adds a when is_binary(token) guard to authorize_refresh/1 and a fallback clause to return a clean error tuple instead of crashing when called with a non-binary (e.g., nil) value.
52952a8 Switches chatbot thread replies from creating a WorkbenchJobActivity to creating a QueuedPrompt with an immediate dequeue time, enabling safe reply enqueueing regardless of the parent job's current status. Simplifies parent_job/1 to return the job unconditionally and adds a new chat_reply.md.eex prompt template for follow-up context.
7315c57 Tunes the chatbot reply prompt and related test assertions, refining the reply message wording and verifying the new QueuedPrompt fields and job state expectations.

Deploy in Soffi


Updated: 2026-07-28 23:08 UTC

@greptile-apps

greptile-apps Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds defensive refresh-token handling.

  • Restricts the existing refresh-token lookup path to binary tokens.
  • Returns an explicit error tuple when authorize_refresh/1 receives any non-binary value.

Confidence Score: 5/5

The PR appears safe to merge, with no actionable defects identified in the changed refresh-token handling.

The normal GraphQL path already supplies a required string token, while direct non-binary calls now return the service's established error-tuple shape instead of entering the database lookup.

Important Files Changed

Filename Overview
lib/console/services/users.ex Adds a binary guard and safe fallback to prevent malformed refresh-token values from reaching the token lookup.

Reviews (1): Last reviewed commit: "Add proper binary guards for authorize_r..." | Re-trigger Greptile

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot 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.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot 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.

@michaeljguarino

Copy link
Copy Markdown
Member Author

plural deploy this

@plural-copilot plural-copilot 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant