Fix AI bot messages rendered as user messages on staging#4253
Conversation
… 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>
|
hmmm, it looks like the change didn't work. would you mind if I debugged the factory in this branch? |
|
@habdelra yeah that would be great, thanks! |
|
@jurgenwerk ok--all green! |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
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
matrixServerNameviaMATRIX_SERVER_NAME(fallback to Matrix URL hostname). - Set
MATRIX_SERVER_NAMEexplicitly 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.
|
tested in staging and i can see ai assistant tool calls working now. |
Summary
matrixServerNamein the host app config withmatrixClient.matrixURL.hostname(e.g.matrix-staging.stack.cards), but the actual Matrix server_name used in user IDs isstack.cards(due to Matrix delegation)aiBotUserIdto be@aibot:matrix-staging.stack.cardsinstead of@aibot:stack.cards, so all AI bot messages were rendered as user messages — no Monaco editor, no diff view, no Apply buttonFix
MATRIX_SERVER_NAMEfrom environment inserver.ts, falling back to URL hostnameMATRIX_SERVER_NAME=stack.cardsin staging start scriptMATRIX_SERVER_NAME=boxel.aiin production start scriptMATRIX_SERVER_NAMEin software factory test harnessTest plan
boxel.ai)🤖 Generated with Claude Code