Skip to content

ADR-0053 Phase 2 · Slice 2: thread context into applyFormulaPlan (read-time formula fields) #1979

Description

@os-zhuang

Part of ADR-0053 Phase 2. Design: #1975 · Parent: #1928.

Slice 2 of 6 — independent of timezone; worth doing on its own. Fix the read-time formula evaluation blind spot.

Problem

applyFormulaPlan evaluates read-time formula virtual fields with only { record } — no now, no execution context, no timezone — packages/objectql/src/engine.ts:88-96, called from find/findOne at engine.ts:1841 and :1907. So today()/daysBetween() inside a formula field run against live wall-clock UTC with no determinism and no user/org access.

Scope

  • Thread { now: nowSnap, timezone, user, org } from opCtx.context (the ExecutionContext already held by find/findOne) into applyFormulaPlan.
  • Mirror applyFieldDefaults, which already does this correctly — packages/objectql/src/engine.ts:691-719.

Acceptance criteria

  • Read-time formula fields receive a pinned now (determinism within one operation) and user/org.
  • Once slice 1 lands, they also receive timezone (until then, 'UTC').
  • Regression: existing formula fields (e.g. days_to_close in example-crm) unchanged in value.

Depends on

Slice 1 for the timezone value (degrades to 'UTC' without it). The now/user/org threading can land immediately.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions