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
7 changes: 4 additions & 3 deletions connectors/github/src/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2246,9 +2246,10 @@ async function readNamed(
unseenComments,
);
if (issueRows.length === 0 && commentRows.length === 0) continue;
// A transfer copies a comment, so the old one is gone with the issue's
// old address answering 301. Ask it, so the row follows the copy before
// it is archived with an edit waiting.
// The old issue address answers 301 after a transfer, while the REST
// reference lists only 404 for a comment address (read 2026-12-04). Ask the
// issue, so the row follows the copy before it is archived with an edit
// waiting.
const owners =
commentRows.length === 0
? []
Expand Down
8 changes: 4 additions & 4 deletions connectors/github/src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
import { status, type Client } from "./github.js";
import { issuesByNode, nodesOfNumbers } from "./graph.js";

// A transfer gives an issue a new node, number and address, and copies its comments with new nodes and the old times.
// The old address answering 301 to the new issue is the proof; titles are never matched.
// GitHub shows the new issue before it records the transfer, so a possible mid-transfer issue is not written until known.
// A transfer gives an issue a new node, number and address and keeps its comments. The old address answering 301 to the new issue is the proof; titles are never matched.
// GitHub documents the 301, the kept comments, the `TransferredEvent` and the `issues.transferred` delivery (docs.github.com "Transferring an issue to another repository", REST "Get an issue", GraphQL schema, read 2026-12-04).
// Not documented, so assumed and guarded: that the issue and its comment copies get new nodes and the comments keep their old times, and that the new issue shows before its `TransferredEvent`, so a possible mid-transfer issue is not written until known.

type Context = Pick<
RunContext<SettingsDeclaration>,
Expand Down Expand Up @@ -371,7 +371,7 @@ export async function withMovedComments(
});
}

// The copies of a transfer keep the old times, so no listing of what changed since names them.
// A transfer is assumed to keep the comments' old times, so no listing of what changed since names them.
export async function commentsOf(
octokit: Client,
issue: Issue,
Expand Down
9 changes: 6 additions & 3 deletions connectors/google-calendar/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ export class CalendarApi {
: `${events}/${encodeURIComponent(eventId)}`;
}

// Google answers 409 where the calendar already holds the id, deleted or not.
// 409 `duplicate` where the calendar already holds the id
// (developers.google.com/workspace/calendar/api/guides/errors, read 2026-12-04).
// `get` returns a deleted event until Google drops it, so a deleted id is taken to answer 409 too; no page says so.
// The create's own id is how a lost answer is found again: do not replace it with an id Google makes.
async insert(calendarId: string, event: Json): Promise<Json> {
const made = await this.write(
Expand All @@ -160,7 +162,8 @@ export class CalendarApi {
return made;
}

// Google answers 412 where the event changed since `etag`.
// 412 `conditionNotMet` where `If-Match` holds a stale etag
// (developers.google.com/workspace/calendar/api/guides/version-resources, read 2026-12-04).
async patch(
calendarId: string,
eventId: string,
Expand Down Expand Up @@ -199,7 +202,7 @@ export class CalendarApi {
}
}

// Google answers 412 where the event changed since `etag`.
// The move page names no `If-Match`: 412 is taken to answer as for `patch`.
async move(
calendarId: string,
eventId: string,
Expand Down
1 change: 1 addition & 0 deletions connectors/google-calendar/src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ async function splitAgain(
const splitPiece = /_R\d{8}(?:T\d{6}Z?)?$/;

// Narrow on purpose: a 400 for any other event is a refusal, since making it anew would drop what Google holds of it.
// No Google page names this 400 (read 2026-12-04).
function lostSplit(error: unknown, eventId: string): boolean {
return (
error instanceof GoogleError &&
Expand Down
7 changes: 5 additions & 2 deletions connectors/todoist/src/todoist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ export async function user(
return ((await response.json()) as SyncAnswer).user;
}

// Todoist takes a window of up to three months on its completed tasks; twelve weeks fits inside any three months.
// The completed-tasks endpoint takes a range of up to 3 months
// (developer.todoist.com/api/v1, read 2026-12-04); twelve weeks fits inside any three months.
const completedWindowMs = 84 * 86_400_000;

export async function completed(
Expand Down Expand Up @@ -342,7 +343,9 @@ export function describeError(error: CommandError): string {
return `${error.error ?? "an error without a message"}${code}`;
}

// A resent batch reuses its command uuids: do not give a resend fresh ones.
// A resent batch reuses its command uuids: do not give a resend fresh ones. Todoist skips a command whose
// uuid a successful one already used, and remembers it at least 14 days
// (developer.todoist.com/api/v1, Command UUID, read 2026-12-04).
export async function send(
base: string,
token: string,
Expand Down
2 changes: 0 additions & 2 deletions host/src/start-sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ function valid(sequence: unknown): sequence is number {
export function readMintRecord(path: string): MintRecord | undefined {
const text = readIfThere(path);
if (text === undefined) return undefined;
// An earlier release wrote only the version, with no sequence: read it as sequence 0, not as a lost record.
if (/^\d+\.\d+\.\d+$/.test(text)) return { version: text, start_sequence: 0 };
let record: Partial<MintRecord> | null;
try {
record = JSON.parse(text) as Partial<MintRecord> | null;
Expand Down
5 changes: 3 additions & 2 deletions host/test/supervisor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe("the connector host's supervisor", () => {
["missing its sequence", '{"version":"0.0.1"}'],
["holding a version that is no text", '{"version":1,"start_sequence":4}'],
["holding a negative sequence", '{"version":"0.0.1","start_sequence":-1}'],
["only a version", "0.0.1"],
])(
"takes a launch record that is %s as lost, and mints a key it reports with",
async (_, text) => {
Expand Down Expand Up @@ -490,7 +491,7 @@ describe("the connector host's supervisor", () => {
async (ownId) => {
const { api, server, step, starts, home } = supervised(undefined, "off");
writeSecret(home.key("rss"), "cached-test-token");
writeWhole(home.minted("rss"), "0.0.1");
writeWhole(home.minted("rss"), '{"version":"0.0.1","start_sequence":0}');
const identity = vi.spyOn(api, "connectorKeyId").mockResolvedValue(ownId);
api.connectors = [
assigned("rss", "0.0.1", server.serve("rss", connectorCode()), {
Expand All @@ -515,7 +516,7 @@ describe("the connector host's supervisor", () => {
"off",
);
writeSecret(home.key("rss"), "cached-token");
writeWhole(home.minted("rss"), "0.0.1");
writeWhole(home.minted("rss"), '{"version":"0.0.1","start_sequence":0}');
vi.spyOn(api, "connectorKeyId").mockResolvedValue("cached-id");
const entry = assigned(
"rss",
Expand Down
2 changes: 1 addition & 1 deletion kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ if (result.ok) properties.thumbnail = result.uri;
| WebP, lossy or lossless | 200 to 280 | 310 to 480 |
| JPEG in CMYK or YCCK | 470 to 750 | 810 to 1440 |

The JPEG decoder is mozjpeg in WebAssembly (`@jsquash/jpeg`). It decodes into its own memory and copies the 8-bit pixels out, so a JPEG at the limit holds its pixels twice, about 215 MB, and the peak is the same however the picture is subsampled. PNG decoding inflates the data and then unfilters it, and neither step can be skipped, so a PNG is the largest of the common kinds. Each JPEG is read by a decoder of its own, and a large picture's memory is free to go once it is read. Almost all of this memory is outside the connector's 512 MB heap, which holds JavaScript objects and not these buffers. A CMYK or YCCK JPEG is the exception: mozjpeg as built cannot turn CMYK into RGB, so `jpeg-js` reads it instead, and keeps every block of coefficients as its own small array in the heap. In the table the lower figure is a subsampled picture and the higher one is not, and a CMYK JPEG at 25 million pixels that is not subsampled would need between 320 and 384 MB of the heap, which is why such a JPEG is refused above 16 million. A connector that makes thumbnails of large pictures should make one at a time. The decoders are JavaScript and WebAssembly, carried inside the connector's bundle: nothing is read from the disk, and no process or worker starts. A connector that does not import this module does not carry them.
The JPEG decoder is mozjpeg in WebAssembly (`@jsquash/jpeg`). It decodes into its own memory and copies the 8-bit pixels out, so a JPEG at the limit holds its pixels twice, about 215 MB, and the peak is the same however the picture is subsampled. PNG decoding inflates the data and then unfilters it, and neither step can be skipped, so a PNG is the largest of the common kinds. Each JPEG is read by a decoder of its own, and a large picture's memory is free to go once it is read. Almost all of this memory is outside the connector's 512 MB heap, which holds JavaScript objects and not these buffers. A CMYK or YCCK JPEG is the exception: mozjpeg in `@jsquash/jpeg` 1.6.0 refuses CMYK and YCCK, so `jpeg-js` 0.4.4 reads it instead, and keeps every block of coefficients as its own small array in the heap. Its decode peaks at about 13 bytes a pixel, about 325 MB of the heap for a CMYK JPEG at 25 million pixels that is not subsampled, which is why such a JPEG is refused above 16 million. A connector that makes thumbnails of large pictures should make one at a time. The decoders are JavaScript and WebAssembly, carried inside the connector's bundle: nothing is read from the disk, and no process or worker starts. A connector that does not import this module does not carry them.

- **It throws** only for a `maxBytes` that is not a positive whole number.

Expand Down
13 changes: 8 additions & 5 deletions kit/src/thumbnails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export const thumbnailLongSide = 256;
export const maxThumbnailPixels = 25_000_000;

/**
* The most pixels for a CMYK or YCCK JPEG: `jpeg-js` keeps its coefficients in
* the heap, an error no run can catch.
* The most pixels for a CMYK or YCCK JPEG, which `jpeg-js` decodes in the
* heap, where running out ends the process. `jpeg-js` 0.4.4 peaked at 13 bytes
* a pixel, 208 MB at this cap, under `--max-old-space-size=512` (Node 26.13.1).
*/
export const maxInkJpegPixels = 16_000_000;

Expand Down Expand Up @@ -206,9 +207,11 @@ function jpegComponents(bytes: Uint8Array): number {
return 0;
}

// mozjpeg as built cannot turn CMYK or YCCK into RGB, so `jpeg-js` reads them:
// it turns the inks of an Adobe file into RGB and refuses four components with
// no Adobe marker. Strict mode refuses a damaged file rather than repair it.
// mozjpeg in `@jsquash/jpeg` 1.6.0 refuses CMYK and YCCK with "Unsupported
// color conversion request" (libjpeg has no such conversion), so `jpeg-js`
// reads them: it turns the inks of an Adobe file into RGB and refuses four
// components with no Adobe marker. Strict mode refuses a damaged file rather
// than repair it.
function inkJpegSource(bytes: Uint8Array): Source {
const { width, height, data } = jpegJs.decode(bytes, {
useTArray: true,
Expand Down
26 changes: 26 additions & 0 deletions kit/test/thumbnails.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { readFileSync } from "node:fs";
import { encode as encodePng } from "fast-png";
import createJpegDecoder from "@jsquash/jpeg/codec/dec/mozjpeg_dec.js";
import jpegJs from "jpeg-js";
import { describe, expect, it } from "vitest";
import { jpegDecoderWasm } from "../src/codec-wasm.js";
import type { Picture } from "../src/pictures.js";
import {
makeThumbnail,
Expand Down Expand Up @@ -604,6 +606,30 @@ describe("JPEGs as other encoders write them", () => {
},
);

it.each(["adobe-cmyk-halves.jpg", "adobe-ycck.jpg"])(
"refuses %s in the @jsquash/jpeg decoder, which is why jpeg-js reads four-ink JPEGs",
async (name) => {
const messages: string[] = [];
const decoder = await (
createJpegDecoder as unknown as (options: object) => Promise<{
decode(data: ArrayBuffer, preserveOrientation: boolean): unknown;
}>
)({
noInitialRun: true,
print: () => undefined,
printErr: (message: string) => messages.push(message),
wasmBinary: jpegDecoderWasm(),
});
const bytes = picture(name);
const data = bytes.buffer.slice(
bytes.byteOffset,
bytes.byteOffset + bytes.byteLength,
) as ArrayBuffer;
expect(() => decoder.decode(data, false)).toThrow();
expect(messages).toContain("Unsupported color conversion request");
},
);

it("refuses a YCCK JPEG whose data stops short, as the other decoder does", async () => {
const whole = picture("adobe-ycck.jpg");
expect(await refusal(whole.slice(0, Math.floor(whole.length * 0.6)))).toBe(
Expand Down
1 change: 1 addition & 0 deletions scripts/proof/github-stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ export class GitHubStub {
}

// A transfer makes a new issue (new id, node and number; old times, author, text and comment copies) and the old node stops resolving: its comments answer 404 and its address 301.
// GitHub documents the 301, the `TransferredEvent` and the `issues.transferred` delivery (read 2026-12-04); the copies' new nodes and old times and the lag below are assumed.
// `lagging` hides the TransferredEvent until `settleTransfers`; `late` also keeps the old issue as it was; `late` with `showing` shows the event while the old issue still answers 200.
transfer(
issue: Issue,
Expand Down