codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

fix(pull): read updated conversations from primary #107

Merged
pat-s merged 1 commit from t3code/fix-review-read-consistency into v16.0/forgejo-codefloe 2026-09-05 10:16:42 +00:00
Owner

Summary

  • Route the review conversation refetch through the primary database after comment and resolution mutations.
  • Add db.WithMaster, a reusable primary-scoped database context that reuses an existing transaction and closes its session.
  • Answer an unexpectedly empty conversation with 404 instead of indexing an empty slice in the template.
  • Drop the second LoadAttachments call in renderConversation, which reran on the replica and overwrote the attachments already loaded on the primary.
  • Resolve the web context through context.WebContextFromContext in the markup processor helper, so mentions and permalinks keep the Doer when rendering inside a db.WithMaster or db.WithTx callback.
  • Keep the change out of upstream files where possible: no engine.go hunk, context.go untouched, all new code and tests in _codefloe files.

Motivation

Forgejo's engine group routes autocommit reads to replicas.
Immediately after writing a review comment, replication lag can therefore make FetchCodeConversation return an empty slice.
The conversation template indexes the first comment, which then fails with a slice index out of range error even though the comment write succeeded.

This keeps ordinary reads on replicas and sends only the mutation response's conversation refetch to the primary.

Files

  • models/db/context_codefloe.go: WithMaster, built on the package's master engine like WithTx.
  • models/db/context_codefloe_test.go: stale replica vs primary read, error passthrough (typed errors stay assertable), transaction reuse.
  • routers/web/repo/pull_review_codefloe.go: fetchCodeConversationFromPrimary, reports an empty result as ErrCommentNotExist.
  • routers/web/repo/pull_review_codefloe_test.go: empty conversation renders 404.
  • routers/web/repo/pull_review.go: call the helper, NotFoundOrServerError, remove the duplicate attachment load.
  • services/context/context_codefloe.go: WebContextFromContext.
  • services/markup/processorhelper_codefloe_test.go: private user is mentionable from a wrapped web context.
  • services/markup/processorhelper.go: use WebContextFromContext for the two Doer lookups.

Testing

  • go vet -tags 'sqlite sqlite_unlock_notify' ./models/db ./routers/web/repo ./services/markup ./services/context
  • go test -race -count=1 -tags 'sqlite sqlite_unlock_notify' ./models/db ./services/markup ./services/context
  • go test -race -count=1 -tags 'sqlite sqlite_unlock_notify' ./routers/web/repo -run TestRenderConversation
  • golangci-lint run on the four packages with the pinned go1.26.7 toolchain: only a pre-existing modernize hit in routers/web/repo/pull.go:977, untouched by this PR.
  • git diff --check
## Summary - Route the review conversation refetch through the primary database after comment and resolution mutations. - Add `db.WithMaster`, a reusable primary-scoped database context that reuses an existing transaction and closes its session. - Answer an unexpectedly empty conversation with 404 instead of indexing an empty slice in the template. - Drop the second `LoadAttachments` call in `renderConversation`, which reran on the replica and overwrote the attachments already loaded on the primary. - Resolve the web context through `context.WebContextFromContext` in the markup processor helper, so mentions and permalinks keep the `Doer` when rendering inside a `db.WithMaster` or `db.WithTx` callback. - Keep the change out of upstream files where possible: no `engine.go` hunk, `context.go` untouched, all new code and tests in `_codefloe` files. ## Motivation Forgejo's engine group routes autocommit reads to replicas. Immediately after writing a review comment, replication lag can therefore make `FetchCodeConversation` return an empty slice. The conversation template indexes the first comment, which then fails with a slice index out of range error even though the comment write succeeded. This keeps ordinary reads on replicas and sends only the mutation response's conversation refetch to the primary. ## Files - `models/db/context_codefloe.go`: `WithMaster`, built on the package's master engine like `WithTx`. - `models/db/context_codefloe_test.go`: stale replica vs primary read, error passthrough (typed errors stay assertable), transaction reuse. - `routers/web/repo/pull_review_codefloe.go`: `fetchCodeConversationFromPrimary`, reports an empty result as `ErrCommentNotExist`. - `routers/web/repo/pull_review_codefloe_test.go`: empty conversation renders 404. - `routers/web/repo/pull_review.go`: call the helper, `NotFoundOrServerError`, remove the duplicate attachment load. - `services/context/context_codefloe.go`: `WebContextFromContext`. - `services/markup/processorhelper_codefloe_test.go`: private user is mentionable from a wrapped web context. - `services/markup/processorhelper.go`: use `WebContextFromContext` for the two `Doer` lookups. ## Testing - `go vet -tags 'sqlite sqlite_unlock_notify' ./models/db ./routers/web/repo ./services/markup ./services/context` - `go test -race -count=1 -tags 'sqlite sqlite_unlock_notify' ./models/db ./services/markup ./services/context` - `go test -race -count=1 -tags 'sqlite sqlite_unlock_notify' ./routers/web/repo -run TestRenderConversation` - `golangci-lint run` on the four packages with the pinned `go1.26.7` toolchain: only a pre-existing `modernize` hit in `routers/web/repo/pull.go:977`, untouched by this PR. - `git diff --check`
pat-s force-pushed t3code/fix-review-read-consistency from 952fef1268
Some checks failed
testing / frontend-checks (pull_request) Successful in 55s
testing / backend-checks (pull_request) Successful in 7m24s
testing / test-unit (pull_request) Successful in 9m14s
testing / test-remote-cacher (redis) (pull_request) Successful in 3m16s
testing / test-sqlite (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m16s
testing / test-remote-cacher (valkey) (pull_request) Successful in 3m16s
testing / test-e2e (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
to d108267eb0
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m1s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / backend-checks (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
2026-09-05 09:13:08 +00:00
Compare
pat-s force-pushed t3code/fix-review-read-consistency from d108267eb0
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m1s
testing / test-unit (pull_request) Has been cancelled
testing / test-e2e (pull_request) Has been cancelled
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / backend-checks (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
to f8ccfafc59
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m13s
testing / backend-checks (pull_request) Successful in 6m34s
testing / test-unit (pull_request) Successful in 11m38s
testing / test-remote-cacher (valkey) (pull_request) Successful in 3m37s
testing / test-remote-cacher (garnet) (pull_request) Successful in 3m49s
testing / test-remote-cacher (redis) (pull_request) Successful in 3m49s
testing / test-e2e (pull_request) Successful in 28m3s
testing / test-mysql (pull_request) Successful in 30m55s
testing / test-sqlite (pull_request) Successful in 47m13s
testing / test-pgsql (pull_request) Successful in 50m15s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
2026-09-05 09:14:11 +00:00
Compare
pat-s merged commit 8884a13b04 into v16.0/forgejo-codefloe 2026-09-05 10:16:42 +00:00
pat-s deleted branch t3code/fix-review-read-consistency 2026-09-05 10:16:42 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!107
No description provided.