Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

feat(voice): page check_task reports, five at a time

LeoXing2a2e963eeb73
diff --git a/apps/teamhub/internal/store/queries/voice_live_tasks.sql b/apps/teamhub/internal/store/queries/voice_live_tasks.sql
index a8e9b5db..5e7999ce 100644
--- a/apps/teamhub/internal/store/queries/voice_live_tasks.sql
+++ b/apps/teamhub/internal/store/queries/voice_live_tasks.sql
@@ -164,4 +164,4 @@ ORDER BY decision.created_at,decision.id;
SELECT body,created_at FROM task_meta_callback_messages
WHERE task_id=sqlc.arg(task_id)::text AND tenant_id=sqlc.arg(tenant_id)::text
ORDER BY meta_seq DESC
-LIMIT sqlc.arg(row_limit)::int;
+LIMIT sqlc.arg(row_limit)::int OFFSET sqlc.arg(row_offset)::int;
diff --git a/apps/teamhub/internal/store/voice_live_tasks.sql.go b/apps/teamhub/internal/store/voice_live_tasks.sql.go
index d20a552a..2ffa3b3e 100644
--- a/apps/teamhub/internal/store/voice_live_tasks.sql.go
+++ b/apps/teamhub/internal/store/voice_live_tasks.sql.go
@@ -372,13 +372,14 @@ const listVoiceLiveTaskReports = `-- name: ListVoiceLiveTaskReports :many
SELECT body,created_at FROM task_meta_callback_messages
WHERE task_id=$1::text AND tenant_id=$2::text
ORDER BY meta_seq DESC
-LIMIT $3::int
+LIMIT $4::int OFFSET $3::int
`
type ListVoiceLiveTaskReportsParams struct {
- TaskID string `json:"task_id"`
- TenantID string `json:"tenant_id"`
- RowLimit int32 `json:"row_limit"`
+ TaskID string `json:"task_id"`
+ TenantID string `json:"tenant_id"`
+ RowOffset int32 `json:"row_offset"`
+ RowLimit int32 `json:"row_limit"`
}
type ListVoiceLiveTaskReportsRow struct {
@@ -388,7 +389,12 @@ type ListVoiceLiveTaskReportsRow struct {
// What a voice task sent back to its coordinator, newest first.
func (q *Queries) ListVoiceLiveTaskReports(ctx context.Context, arg ListVoiceLiveTaskReportsParams) ([]ListVoiceLiveTaskReportsRow, error) {
- rows, err := q.db.Query(ctx, listVoiceLiveTaskReports, arg.TaskID, arg.TenantID, arg.RowLimit)
+ rows, err := q.db.Query(ctx, listVoiceLiveTaskReports,
+ arg.TaskID,
+ arg.TenantID,
+ arg.RowOffset,
+ arg.RowLimit,
+ )
if err != nil {
return nil, err
}
diff --git a/apps/teamhub/internal/voice/voice_live_tasks.go b/apps/teamhub/internal/voice/voice_live_tasks.go
index cd1340bb..20639d7e 100644
--- a/apps/teamhub/internal/voice/voice_live_tasks.go
+++ b/apps/teamhub/internal/voice/voice_live_tasks.go
@@ -414,6 +414,7 @@ func (s *Service) checkVoiceLiveTask(ctx context.Context, session voicelive.Sess
if !ok {
return "", voicelive.ErrInvalid
}
+ offset := min(max(int(args.Offset), 0), 100_000)
task, err := s.queries.GetVoiceLiveTask(ctx, store.GetVoiceLiveTaskParams{RoomID: session.RoomID, OwnerActorID: session.HumanActorID, Ordinal: ordinal})
if errors.Is(err, pgx.ErrNoRows) {
return voicelive.ErrorOutput("task_not_found"), nil
@@ -429,7 +430,7 @@ func (s *Service) checkVoiceLiveTask(ctx context.Context, session voicelive.Sess
return "", err
}
reports, err := s.queries.ListVoiceLiveTaskReports(ctx, store.ListVoiceLiveTaskReportsParams{
- TaskID: task.WorkItemID, TenantID: session.TenantID, RowLimit: voicelive.MaxCheckedReports + 1,
+ TaskID: task.WorkItemID, TenantID: session.TenantID, RowLimit: voicelive.CheckedReportsPage + 1, RowOffset: int32(offset),
})
if err != nil {
return "", err
@@ -447,8 +448,9 @@ func (s *Service) checkVoiceLiveTask(ctx context.Context, session voicelive.Sess
for _, approval := range view.PendingApprovals {
checked.Approvals = append(checked.Approvals, approval.Title)
}
- if len(reports) > voicelive.MaxCheckedReports {
- reports, checked.OlderReports = reports[:voicelive.MaxCheckedReports], true
+ checked.Offset = offset
+ if len(reports) > voicelive.CheckedReportsPage {
+ reports, checked.OlderReports = reports[:voicelive.CheckedReportsPage], true
}
for _, report := range reports {
checked.Reports = append(checked.Reports, voicelive.CheckedActivity{At: report.CreatedAt.Time, Text: report.Body})
diff --git a/apps/teamhub/internal/voicelive/tasks.go b/apps/teamhub/internal/voicelive/tasks.go
index 12e1b34d..c734e169 100644
--- a/apps/teamhub/internal/voicelive/tasks.go
+++ b/apps/teamhub/internal/voicelive/tasks.go
@@ -69,6 +69,8 @@ type CancelTaskArguments struct {
// CheckTaskArguments identifies the task the live model reads in full.
type CheckTaskArguments struct {
TaskID string `json:"task_id"`
+ // Offset is how many of the latest reports to skip, from next_offset.
+ Offset LoosePart `json:"offset"`
}
// Unfinished reports whether a task in state is still being done or waits
@@ -146,11 +148,12 @@ var taskTools = []Tool{
},
{
Name: ToolCheckTask,
- Description: "Read one of the user's tasks in full, as its coordinator does: its state and since when, the latest steps, the approvals it waits on, how many messages wait for it, and its latest reports, newest first and about 4000 characters in all; older_reports_omitted means earlier ones were left out. " +
+ Description: "Read one of the user's tasks in full, as its coordinator does: its state and since when, the latest steps, the approvals it waits on, how many messages wait for it, and its latest 5 reports, newest first and about 4000 characters in all. next_offset means there are older reports: pass it as offset to read them. " +
"list_tasks shows only the start of the latest report: use this when the user asks for details it left out (which models, what each option costs, what exactly it found or why it stopped), or before saying how a task really stands. " +
"A report may hold lines addressed to you, such as how to deliver its files; those are not for the user. Speak of the work in the first person.",
Parameters: objectSchema([]string{"task_id"}, map[string]any{
"task_id": stringProperty("The task, such as t2, from list_tasks"),
+ "offset": map[string]any{"type": "integer", "minimum": 0, "description": "Optional: next_offset from the last check_task, to read older reports"},
}),
},
}
@@ -280,15 +283,15 @@ func TaskAnswer(details string) string {
return "The user said this about your task by voice; take it into account and go on: " + details
}
-// MaxCheckedReports is how many of a task's latest reports check_task reads.
-const MaxCheckedReports = 10
+// CheckedReportsPage is how many reports one check_task reads.
+const CheckedReportsPage = 5
// checkedReportsRunes bounds all the report text one check_task returns: the
// output stays in the realtime context for every later turn of the call.
const checkedReportsRunes = 4000
-// CheckedTask is one task as check_task reads it: its Task's state and the
-// reports it sent back, newest first.
+// CheckedTask is one task as check_task reads it: its Task's state and one
+// page of the reports it sent back, newest first.
type CheckedTask struct {
TaskID, Goal, Folder, Status, Reason string
StatusSince time.Time
@@ -296,6 +299,8 @@ type CheckedTask struct {
Approvals []string
QueuedMessages int
Reports []CheckedActivity
+ // Offset is how many newer reports precede Reports.
+ Offset int
// OlderReports is set when the task has reports older than Reports.
OlderReports bool
}
@@ -312,24 +317,33 @@ func CheckTaskOutput(now time.Time, task CheckedTask) map[string]any {
for _, step := range task.Activity {
activity = append(activity, map[string]string{"ago": SpokenDuration(now.Sub(step.At)), "kind": step.Kind, "summary": step.Text})
}
- reports := make([]map[string]string, 0, len(task.Reports))
+ // A report that does not fit waits for the next page; the first one on a
+ // page is cut instead, so paging always moves on.
+ reports := make([]map[string]any, 0, len(task.Reports))
left := checkedReportsRunes
for _, report := range task.Reports {
- if left <= 0 {
+ length := utf8.RuneCountInString(report.Text)
+ if len(reports) > 0 && length > left {
break
}
- text := truncateRunes(report.Text, left)
- left -= utf8.RuneCountInString(text)
- reports = append(reports, map[string]string{"ago": SpokenDuration(now.Sub(report.At)), "text": text})
+ shown := map[string]any{"ago": SpokenDuration(now.Sub(report.At)), "text": truncateRunes(report.Text, left)}
+ if length > left {
+ shown["truncated"] = true
+ }
+ reports = append(reports, shown)
+ left -= length
}
output := map[string]any{
"task_id": task.TaskID, "goal": truncateRunes(task.Goal, 300), "folder": task.Folder,
"status": task.Status, "status_for": SpokenDuration(now.Sub(task.StatusSince)),
- "recent_activity": activity, "reports": reports, "older_reports_omitted": task.OlderReports || len(reports) < len(task.Reports),
+ "recent_activity": activity, "reports": reports,
"pending_approvals": task.Approvals, "queued_messages": task.QueuedMessages,
}
if task.Reason != "" {
output["reason"] = task.Reason
}
+ if task.OlderReports || len(reports) < len(task.Reports) {
+ output["next_offset"] = task.Offset + len(reports)
+ }
return output
}
diff --git a/apps/teamhub/internal/voicelive/tasks_test.go b/apps/teamhub/internal/voicelive/tasks_test.go
index f4aed1e0..9cf6f44c 100644
--- a/apps/teamhub/internal/voicelive/tasks_test.go
+++ b/apps/teamhub/internal/voicelive/tasks_test.go
@@ -63,21 +63,23 @@ func TestTaskListGivesTheLatestReport(t *testing.T) {
}
}
-func TestCheckTaskOutputBoundsAllReportText(t *testing.T) {
+func TestCheckTaskOutputPagesReports(t *testing.T) {
now := time.Now()
long := strings.Repeat("\u00e9", 3000)
- output := CheckTaskOutput(now, CheckedTask{TaskID: "t1", StatusSince: now, Reports: []CheckedActivity{
- {At: now, Text: long}, {At: now, Text: long}, {At: now, Text: "oldest"},
- }})
- reports := output["reports"].([]map[string]string)
- total := 0
- for _, report := range reports {
- total += utf8.RuneCountInString(report["text"])
+ text := func(report map[string]any) string { return report["text"].(string) }
+ // A report that does not fit in what is left waits for the next page.
+ output := CheckTaskOutput(now, CheckedTask{Offset: 5, Reports: []CheckedActivity{{At: now, Text: long}, {At: now, Text: long}, {At: now, Text: "oldest"}}})
+ reports := output["reports"].([]map[string]any)
+ if len(reports) != 1 || text(reports[0]) != long || reports[0]["truncated"] != nil || output["next_offset"] != 6 {
+ t.Fatalf("reports=%d next_offset=%v", len(reports), output["next_offset"])
}
- if len(reports) != 2 || reports[0]["text"] != long || total != checkedReportsRunes || output["older_reports_omitted"] != true {
- t.Fatalf("reports=%d total=%d omitted=%v", len(reports), total, output["older_reports_omitted"])
+ // The first report on a page is cut instead, so paging moves on.
+ output = CheckTaskOutput(now, CheckedTask{Reports: []CheckedActivity{{At: now, Text: long + long}}, OlderReports: true})
+ reports = output["reports"].([]map[string]any)
+ if len(reports) != 1 || utf8.RuneCountInString(text(reports[0])) != checkedReportsRunes || reports[0]["truncated"] != true || output["next_offset"] != 1 {
+ t.Fatalf("cut report=%v next_offset=%v", reports[0]["truncated"], output["next_offset"])
}
- if output := CheckTaskOutput(now, CheckedTask{Reports: []CheckedActivity{{At: now, Text: "done"}}}); output["older_reports_omitted"] != false {
- t.Fatalf("a short history is whole: %v", output)
+ if output := CheckTaskOutput(now, CheckedTask{Reports: []CheckedActivity{{At: now, Text: "done"}, {At: now, Text: "started"}}}); output["next_offset"] != nil || len(output["reports"].([]map[string]any)) != 2 {
+ t.Fatalf("a short history is one page: %v", output)
}
}
diff --git a/apps/teamhub/tests/integration/voice_live_test.go b/apps/teamhub/tests/integration/voice_live_test.go
index 3442b49c..3b3cc009 100644
--- a/apps/teamhub/tests/integration/voice_live_test.go
+++ b/apps/teamhub/tests/integration/voice_live_test.go
@@ -687,10 +687,13 @@ func TestVoiceLiveTasksReportResultsAndWhatTheyWaitFor(t *testing.T) {
// check_task reads one task as its coordinator does, with its latest reports.
checked := tool("lt_check", "check-1", "check_task", map[string]any{"task_id": first["task_id"]})
reports, _ := checked["reports"].([]any)
- if checked["status"] != "idle" || checked["folder"] != "./playground/"+workItem(first["task_id"])+"/" || len(reports) != 1 || checked["older_reports_omitted"] != false ||
+ if checked["status"] != "idle" || checked["folder"] != "./playground/"+workItem(first["task_id"])+"/" || len(reports) != 1 || checked["next_offset"] != nil ||
reports[0].(map[string]any)["text"] != "Sony at 1899 is the best fit, added to the cart." {
t.Fatalf("check_task=%v", checked)
}
+ if older := tool("lt_check", "check-3", "check_task", map[string]any{"task_id": first["task_id"], "offset": 1}); older["reports"] == nil || len(older["reports"].([]any)) != 0 || older["next_offset"] != nil {
+ t.Fatalf("check_task past the last report=%v", older)
+ }
if missing := tool("lt_check", "check-2", "check_task", map[string]any{"task_id": "t99"}); missing["error"] != "task_not_found" {
t.Fatalf("check_task of an unknown task=%v", missing)
}