2.4 KiB
2.4 KiB
id, title, status, wave, depends_on, plan, spec
| id | title | status | wave | depends_on | plan | spec |
|---|---|---|---|---|---|---|
| message-queue-merge-01 | Backend repository merge | completed | 1 | None | plan.md | ../../specs/ui/message-queue-merge.md |
Task 01: Backend repository merge
Acceptance
Repository.MergeIntoAbove(ctx, sessionID, sourceID, queuedBy)is defined ininternal/orchestrator/messagequeue/repository.goand implemented in bothrepository_sqlite.go(single transaction) andrepository_memory.go, withErrNoMergeTargetandMetadataSenderTaskIDadded totypes.go.- The same-sender-kind rules hold: user merges only into a user entry owned by
the caller; agent merges only into an agent entry with the identical
sender_task_id; everything else (head, workflow/server/system, mismatched kind, in-flight reserved target) returnsErrNoMergeTarget; a drained source returnsErrEntryNotFound. - Merged entry keeps the target's identity (id/position/queued_by/queued_at);
content joins with
\n\n(no leading blank line when the target content is empty), attachments concatenate,entity_referencesmetadata is the ref-deduplicated union; the source row is deleted; ordering of remaining entries is preserved.
Verification
cd apps/backend && go test -race ./internal/orchestrator/messagequeue/...
Files
apps/backend/internal/orchestrator/messagequeue/types.goapps/backend/internal/orchestrator/messagequeue/repository.goapps/backend/internal/orchestrator/messagequeue/repository_sqlite.goapps/backend/internal/orchestrator/messagequeue/repository_memory.goapps/backend/internal/orchestrator/messagequeue/repository_sqlite_merge_test.goapps/backend/internal/orchestrator/messagequeue/service_test.go
Inputs
- Spec sections:
API surface,Data model,Permissions,Failure modes,Scenarios(all merge scenarios). - Plan sections:
Backend → Message-queue package,Tests(repository rows). - Pattern to mirror:
UpdateContentAndMetadataguard + tx inrepository_sqlite.go:691;append/applyMetadataUpdateshelpers; the memory repo's locking style.
Risks
- Function size/complexity limits (≤80 lines, ≤50 statements, complexity ≤15) — extract the kind gate and the reference-union into helpers.
- goconst: reuse a new
MetadataSenderTaskIDconstant for"sender_task_id". - Reserved lifecycle rows: a reserved-in-flight target must be rejected, never merged into.