fix(hitl): keep the diagnosis in the HITL ledger so edited messages retain evidence and rationale

버튼 처리·만료 후 메시지를 편집할 때 빈 진단으로 다시 그려 증거·근거 필드가 "-"로 지워지던
결함을 고친다. ai.hitl_messages에 diagnosis jsonb를 추가해 게시 시점의 진단을 저장하고
편집 시 그대로 재사용한다.
This commit is contained in:
seon committed 2026-10-08 01:47:04 +09:00
1 parent c442601ab3
commit 43696d48c8
2 files changed
+12 -13

No files matched your search

+3 -8
View File
@@ -131,7 +131,7 @@ func (b *Bot) Post(ctx context.Context, req PostRequest) error {
if err != nil {
return err
}
if err := b.store.InsertHitl(ctx, rag.HitlMessage{Token: req.Token, ChannelID: msg.ChannelID, MessageID: msg.ID, ActionID: req.ActionID, Target: req.Target, RunID: req.RunID, ScenarioID: req.ScenarioID, SessionID: req.SessionID, ExpiresAt: expires}); err != nil {
if err := b.store.InsertHitl(ctx, rag.HitlMessage{Token: req.Token, ChannelID: msg.ChannelID, MessageID: msg.ID, ActionID: req.ActionID, Target: req.Target, Diagnosis: req.Diagnosis, RunID: req.RunID, ScenarioID: req.ScenarioID, SessionID: req.SessionID, ExpiresAt: expires}); err != nil {
return err
}
b.arm(req.Token, time.Until(expires))
@@ -217,14 +217,9 @@ func (b *Bot) Decide(ctx context.Context, token, decision, by string) (string, e
return "", fmt.Errorf("unknown decision %s", decision)
}
// edit re-renders the original message with the stored diagnosis, the new status and disabled buttons.
func (b *Bot) edit(m *rag.HitlMessage, status string, color int, result map[string]any) error {
ctx := context.Background()
d := map[string]any{}
if se, err := b.store.GetHitl(ctx, m.Token); err == nil {
m = se
}
em := embedFor(d, m.ActionID, m.Target, m.RunID, m.ScenarioID, status, color)
em.Fields = em.Fields[1:] // the diagnosis fields are already in the original message; keep the edit compact
em := embedFor(m.Diagnosis, m.ActionID, m.Target, m.RunID, m.ScenarioID, status, color)
if result != nil {
rb, _ := json.Marshal(result)
em.Fields = append(em.Fields, &discordgo.MessageEmbedField{Name: "Result", Value: "```json\n" + truncate(string(rb), 900) + "\n```"})