Files
kandev/apps/backend/internal/runs/commentkeys/commentkeys.go
T
Carlos Florêncio 2d73a3d1db fix: keep completed office comments editable (#1548)
* fix: keep completed office comments editable

Keep the office task detail composer editable after completed sessions load,

including projectless office tasks.

Update verification tests for SHA-pinned GitHub actions. Extract the

dockview main area to satisfy the existing max-lines lint rule.

* fix: preserve upload artifact version guard

* fix: clarify upload artifact pin check

* fix: wake completed office sessions on comments

* fix: queue completed office comment runs

* fix: preserve dispatcher session lookup errors

* fix: resolve office comment wake review issues

* fix: stabilize comment wake idempotency

* fix: salt custom comment wake keys

* fix: address comment wake review cleanup

* fix: avoid comment payload allocation overflow pattern

* fix: salt comment wake action variants

* fix: resolve cross-task primary by target step

* fix: resolve cross-task participant roles

* fix: surface cross-task comment run status

* fix: use target steps for cross-task queue runs

* fix: avoid comment run lookup scan regression

* fix: cover cross-task queue run edge cases

* fix: index comment payload run lookup

* fix: support postgres comment run index

* fix: tighten queue run target test coverage

* fix: route source comment run updates

* fix: preserve cross-task comment wakes

* fix: tighten comment wake identity

* fix: align comment wake routing

* fix: remove stale primary resolver

* fix: dedupe comment run status

* fix: tighten legacy comment wake dedupe

* fix: remove unreachable comment wake guard

* fix: skip duplicate comment reactivity wakes

* fix: route comment wakes synchronously

* fix: share comment engine dispatch contracts

* fix: preserve comment wake fallbacks

* fix: preserve done comment runner

* fix: guard empty task runner fallback

* fix: handle empty task runner fallback

* fix: stabilize completed comment wakes

* fix: index comment runner fallback

---------

Co-authored-by: root <root@kandev.ts.net>
2026-06-30 13:10:40 +01:00

81 lines
2.4 KiB
Go

// Package commentkeys centralizes the idempotency-key contract that links
// office comments to queued runs.
package commentkeys
import (
"encoding/json"
"strings"
)
const (
// TaskCommentPrefix prefixes run idempotency keys that originate from an
// office task comment.
TaskCommentPrefix = "task_comment:"
// TaskCommentReason is the run reason used for comment-triggered runs.
TaskCommentReason = "task_comment"
// EngineDispatchedValue marks comment events whose synchronous publisher
// path already routed the trigger through the workflow engine.
EngineDispatchedValue = "true"
)
// TaskComment builds the canonical same-task comment idempotency key.
func TaskComment(commentID string) string {
return TaskCommentPrefix + commentID
}
// HasTaskCommentPrefix reports whether key uses the comment idempotency prefix.
func HasTaskCommentPrefix(key string) bool {
return strings.HasPrefix(key, TaskCommentPrefix)
}
// TrimTaskCommentPrefix removes the comment idempotency prefix when present.
func TrimTaskCommentPrefix(key string) string {
return strings.TrimPrefix(key, TaskCommentPrefix)
}
// CommentIDFromKey extracts the leading comment id from canonical and salted
// task_comment keys. Salted keys append extra colon-separated fields after the
// comment id.
func CommentIDFromKey(key string) string {
if !HasTaskCommentPrefix(key) {
return ""
}
id := TrimTaskCommentPrefix(key)
if before, _, found := strings.Cut(id, ":"); found {
return before
}
return id
}
// IsSaltedTaskCommentKey reports whether a task_comment key carries extra
// salt after the leading comment id.
func IsSaltedTaskCommentKey(key string) bool {
if !HasTaskCommentPrefix(key) {
return false
}
return strings.Contains(TrimTaskCommentPrefix(key), ":")
}
// IdentityFromPayload extracts the task/comment pair used to link a run back
// to a comment. Cross-task wakes execute on task_id but the UI badge/comment
// anchor belongs to source_task_id, so source_task_id wins when present.
func IdentityFromPayload(payloadJSON string) (taskID, commentID string) {
if payloadJSON == "" {
return "", ""
}
var p struct {
TaskID string `json:"task_id"`
SourceTaskID string `json:"source_task_id"`
CommentID string `json:"comment_id"`
}
if err := json.Unmarshal([]byte(payloadJSON), &p); err != nil {
return "", ""
}
if p.SourceTaskID != "" {
taskID = p.SourceTaskID
} else {
taskID = p.TaskID
}
return taskID, p.CommentID
}