feat: add message audit foundation #3
Reference in New Issue
Block a user
Delete Branch "feature/message-audit-foundation"
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?
Summary
channel_actors,channel_conversations, andmessagesin migration000003_message_audit.turnsto request/answer messages and persist the resolved agent ID.Data integrity and idempotency
BeginTurntransaction.FinishTurntransaction.Security boundaries
Verification
go vetpasses for all changed runtime packages.go build ./cmd/dobotaipasses.git diff --checkpasses.000001and000002are unchanged.Not performed
Merge scope
Creating this PR is for review only. Do not merge or deploy until the PostgreSQL rehearsal and final approval are complete.
Hermes review summary
Verdict: changes requested before merge
Critical
Warnings
internal/qa/service.go:228-233— stable identity values are only checked withTrimSpace, but the untrimmed values continue into session keys and the audit tables.Authenticated HTTP clients can therefore create separate actors/conversations/idempotency keys for
user-1anduser-1. Canonicalize the stable string identifiers once beforeBuildKeyandBeginTurn(trim only; do not alter case-sensitive external IDs).internal/qa/service.go:216-222— the QA pipeline acceptscardandfeedbackmessage types.Those values belong to the broader message ledger but should not enter the WeKnora question-answer path. Limit the QA pipeline to
text,image, andrich_text; future feedback/card flows should write through their dedicated services.Suggestions
db/migrations/000003_message_audit.up.sql:20-21,39-40— redundant lookup indexes.The two
UNIQUE (tenant_key, channel, external_*_id)constraints already create equivalent B-tree indexes. Remove the duplicate explicit indexes to avoid extra storage and write amplification.db/migrations/000003_message_audit.up.sql:77-78— correlation index is not tenant-prefixed.Prefer
(tenant_key, correlation_id)so normal audit queries preserve tenant isolation in the index access path.Required verification before merge
000003up, repeated up, down, and rollback/order checks against a disposable PostgreSQL 16 database.BeginTurnwrites and verify exactly one inbound message and one turn are created.Looks good
d857853ea34e44edef8b04e5dd364778b486689f.No merge or deployment approval is given by this review.
Follow-up review
Commit
32b76b84cbda6b8bed5d95d5d2077c951fc9fae3resolves all four code-review findings:TrimSpacebefore resolver, session-key, idempotency, and audit writes; question content remains unchanged.cardandfeedbackbefore database/model side effects.(tenant_key, correlation_id).Verification after the fixes:
go vet,go build ./cmd/dobotai, andgit diff --checkpass.Code findings are resolved. The remaining merge blocker is the disposable PostgreSQL 16 up/re-run/concurrency/down rehearsal.
PostgreSQL 16 migration rehearsal passed
The remaining review blocker has been cleared against a disposable, loopback-only PostgreSQL 16.14 instance using tmpfs storage.
Results:
000001+000002: PASS000003first up: PASS000003repeated up: PASS (expectedIF NOT EXISTSnotices only)BeginTurncalls: exactly 1 turn/inbound message created000003first down: PASS000003repeated down: PASS000002.media_jsonsurvived down: PASSAll code-review and migration-rehearsal blockers are now cleared. The PR remains open and unmerged for the owner's merge decision. No production migration or deployment was performed.