Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(swarm): Lent accrual no longer wakes the machine's own host every 15 s (#1818)

0xken15a40af3c7e66b
diff --git a/backend/integration/superTabRead.test.ts b/backend/integration/superTabRead.test.ts
index 35966a54e..448d3d1ff 100644
--- a/backend/integration/superTabRead.test.ts
+++ b/backend/integration/superTabRead.test.ts
@@ -518,6 +518,17 @@ describe('host form (design 4.10)', () => {
expect((await host(cursor)).body.data).toMatchObject({ tabs: [], removedTabIds: [] })
})
+ it('sleeps through the Lent hours a reading credits to the machine\'s running workers', async () => {
+ const s = await hostScene()
+ await reading(s.tabId, (await fullRead(s.tabId)).generation)
+ const { cursor, generation } = await fullRead(s.tabId)
+ await reading(s.tabId, generation)
+ const lent = await db.$transaction(async tx => (await parts.loadActive(tx, s.tabId)).machines.find(m => m.key === machine)!.data!.contribution?.lent)
+ expect(lent?.[0]?.agentMs).toBeGreaterThan(0)
+ clock = Date.now()
+ expect((await host(cursor)).body.data).toMatchObject({ tabs: [], removedTabIds: [] })
+ })
+
it('names a Swarm that no longer lists the machine', async () => {
const s = await hostScene()
clock = NOW
diff --git a/backend/src/superTabs/parts/commit.test.ts b/backend/src/superTabs/parts/commit.test.ts
index fcef77806..10cdeffb9 100644
--- a/backend/src/superTabs/parts/commit.test.ts
+++ b/backend/src/superTabs/parts/commit.test.ts
@@ -44,6 +44,15 @@ describe('what a write tells host reads (review round 1)', () => {
expect(hostMarker('machine', machine(), machine({}, reading(2)), none, 9)).toEqual({})
})
+ it('leaves it alone when only the Lent hours credited from that reading changed', () => {
+ const lent = (agentMs: number, observation?: Record<string, unknown>) => {
+ const part = machine({}, observation)
+ return { ...part, contribution: { ...part.contribution, lent: [{ week: 0, agentMs }] } }
+ }
+ expect(hostMarker('machine', machine({}, reading(1)), lent(15_000, reading(2)), none, 9)).toEqual({})
+ expect(hostMarker('machine', lent(15_000), lent(30_000), none, 9)).toEqual({})
+ })
+
it('moves it for a change to the machine\'s settings or ledger, and when the part is added or removed', () => {
const at = { host: { hostChangedAt: new Date(9) } }
const paused = machine({}, reading(2))
diff --git a/backend/src/superTabs/parts/commit.ts b/backend/src/superTabs/parts/commit.ts
index 43f549624..3c91f886c 100644
--- a/backend/src/superTabs/parts/commit.ts
+++ b/backend/src/superTabs/parts/commit.ts
@@ -90,10 +90,11 @@ export function capReleased(state: SuperTabState): void {
* counters or the visibility epoch move, and the index row when a person, invitation or machine reference was added or
* removed. Every write is guarded by the version it was read at.
*/
-/** A machine part without its machine's own reading: what that machine's host needs to hear about. */
+/** A machine part without its machine's own reading, nor the Lent hours each reading credits (leaderboard/lent.ts): what
+ * that machine's host needs to hear about. */
const withoutReading = (data: unknown) => {
const machine = data as MachineData | undefined
- return machine && { ...machine, contribution: machine.contribution && { ...machine.contribution, observation: undefined } }
+ return machine && { ...machine, contribution: machine.contribution && { ...machine.contribution, observation: undefined, lent: undefined } }
}
/**