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
16 changes: 9 additions & 7 deletions pkgs/id/src/web/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1955,11 +1955,12 @@ fn collect_link_reference_definitions(markdown: &str) -> Vec<(usize, String)> {
found
}
};
let single_start = is_link_reference_definition_start(def_stripped).then(|| {
let close =
link_reference_definition_label_close(def_stripped).expect("start shape checked");
(vec![line], def_stripped[close + 2..].to_string(), i + 1)
});
let single_start = if is_link_reference_definition_start(def_stripped) {
link_reference_definition_label_close(def_stripped)
.map(|close| (vec![line], def_stripped[close + 2..].to_string(), i + 1))
} else {
None
};
// A line carrying a list marker starts a NEW list item
// and so a fresh block: `- [url]: ...` after `- Body` is a
// definition in its own item, not a continuation of the
Expand All @@ -1973,8 +1974,9 @@ fn collect_link_reference_definitions(markdown: &str) -> Vec<(usize, String)> {
&& (!in_footnote_block || new_list_item)
&& (single_start.is_some() || multiline_start.is_some())
{
let (mut block, mut after, mut j) =
single_start.or(multiline_start).expect("start checked");
let Some((mut block, mut after, mut j)) = single_start.or(multiline_start) else {
continue;
};
// Rollback point for a title attempted on a FOLLOWING
// line (twenty-first cut): (block length, `after`, j)
// before the first such line is appended. A title that
Expand Down
7 changes: 5 additions & 2 deletions pkgs/id/src/world_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1879,12 +1879,15 @@ impl WorldSessions {
let session = self
.roots
.get(&key.0)
.expect("root inserted above")
.context("root inserted above")?
.open_session(world)
.await?;
self.sessions.insert(key.clone(), session);
}
Ok(self.sessions.get_mut(&key).expect("session inserted above"))
Ok(self
.sessions
.get_mut(&key)
.context("session inserted above")?)
}

/// The live session for (`addr`, `world`), if one is open.
Expand Down
34 changes: 11 additions & 23 deletions pkgs/id/web/src/collab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,11 @@ describe("initCollab protocol handling (#1463, #2824)", () => {

it("caps repeated open-then-drop failures until Init succeeds", () => {
const statuses: string[] = [];
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
null,
undefined,
(status) => statuses.push(status),
));
const conn = track(
initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", null, undefined, (status) =>
statuses.push(status),
),
);

let socket = FakeWebSocket.instances[0];
// The initial connection plus ten reconnects all reach OPEN, but the
Expand All @@ -207,15 +203,11 @@ describe("initCollab protocol handling (#1463, #2824)", () => {

it("starts a fresh retry budget after receiving Init", () => {
const statuses: string[] = [];
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
"notes.md",
null,
undefined,
(status) => statuses.push(status),
));
const conn = track(
initCollab("ws://example.test/collab", makeContainer(), "doc-1", "notes.md", null, undefined, (status) =>
statuses.push(status),
),
);

let socket = FakeWebSocket.instances[0];
for (let i = 0; i < 10; i++) {
Expand Down Expand Up @@ -252,11 +244,7 @@ describe("initCollab protocol handling (#1463, #2824)", () => {
});

it("does not reconnect after an intentional disconnect", () => {
const conn = track(initCollab(
"ws://example.test/collab",
makeContainer(),
"doc-1",
));
const conn = track(initCollab("ws://example.test/collab", makeContainer(), "doc-1"));
const socket = FakeWebSocket.instances[0];

socket.open();
Expand Down
7 changes: 6 additions & 1 deletion pkgs/id/web/src/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,12 @@ function initWorld(): void {
if (frame.type === "upload_ready" && !uploadStarted) {
uploadStarted = true;
const chunkBytes = frame.chunk_bytes;
if (typeof chunkBytes !== "number" || !Number.isInteger(chunkBytes) || chunkBytes < 1 || chunkBytes > 6 * 1024) {
if (
typeof chunkBytes !== "number" ||
!Number.isInteger(chunkBytes) ||
chunkBytes < 1 ||
chunkBytes > 6 * 1024
) {
setStatus("Host returned an invalid module chunk size", "error");
upload.close();
return;
Expand Down
20 changes: 19 additions & 1 deletion pkgs/id/worker-poc/package.json
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
{"description":"PoC (#2271): plaza_* example worlds running unmodified in a Worker isolate, journal equality vs the native wasmtime host.","devDependencies":{"typescript":"^5.6.0","wrangler":"^3.90.0"},"name":"id-worker-poc","private":true,"scripts":{"dev":"wrangler dev","smoke":"node smoke/counter-smoke.mjs && node smoke/post-update-failure.mjs","typecheck":"tsc --noEmit","compare":"node compare/compare.mjs","do-cold-start":"node compare/do-cold-start.mjs","participant-clamp":"node smoke/participant-clamp.mjs","post-update-failure":"node smoke/post-update-failure.mjs"},"type":"module"}
{
"description": "PoC (#2271): plaza_* example worlds running unmodified in a Worker isolate, journal equality vs the native wasmtime host.",
"devDependencies": {
"typescript": "^5.6.0",
"wrangler": "^3.90.0"
},
"name": "id-worker-poc",
"private": true,
"scripts": {
"dev": "wrangler dev",
"smoke": "node smoke/counter-smoke.mjs && node smoke/post-update-failure.mjs",
"typecheck": "tsc --noEmit",
"compare": "node compare/compare.mjs",
"do-cold-start": "node compare/do-cold-start.mjs",
"participant-clamp": "node smoke/participant-clamp.mjs",
"post-update-failure": "node smoke/post-update-failure.mjs"
},
"type": "module"
}
14 changes: 12 additions & 2 deletions pkgs/id/worker-poc/src/guest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ export class PlazaGuest {
): Promise<PlazaGuest> {
const instance = await WebAssembly.instantiate(module, {});
const ex = instance.exports as unknown as PlazaExports;
for (const name of ["memory", "plaza_alloc", "plaza_free", "plaza_init", "plaza_update", "plaza_view", "plaza_out_len"] as const) {
for (const name of [
"memory",
"plaza_alloc",
"plaza_free",
"plaza_init",
"plaza_update",
"plaza_view",
"plaza_out_len",
] as const) {
if (ex[name] === undefined) throw new Error(`guest must export \`${name}\``);
}
if ((ex.plaza_snapshot === undefined) !== (ex.plaza_restore === undefined)) {
Expand Down Expand Up @@ -110,7 +118,9 @@ export class PlazaGuest {
// ID above i32::MAX); -Infinity is a negative non-finite and is
// rejected.
if (typeof participant !== "number" || Number.isNaN(participant)) {
throw new Error(`guest participant must be a non-negative integer, got ${String(participant)} (NaN or non-number)`);
throw new Error(
`guest participant must be a non-negative integer, got ${String(participant)} (NaN or non-number)`,
);
}
if (participant === -Infinity) {
throw new Error("guest participant must be a non-negative integer, got -Infinity");
Expand Down
9 changes: 2 additions & 7 deletions pkgs/id/worker-poc/src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ export interface HostedManifest {

export function assertHostable(manifest: HostedManifest): void {
if (manifest.portability === "native") {
throw new Error(
`manifest ${manifest.name}: portability=native is not hostable in a Worker isolate`,
);
throw new Error(`manifest ${manifest.name}: portability=native is not hostable in a Worker isolate`);
}
if (
manifest.wasm_memory_bytes !== undefined &&
manifest.wasm_memory_bytes > HOSTED_MEMORY_CEILING_BYTES
) {
if (manifest.wasm_memory_bytes !== undefined && manifest.wasm_memory_bytes > HOSTED_MEMORY_CEILING_BYTES) {
throw new Error(
`manifest ${manifest.name}: declared memory ${manifest.wasm_memory_bytes} exceeds hosted ceiling ${HOSTED_MEMORY_CEILING_BYTES} (64MB)`,
);
Expand Down
17 changes: 9 additions & 8 deletions pkgs/id/worker-poc/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ export class WorldObject {
if (this.guest) return Promise.resolve(this.guest);
if (!this.guestPromise) {
this.guestPromise = (async () => {
const rows = this.sql
.exec(`SELECT step, snapshot FROM journal ORDER BY step DESC LIMIT 1`)
.toArray();
const rows = this.sql.exec(`SELECT step, snapshot FROM journal ORDER BY step DESC LIMIT 1`).toArray();
const guest = await loadHostedModule(MANIFEST, COUNTER_WASM as WebAssembly.Module, SEED);
if (rows.length > 0) {
guest.restore(asBytes(rows[0].snapshot));
Expand Down Expand Up @@ -134,9 +132,7 @@ export class WorldObject {
if (req.method === "POST" && url.pathname === "/step") {
// Validate before touching the guest: a malformed request must never
// mutate state it cannot journal.
const body = (await req.json().catch(() => null)) as
| { participant?: unknown; event?: unknown }
| null;
const body = (await req.json().catch(() => null)) as { participant?: unknown; event?: unknown } | null;
const participant = body?.participant;
const event = body?.event;
if (
Expand Down Expand Up @@ -165,8 +161,13 @@ export class WorldObject {
snapshotHash = await sha256Hex(snapshot);
this.sql.exec(
`INSERT INTO journal (step, participant, event, snapshot, view, records, snapshot_hash) VALUES (?, ?, ?, ?, ?, ?, ?)`,
nextStep, participant, event, snapshot, dec.decode(view),
records ? dec.decode(records) : null, snapshotHash,
nextStep,
participant,
event,
snapshot,
dec.decode(view),
records ? dec.decode(records) : null,
snapshotHash,
);
} catch (err) {
// Any failure before the journal commit may leave the guest advanced
Expand Down
15 changes: 14 additions & 1 deletion pkgs/id/worker-poc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
{"compilerOptions":{"allowImportingTsExtensions":true,"lib":["ES2022","DOM"],"module":"ESNext","moduleResolution":"bundler","noEmit":true,"skipLibCheck":true,"strict":true,"target":"ES2022","types":[]},"include":["src/**/*.ts"]}
{
"compilerOptions": {
"allowImportingTsExtensions": true,
"lib": ["ES2022", "DOM"],
"module": "ESNext",
"moduleResolution": "bundler",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022",
"types": []
},
"include": ["src/**/*.ts"]
}
Loading