Repository navigation
Commit b6e6545
feat(runtime): package jobs honour the host's per-kernel scheduledWorkPolicy (#31423)
<!-- claude-projects-attribution: {"github_login":"os-project-manager"}
-->
_Requested by **Leehom** · [project
thread](https://claude.ai/code/project/chan_01TenzsRopZj4jMbvjX8uz1X?thread=cmsg_01TenzsRopZj4jMbvjX8uz1XUJTu64tU69Q3BhNU1nAuhF)_
Fixes #31382
Clause-②: yes — an optional `scheduledWorkPolicy` member on `AppPlugin`
/ `AppArtifactJobSchedulingOptions` (both exported from runtime's `.`
entry, measured: `packages/runtime/src/index.ts` exports `AppPlugin` and
the type `AppArtifactJobSchedulingOptions`) and two names newly exported
by `@objectstack/types` (`ScheduledWorkPolicySource`,
`readScheduledWorkPolicy`) widen published surfaces; nothing narrows
Metadata-protocol: none
## 维护者速读
- 改了什么:`AppPlugin` 和包 job 排程器 `scheduleAppArtifactJobs` 现在接受宿主按内核给的
`scheduledWorkPolicy`(值或解析函数),和引擎、两个时间触发器用的是同一个类型。策略关掉时,这个内核不排程包里的
`jobs`,之前排过的取消,日志写宿主自己的原因。
- 为什么改:宿主(云端托管运行时)按内核关掉定时工作后,`schedule` 流程不武装,但同一个包的 `jobs` 还在跑。云端实测
Free 环境 2.5 秒写了 5 行(cloud#3733 等这个缝)。
- 风险与回滚:不传策略时逐字节照旧,只读部署开关 `OS_AUTOMATION_SCHEDULED_WORK_ENABLED`(新增
CONTROL 钉住)。`ScheduledWorkPolicySource` / `readScheduledWorkPolicy` 从
`@objectstack/trigger-schedule` 挪到 `@objectstack/types`,trigger-schedule
原名再导出,导入方不用改。回滚即还原本 PR。
- 先看:`packages/runtime/src/app-artifact-handlers.ts` 的
`scheduleAppArtifactJobs` 开关段(`hostPolicy`
一读两用);`packages/types/src/env.ts`
新增的两个名字;`packages/runtime/src/app-plugin.ts` 构造参数。
- 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run
src/app-plugin.scheduled-work-policy.test.ts`,预期 9 个用例全部通过。
- 需要你做的:无,席位落地。
## What changes
- `AppArtifactJobSchedulingOptions` gains an optional
`scheduledWorkPolicy?: ScheduledWorkPolicySource` (a
`ScheduledWorkPolicy` value or a resolver). When it is present,
`scheduleAppArtifactJobs` reads it **once** per call and uses that one
reading in place of both zero-argument reads: `enabled` for the gate
(instead of `resolveScheduledWorkEnabled()`), and
`requiresActingOrganization` / `runOwnership` for the per-job
organization rule (instead of `resolveScheduledWorkPolicy()`).
- Off: nothing is scheduled, `withheld: 'scheduled-work-disabled'`, the
app's previously scheduled jobs are cancelled through `retireAppJobs` as
today, and the one `info` line carries
`scheduledWorkDisabledReason(policy)`, so a host's `hostDisabledReason`
(#21110) is printed instead of the deployment sentence.
- A host resolver that throws fails closed, like the deployment posture
read: nothing scheduled, prior jobs cancelled, `withheld:
'scheduled-work-policy-unreadable'`, one `error` line.
- `AppPlugin`'s third constructor argument gains the same optional
`scheduledWorkPolicy` and hands it to the binder on `kernel:ready`.
- Absent policy: the code path is the old one, read for read
(`resolveScheduledWorkEnabled()` before the job-service probe,
`resolveScheduledWorkPolicy()` after it).
- One spelling of the source type: `@objectstack/runtime` does not
depend on `@objectstack/trigger-schedule` (and should not), so
`ScheduledWorkPolicySource` and `readScheduledWorkPolicy` move into
`@objectstack/types` `env.ts` beside `ScheduledWorkPolicy`.
`schedule-trigger.ts` imports them from there and re-exports both under
the same names, so `@objectstack/trigger-schedule`'s entry still exports
`ScheduledWorkPolicySource` and the triggers' behaviour is unchanged.
The seat widened the claim's file face for this before any edit (claim
6718074628).
- Changeset `31382-package-jobs-host-scheduled-work-policy.md`:
`@objectstack/runtime` patch, `@objectstack/types` patch,
`@objectstack/trigger-schedule` patch (ruling A, #25105: a widening of
TypeScript exports is not a metadata-protocol change).
## Tests
New `packages/runtime/src/app-plugin.scheduled-work-policy.test.ts` (9
cells), the deployment switch ON as the hosted runtime sets it:
- Two kernels in one process, each with the real `CronJobAdapter`: the
`AppPlugin` handed `enabled: false` holds no job and never runs it; the
sibling handed `enabled: true` holds the same job and runs it on
trigger.
- A resolver policy is read at `kernel:ready`; a third kernel in the
same process with no policy stays on the deployment switch.
- Cancel: a kernel rebuilt with an off policy on the same job service
cancels the job the earlier boot scheduled.
- Host reason: one `info` line containing `hostDisabledReason`, and not
naming `OS_AUTOMATION_SCHEDULED_WORK_ENABLED`.
- Binder: off ⇒ `withheld`, prior jobs in `cancelled`; an `isolated`
policy (`requiresActingOrganization: true`) puts an org-less job in
`missingOrganization` while the deployment posture is `single`; a
throwing resolver ⇒ `scheduled-work-policy-unreadable`, prior job
cancelled, one `error`.
- Absent policy (CONTROL): switch off ⇒ the `info` line is exactly
`[Test] declarative jobs NOT scheduled — ` plus
`SCHEDULED_WORK_DISABLED_REASON`; switch off but host hands `enabled:
true` ⇒ scheduled.
The existing suites `app-plugin.jobs.test.ts`,
`app-artifact-handlers.jobs.test.ts`,
`app-artifact-handlers.job-pull.test.ts` (zero-argument path, deployment
sentence, posture rules) are unchanged and green.
<details><summary>Red first and ablations</summary>
Red first on `77a675db` (`main`), the new file in place and no fix:
`Tests 8 failed | 1 passed (9)`. The one green was the absent-policy
deployment-sentence CONTROL. The two-kernels cell read `AssertionError:
the off kernel holds no job: expected [ 'hourly_sweep' ] to deeply equal
[]`; the posture cell read `expected [] to deeply equal [ 'orgless_job'
]`.
Ablations via `node scripts/ablation-replace.mjs` on the committed fix
(`260d1c1d`); each printed `ok mutation landed: anchor 1 -> 0` and then
`ok restored: blob == HEAD (f980f08) and git diff HEAD is empty`:
1. Gate back to the deployment switch only (`if
(!resolveScheduledWorkEnabled())`): `Tests 6 failed | 3 passed (9)`
(two-kernels, resolver, cancel, host reason, binder off,
throwing-resolver cells).
2. Reason back to the deployment constant: `Tests 1 failed | 8 passed
(9)`, the host-reason cell.
3. Posture half back to `resolveScheduledWorkPolicy()`: `Tests 1 failed
| 8 passed (9)`, the `requiresActingOrganization` cell.
</details>
## Acceptance notes
- Out of scope, recorded: `AutomationEngineOptions.scheduledWorkPolicy`
in `packages/services/service-automation/src/engine.ts` still spells the
union inline (`ScheduledWorkPolicy | (() => ScheduledWorkPolicy)`) and
keeps its own private `readScheduledWorkPolicy()`. It is structurally
the same type, so a host passes one value to all three; pointing it at
`@objectstack/types`' `ScheduledWorkPolicySource` is a follow-up for the
seat.
- `@objectstack/trigger-schedule` keeps exporting
`ScheduledWorkPolicySource` from its entry; `readScheduledWorkPolicy`
was and stays off its entry (only `schedule-trigger.ts` re-exports it,
for `time-relative-trigger.ts`).
## Verification
All local runs on head `85ab0691` (branch merged with `origin/main` at
`00a88375`); the second commit only adds a module-top `import
'@objectstack/metadata'` to the new test, after which
`check:test-source-alias`, the new suite and runtime `typecheck` were
re-run green.
- `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack`: 69 derived families. `--ran` with exit
codes recorded: `69 derived, 68 run, 1 NOT-MEASURED, 0 UNRUN`.
- NOT MEASURED: `pnpm check:dual-build-cjs-loads` (exit 3, `PREREQUISITE
NOT MET`: reads every package's `dist/`, and only the runtime /
trigger-schedule closures were built here). CI builds the full tree and
runs it.
- First pass reds, fixed and re-run green: `check:test-source-alias`
(the new test reached `@objectstack/metadata` through `AppPlugin`'s
dynamic import; fixed with the convention's module-top import),
`check-plugin-teardown-shape --self-test` (exit 3, shallow clone; `git
fetch --depth=1` of the pinned fixture commit, then exit 0),
`@objectstack/trigger-schedule` test/typecheck (its devDependency
`@objectstack/service-automation` was not built; after building
`@objectstack/trigger-schedule^...`, exit 0).
- Package suites: `@objectstack/runtime` test `Test Files 556 passed
(556)`, `Tests 8966 passed | 19 skipped (8985)`; `@objectstack/types`
test `Test Files 37 passed (37)`, `Tests 870 passed (870)`;
`@objectstack/trigger-schedule` test and typecheck exit 0; runtime and
types typecheck exit 0.
- `pnpm exec eslint` on the five touched source files: exit 0.
- Full record: `pm-orders/server/31382-gates-ran.txt` (command :: exit
code).
---
_Generated by [Claude
Code](https://claude.ai/code/session_01FEkQ5oC5iX95o2LveAatWo)_
<!-- signed: domain:server#5 · os-project-manager ·
session_01FEkQ5o8PE7ZtVjcor51wBZ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 3d73c1d commit b6e6545
6 files changed
Lines changed: 376 additions & 32 deletions
File tree
- .changeset
- packages
- runtime/src
- triggers/trigger-schedule/src
- types/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
| 145 | + | |
144 | 146 | | |
| 147 | + | |
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
| |||
629 | 632 | | |
630 | 633 | | |
631 | 634 | | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
632 | 652 | | |
633 | 653 | | |
634 | 654 | | |
635 | 655 | | |
636 | 656 | | |
637 | 657 | | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
642 | 663 | | |
643 | 664 | | |
644 | 665 | | |
| |||
764 | 785 | | |
765 | 786 | | |
766 | 787 | | |
767 | | - | |
768 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
769 | 811 | | |
770 | 812 | | |
771 | 813 | | |
| |||
786 | 828 | | |
787 | 829 | | |
788 | 830 | | |
789 | | - | |
| 831 | + | |
790 | 832 | | |
791 | 833 | | |
792 | 834 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
0 commit comments