Browse Source

fix(host): give Apply a ValidUntil that can wait out GET_TEMPERATURE

Pending temperature scans after startup made 2s test/RTL deadlines
unmeetable (6.5s mock / 20s UART remaining). Host clients must cover the
scan budget; the RTL tap now starts its hold before hthd so GET_TEMPERATURE
stays off during delayed startup.

Co-authored-by: Cursor <cursoragent@cursor.com>
root 3 months ago
parent
commit
8003e25366

+ 2 - 2
internal/device/device_test.go

@@ -91,7 +91,7 @@ func batch(d *device.Device, l *hthv1.ControlLease, id string, doors uint8) *hth
 	return &hthv1.ActionBatch{
 		DeviceId: d.ID(), CommandId: id, LeaseId: l.LeaseId, LeaseEpoch: l.LeaseEpoch,
 		BasedOnSnapshotSeq: s.SnapshotSeq, ExpectedControlRevision: s.ControlRevision,
-		ValidUntil: timestamppb.New(time.Now().Add(2 * time.Second)),
+		ValidUntil: timestamppb.New(time.Now().Add(20 * time.Second)),
 		ClientId:   "test",
 		ContinuousTargets: []*hthv1.ContinuousTarget{
 			{Id: ids.Fan1, Value: 20}, {Id: ids.Fan2, Value: 20}, {Id: ids.Fan3, Value: 20}, {Id: ids.Fan4, Value: 20},
@@ -710,7 +710,7 @@ func TestReconnectDoesNotRestoreOldPTC(t *testing.T) {
 	partial := &hthv1.ActionBatch{
 		DeviceId: d.ID(), CommandId: "partial-fan-only", LeaseId: l2.LeaseId, LeaseEpoch: l2.LeaseEpoch,
 		BasedOnSnapshotSeq: d.Snapshot().SnapshotSeq, ExpectedControlRevision: d.Snapshot().ControlRevision,
-		ValidUntil: timestamppb.New(time.Now().Add(2 * time.Second)), ClientId: "test",
+		ValidUntil: timestamppb.New(time.Now().Add(20 * time.Second)), ClientId: "test",
 		ContinuousTargets: []*hthv1.ContinuousTarget{{Id: ids.Fan1, Value: 30}},
 	}
 	pr := d.ApplyAction(context.Background(), partial)

+ 3 - 3
tests/grpc_uds_test.go

@@ -45,7 +45,7 @@ watchdog:
   heartbeat_period_ms: 80
 lease:
   min_ttl_ms: 50
-  max_ttl_ms: 2000
+  max_ttl_ms: 20000
 safety:
   fan: 10
   ptc: 0
@@ -177,14 +177,14 @@ func TestSlowSubscriberDoesNotBlockControl(t *testing.T) {
 		t.Fatal(err)
 	}
 	ctrl := hthv1.NewControlServiceClient(cconn)
-	lease, err := ctrl.AcquireControlLease(ctx, &hthv1.AcquireControlLeaseRequest{DeviceId: "prod2u-0", Holder: "slow", Ttl: durationpb.New(2 * time.Second)})
+	lease, err := ctrl.AcquireControlLease(ctx, &hthv1.AcquireControlLeaseRequest{DeviceId: "prod2u-0", Holder: "slow", Ttl: durationpb.New(15 * time.Second)})
 	if err != nil {
 		t.Fatal(err)
 	}
 	start := time.Now()
 	res, err := ctrl.ApplyAction(ctx, &hthv1.ApplyActionRequest{Batch: &hthv1.ActionBatch{
 		DeviceId: "prod2u-0", CommandId: "while-slow", LeaseId: lease.Lease.LeaseId, LeaseEpoch: lease.Lease.LeaseEpoch,
-		ValidUntil:        timestamppb.New(time.Now().Add(2 * time.Second)),
+		ValidUntil:        timestamppb.New(time.Now().Add(20 * time.Second)),
 		ContinuousTargets: []*hthv1.ContinuousTarget{{Id: ids.Fan2, Value: 12}},
 	}})
 	if err != nil || !res.Accepted {

+ 4 - 4
tests/pty_fault_linux_test.go

@@ -96,12 +96,12 @@ func applyDoors(t *testing.T, obs, ctl, cmd string, door float64) *hthv1.ActionR
 		t.Fatal(err)
 	}
 	defer cc.Close()
-	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
+	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel()
 	obsCli := hthv1.NewObserveServiceClient(oc)
 	ctrl := hthv1.NewControlServiceClient(cc)
 	lease, err := ctrl.AcquireControlLease(ctx, &hthv1.AcquireControlLeaseRequest{
-		DeviceId: "prod2u-0", Holder: "pty-fault", Ttl: durationpb.New(2 * time.Second),
+		DeviceId: "prod2u-0", Holder: "pty-fault", Ttl: durationpb.New(20 * time.Second),
 	})
 	if err != nil {
 		t.Fatal(err)
@@ -113,7 +113,7 @@ func applyDoors(t *testing.T, obs, ctl, cmd string, door float64) *hthv1.ActionR
 	res, err := ctrl.ApplyAction(ctx, &hthv1.ApplyActionRequest{Batch: &hthv1.ActionBatch{
 		DeviceId: "prod2u-0", CommandId: cmd, LeaseId: lease.Lease.LeaseId, LeaseEpoch: lease.Lease.LeaseEpoch,
 		BasedOnSnapshotSeq: snap.Snapshot.SnapshotSeq, ExpectedControlRevision: snap.Snapshot.ControlRevision, AllowClamp: true,
-		ValidUntil: timestamppb.New(time.Now().Add(2 * time.Second)),
+		ValidUntil: timestamppb.New(time.Now().Add(20 * time.Second)),
 		ContinuousTargets: []*hthv1.ContinuousTarget{
 			{Id: ids.DoorX, Value: door}, {Id: ids.DoorY, Value: door}, {Id: ids.DoorZ, Value: door},
 		},
@@ -223,7 +223,7 @@ func TestPTYDisconnectInvalidatesOldLease(t *testing.T) {
 	defer acancel()
 	res, err := ctrl.ApplyAction(actx, &hthv1.ApplyActionRequest{Batch: &hthv1.ActionBatch{
 		DeviceId: "prod2u-0", CommandId: "after-disc", LeaseId: lease.Lease.LeaseId, LeaseEpoch: lease.Lease.LeaseEpoch,
-		ValidUntil:        timestamppb.New(time.Now().Add(2 * time.Second)),
+		ValidUntil:        timestamppb.New(time.Now().Add(20 * time.Second)),
 		ContinuousTargets: []*hthv1.ContinuousTarget{{Id: ids.Fan1, Value: 10}},
 	}})
 	if err != nil {

+ 3 - 3
tests/pty_serial_test.go

@@ -99,9 +99,9 @@ grpc:
 	ctrl := hthv1.NewControlServiceClient(cc)
 	waitUntilReady(t, obs, 20*time.Second)
 	waitSlewBudget()
-	ctx2, cancel2 := context.WithTimeout(context.Background(), 3*time.Second)
+	ctx2, cancel2 := context.WithTimeout(context.Background(), 30*time.Second)
 	defer cancel2()
-	lease, err := ctrl.AcquireControlLease(ctx2, &hthv1.AcquireControlLeaseRequest{DeviceId: "prod2u-0", Holder: "pty", Ttl: durationpb.New(2 * time.Second)})
+	lease, err := ctrl.AcquireControlLease(ctx2, &hthv1.AcquireControlLeaseRequest{DeviceId: "prod2u-0", Holder: "pty", Ttl: durationpb.New(20 * time.Second)})
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -112,7 +112,7 @@ grpc:
 	b := &hthv1.ActionBatch{
 		DeviceId: "prod2u-0", CommandId: "pty-1", LeaseId: lease.Lease.LeaseId, LeaseEpoch: lease.Lease.LeaseEpoch,
 		BasedOnSnapshotSeq: snap.Snapshot.SnapshotSeq, ExpectedControlRevision: snap.Snapshot.ControlRevision, AllowClamp: true,
-		ValidUntil: timestamppb.New(time.Now().Add(2 * time.Second)),
+		ValidUntil: timestamppb.New(time.Now().Add(20 * time.Second)),
 		ContinuousTargets: []*hthv1.ContinuousTarget{
 			{Id: ids.Fan1, Value: 10}, {Id: ids.Fan2, Value: 10}, {Id: ids.Fan3, Value: 10}, {Id: ids.Fan4, Value: 10},
 			{Id: ids.PTC1, Value: 0}, {Id: ids.PTC2, Value: 0}, {Id: ids.PTC3, Value: 0}, {Id: ids.PTC4, Value: 0},

+ 2 - 2
tests/soak_test.go

@@ -98,7 +98,7 @@ func TestShortSoakMock(t *testing.T) {
 			DeviceId: "prod2u-0", CommandId: time.Now().Format("soak-20060102150405.000000000"),
 			LeaseId: lease.Lease.LeaseId, LeaseEpoch: lease.Lease.LeaseEpoch,
 			BasedOnSnapshotSeq: snap.Snapshot.SnapshotSeq, ExpectedControlRevision: snap.Snapshot.ControlRevision, ClientId: "soak",
-			ValidUntil: timestamppb.New(time.Now().Add(2 * time.Second)),
+			ValidUntil: timestamppb.New(time.Now().Add(20 * time.Second)),
 			ContinuousTargets: []*hthv1.ContinuousTarget{
 				{Id: ids.Fan1, Value: 10}, {Id: ids.Fan2, Value: 10}, {Id: ids.Fan3, Value: 10}, {Id: ids.Fan4, Value: 10},
 				{Id: ids.PTC1, Value: 0}, {Id: ids.PTC2, Value: 0}, {Id: ids.PTC3, Value: 0}, {Id: ids.PTC4, Value: 0},
@@ -168,7 +168,7 @@ func TestPRSoakMock(t *testing.T) {
 			DeviceId: "prod2u-0", CommandId: time.Now().Format("prsoak-20060102150405.000000000"),
 			LeaseId: lease.Lease.LeaseId, LeaseEpoch: lease.Lease.LeaseEpoch,
 			BasedOnSnapshotSeq: snap.Snapshot.SnapshotSeq, ExpectedControlRevision: snap.Snapshot.ControlRevision, ClientId: "soak-pr",
-			ValidUntil: timestamppb.New(time.Now().Add(3 * time.Second)),
+			ValidUntil: timestamppb.New(time.Now().Add(20 * time.Second)),
 			ContinuousTargets: []*hthv1.ContinuousTarget{
 				{Id: ids.Fan1, Value: 10}, {Id: ids.Fan2, Value: 10}, {Id: ids.Fan3, Value: 10}, {Id: ids.Fan4, Value: 10},
 				{Id: ids.PTC1, Value: 0}, {Id: ids.PTC2, Value: 0}, {Id: ids.PTC3, Value: 0}, {Id: ids.PTC4, Value: 0},

+ 4 - 2
tools/rtl_uart_cosim/run_hthd_pty_rtl.py

@@ -157,7 +157,7 @@ serial:
   io_timeout_ms: 28000
   inter_byte_timeout_ms: 2000
   response_timeout_ms: 28000
-  get_temp_timeout_ms: 20000
+  get_temp_timeout_ms: 90000
   get_motor_timeout_ms: 28000
   probe_timeout_ms: 28000
   set_all_timeout_ms: 2000
@@ -387,6 +387,7 @@ async def main():
         async with await client.acquire_lease("prod2u-0", "rtl-l3", timedelta(seconds=30), auto_renew=False) as lease:
             snap = await client.get_snapshot("prod2u-0")
             b = ActionBatch.builder("prod2u-0", capabilities=caps).based_on(snap.snapshot_seq, snap.control_revision)
+            b.valid_for(timedelta(seconds=180))
             for act in caps.actuators:
                 if "door" in act.id and "close_percent" in act.id:
                     b.set(act.id, 50)
@@ -435,6 +436,7 @@ async def main():
             print("SAFE_ACCEPTED", safe.accepted, safe.dispatch_state, safe.confirmation)
             snap = await client.get_snapshot("prod2u-0")
             rb = ActionBatch.builder("prod2u-0", capabilities=caps).based_on(snap.snapshot_seq, snap.control_revision)
+            rb.valid_for(timedelta(seconds=180))
             for act in caps.actuators:
                 if act.id.startswith("fan."):
                     rb.set(act.id, 10)
@@ -654,8 +656,8 @@ def main() -> int:
         # timeout and look like a reconnect loop. After hthd starts, the UART
         # tap holds MOTOR_STATUS.startup_complete=0 for 10s wall-clock so the
         # production UART path proves no GET_TEMPERATURE during delayed startup.
-        hthd = subprocess.Popen([str(hthd_bin), "--config", str(cfg)], cwd=str(HOST), env={**os.environ})
         tap.mark_hthd_start()
+        hthd = subprocess.Popen([str(hthd_bin), "--config", str(cfg)], cwd=str(HOST), env={**os.environ})
         for _ in range(200):
             if Path(obs).exists() and Path(ctl).exists():
                 break