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.

fix(activities): keep turnless linked calls and send usage alone

LeoXing2e6ede7bfab6
diff --git a/apps/node-services/src/agent/runner-gateway/runner-operations.ts b/apps/node-services/src/agent/runner-gateway/runner-operations.ts
index 2ae99d87..cc832ddf 100644
--- a/apps/node-services/src/agent/runner-gateway/runner-operations.ts
+++ b/apps/node-services/src/agent/runner-gateway/runner-operations.ts
@@ -346,7 +346,9 @@ export class RunnerOperations {
return;
const usage = operation.terminal ? operation.usage : undefined;
if (operation.terminal && !usage) return;
- const turnId = operation.turnId;
+ // The turn goes with run.started and usage goes alone, so a TeamHub
+ // that rejects the turn field during a rolling deploy still lands usage.
+ const turnId = operation.terminal ? undefined : operation.turnId;
void record({
contextKey: operation.start.execution_context_key,
epoch,
diff --git a/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts b/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts
index b7730ba0..b264449c 100644
--- a/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts
+++ b/apps/node-services/tests/agent/runner-gateway/runner-operations-public.test.ts
@@ -165,11 +165,7 @@ describe("RunnerGateway", () => {
}),
);
await expect(operation.result).resolves.toMatchObject({ type: "run" });
- expect(recordRunOperation).toHaveBeenLastCalledWith({
- ...identity,
- turnId: "turn-1",
- usage,
- });
+ expect(recordRunOperation).toHaveBeenLastCalledWith({ ...identity, usage });
expect(recordRunOperation).toHaveBeenCalledTimes(3);
});
diff --git a/apps/teamhub/internal/collaboration/message_activities.go b/apps/teamhub/internal/collaboration/message_activities.go
index 67daf124..163d9ea2 100644
--- a/apps/teamhub/internal/collaboration/message_activities.go
+++ b/apps/teamhub/internal/collaboration/message_activities.go
@@ -197,17 +197,23 @@ func readMessageActivityRecords(
return records, false, nil
}
+// messageActivityRecordMatches selects a Run's records: those of its turns,
+// and linked calls a Runtime wrote without a turn ID, as a Codex Daemon that
+// does not carry the turn forward does. A linked call stamped with another
+// turn stays out.
func messageActivityRecordMatches(
record roomagent.RuntimeHistoryRecord,
callIDs map[string]struct{},
turnIDs map[string]struct{},
) bool {
- if len(turnIDs) > 0 {
- _, exact := turnIDs[record.TurnID]
- return exact
+ if _, turn := turnIDs[record.TurnID]; turn && record.TurnID != "" {
+ return true
}
- _, exact := callIDs[record.ToolCallID]
- return exact
+ if len(turnIDs) > 0 && record.TurnID != "" {
+ return false
+ }
+ _, call := callIDs[record.ToolCallID]
+ return call
}
func messageActivityLogFromIdentity(
diff --git a/apps/teamhub/internal/collaboration/message_activities_test.go b/apps/teamhub/internal/collaboration/message_activities_test.go
index 333cc171..dd1c607a 100644
--- a/apps/teamhub/internal/collaboration/message_activities_test.go
+++ b/apps/teamhub/internal/collaboration/message_activities_test.go
@@ -2,6 +2,7 @@ package collaboration
import (
"context"
+ "fmt"
"testing"
"github.com/simplexai-labs/linger/apps/teamhub/internal/roomagent"
@@ -19,6 +20,8 @@ func TestMessageActivityRecordMatchesNativeTurn(t *testing.T) {
{name: "same turn tool", record: roomagent.RuntimeHistoryRecord{TurnID: "turn-target", ToolCallID: "call-target"}, want: true},
{name: "same call other turn", record: roomagent.RuntimeHistoryRecord{TurnID: "turn-other", ToolCallID: "call-target"}, want: false},
{name: "other turn", record: roomagent.RuntimeHistoryRecord{TurnID: "turn-other"}, want: false},
+ {name: "same call without turn", record: roomagent.RuntimeHistoryRecord{ToolCallID: "call-target"}, want: true},
+ {name: "other call without turn", record: roomagent.RuntimeHistoryRecord{ToolCallID: "call-other"}, want: false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
@@ -147,6 +150,36 @@ func TestMessageActivityHistoryReadsRecordedTurnWithoutLinkedCall(t *testing.T)
}
}
+func TestMessageActivityHistoryKeepsLinkedCallsAnOlderDaemonLeftWithoutTurn(t *testing.T) {
+ // A Daemon that does not carry Codex turns forward stamps only the
+ // lifecycle records; its linked calls still belong to the Run.
+ inspector := &messageActivityInspectorStub{pages: map[string]roomagent.RuntimeHistory{
+ "": {Status: "available", ProviderKind: "codex", Records: []roomagent.RuntimeHistoryRecord{
+ {Ordinal: 1, TurnID: "turn-run", Category: "lifecycle"},
+ {Ordinal: 2, ToolCallID: "call-target", Category: "tool_call"},
+ {Ordinal: 3, ToolCallID: "call-target", Category: "tool_result"},
+ {Ordinal: 4, ToolCallID: "call-other", Category: "tool_call"},
+ {Ordinal: 5, TurnID: "turn-run", Category: "lifecycle"},
+ }},
+ }}
+ activities := map[string]struct{}{"call-target": {}}
+ identity, err := findMessageActivityIdentity(context.Background(), inspector, roomagent.RuntimeContextTarget{}, activities, []string{"turn-run"}, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ records, _, err := readMessageActivityRecords(context.Background(), inspector, roomagent.RuntimeContextTarget{}, identity)
+ if err != nil {
+ t.Fatal(err)
+ }
+ ordinals := make([]int, 0, len(records))
+ for _, record := range records {
+ ordinals = append(ordinals, record.Ordinal)
+ }
+ if want := []int{1, 2, 3, 5}; fmt.Sprint(ordinals) != fmt.Sprint(want) {
+ t.Fatalf("ordinals=%v want=%v", ordinals, want)
+ }
+}
+
type messageActivityInspectorStub struct {
pages map[string]roomagent.RuntimeHistory
}