Skip to content

Commit dbefc5e

Browse files
d-csclaude
andcommitted
perf(run-engine): pass the records gate its arguments positionally
The gate took an options object, so every resume allocated a literal to ask a question that is answered no for every organisation today. Two positional arguments make the disabled path allocate nothing, which is what the earlier claim of costing nothing needed in order to be true rather than nearly true. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 3ac2c12 commit dbefc5e

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

internal-packages/run-engine/src/engine/systems/waitpointSystem.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ export type WaitpointSystemOptions = {
3838
* transitioning from, so it costs nothing to pass. The run id rides along for logging and for
3939
* any future per-run override.
4040
*
41+
* Positional rather than an options object, deliberately: an object literal here would be
42+
* allocated on every resume, including the ones that exist only to be told no. Two arguments
43+
* make the disabled path genuinely free rather than nearly free.
44+
*
4145
* Defaults to never. A record set is only reachable through the snapshot store, so until the
4246
* ticket that wires that store supplies this predicate there is no run for which one could
4347
* exist, and no resume does any of this work.
4448
*/
45-
completedWaitpointRecordsEnabled?: (args: { runId: string; organizationId: string }) => boolean;
49+
completedWaitpointRecordsEnabled?: (runId: string, organizationId: string) => boolean;
4650
};
4751

4852
type WaitpointContinuationWaitpoint = Pick<Waitpoint, "id" | "type" | "completedAfter" | "status">;
@@ -66,7 +70,7 @@ export class WaitpointSystem {
6670
private readonly executionSnapshotSystem: ExecutionSnapshotSystem;
6771
private readonly enqueueSystem: EnqueueSystem;
6872
private readonly coordinator: WaitpointCoordinator;
69-
private readonly recordsEnabled: (args: { runId: string; organizationId: string }) => boolean;
73+
private readonly recordsEnabled: (runId: string, organizationId: string) => boolean;
7074

7175
constructor(private readonly options: WaitpointSystemOptions) {
7276
this.$ = options.resources;
@@ -807,7 +811,7 @@ export class WaitpointSystem {
807811
// nothing to build, and deciding that by walking its blocking waitpoints made every resume
808812
// for every organisation pay a scan proportional to its fan-in to reach the same answer.
809813
// Defaults to never, so today this returns here for everyone.
810-
if (!this.recordsEnabled({ runId, organizationId })) {
814+
if (!this.recordsEnabled(runId, organizationId)) {
811815
return undefined;
812816
}
813817

internal-packages/run-engine/src/engine/tests/completedWaitpointRecordsGate.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ vi.setConfig({ testTimeout: 60_000 });
3434
function engineWith(
3535
prisma: never,
3636
redisOptions: never,
37-
completedWaitpointRecordsEnabled?: (args: { runId: string; organizationId: string }) => boolean
37+
completedWaitpointRecordsEnabled?: (runId: string, organizationId: string) => boolean
3838
) {
3939
return new RunEngine({
4040
prisma,
@@ -65,8 +65,8 @@ describe("the completed-waitpoint records gate", () => {
6565
"is consulted exactly once per resume, with the run's organisation",
6666
async ({ prisma, redisOptions }) => {
6767
const consulted: { runId: string; organizationId: string }[] = [];
68-
const engine = engineWith(prisma as never, redisOptions as never, (args) => {
69-
consulted.push(args);
68+
const engine = engineWith(prisma as never, redisOptions as never, (runId, organizationId) => {
69+
consulted.push({ runId, organizationId });
7070
return false;
7171
});
7272

internal-packages/run-engine/src/engine/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ export type RunEngineOptions = {
8585
* run id rides along for logging and for any future per-run override; resolving the
8686
* organisation from it would put a read back on the path this gate keeps free.
8787
*
88+
* Positional arguments, so the disabled path allocates nothing at all.
89+
*
8890
* Omitted means never, so no resume builds a record set.
8991
*/
90-
completedWaitpointRecordsEnabled?: (args: { runId: string; organizationId: string }) => boolean;
92+
completedWaitpointRecordsEnabled?: (runId: string, organizationId: string) => boolean;
9193
queue: {
9294
redis: RedisOptions;
9395
shardCount?: number;

0 commit comments

Comments
 (0)