Skip to content

Fix AI bot messages rendered as user messages on staging#4253

Merged
habdelra merged 8 commits intomainfrom
cs-10535-investigate-broken-code-formatting-in-staging
Mar 26, 2026
Merged

Fix AI bot messages rendered as user messages on staging#4253
habdelra merged 8 commits intomainfrom
cs-10535-investigate-broken-code-formatting-in-staging

Conversation

@jurgenwerk
Copy link
Contributor

Summary

  • The realm server was overriding matrixServerName in the host app config with matrixClient.matrixURL.hostname (e.g. matrix-staging.stack.cards), but the actual Matrix server_name used in user IDs is stack.cards (due to Matrix delegation)
  • This caused aiBotUserId to be @aibot:matrix-staging.stack.cards instead of @aibot:stack.cards, so all AI bot messages were rendered as user messages — no Monaco editor, no diff view, no Apply button
  • Introduced in b14a1cc ("Use dynamic software factory harness ports")

Fix

  • Read MATRIX_SERVER_NAME from environment in server.ts, falling back to URL hostname
  • Set MATRIX_SERVER_NAME=stack.cards in staging start script
  • Set MATRIX_SERVER_NAME=boxel.ai in production start script
  • Pass MATRIX_SERVER_NAME in software factory test harness

Test plan

  • Deploy to staging and verify AI bot messages show code editor / Apply button
  • Verify production config is correct (boxel.ai)
  • Run software factory tests

🤖 Generated with Claude Code

… mismatch

The realm server was overriding `matrixServerName` in the host app config
with `matrixClient.matrixURL.hostname` (e.g. `matrix-staging.stack.cards`),
but the actual Matrix server_name used in user IDs is different
(e.g. `stack.cards`) due to Matrix delegation/.well-known.

This caused `aiBotUserId` to be constructed as
`@aibot:matrix-staging.stack.cards` instead of `@aibot:stack.cards`,
so all AI bot messages were rendered as user messages — no code editor,
no diff view, no Apply button for code patches.

Fix: read `MATRIX_SERVER_NAME` from the environment (matching how the
host app already configures it), falling back to the URL hostname for
local dev where they're typically the same.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Mar 26, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   1h 58m 15s ⏱️ - 11m 5s
2 056 tests ±0  2 041 ✅ ±0  15 💤 ±0  0 ❌ ±0 
2 071 runs  ±0  2 056 ✅ ±0  15 💤 ±0  0 ❌ ±0 

Results for commit 65fe8c2. ± Comparison against base commit a059fc7.

♻️ This comment has been updated with latest results.

@habdelra
Copy link
Contributor

hmmm, it looks like the change didn't work. would you mind if I debugged the factory in this branch?

@jurgenwerk
Copy link
Contributor Author

@habdelra yeah that would be great, thanks!

@habdelra
Copy link
Contributor

@jurgenwerk ok--all green!

@habdelra habdelra marked this pull request as ready for review March 26, 2026 15:41
@habdelra habdelra requested a review from Copilot March 26, 2026 15:42
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7b1ed8074c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes incorrect Matrix server_name propagation into the host app configuration (notably on staging where Matrix delegation makes the homeserver URL hostname differ from the server_name used in Matrix user IDs), which caused AI bot messages to be treated/rendered as normal user messages.

Changes:

  • Allow realm-server to override matrixServerName via MATRIX_SERVER_NAME (fallback to Matrix URL hostname).
  • Set MATRIX_SERVER_NAME explicitly in staging/production start scripts.
  • Update software-factory harness and Synapse startup logic to support dynamic ports and pass MATRIX_SERVER_NAME.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/software-factory/src/harness/shared.ts Adjusts managed-process shutdown logic (stop/kill/exit waiting).
packages/software-factory/src/harness/isolated-realm-stack.ts Passes MATRIX_SERVER_NAME into realm-server/worker-manager env in the harness.
packages/realm-server/server.ts Uses process.env.MATRIX_SERVER_NAME when injecting host config.
packages/realm-server/scripts/start-staging.sh Sets MATRIX_SERVER_NAME=stack.cards for staging.
packages/realm-server/scripts/start-production.sh Sets MATRIX_SERVER_NAME=boxel.ai for production.
packages/matrix/docker/synapse/index.ts Introduces dynamic host-port selection and config templating changes for Synapse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@habdelra
Copy link
Contributor

tested in staging and i can see ai assistant tool calls working now.

@habdelra habdelra merged commit b891d7a into main Mar 26, 2026
136 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.

3 participants