refactor: thread context.Context into both SQLite handles #452
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman#452
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Code-quality audit (P2). Neither SQLite handle uses context-aware
database/sqlcalls.In
internal/db/andinternal/state/:QueryContext/QueryRowContext/ExecContextappear 0 times in non-test code;Query/QueryRow/Execappear 376 times.Why it matters
Two concrete consequences:
internal/db/sessions.go:22) runs correlated subqueries over the wholemessagetable; a client that navigates away cannot stop it.otelsqlinstrumentation on both handles, butotelsqlderives the DB span from the context passed to the call. WithQuery/Execthere is no context, so every DB span is orphaned — it never attaches to theotelhttpserver span. The tracing feature is effectively non-functional for DB work.Suggested fix
Thread
context.Contextas the first parameter through the query layer and switch to the*Contextvariants. Do it incrementally, request-path first:internal/db/sessions.go:122and the other aggregates reachable from/api/sessions.internal/dbreaders.internal/statewriters.Handlers pass
r.Context(); background loops pass their own ctx.Acceptance criteria
ctxand useQueryContext/QueryRowContext/ExecContext.context.Canceled).Effort: L.