Skip to content

ci: add Semgrep OSS scanning workflow#1376

Merged
whoiskatrin merged 6 commits into
mainfrom
hrushikesh/add-semgrep-oss-workflow
May 5, 2026
Merged

ci: add Semgrep OSS scanning workflow#1376
whoiskatrin merged 6 commits into
mainfrom
hrushikesh/add-semgrep-oss-workflow

Conversation

@hrushikeshdeshpande
Copy link
Copy Markdown
Contributor

@hrushikeshdeshpande hrushikeshdeshpande commented Apr 23, 2026

Summary

Adds Semgrep Community Edition (OSS) scanning to this repository as part of the App&ProdSec team's migration from Semgrep Pro to Semgrep CE, plus a fix for the closed-WebSocket replay race in agents/chat.

Semgrep workflow

  • Runs on every PR, on push to the main/master branch, and on the first Saturday of each month.
  • Uses actions/cache@v5 so pip install semgrep only runs on cold cache (first run, version bump, or 7-day idle).
  • Pinned to semgrep==1.160.0 with --config=auto (default OSS ruleset).
  • Runs on ubuntu-slim with contents: read token scope.
  • A small gate job filters scheduled runs to the first 7 days of the month so the schedule means "first Saturday only" without relying on POSIX cron's day-of-month / day-of-week OR semantics.

Closed-WebSocket replay race (agents/chat)

  • ResumableStream.replayChunks and replayCompletedChunksByRequestId route every connection.send() through a sendIfOpen helper that swallows the TypeError: WebSocket send() after close race and reports failure to the caller.
  • The matching fallback in @cloudflare/ai-chat's stream-resume ACK handler also goes through sendIfOpen.
  • If the socket drops mid-replay during replayChunks, the stream is left active so the next reconnect can retry from the start. The orphan-cleanup branch still calls complete() and returns the stream id even if the final done send misses, so the caller persists the reconstructed message regardless of whether this particular socket received the frame.

Review & Testing Checklist for Human

  • Confirm the gate job + 0 0 * * 6 cron is acceptable for the App&ProdSec team's "monthly, staggered" intent (vs. accepting the original ~10x/month POSIX-OR schedule).
  • Sanity check that triggering this workflow via workflow_dispatch on main after merge produces a Semgrep findings summary as expected.
  • (Optional) Decide whether @cloudflare/think's _handleStreamResumeAck fallback should mirror the sendIfOpen change here in a follow-up PR — Devin Review flagged the same pattern in packages/think/src/think.ts:2601, but the original author marked the think.ts path as out of this PR's scope.

Notes

  • Devin Review feedback addressed in this PR: bumped actions/checkout@v6 for consistency, gated the cron schedule, and wrapped the remaining bare connection.send() calls in replayChunks.
  • The @cloudflare/think consumer of replayCompletedChunksByRequestId still uses a bare connection.send() and was intentionally left out of scope here.

Link to Devin session: https://app.devin.ai/sessions/303193c332f24e08b4c8525adb58e285
Requested by: @whoiskatrin


Open in Devin Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

🦋 Changeset detected

Latest commit: fdd982c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/ai-chat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

whoiskatrin and others added 2 commits May 5, 2026 11:28
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@whoiskatrin whoiskatrin force-pushed the hrushikesh/add-semgrep-oss-workflow branch from 517bd09 to 7c9fa07 Compare May 5, 2026 12:47
devin-ai-integration[bot]

This comment was marked as resolved.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1376

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1376

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1376

hono-agents

npm i https://pkg.pr.new/hono-agents@1376

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1376

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1376

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1376

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1376

commit: fdd982c

Address Devin Review feedback:
- packages/agents/src/chat/resumable-stream.ts: wrap remaining bare
  connection.send() calls in replayChunks with sendIfOpen so a
  WebSocket closing mid-replay no longer throws.
- .github/workflows/semgrep.yml: switch the schedule to '0 0 * * 6'
  and add a gate job that filters scheduled runs to the first
  Saturday of each month, avoiding POSIX cron's day-of-month /
  day-of-week OR semantics.
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 11 additional findings in Devin Review.

Open in Devin Review

Comment thread packages/agents/src/chat/resumable-stream.ts
@whoiskatrin whoiskatrin merged commit 6561a3f into main May 5, 2026
8 checks passed
@whoiskatrin whoiskatrin deleted the hrushikesh/add-semgrep-oss-workflow branch May 5, 2026 13:30
@github-actions github-actions Bot mentioned this pull request May 5, 2026
whoiskatrin added a commit that referenced this pull request May 5, 2026
Mirror the sendIfOpen pattern that ai-chat already uses for the
stream-resume ACK fallback. Without this, when the WebSocket closes
during ResumableStream.replayCompletedChunksByRequestId the method
now returns false (since #1376), and the fallback bare connection.send()
in _handleStreamResumeAck throws TypeError: WebSocket send() after close
up through onMessage.
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