Skip to content

Fix superfluous WriteHeader in bot connect digest handler - #2383

Open
lieut-data wants to merge 1 commit into
masterfrom
fix-digest-double-writeheader
Open

Fix superfluous WriteHeader in bot connect digest handler#2383
lieut-data wants to merge 1 commit into
masterfrom
fix-digest-double-writeheader

Conversation

@lieut-data

@lieut-data lieut-data commented Jul 27, 2026

Copy link
Copy Markdown
Member

Summary

Fix http: superfluous response.WriteHeader call as seen on Hub ERROR logs -- BotHandler.connect() (GET /bot/connect) always wrote w.WriteHeader(http.StatusOK) at the end, even when the digest-sending closure it just invoked had already written an error response via HandleError.

Now we rely (and test!) on net/http's implicit 200 on success -- note that I opted not to add all the mock infrastructure just to verify that we don't emit the superfluous headers themselves. Instead, just verifying the end-user visible semantics.

Checklist

  • Gated by experimental feature flag
  • Unit tests updated
  • Planned cherry-picks: release-X.Y

@lieut-data
lieut-data force-pushed the fix-digest-double-writeheader branch 5 times, most recently from 5feffa1 to 4766f17 Compare July 27, 2026 18:05
@lieut-data
lieut-data force-pushed the fix-digest-double-writeheader branch from 4766f17 to 8a4f6f4 Compare July 27, 2026 18:11
@lieut-data
lieut-data marked this pull request as ready for review July 27, 2026 18:14
@lieut-data
lieut-data enabled auto-merge (squash) July 27, 2026 18:15
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The bot connect handler now returns after invoking the selected digest sender without explicitly writing a success status. End-to-end coverage verifies successful responses, first-request digest delivery, and suppression of an immediate duplicate digest.

Changes

Bot connect behaviour

Layer / File(s) Summary
Connect response and digest validation
server/api/bot.go, server/api_bot_test.go
The handler relies on the default successful response, while TestBotConnect verifies digest direct-message delivery on the first request and no new digest on an immediate second request.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: removing a redundant WriteHeader call in the bot connect handler.
Description check ✅ Passed The description is directly related to the change and its tests, so it is clearly on-topic.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-digest-double-writeheader

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/api_bot_test.go`:
- Around line 101-105: Update the second-connect verification around
GetPostsSince to query from digestPost.CreateAt minus one millisecond, then
exclude digestPost.Id when checking for duplicates. Ensure the assertion fails
if any other post appears, including one created in the same millisecond as
digestPost.
- Around line 76-105: The connect tests currently cover only successful
responses and do not exercise the changed error path. Add a sender-failure test
around the bot connect handler using a response-writer spy, force the digest
send to fail, and assert that HandleError is not followed by a second
WriteHeader; retain the existing successful-connect assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6cbdaac0-53a3-4eee-907d-1368ddeb4c80

📥 Commits

Reviewing files that changed from the base of the PR and between 2192568 and 8a4f6f4.

📒 Files selected for processing (2)
  • server/api/bot.go
  • server/api_bot_test.go
💤 Files with no reviewable changes (1)
  • server/api/bot.go

Comment thread server/api_bot_test.go
Comment thread server/api_bot_test.go

@cursor cursor 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.

This PR is a bug fix: it removes a superfluous w.WriteHeader(http.StatusOK) in BotHandler.connect() that can run after the digest sender has already written an error via HandleError, producing Hub http: superfluous response.WriteHeader call noise. Supported lines come from the Version Support table in README on master. Each supported Playbooks release still has the same double-write pattern in server/api/bot.go, and the fix applies cleanly there — so cherry-picks are recommended for all currently supported release branches (master itself is the PR target).

MM version Playbooks branch Cherry Pick? Reason
master master No PR already targets master
v11.10 release-2.11 Yes Bug present; fix applies cleanly
v11.9 release-2.10 Yes Bug present; fix applies cleanly
v11.8 release-2.9 Yes Bug present; fix applies cleanly
v11.7 ESR release-2.9 Yes Bug present; fix applies cleanly
v10.11 ESR release-2.4 Yes Bug present; fix applies cleanly
Open in Web View Automation 

Sent by Cursor Automation: Playbooks cherry pick recommender

Comment thread server/api_bot_test.go
Comment thread server/api_bot_test.go

// GetPostsSince is exclusive (server queries UpdateAt > since), so digestPost
// itself won't reappear here.
sincePosts, _, err := e.ServerClient.GetPostsSince(context.Background(), dmChannel.Id, digestPost.CreateAt, false)

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.

Because we're using a global variables here and the subtests are dependent, we should require.NotNil on digestPost.

Having the protection inside for first subtest does not protect the second one, and the second subtest will panic.

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