- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/apply-entry.ts --json
- JSON
- /christopher/abso-core/blame/worker/project/apply-entry.ts?format=json
333 linesFirst import 78% · pinch 13% · speed 5% · codex-capacity-chair 4% · capacity 1% · infra-split 1%Last change capacity in version 200,
333 lines from 7 changes in 7 versions.
2// ApplyEntryHost; today the host is Project. Membership (which atoms are in
3// which space) is applied first, in spaces.ts.
5import type { AtomId, Graph } from "../../src/engine/index.ts";
capacity200Project abso's memory, cut by a third (abso Capacity, prod abso hit its isolate memory limit at 7:20 and 7:25 PM CT). (1) The in-memory membership cache is one least-recently-used cache of 16 sets across every space, not up to 17 per space: each named draft cached whole copies of shared's set, 37 MB on prod abso with 106 drafts. Keyed by the space object, so a space rebuilt under the same name never gets old sets. (2) An agent keeps at most 200 unheard news lines (trimmed in batches of 50), the oldest dropped behind one line counting them: stopped agents kept every line, 7 MB. Measured on Engine's prod export of abso (81,855 entries) with measure-memory.ts --disk --reads: 96.6 MB after load before, 61.1 MB after; 105.3 MB after the heaviest reads before, 66.3 MB after. New tests membership-cache.test.ts and news-cap.test.ts.Compare6import { capNews, outlastsSync } from "./news.ts";
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare8import type {
9 AgentState,
10 ChangeRecord,
11 Entry,
12 NoteRecord,
13 QueuedPublish,
14 Refusal,
15 TellRecord,
16} from "./project-types.ts";
19/** What applying one log entry needs from a project. */
20export interface ApplyEntryHost {
21 readonly graph: Graph;
22 readonly agents: Map<string, AgentState>;
23 readonly atomAt: number[];
24 readonly mods: string[];
25 readonly notes: Map<number, NoteRecord>;
26 readonly changes: Map<number, ChangeRecord>;
27 readonly labels: Map<string, number[]>;
28 readonly refusals: Refusal[];
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare29 /** The newest tells, by id in the order sent, at most TELLS_KEPT. */
30 readonly tells: Map<number, TellRecord>;
32 stamp(time: number | undefined): void;
33 applyMembership(entry: Entry, at: number): void;
34 agentOf(name: string): AgentState;
35 active(agent: AgentState, time: number): void;
36 joinChange(
37 agent: AgentState,
38 entry: Extract<Entry, { type: "publish" | "land" }>,
39 at: number,
40 draft: string | null,
41 landed?: string,
42 ): void;
43 space(name: string): Space;
44 queued(): QueuedPublish[];
45 setQueued(items: QueuedPublish[]): void;
46 setQueuedId(id: number): void;
47 queuedId(): number;
48 setLastNote(id: number): void;
49 lastNote(): number;
50 setAnnounced(n: number): void;
51 announced(): number;
52 at(space: Space, version: number): ReadonlySet<AtomId>;
53 spaceOf(agent: AgentState): Space;
54 draft(agent: AgentState): AtomId[];
55 currentChange(agent: AgentState, time: number): number | undefined;
56 changeRecord(id: number, agent: AgentState, time: number): ChangeRecord;
57}
59/**
60 * Apply one log entry at position `at`. `time` is the entry's time when it
61 * has one, used for news that was logged before every item carried its own.
62 */
63export function applyEntry(host: ApplyEntryHost, entry: Entry, at: number, time: number | undefined): void {
64 const stamped = entry.type === "draft" ? entry.atom.time : "time" in entry ? entry.time : undefined;
65 host.stamp(stamped);
66 // Which atoms are in which space at which version: kept in spaces.ts, the same rules the tables use.
67 host.applyMembership(entry, at);
68 switch (entry.type) {
69 case "init": {
70 host.atomAt[entry.atom.seq] = at;
71 host.graph.add(entry.atom);
72 break;
73 }
74 case "join":
75 host.agents.set(entry.agent, {
76 name: entry.agent,
77 space: SHARED,
78 base: entry.version,
79 synced: false,
80 mine: [],
81 news: [],
82 newsAt: [],
83 told: new Set(),
84 parked: new Map(),
85 marked: [],
86 joined: at,
87 });
88 break;
89 case "draft": {
90 host.atomAt[entry.atom.seq] = at;
91 host.graph.add(entry.atom);
92 const agent = host.agentOf(entry.agent);
93 host.active(agent, entry.atom.time);
94 agent.mine.push(entry.atom.id);
95 agent.lastEdit = {
96 time: entry.atom.time,
97 ...(entry.session ? { session: entry.session } : {}),
98 ...(entry.client ? { client: entry.client } : {}),
99 };
100 if (entry.client?.startsWith("avcs-mod/") && !host.mods.includes(entry.client)) host.mods.push(entry.client);
101 break;
102 }
103 case "publish": {
104 host.atomAt[entry.tie.seq] = at;
105 host.graph.add(entry.tie);
106 const space = host.space(entry.space ?? SHARED);
107 const agent = host.agentOf(entry.agent);
108 if (entry.rebase) {
109 agent.base = entry.version;
110 agent.mine = [];
111 } else {
112 agent.mine.push(entry.tie.id);
113 }
114 host.joinChange(agent, entry, at, space.name === SHARED ? null : space.name);
115 agent.marked = agent.marked.filter((r) => r.space !== (entry.space ?? SHARED));
speed160A held push keeps its message, and why tells every settle: the refusal stores the push's message; why on a line kept by abso settle --yours, --theirs or --both names the collision it was kept from, and both kinds of settle list the settler's held push with its reason; the settle's news and the change page carry it too, and a lone push's change now lists the refusals on its wayCompare116 delete agent.held;
init0Start the project117 if (entry.queued !== undefined) host.setQueued(host.queued().filter((q) => q.id !== entry.queued));
118 break;
119 }
120 case "queued": {
121 const agent = host.agentOf(entry.agent);
122 host.active(agent, entry.time);
123 host.queued().push({
124 id: entry.id,
125 agent: entry.agent,
126 message: entry.message,
127 time: entry.time,
128 changes: [...entry.changes],
129 resolves: [...entry.resolves],
130 ...(entry.settled ? { settled: entry.settled } : {}),
131 ...(entry.change !== undefined ? { change: entry.change } : {}),
132 ...(entry.change !== undefined && entry.change === agent.noteAt && agent.starting
133 ? { note: agent.starting }
134 : {}),
135 });
136 host.setQueuedId(Math.max(host.queuedId(), entry.id));
137 // Its markers were settled when it was queued; what it kept goes out when it lands.
138 agent.marked = agent.marked.filter((r) => r.space !== SHARED);
139 break;
140 }
141 case "note": {
142 if (!entry.person) host.agentOf(entry.agent);
143 const { type: _, ...note } = entry;
144 host.notes.set(entry.id, { ...note, lines: [...entry.lines], at });
145 host.setLastNote(Math.max(host.lastNote(), entry.id));
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare146 if (entry.change !== undefined) {
147 const change = host.changes.get(entry.change);
148 if (change) {
149 change.last = at;
150 host.changes.set(entry.change, change);
151 }
152 }
154 }
155 case "note-closed": {
156 const note = host.notes.get(entry.id);
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare157 if (note) {
158 note.closed = { agent: entry.agent, how: entry.how, time: entry.time };
159 host.notes.set(entry.id, note);
160 }
162 }
163 case "pulled":
164 host.setQueued(host.queued().filter((q) => q.id !== entry.id));
165 host.uncheck(entry.id);
166 break;
167 case "starting": {
168 const agent = host.agentOf(entry.agent);
169 host.active(agent, entry.time);
170 if (entry.text === null) {
171 delete agent.starting;
172 delete agent.noteAt;
173 } else {
174 agent.starting = {
175 text: entry.text,
176 files: [...(entry.files ?? [])],
177 time: entry.time,
178 ...(entry.issue !== undefined ? { issue: entry.issue } : {}),
179 };
180 agent.noteAt = at;
181 }
182 break;
183 }
184 case "sync": {
185 const agent = host.agentOf(entry.agent);
186 agent.base = entry.version;
187 agent.synced = true;
188 // The version it moved to: the newest, or an older one with a label.
189 const set = host.at(host.spaceOf(agent), entry.version);
190 agent.mine = agent.mine.filter((id) => !set.has(id));
191 break;
192 }
193 case "news": {
194 const agent = host.agentOf(entry.agent);
195 agent.news.push(...entry.text);
196 agent.newsAt.push(...entry.text.map(() => time));
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare197 entry.pairs.forEach((p, i) => {
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare199 if (!p.startsWith("announce ")) return;
200 const id = Number(p.slice(9)) || 0;
201 host.setAnnounced(Math.max(host.announced(), id));
202 tellSent(host.tells, id, entry.text[i] ?? entry.text[0] ?? "", agent.name, time);
203 });
capacity200Project abso's memory, cut by a third (abso Capacity, prod abso hit its isolate memory limit at 7:20 and 7:25 PM CT). (1) The in-memory membership cache is one least-recently-used cache of 16 sets across every space, not up to 17 per space: each named draft cached whole copies of shared's set, 37 MB on prod abso with 106 drafts. Keyed by the space object, so a space rebuilt under the same name never gets old sets. (2) An agent keeps at most 200 unheard news lines (trimmed in batches of 50), the oldest dropped behind one line counting them: stopped agents kept every line, 7 MB. Measured on Engine's prod export of abso (81,855 entries) with measure-memory.ts --disk --reads: 96.6 MB after load before, 61.1 MB after; 105.3 MB after the heaviest reads before, 66.3 MB after. New tests membership-cache.test.ts and news-cap.test.ts.Compare204 capNews(agent);
206 }
207 case "discard": {
208 const agent = host.agentOf(entry.agent);
209 const gone = new Set(entry.atoms);
210 agent.mine = agent.mine.filter((id) => !gone.has(id));
211 if (entry.markers) agent.marked.push(...entry.markers.map((r) => ({ ...r, space: agent.space })));
212 break;
213 }
214 case "heard": {
215 const agent = host.agentOf(entry.agent);
speed161A pull keeps the news of what a settle kept: it used to drop it with the news it makes moot, though the pull only brings the file, not whose side survivedCompare216 // A sync's stale heard keeps announcements and settles' news (outlastsSync), so it hears no tell.
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare217 if (entry.stale !== true)
218 for (const tell of host.tells.values())
219 if (tell.heard.get(agent.name) === null) tell.heard.set(agent.name, { at: time });
speed161A pull keeps the news of what a settle kept: it used to drop it with the news it makes moot, though the pull only brings the file, not whose side survivedCompare220 const keep = agent.news.map((t) => entry.stale === true && outlastsSync(t));
222 agent.newsAt = agent.newsAt.filter((_, i) => keep[i]);
223 break;
224 }
225 case "drop": {
226 const gone = new Set(entry.atoms);
227 // Agents keep their own published-but-unsynced atoms in `mine`; dropped ones leave.
228 for (const agent of host.agents.values()) {
229 agent.mine = agent.mine.filter((id) => !gone.has(id));
230 for (const p of agent.parked.values()) p.mine = p.mine.filter((id) => !gone.has(id));
231 }
232 break;
233 }
234 case "label": {
235 const list = (host.labels.get(entry.name) ?? []).filter((v) => v !== entry.version);
236 if (!entry.remove) list.push(entry.version);
237 list.sort((a, b) => a - b);
238 if (list.length > 0) host.labels.set(entry.name, list);
239 else host.labels.delete(entry.name);
240 break;
241 }
242 case "refused":
243 host.refusals.push({
244 agent: entry.agent,
245 draft: entry.space ?? null,
246 via: entry.via,
247 time: entry.time,
248 collisions: entry.collisions.map((c) => ({ ...c })),
speed160A held push keeps its message, and why tells every settle: the refusal stores the push's message; why on a line kept by abso settle --yours, --theirs or --both names the collision it was kept from, and both kinds of settle list the settler's held push with its reason; the settle's news and the change page carry it too, and a lone push's change now lists the refusals on its wayCompare249 ...(entry.message ? { message: entry.message } : {}),
251 {
252 // On the change the agent was working on, when there is one (#44).
253 const agent = host.agentOf(entry.agent);
254 host.active(agent, entry.time);
255 const id = host.currentChange(agent, entry.time);
speed160A held push keeps its message, and why tells every settle: the refusal stores the push's message; why on a line kept by abso settle --yours, --theirs or --both names the collision it was kept from, and both kinds of settle list the settler's held push with its reason; the settle's news and the change page carry it too, and a lone push's change now lists the refusals on its wayCompare256 const refusal = {
257 at,
258 time: entry.time,
259 kinds: [...new Set(entry.collisions.map((c) => c.kind))].sort(),
260 files: [...new Set(entry.collisions.map((c) => c.file))].sort(),
261 ...(entry.message ? { message: entry.message } : {}),
262 };
264 const rec = host.changeRecord(id, agent, entry.time);
speed160A held push keeps its message, and why tells every settle: the refusal stores the push's message; why on a line kept by abso settle --yours, --theirs or --both names the collision it was kept from, and both kinds of settle list the settler's held push with its reason; the settle's news and the change page carry it too, and a lone push's change now lists the refusals on its wayCompare265 rec.refusals.push({ ...refusal, files: [...refusal.files], kinds: [...refusal.kinds] });
codex-capacity-chair109Add opt-in persistent writer state, checked reopen and bounded adoptionCompare267 host.changes.set(id, rec);
speed160A held push keeps its message, and why tells every settle: the refusal stores the push's message; why on a line kept by abso settle --yours, --theirs or --both names the collision it was kept from, and both kinds of settle list the settler's held push with its reason; the settle's news and the change page carry it too, and a lone push's change now lists the refusals on its wayCompare269 // Kept until it pushes: the settle tells the held push's reason, and its change lists the refusal.
270 if (entry.via === "publish")
271 agent.held = [...(agent.held ?? []), { ...refusal, ...(id !== undefined ? { change: id } : {}) }];
273 break;
274 case "switch": {
275 const agent = host.agentOf(entry.agent);
276 const carry = entry.carry ?? true;
277 const draft = host.draft(agent);
278 const carried = new Set(carry ? draft : []);
279 agent.parked.set(agent.space, { base: agent.base, mine: agent.mine.filter((id) => !carried.has(id)) });
280 const back = carry ? undefined : agent.parked.get(entry.space);
281 agent.parked.delete(entry.space);
282 agent.space = entry.space;
283 agent.base = back ? back.base : entry.version;
284 agent.mine = back ? back.mine : [...carried];
285 agent.synced = true;
286 break;
287 }
288 case "land": {
289 host.atomAt[entry.tie.seq] = at;
290 host.graph.add(entry.tie);
291 host.joinChange(host.agentOf(entry.agent), entry, at, null, entry.space);
292 break;
293 }
294 case "amend":
295 case "space":
296 case "space-sync":
297 // Membership only: Membership.apply has done it.
298 break;
299 default: {
300 // A kind this engine doesn't know was written by a newer one. Skipping
301 // it would show, and then build on, a project without that entry, so
infra-split37Comments and test names give each reason in plain words, without naming who raised it
Notes like "(#37, Builder 5)" or "(AVCS - Security)" become "(#37)" or go, and a private commit hash after a name goes with it. Issue numbers and references such as git's CVE-2019-1353 stay. Only comments and test names change; no behavior changes.Compare302 // the load stops instead.
304 throw new ProjectError(
305 "unknown-entry",
306 `log entry ${String(at)} is of kind ${JSON.stringify(kind)}, which this version of abso doesn't know: a newer version wrote it, so this one won't load the project`,
307 );
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare308 }
309 }
310}
312/** How many tells the project keeps who-heard-what for (status's tells). */
313export const TELLS_KEPT = 50;
315/** A tell's news reached one recipient's queue: the tell is kept, the oldest dropped past TELLS_KEPT. */
316function tellSent(
317 tells: Map<number, TellRecord>,
318 id: number,
319 text: string,
320 agent: string,
321 time: number | undefined,
322): void {
323 let tell = tells.get(id);
324 if (tell === undefined) {
325 tell = { id, text, at: time, heard: new Map() };
326 tells.set(id, tell);
327 for (const old of tells.keys()) {
328 if (tells.size <= TELLS_KEPT) break;
329 tells.delete(old);
331 }
pinch31status lists the newest tells and who has heard each: every recipient, with the time its client handed the tell over (or not yet). It's read from the news and heard entries the log already keeps, so nothing new is recorded. Unlike announcements, which lists only what is still undelivered, a tell stays listed once heard, and two tells with the same words stay two. The last 50 are kept. A sync's reset hears no tell. Tests in worker/project/test/tells.test.ts.Compare332 if (!tell.heard.has(agent)) tell.heard.set(agent, null);