Skip to content

Commit 4fd76d0

Browse files
Wintermutethomaspblock
andcommitted
fix(projects): address review — assignment fetch bounds, partial-publish recovery, timestamp cap
Review items from #5792 (wpfleger96): 1. Drop the GHCR login retry from docker.yml — unrelated to Projects v3; will be proposed separately with rationale applied to all four login sites if still wanted. 2. Mirror the ACP path's +300s created_at cap in the desktop publish_project_owner_announcement command (moved into the validate function, with a unit test). These are addressable events where latest created_at wins; a far-future stamp would wedge the head. 3. Ack-and-drop unparseable entity deep links instead of leaving them queued, so one bad link can no longer wedge every later link behind the queue head. Unmount still leaves links queued for the next listener. 4. Make add-repository retry heal a dangling project member instead of throwing. The two-event publish can fail between the project head and the repository event; previously the "already contains" guard made that state unrecoverable. Now: - buildAddedRepositoryEventTemplatesFromHead accepts repositoryHeadExists and returns resume templates (publish only the missing repository event) when the live head references a coordinate with no repository head; - the owner-agent path consumes the ACP frame's partial-success events (PartialAnnouncementPublishError) and resumes in-flight; - the dominated-write guard no longer blocks the heal (resume publishes no project head, so nothing can be clobbered). Covered by tests for the retry-after-event-2-failure flow and the still-a-conflict case when a live repository head exists. 5. Load assignment/unassignment operations to exhaustion instead of trusting the bounded comment windows (500/repo in hooks.ts, 2,000 shared in projectWorkItems.ts). A dedicated #t-filtered query paginates with an id-deduped until cursor and merges into the comment set before reduction; a failed query surfaces as a failed "assignments" section rather than silently dropping assignees. Regression test: an assignment older than 500+ unrelated comments still reduces to an assignee. Co-authored-by: Thomas Petersen <[email protected]> Signed-off-by: Thomas Petersen <[email protected]>
1 parent 8f16c4c commit 4fd76d0

13 files changed

Lines changed: 672 additions & 84 deletions

‎.github/workflows/docker.yml‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,7 @@ jobs:
377377
[worker.oci]
378378
max-parallelism = 2
379379
- name: Log in to GHCR
380-
id: ghcr-login
381380
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
382-
continue-on-error: true
383-
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
384-
with:
385-
registry: ghcr.io
386-
username: ${{ github.repository_owner }}
387-
password: ${{ secrets.GITHUB_TOKEN }}
388-
- name: Retry GHCR login
389-
if: steps.ghcr-login.outcome == 'failure'
390381
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
391382
with:
392383
registry: ghcr.io

‎desktop/src-tauri/src/commands/project_git_workflow.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ fn validate_project_owner_announcement(
173173
if !has_valid_d_tag {
174174
return Err("Project and repository announcements require a non-empty d tag.".to_string());
175175
}
176+
if let Some(created_at) = input.created_at {
177+
// Mirror the ACP publish path (`build_project_owner_announcement_events`):
178+
// these are addressable events where the latest created_at wins, so a
179+
// far-future timestamp would wedge the head until that time. Reject
180+
// anything more than 5 minutes ahead.
181+
if created_at > Timestamp::now().as_secs().saturating_add(300) {
182+
return Err("Announcement timestamp is too far in the future.".to_string());
183+
}
184+
}
176185
Ok(())
177186
}
178187

@@ -730,6 +739,29 @@ mod tests {
730739
);
731740
}
732741

742+
#[test]
743+
fn project_owner_announcement_rejects_far_future_timestamps() {
744+
// Mirrors the ACP path's +300s cap: an addressable head stamped far in
745+
// the future could not be superseded until that time.
746+
let base = ProjectOwnerAnnouncementInput {
747+
target_owner: "a".repeat(64),
748+
kind: 30_621,
749+
content: String::new(),
750+
created_at: Some(Timestamp::now().as_secs() + 200),
751+
tags: vec![vec!["d".to_string(), "project".to_string()]],
752+
};
753+
assert!(validate_project_owner_announcement(&base).is_ok());
754+
755+
let far_future = ProjectOwnerAnnouncementInput {
756+
created_at: Some(Timestamp::now().as_secs() + 301),
757+
..base
758+
};
759+
assert_eq!(
760+
validate_project_owner_announcement(&far_future),
761+
Err("Announcement timestamp is too far in the future.".to_string())
762+
);
763+
}
764+
733765
#[test]
734766
fn repository_comparison_normalizes_git_suffix_and_trailing_slash() {
735767
assert!(same_repository(
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import assert from "node:assert/strict";
2+
import test from "node:test";
3+
4+
import {
5+
fetchAssignmentOperationEvents,
6+
mergeEventsById,
7+
} from "./assignmentOperationFetch.ts";
8+
import { fetchProjectsWorkItems } from "./projectWorkItems.ts";
9+
10+
const REPO_OWNER = "a".repeat(64);
11+
const REPO_ADDRESS = `30617:${REPO_OWNER}:relay`;
12+
const ISSUE_ID = "1".repeat(64);
13+
const ASSIGNEE = "b".repeat(64);
14+
15+
function makeIssue() {
16+
return {
17+
id: ISSUE_ID,
18+
kind: 1621,
19+
pubkey: REPO_OWNER,
20+
created_at: 100,
21+
content: "An issue",
22+
tags: [
23+
["a", REPO_ADDRESS],
24+
["subject", "Fix the thing"],
25+
],
26+
};
27+
}
28+
29+
/** Owner-signed assignment operation (kind:1, `t: assignment`). */
30+
function makeAssignment(id, createdAt) {
31+
return {
32+
id,
33+
kind: 1,
34+
pubkey: REPO_OWNER,
35+
created_at: createdAt,
36+
content: "Assigned",
37+
tags: [
38+
["e", ISSUE_ID, "", "root"],
39+
["a", REPO_ADDRESS],
40+
["p", ASSIGNEE],
41+
["t", "assignment"],
42+
],
43+
};
44+
}
45+
46+
function makeComment(id, createdAt) {
47+
return {
48+
id,
49+
kind: 1,
50+
pubkey: REPO_OWNER,
51+
created_at: createdAt,
52+
content: `Comment ${id.slice(0, 4)}`,
53+
tags: [
54+
["e", ISSUE_ID, "", "root"],
55+
["a", REPO_ADDRESS],
56+
],
57+
};
58+
}
59+
60+
function eventId(index) {
61+
return index.toString(16).padStart(64, "0");
62+
}
63+
64+
// ── fetchAssignmentOperationEvents: pagination to exhaustion ────────────────
65+
66+
test("fetchAssignmentOperationEvents paginates past the page limit", async () => {
67+
// 1,203 operations — three pages at the 500-event page limit. The stub
68+
// honors `until` (inclusive) and `limit` like a relay: newest first.
69+
const operations = Array.from({ length: 1_203 }, (_, index) =>
70+
makeAssignment(eventId(index + 1), 1_000_000 + index),
71+
);
72+
const calls = [];
73+
const fetchEvents = async (filter) => {
74+
calls.push(filter);
75+
assert.deepEqual(filter["#t"], ["assignment", "unassignment"]);
76+
const until = filter.until ?? Number.POSITIVE_INFINITY;
77+
return operations
78+
.filter((event) => event.created_at <= until)
79+
.sort((left, right) => right.created_at - left.created_at)
80+
.slice(0, filter.limit);
81+
};
82+
83+
const events = await fetchAssignmentOperationEvents(
84+
[REPO_ADDRESS],
85+
fetchEvents,
86+
);
87+
88+
assert.equal(events.length, 1_203, "every operation must be loaded");
89+
assert.ok(calls.length >= 3, "must page past the 500-event window");
90+
});
91+
92+
test("fetchAssignmentOperationEvents stops when a page adds nothing unseen", async () => {
93+
// A degenerate relay that always returns the same full page must not loop
94+
// forever: a page with zero unseen events terminates pagination.
95+
const page = Array.from({ length: 500 }, (_, index) =>
96+
makeAssignment(eventId(index + 1), 1_000),
97+
);
98+
let callCount = 0;
99+
const fetchEvents = async () => {
100+
callCount += 1;
101+
return page;
102+
};
103+
104+
const events = await fetchAssignmentOperationEvents(
105+
[REPO_ADDRESS],
106+
fetchEvents,
107+
);
108+
109+
assert.equal(events.length, 500);
110+
assert.equal(callCount, 2, "second identical page must terminate the loop");
111+
});
112+
113+
test("fetchAssignmentOperationEvents skips the relay for zero repositories", async () => {
114+
const events = await fetchAssignmentOperationEvents([], async () => {
115+
throw new Error("must not query the relay");
116+
});
117+
assert.deepEqual(events, []);
118+
});
119+
120+
test("mergeEventsById drops duplicates and keeps both sources", () => {
121+
const shared = makeAssignment(eventId(1), 10);
122+
const merged = mergeEventsById(
123+
[shared, makeComment(eventId(2), 11)],
124+
[shared, makeAssignment(eventId(3), 12)],
125+
);
126+
assert.deepEqual(
127+
merged.map((event) => event.id),
128+
[eventId(1), eventId(2), eventId(3)],
129+
);
130+
});
131+
132+
// ── Regression: assignment predating a full comment window ─────────────────
133+
//
134+
// The reduction in projectIssues.mjs is only as complete as the events it is
135+
// handed. The general comment fetch is bounded (2,000 shared across repos in
136+
// fetchProjectsWorkItems), so an old assignment operation can be evicted by
137+
// newer unrelated comments. The dedicated `#t`-filtered exhaustive query must
138+
// restore it.
139+
140+
test("an assignment older than 500+ newer comments still reduces to an assignee", async () => {
141+
const issue = makeIssue();
142+
// Operation at t=200, then 600 newer comments that fill the bounded window.
143+
const assignment = makeAssignment(eventId(9_999), 200);
144+
const comments = Array.from({ length: 600 }, (_, index) =>
145+
makeComment(eventId(index + 1), 300 + index),
146+
);
147+
148+
const fetchEvents = async (filter) => {
149+
if (filter.kinds?.includes(1621)) return [issue];
150+
if (filter["#t"]) return [assignment];
151+
if (filter.kinds?.includes(1)) {
152+
// Bounded comment window: newest first, capped — the assignment
153+
// operation has been pushed out.
154+
return comments
155+
.sort((left, right) => right.created_at - left.created_at)
156+
.slice(0, 500);
157+
}
158+
return [];
159+
};
160+
161+
const result = await fetchProjectsWorkItems(
162+
[{ repositories: [{ repoAddress: REPO_ADDRESS }] }],
163+
fetchEvents,
164+
);
165+
166+
assert.equal(result.issues.items.length, 1);
167+
assert.deepEqual(
168+
result.issues.items[0].issue.assignees,
169+
[ASSIGNEE],
170+
"assignee evicted from the comment window must be restored by the dedicated assignment query",
171+
);
172+
});
173+
174+
test("a failed assignment query surfaces as a failed section instead of silent loss", async () => {
175+
const issue = makeIssue();
176+
const fetchEvents = async (filter) => {
177+
if (filter.kinds?.includes(1621)) return [issue];
178+
if (filter["#t"]) throw new Error("relay hiccup");
179+
return [];
180+
};
181+
182+
const result = await fetchProjectsWorkItems(
183+
[{ repositories: [{ repoAddress: REPO_ADDRESS }] }],
184+
fetchEvents,
185+
);
186+
187+
assert.ok(result.issues.failedSections.includes("assignments"));
188+
});
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { relayClient } from "@/shared/api/relayClient";
2+
import type { RelayEvent } from "@/shared/api/types";
3+
import { KIND_TEXT_NOTE } from "@/shared/constants/kinds";
4+
import {
5+
ISSUE_ASSIGNMENT_LABEL,
6+
ISSUE_UNASSIGNMENT_LABEL,
7+
} from "./projectIssues.mjs";
8+
9+
type FetchEventsInput = Parameters<(typeof relayClient)["fetchEvents"]>[0];
10+
11+
const ASSIGNMENT_PAGE_LIMIT = 500;
12+
13+
/**
14+
* Loads every assignment/unassignment operation for the given repositories,
15+
* paginating to exhaustion instead of trusting a bounded comment window.
16+
*
17+
* Why: assignment state is reduced from kind:1 operations (`t: assignment` /
18+
* `t: unassignment`), but the general comment fetches are bounded (500 per
19+
* repo in `hooks.ts`, 2,000 shared in `projectWorkItems.ts`). Once newer
20+
* comments push an older operation out of that window, its assignee silently
21+
* vanishes from the issue — and a later self-service operation can reduce
22+
* against the wrong `prior` head. Operations are rare relative to comments,
23+
* so a label-filtered exhaustive query stays small.
24+
*
25+
* Pagination uses an inclusive `until` cursor with id-level dedupe and stops
26+
* when a page yields nothing unseen. A bare `until` cursor cannot escape a
27+
* single second denser than one full page (see `ChannelPageCursor` in
28+
* shared/api/types.ts), but that would require >500 assignment operations
29+
* signed within one second — not producible by any supported writer.
30+
*/
31+
export async function fetchAssignmentOperationEvents(
32+
repoAddresses: string[],
33+
fetchEvents: (
34+
filter: FetchEventsInput,
35+
) => Promise<RelayEvent[]> = relayClient.fetchEvents.bind(relayClient),
36+
): Promise<RelayEvent[]> {
37+
if (repoAddresses.length === 0) return [];
38+
const seen = new Map<string, RelayEvent>();
39+
let until: number | undefined;
40+
for (;;) {
41+
const page = await fetchEvents({
42+
kinds: [KIND_TEXT_NOTE],
43+
"#a": repoAddresses,
44+
"#t": [ISSUE_ASSIGNMENT_LABEL, ISSUE_UNASSIGNMENT_LABEL],
45+
limit: ASSIGNMENT_PAGE_LIMIT,
46+
...(until === undefined ? {} : { until }),
47+
});
48+
let unseen = 0;
49+
for (const event of page) {
50+
if (!seen.has(event.id)) {
51+
seen.set(event.id, event);
52+
unseen += 1;
53+
}
54+
}
55+
if (unseen === 0 || page.length < ASSIGNMENT_PAGE_LIMIT) break;
56+
until = Math.min(...page.map((event) => event.created_at));
57+
}
58+
return [...seen.values()];
59+
}
60+
61+
/** Merge two event lists, dropping duplicates by event id. */
62+
export function mergeEventsById(
63+
base: RelayEvent[],
64+
extra: RelayEvent[],
65+
): RelayEvent[] {
66+
const ids = new Set(base.map((event) => event.id));
67+
return [...base, ...extra.filter((event) => !ids.has(event.id))];
68+
}

‎desktop/src/features/projects/hooks.ts‎

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ import type {
3838
RelayEvent,
3939
} from "@/shared/api/types";
4040
import { summarizeProjectActivityEvents } from "./projectActivity.mjs";
41+
import {
42+
fetchAssignmentOperationEvents,
43+
mergeEventsById,
44+
} from "./assignmentOperationFetch";
4145
import type { ProjectIssue } from "./projectIssues.mjs";
4246
import {
4347
nextProjectIssueCommentCreatedAt,
@@ -224,30 +228,39 @@ async function fetchRepoState(project: Repository): Promise<RepoState | null> {
224228
async function fetchProjectIssues(
225229
project: Repository,
226230
): Promise<ProjectIssue[]> {
227-
const [issueEvents, statusEvents, commentEvents] = await Promise.all([
228-
relayClient.fetchEvents({
229-
kinds: [KIND_GIT_ISSUE],
230-
"#a": [project.repoAddress],
231-
limit: 200,
232-
}),
233-
relayClient.fetchEvents({
234-
kinds: [
235-
KIND_GIT_STATUS_OPEN,
236-
KIND_GIT_STATUS_MERGED,
237-
KIND_GIT_STATUS_CLOSED,
238-
KIND_GIT_STATUS_DRAFT,
239-
],
240-
"#a": [project.repoAddress],
241-
limit: 500,
242-
}),
243-
relayClient.fetchEvents({
244-
kinds: [KIND_TEXT_NOTE],
245-
"#a": [project.repoAddress],
246-
limit: 500,
247-
}),
248-
]);
231+
const [issueEvents, statusEvents, commentEvents, assignmentEvents] =
232+
await Promise.all([
233+
relayClient.fetchEvents({
234+
kinds: [KIND_GIT_ISSUE],
235+
"#a": [project.repoAddress],
236+
limit: 200,
237+
}),
238+
relayClient.fetchEvents({
239+
kinds: [
240+
KIND_GIT_STATUS_OPEN,
241+
KIND_GIT_STATUS_MERGED,
242+
KIND_GIT_STATUS_CLOSED,
243+
KIND_GIT_STATUS_DRAFT,
244+
],
245+
"#a": [project.repoAddress],
246+
limit: 500,
247+
}),
248+
relayClient.fetchEvents({
249+
kinds: [KIND_TEXT_NOTE],
250+
"#a": [project.repoAddress],
251+
limit: 500,
252+
}),
253+
// Assignment state must reduce over the complete operation history, not
254+
// whatever survives the bounded comment window above — see
255+
// fetchAssignmentOperationEvents.
256+
fetchAssignmentOperationEvents([project.repoAddress]),
257+
]);
249258

250-
return projectIssueEventsToIssues(issueEvents, statusEvents, commentEvents);
259+
return projectIssueEventsToIssues(
260+
issueEvents,
261+
statusEvents,
262+
mergeEventsById(commentEvents, assignmentEvents),
263+
);
251264
}
252265

253266
async function fetchProjectPullRequests(

0 commit comments

Comments
 (0)