Amazon Ergo 1.0 · Balanced
feature-can-edit-category-host-relationships-for-embedding-discourse-cursor
Discourse · Ruby · M · 100–299 lines · 6 files
The normal review, with one generalist agent. Judge: Claude Opus 5.5.
- Gold bugs found
- 3 of 10
- Comments published
- 5
- Comments matching a bug
- 3
- Comments not matching
- 2
- Cost of this PR
- $3.382
Published comments (5)
Nil dereference when embed_category matches no category — The upgrade aborts before the `category_id == 0` fallback can run: an unmatched `embed_category` makes `execute(...)[0]['id']` raise `NoMethodError`. Check `cmd_tuples` or `first` and fall back to `uncategorized_category_id` instead of indexing `[0]` directly.
Legacy embeddable_hosts values migrated without scheme/path normalization — Embedding silently stops for migrated hosts because scheme/path values never match the bare hostname from `URI#host` in `EmbeddableHost.record_for_host`. Normalize each value with the same stripping as `before_validation`, and insert it using `quote` rather than SQL interpolation.
Validated host ports can never match in record_for_host — A saved `example.com:3000` passes validation and appears in the admin UI, yet `host_allowed?` can never return true because `record_for_host` compares against `URI#host`, which omits the port. Reject ports in validation or compare host and port consistently.
Generic *_ids hydration can discard valid payload fields — Consumers lose `muted_category_ids` and `tracked_category_ids` to bogus `muted_categorys`/`tracked_categorys` arrays because no category pluralization is registered, and null `*_ids` values make `obj[k].map` throw. Only hydrate known sideloaded keys when `Array.isArray(obj[k])` and every `_lookupSubType` lookup succeeds, leaving the original key untouched otherwise.
Imports without an EmbeddableHost lose their category — Feed-polled topics can end up uncategorized because `TopicEmbed.import` relies solely on `EmbeddableHost.record_for_host(url)`, and arbitrary feed-item URLs often have no matching `EmbeddableHost` row. Preserve a default-category fallback, such as `SiteSetting.embed_category`, for those imports.