Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/bus/bus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe("bus — watch", () => {
const listResult = run("list", "--to", "otto", "--json");
const msgs = JSON.parse(listResult.stdout) as Array<{ timestamp: string }>;
expect(msgs.length).toBeGreaterThan(0);
const existingTs = msgs[0].timestamp;
const existingTs = msgs[0]!.timestamp;

const r = spawnSync("bun", [SCRIPT, "watch", "--to", "otto", "--timeout", "0", "--json"], {
encoding: "utf-8",
Expand Down
8 changes: 6 additions & 2 deletions tools/bus/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,18 @@ function main(): void {
// hazard where advancing to the newest timestamp permanently drops earlier writes.
const cursorTimestamp = process.env.ZETA_WATCH_INITIAL_CURSOR ?? new Date().toISOString();
const delivered = new Set<string>();
const listOpts = {
...(topicFilter !== undefined && { topic: topicFilter }),
...(toFilter !== undefined && { to: toFilter }),
};
// Seed: exclude all messages already on disk at or before watch-start.
for (const m of list({ topic: topicFilter, to: toFilter })) {
for (const m of list(listOpts)) {
if (m.timestamp <= cursorTimestamp) delivered.add(m.id);
}
const deadline = timeoutSec >= 0 ? Date.now() + timeoutSec * 1_000 : Infinity;

const poll = () => {
const msgs = list({ topic: topicFilter, to: toFilter });
const msgs = list(listOpts);
const fresh = msgs.filter((m) => !delivered.has(m.id));
for (const m of fresh) {
if (asJson) {
Expand Down
2 changes: 1 addition & 1 deletion tools/bus/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function activeClaims(itemId: string): ClaimRecord[] {
id: m.id,
from: m.from,
itemId: p.itemId,
branch: p.branch,
...(p.branch !== undefined && { branch: p.branch }),
timestamp: m.timestamp,
expiresAt: m.expiresAt,
});
Expand Down
Loading