Repository navigation
feat(runtime): a sandboxed body can do time-zone date maths, through Intl.DateTimeFormat - #29031
Conversation
…hrough plain values Hooks, actions and jobs share the QuickJS runner, so all three get the same global: the whole DateTimeFormat API (format, formatToParts, formatRange, formatRangeToParts, resolvedOptions, supportedLocalesOf), answered by the host's Intl from a plain-value snapshot of the locales and options. Every other Intl member stays absent. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5paXMpX75J4HCKYU6Z
…ames Intl.DateTimeFormat The sandbox now provides Intl.DateTimeFormat and nothing else of Intl, so the free-identifier check reads a member reference as Intl.NAME: Intl.DateTimeFormat lowers, every other member (and the bare name) stays host-only and bundled. The globals probe measures the members. The job handler deprecation text and the jobs guide say time-zone date maths moves to body through Intl.DateTimeFormat. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5paXMpX75J4HCKYU6Z
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5paXMpX75J4HCKYU6Z
📓 Docs Drift CheckThis PR changes 3 package(s): 4 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
⛔ 1 release-owned page(s) also name something this change touched. These are read-only:
What this run could not see
Coarse fallback — 180 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin e1ae1315c60cf8a21a5290646779d632dddc0e2b && git checkout e1ae1315c60cf8a21a5290646779d632dddc0e2b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin ab085a048241b0bf1fde06696fc6cbf659a6707f aed5e2959f15158dac89cb24d1f280486b42e628 && git checkout -B drift-repro ab085a048241b0bf1fde06696fc6cbf659a6707f && git merge --no-ff aed5e2959f15158dac89cb24d1f280486b42e628
node scripts/docs-audit/affected-docs.mjs --json ab085a048241b0bf1fde06696fc6cbf659a6707f
|
|
domain:server#2 · os-project-manager · session_0186vfjHHMsRXC9EUT9hTFMo Contract reviewServed-tier: Reviewed: the net diff of ① Derived judgmentsSchema face (the Sandbox safety — the main question. Read
No sandbox-escape-class finding. No private record was written. One seam. CLI lowering ( Metadata and migration text. ② Semver level
③ Boundary flags
Implemented-by: VERDICT: PASS Generated by Claude Code |
|
domain:server#2 · os-project-manager · session_0186vfjHHMsRXC9EUT9hTFMo 席位核对ACCEPT · The maintainer's standing authorisation for landing reviewed PRs, verbatim: 「按照 pm-dispatch 规则复核过的都授权」.
Generated by Claude Code |
|
domain:server#2 · os-project-manager · session_0186vfjHHMsRXC9EUT9hTFMo Landing record · PR #29031
Release: ships Generated by Claude Code |
Requested by Leehom · project thread
Fixes #28898
Clause-②: no
No published schema, type, export or error code moves. The one
packages/specchange is the jobhandlerkey's.describe()text (and the reference page regenerated from it); the accept set is identical. The sandbox's globals are not declared by any spec schema:ScriptBodySchema.sourceis a string, and what it may call is the runtime's answer, which is what changes here.Metadata-protocol: none
What a metadata author can write is unchanged: no key, value, type or default moves. A body
sourcethat callsIntl.DateTimeFormatwas already accepted at every door; it now runs instead of throwingReferenceError.维护者速读
Intl.DateTimeFormat,完整的一整个构造器(format/formatToParts/formatRange/formatRangeToParts/resolvedOptions/supportedLocalesOf),结果由服务器自己的Intl算出,所以 IANA 时区和夏令时边界与服务器一致。Intl的其它成员都不存在。钩子、动作、作业三种 body 共用同一个 runner,所以三者同时获得。os build的降级判断随之按成员判:只用Intl.DateTimeFormat的 handler 现在能降级成 body,用Intl.NumberFormat等仍打包。作业handler的弃用说明补了一句"时区日期计算可用Intl.DateTimeFormat迁到body"。Intl,作业就离不开已弃用的handler。席位裁定走纯运行时路线,不给ctx加日期助手,作业上下文契约不动。Date.now(),无新 I/O。回滚即 revert,无数据迁移。packages/runtime/src/sandbox/sandbox-intl.ts(垫片与宿主侧的值清洗、错误转译);packages/cli/src/utils/detect-free-identifiers.ts的MEMBER_JUDGED_GLOBALS与collectReferences的成员分支;packages/cli/src/utils/sandbox-globals-probe.test.ts的点号探针。pnpm --filter @objectstack/runtime exec vitest run src/sandbox/sandbox-intl.test.ts,预期Tests 12 passed (12)。What changes
packages/runtime/src/sandbox/sandbox-intl.ts(new):installSandboxIntl(vm)installsglobalThis.Intl(non-enumerable, like the built-in) with one member,DateTimeFormat: callable with or withoutnew,supportedLocalesOf, and the whole prototype (formatas a bound getter,formatToParts,formatRange,formatRangeToParts,resolvedOptions,Symbol.toStringTag). The VM-side constructor keeps only a plain-value snapshot oflocalesand of the option keysDateTimeFormatreads; every call asks the host to answer with a hostIntl.DateTimeFormatbuilt from that snapshot (a per-invocation cache of at most 64 formatters, dropped with the VM).resolvedOptions()and the parts arrays are VM objects. A host error becomes a VMRangeError/TypeErrorwith the host's message: the body's own throw, never a host refusal relayed.JSON,Date.nowand friends at install, so a body replacing them cannot steer the host.format()with no argument takes "now" from the VM's own clock.packages/runtime/src/sandbox/quickjs-runner.ts:execute()callsinstallSandboxIntl(vm)right afterinstallCtx. Every body kind (hook, action, job, and the L1 expression path) goes throughexecute(), so this is one seam and one global set.packages/cli/src/utils/detect-free-identifiers.ts: the measured allowlist learns member granularity. NewMEMBER_JUDGED_GLOBALS = {'Intl'};collectReferencesrecords a non-computedIntl.NAMEread asIntl.NAME;SANDBOX_GLOBALSgainsIntl.DateTimeFormat;NODE_ONLY_GLOBALSswapsIntlfor the ten otherIntlmembers Node 22 has. A bareIntluse (const I = Intl,Intl[k]) or an unlisted member is reported host-only, so that handler stays bundled (the safe direction). A local or parameter namedIntlstill binds it.packages/cli/src/utils/extract-hook-body.ts: the host-only refusal sentence says "ofIntlit providesIntl.DateTimeFormatonly" when anIntlname is refused, and "would throw" where it said "would throw ReferenceError" (a missing member throwsTypeError).packages/spec/src/system/job.zod.ts: thehandlerdocblock and.describe()(the deprecation message) say time-zone date maths moves tobodythroughIntl.DateTimeFormat.content/docs/references/system/job.mdxregenerated (gen:schema && gen:docs).content/docs/automation/jobs.mdx: one bullet under "What running in the sandbox means":Intl.DateTimeFormatis there whole, nothing else ofIntlis, the feature test, and that hook and action bodies share it..changeset/28898-sandbox-intl-date-time-format.md:@objectstack/runtime,@objectstack/cli,@objectstack/specpatch; both declaration lines.Tests
packages/runtime/src/sandbox/sandbox-intl.test.ts(12, real QuickJS). Every expected value is computed with the host'sIntlin the test, never a literal (CI's ICU differs from a container's).formatToPartsof two instants either side of New York's 2026-03-08 spring-forward, inAmerica/New_YorkandAsia/Shanghai, equals the host's (anti-vacuity: the zone name changes in New York and not in Shanghai).format,resolvedOptions,formatRange,formatRangeToPartsequal the host's; the period-start shape (calendar date of one instant in two zones:2026-03-08vs2026-03-09); callable withoutnew, boundformatgetter,instanceof, bothtoStringTags,supportedLocalesOf; options read at construction.timeZonethrows the host'sRangeErrortext as a VMRangeError(and uncaught, fails the run with that text);format(NaN),formatRange(0),formatToParts('not a date')throw what the host throws.Object.getOwnPropertyNames(Intl)is['DateTimeFormat'],typeof Intl.NumberFormatis'undefined',Intlis not enumerable.Object.prototype/Array.prototype), fresh per call; no global named like the bridge; a foreign receiver throwsTypeError; replacingJSON.stringify/Date.nowsteers nothing.jobBodyRunnerFactoryjob reportsperiod 2026-03-09.packages/qa/dogfood/test/job-body-time-zone-date.dogfood.test.ts(1): a booted stack declares a job whosebodyinserts each zone's calendar date of one instant; the job service triggers it, andGET /data/tzj_periodreads both zones' own dates (anti-vacuity: the two dates differ; the job is listed as scheduled first).detect-free-identifiers.test.ts(+3:Intl.DateTimeFormathas no free name; the bare namespace is reported; an unlisted member is reported),extract-hook-body.test.ts(+1: a handler usingIntl.DateTimeFormatlowers),hook-body-lowering.test.ts(+1: no finding for it),sandbox-globals-probe.test.ts(dotted names probed as namespace-then-member; +1: every member-judged namespace measures present and owns every dotted member). Theobjectstack buildlowers an inline hook handler that referencesIntlinto the QuickJS body —detect-free-identifiersallowlists host globals the sandbox does not provide, so the handler passes validate/typecheck/test/build and throws ReferenceError in production #14301 refusal pins move fromIntl.DateTimeFormattoIntl.NumberFormat, a member the sandbox still lacks, so the class stays pinned.Red first, green, ablations
a3640933(new runtime test, unchanged source):Tests 12 failed (12), eachReferenceError: 'Intl' is not defined(the hook case:hook 't' threw: ReferenceError: 'Intl' is not defined).src/sandbox/Test Files 35 passed (35),Tests 341 passed (341).scripts/ablation-replace.mjs, anchorinstallSandboxIntl(vm);hit once, blobf779c2c2to8af3c789; the test importssrc):Test Files 1 failed | 34 passed (35),Tests 12 failed | 329 passed (341): exactly the 12 Intl cases. Restored: blobf779c2c2== HEAD,git diff HEADempty.'Intl.DateTimeFormat',deleted fromSANDBOX_GLOBALS, the four files, allsrc):Tests 4 failed | 136 passed (140): the three new lower-it pins and the named-cases pin. The partition pin stays green, as it must: a name removed from a set is no longer probed, which is why the named-cases pin exists. Restored: blob7df744bf== HEAD,git diff HEADempty.void installSandboxIntl;, blobf779c2c2toa8815ee9;pnpm --filter @objectstack/runtime build;ablation-dist-preflight"marker absent from all 12 built files"):Tests 1 failed (1), the job loggedjob 'tzj_period_stamp' threw: ReferenceError: 'Intl' is not definedand the read was{}. Restored: blob == HEAD,git diff HEADempty; restore leg rebuilt, preflight "marker present in 2 built files", "working tree clean against HEAD",Tests 1 passed (1).Acceptance notes
hookBodyRunnerFactory,actionBodyRunnerFactoryandjobBodyRunnerFactory, inapp-plugin.tsandapp-artifact-handlers.ts, hands the body to aQuickJSScriptRunner, one class in separate instances, andQuickJSScriptRunner.execute()is the only place a VM is made;git grep "new QuickJSScriptRunner"outside tests: 5 hits, all those factories), so they get the sameIntl.DateTimeFormat, as the order rules. The L1 expression path goes throughexecute()too.sandbox-globals-probe.test.tsmeasures the sandbox's globals against the lowering allowlist, so the runtime change alone reds it (Intlmeasures present). MovingIntlwholesale to the sandbox set would have lowered a handler usingIntl.NumberFormatinto a body that throws, theobjectstack buildlowers an inline hook handler that referencesIntlinto the QuickJS body —detect-free-identifiersallowlists host globals the sandbox does not provide, so the handler passes validate/typecheck/test/build and throws ReferenceError in production #14301 failure class; leaving it host-only would keep printing "Intl is not provided by the sandbox", which this change makes false. Judging per member is the smallest honest change, and it is whyDateTimeFormatis whole: a lowered handler callingformatRangemust not throw where the in-process one works.hook-bodysubpath).HookBodyExtractionError.freeIdentifiers/nodeOnlyIdentifiersnow name the member (Intl.NumberFormat) where they namedIntl; the error's shape and members are unchanged (published-subpath-hook-body.pin.test.tsgreen). The refusal sentence's host-only branch changed as listed above; the module-scope sentence the docs quote is byte-identical (its pin is green).new Intl.DateTimeFormat().resolvedOptions()reports the server's default locale and time zone, which a body could not read before. Values, not objects; noted for the seat, not treated as a leak.Date.prototype.toLocaleString(locale, { timeZone })exists and ignores its arguments; a handler using it lowers today and formats in the server zone. Not changed here (not class a/b/c with a measured reach). Dedupe words: toLocaleString timeZone sandbox ignored.packages/runtime/src/sandbox/**, the four cli files,system/job.zod.tsorautomation/jobs.mdx(file lists read per PR); search forquickjs,sandbox,detect-free-identifiers,Intl,job body,hook bodyamong open PRs found no related one.Verification
Run on
aed5e295(basea3640933). Each test command underos-verify-lock(VERDICT command-exit 0unless stated).Package suites, type checks, lint
pnpm --filter '@objectstack/cli^...' buildexit 0;pnpm --filter '@objectstack/dogfood^...' buildexit 0;pnpm --filter @objectstack/spec buildexit 0.pnpm --filter @objectstack/runtime test:Test Files 514 passed (514),Tests 8279 passed | 19 skipped (8298).@objectstack/cliunit tier (vitest run --project unit):Test Files 366 passed, 2 failed forpackages/cli is not built(the twopublished-subpath-*.pinfiles); afterpnpm --filter @objectstack/cli buildthose two:Test Files 2 passed (2),Tests 29 passed (29). So 368 of 368 files green. The integration tier is declared to CI (no integration-tier file or spawn entry touched).pnpm --filter @objectstack/runtime typecheckandpnpm --filter @objectstack/cli typecheck: exit 0, bothcheck:test-typecheck: OK.Tests 1 passed (1)on the built dist. The full battery is not owed (no!in the title, no narrowing arm).eslint --no-inline-configover the eleven changed source and test files: exit 0.Derived gates
node scripts/pm/dispatch-gates.mjs --commands(derived onaed5e295against merge basea3640933): 108 families, each run withtimeout 900 bash -c CMDfrom/dev/null, exit captured before any pipe; recordpm-orders/server/28898-gates-ran.txt(CMD :: exit N). Reconciled:✓ dispatch-gates --ran: 108 derived famil(ies) accounted for — 108 run, 0 NOT-MEASURED (a DERIVED zero — all 108 recorded an exit code and none of them is 3).All 108 exit 0, among them
check:docs(235 generated files in sync),check:generated(All 14 generated artifacts are up to date),check:authorable-surface,check:api-surface,check:type-check-debt,check:nul-bytes,check:test-source-alias,check:i18n-coverage,check:dual-build-cjs-loadsandcheck:skill-examples. A first pass onb4099da2(before the dogfood file) read 104 at 0 and 4 at 3 (prerequisite not met: the plugin-teardown self-test needed its pinned commit fetched; the other three needed builds of packages outside this diff); the final pass above ran aftergit fetch --depth=1of that commit and the dogfood closure build. Families CI owns (Test Core, the type-check lanes,pnpm lint) are read on this PR's check-runs.Generated by Claude Code