fix(gateway): chat acts as the control-plane operator and sees every task

This commit is contained in:
sam committed 2026-10-19 11:12:34 +11:00
1 parent caafdb266f
commit 19e5dcd9d0
2 files changed
+12 -36

No files matched your search

+7 -35
View File
@@ -35,12 +35,10 @@ func (a chatTaskControllerAdapter) ApproveChatTask(ctx context.Context, taskID i
if a.approve == nil {
return fmt.Errorf("task approval is unavailable")
}
// The chat-bound identity is both the scope the task must belong to and
// the actor the record names: a chat command has no cross-identity
// authority, and /approve carries no selection syntax, so the review gate
// answer posts every offered finding.
scope := string(actor.Identity)
return a.approve(ctx, &scope, actor, taskID, taskactions.ActionPayload{})
// Chat acts for the operator, as the dashboard does, so it is not
// narrowed to one identity's tasks. /approve carries no selection syntax,
// so the review gate answer posts every offered finding.
return a.approve(ctx, nil, actor, taskID, taskactions.ActionPayload{})
}
func (a chatTaskControllerAdapter) CancelChatTask(ctx context.Context, taskID int64, reason string) error {
@@ -70,7 +68,7 @@ func (a chatTaskControllerAdapter) CancelChatTask(ctx context.Context, taskID in
return err
}
// chatTaskListerAdapter gives the gateway a read view of one identity's tasks.
// chatTaskListerAdapter gives the gateway a read view of the operator's tasks.
// gateway deliberately does not import the task store, so the projection
// happens here, as it does for the writer and controller adapters below.
type chatTaskListerAdapter struct {
@@ -78,21 +76,12 @@ type chatTaskListerAdapter struct {
}
func (a chatTaskListerAdapter) ListChatTasks(ctx context.Context, identity string, limit int) ([]gateway.ChatTaskSummary, error) {
// Over-read before filtering: Tasks applies its limit across the whole
// table, so asking for exactly `limit` would return fewer than that for
// this identity whenever another identity's work is more recent.
rows, err := a.tasks(ctx, limit*taskListOverRead)
rows, err := a.tasks(ctx, limit)
if err != nil {
return nil, err
}
out := make([]gateway.ChatTaskSummary, 0, limit)
for _, task := range rows {
if task.Identity != identity {
continue
}
if len(out) >= limit {
break
}
out = append(out, gateway.ChatTaskSummary{
ID: task.ID,
Repo: task.Owner + "/" + task.Repo,
@@ -110,10 +99,7 @@ func (a chatTaskListerAdapter) ListChatTasks(ctx context.Context, identity strin
// chatTaskLogReaderAdapter gives the gateway a read view of a task's
// persisted log history without importing internal/logging or the task store
// into the gateway package. Each identity's reader is scoped to its own
// tasks: the identity bound at construction is used for authorization, so a
// model cannot read another identity's task logs by passing a different
// identity through the tool input.
// into the gateway package.
type chatTaskLogReaderAdapter struct {
tasks func(context.Context, int64) (*workflow.Task, error)
taskLogs storecontract.TaskLogStore
@@ -129,16 +115,6 @@ func (a chatTaskLogReaderAdapter) ReadChatTaskLogs(
if task == nil {
return gateway.ChatTaskLogResult{}, fmt.Errorf("task %d not found", taskID)
}
// Match the filter chatTaskListerAdapter already applies: a model
// bound to one identity must not read logs for another identity's
// tasks, and tasks with no identity (forge-sourced) are not
// readable through a chat tool at all — they belong to the daemon,
// not a particular identity. "The empty string MUST NOT retain
// special meaning".
if task.Identity != identity {
return gateway.ChatTaskLogResult{}, fmt.Errorf("task %d belongs to %q, not %q", taskID, task.Identity, identity)
}
if attempt <= 0 {
attempt = task.Attempt
}
@@ -179,7 +155,3 @@ func configureTaskCommands(
router.TaskLister = lister
router.Identity = identity
}
// taskListOverRead multiplies the requested limit when reading rows that are
// filtered by identity afterwards.
const taskListOverRead = 5
+5 -1
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/identity"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/gateway"
)
@@ -53,7 +54,10 @@ func Profiles(cfg config.Config) ([]gateway.TaskProfile, string) {
if len(cfg.Repos) == 0 {
return nil, ""
}
return []gateway.TaskProfile{newProfile("", cfg.Repos)}, ""
// Chat acts as the control-plane operator, the identity the dashboard
// stamps on the tasks it creates.
operator := string(identity.OperatorID())
return []gateway.TaskProfile{newProfile(operator, cfg.Repos)}, operator
}
func newProfile(identity string, repos []config.Repo) gateway.TaskProfile {