tasklite-engine 3.0.0.dev0__py3-none-any.whl → 3.0.0.dev2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. tasklite/__init__.py +42 -18
  2. tasklite/__main__.py +205 -0
  3. tasklite/_report.py +562 -0
  4. tasklite/backend/__init__.py +19 -2
  5. tasklite/backend/base.py +327 -156
  6. tasklite/backend/memory.py +261 -339
  7. tasklite/backend/sqlite_backend.py +416 -488
  8. tasklite/edit.py +1276 -0
  9. tasklite/engine/__init__.py +6 -7
  10. tasklite/engine/_worker_bootstrap.py +221 -0
  11. tasklite/engine/_worker_runtime.py +229 -0
  12. tasklite/engine/admission.py +20 -114
  13. tasklite/engine/authorization.py +989 -0
  14. tasklite/engine/channel.py +531 -468
  15. tasklite/engine/completion.py +193 -275
  16. tasklite/engine/config.py +5 -11
  17. tasklite/engine/dispatch.py +299 -384
  18. tasklite/engine/governor.py +134 -69
  19. tasklite/engine/in_flight.py +20 -88
  20. tasklite/engine/launcher.py +1173 -0
  21. tasklite/engine/recovery.py +147 -100
  22. tasklite/engine/resource.py +50 -103
  23. tasklite/engine/runtime.py +158 -525
  24. tasklite/engine/scheduler.py +9 -46
  25. tasklite/engine/session.py +60 -15
  26. tasklite/engine/store.py +235 -462
  27. tasklite/engine/types.py +29 -40
  28. tasklite/engine/wait.py +8 -0
  29. tasklite/exceptions.py +0 -1
  30. tasklite/models/artifact.py +84 -62
  31. tasklite/models/context.py +37 -30
  32. tasklite/models/graph.py +114 -0
  33. tasklite/models/job.py +3 -5
  34. tasklite/models/records.py +482 -0
  35. tasklite/models/state.py +19 -125
  36. tasklite/models/trigger.py +63 -3
  37. tasklite/pipeline.py +92 -100
  38. tasklite/resource.py +79 -2
  39. tasklite/snapshot.py +608 -405
  40. tasklite/testing.py +424 -11
  41. tasklite/utils/artifact.py +1091 -179
  42. tasklite/utils/encoding.py +21 -40
  43. tasklite/utils/ipc.py +49 -1
  44. tasklite/utils/lockfile.py +50 -19
  45. tasklite/wrappers/__init__.py +1 -1
  46. tasklite/wrappers/discovery.py +13 -16
  47. tasklite/wrappers/http.py +77 -43
  48. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev2.dist-info}/METADATA +23 -16
  49. tasklite_engine-3.0.0.dev2.dist-info/RECORD +60 -0
  50. tasklite/contrib/__init__.py +0 -7
  51. tasklite/engine/execution_access.py +0 -39
  52. tasklite/engine/files.py +0 -52
  53. tasklite/engine/ops.py +0 -25
  54. tasklite/engine/selection.py +0 -186
  55. tasklite/hooks.py +0 -49
  56. tasklite/triggers.py +0 -47
  57. tasklite_engine-3.0.0.dev0.dist-info/RECORD +0 -58
  58. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev2.dist-info}/WHEEL +0 -0
  59. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev2.dist-info}/licenses/LICENSE +0 -0
  60. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev2.dist-info}/top_level.txt +0 -0
@@ -1,9 +1,9 @@
1
- """v2 死锁治理深模块:死锁归因与缺口升级。
1
+ """v2 死锁治理深模块:死锁归因、排除停摆剥离与缺口升级。
2
2
 
3
3
  统一内敛:
4
- 1. 死锁分类缺口连续轮次升级治理;
5
- 2. 细粒度死锁归因分析与批量事务熔断(环检测、
6
- 未知/超容资源、畸形条目)。
4
+ 1. Kahn 入度消减排除停摆拓扑分析(``SelectionStandstill`` / ``partition_standstill``);
5
+ 2. 死锁分类缺口连续轮次升级治理;
6
+ 3. 细粒度死锁归因分析与批量事务熔断(环检测、未知/超容资源、畸形条目)。
7
7
 
8
8
  术语口径:死锁熔断的终态落点是失败档案(failed)——按 uid 唯一
9
9
  终态、与 successes 全局互斥,由 store 的批量失败出口收敛。
@@ -11,55 +11,140 @@
11
11
  from __future__ import annotations
12
12
 
13
13
  import logging
14
- import time
15
14
  from collections.abc import Sequence
16
15
  from dataclasses import dataclass, field
17
- from typing import Any, Protocol
16
+ from typing import Any, TYPE_CHECKING
18
17
 
19
18
  from ..exceptions import TaskLiteError
20
19
  from ..models.job import Job
21
20
  from ..models.state import PipelineState, job_uid_from_snapshot
22
21
  from .scheduler import StandstillFacts
23
- from .selection import SelectionStandstill
22
+
23
+ if TYPE_CHECKING:
24
+ from .session import RunSession
25
+ from .store import StateStore
24
26
 
25
27
  logger = logging.getLogger("tasklite")
26
28
 
27
29
  DEADLOCK_GAP_MAX_ROUNDS = 5
28
30
 
29
31
 
30
- class BulkFailureOutcome(Protocol):
31
- """批量失败转移结果的鸭子形状(失败与级联 UID 列表)。"""
32
+ @dataclass(frozen=True)
33
+ class SelectionStandstill:
34
+ """排除规则与临时排除下的停摆拓扑判定(Kahn 入度消减结果)。
35
+
36
+ 以 ``deferred_uids``(Exclude 命中行 + 运行期临时排除行)为延迟波前,
37
+ 对剩余「允许执行」作业做入度消减:
38
+
39
+ - ``stuck_uids``:入度无法消减为 0 的允许作业,可能包含环成员、缺口
40
+ 及其下游;
41
+ - ``cycle_uids``:仅从 stuck 子图中由 PipelineState 的依赖环检测器识别
42
+ 的真实环成员,供 governor 沿用既有环归因;
43
+ - ``blocked_uids``:入度可消减、且传递依赖最终落在 deferred 波前上的
44
+ 允许作业——本次仅因上游被排除而无法完成,必须留队等待下次 run;
45
+ - ``unblocked_uids``:入度可消减但仍有余量(如资源等待)的允许作业,
46
+ 存在本 run 继续推进的可能,不得据此终止运行。
47
+
48
+ 结论 ``only_blocked_by_exclusion`` 为真当且仅当没有任何允许作业可能
49
+ 在本 run 完成(无 stuck、无 unblocked):此时本 run 干净终止,队列保留。
50
+ """
32
51
 
33
- @property
34
- def failed_uids(self) -> list[str]: ...
52
+ excluded_uids: tuple[str, ...] = ()
53
+ blocked_uids: tuple[str, ...] = ()
54
+ unblocked_uids: tuple[str, ...] = ()
55
+ stuck_uids: tuple[str, ...] = ()
56
+ cycle_uids: tuple[str, ...] = ()
57
+ blocked_by: tuple[tuple[str, str], ...] = ()
35
58
 
36
59
  @property
37
- def cascaded_uids(self) -> list[str]: ...
60
+ def only_blocked_by_exclusion(self) -> bool:
61
+ """剩余队列是否全部为「排除 + 仅被其阻塞」的作业。"""
62
+ return not self.stuck_uids and not self.unblocked_uids
38
63
 
39
64
 
40
- class ArbitrationStore(Protocol):
41
- """死锁仲裁所需的 store 契约。
65
+ def partition_standstill(
66
+ state: PipelineState,
67
+ session: "RunSession",
68
+ ) -> SelectionStandstill | None:
69
+ """以 Kahn 入度消减剥离选择停摆:区分真死锁与「仅被排除阻塞」。
42
70
 
43
- ``state`` 提供只读事实(queue / successes / 环检测);
44
- ``apply_bulk_failure`` 是批量失败档案写入的单一出口(原子提交
45
- 失败档案行、按 uid 删除队列行并级联下游,返回转移结果)。
71
+ 返回 None 表示未启用排除或队列存在畸形行(无可信拓扑事实),交既有
72
+ 配置无效归因。纯计算、无状态变更。
46
73
  """
47
-
48
- @property
49
- def state(self) -> PipelineState: ...
50
-
51
- def apply_bulk_failure(
52
- self, uids_metas: Sequence[tuple[str, dict[str, Any]]]
53
- ) -> BulkFailureOutcome: ...
54
-
55
-
56
- class SelectionStandstillSource(Protocol):
57
- """死锁仲裁消费的执行选择停摆事实源契约(SelectionMachine 自动满足)。"""
58
-
59
- @property
60
- def is_active(self) -> bool: ...
61
-
62
- def partition_standstill(self) -> SelectionStandstill | None: ...
74
+ if not session.has_exclusions:
75
+ return None
76
+ queue = state.queue
77
+ if not queue:
78
+ return SelectionStandstill()
79
+ facts: dict[str, tuple[str, tuple[str, ...]]] = {}
80
+ for job_snapshot in queue:
81
+ try:
82
+ parsed = Job.from_dict(job_snapshot)
83
+ uid, task_type, depends_on = (
84
+ parsed.uid,
85
+ parsed.task_type,
86
+ tuple(parsed.depends_on),
87
+ )
88
+ except (KeyError, TypeError, ValueError, TaskLiteError):
89
+ return None
90
+ facts[uid] = (task_type, tuple(depends_on))
91
+
92
+ deferred = {
93
+ uid
94
+ for uid, (task_type, _deps) in facts.items()
95
+ if session.is_excluded(uid, task_type)
96
+ }
97
+ excluded = set(deferred)
98
+ allowed = set(facts) - deferred
99
+
100
+ # Kahn:只有允许作业参与消减;deferred 与 successes 同为已满足波前。
101
+ indegree: dict[str, int] = {}
102
+ dependents: dict[str, list[str]] = {}
103
+ for uid in allowed:
104
+ count = 0
105
+ for dep in facts[uid][1]:
106
+ if dep in deferred or state.dependency_ready(dep):
107
+ continue
108
+ count += 1
109
+ dependents.setdefault(dep, []).append(uid)
110
+ indegree[uid] = count
111
+ ready = [uid for uid, count in indegree.items() if count == 0]
112
+ reduced: set[str] = set()
113
+ while ready:
114
+ uid = ready.pop()
115
+ reduced.add(uid)
116
+ for child in dependents.get(uid, ()):
117
+ indegree[child] -= 1
118
+ if indegree[child] == 0:
119
+ ready.append(child)
120
+ stuck = allowed - reduced
121
+ cycle_uids = state.find_dependency_cycles(node_uids=stuck) if stuck else []
122
+
123
+ # 仅因排除受阻:从 deferred 沿依赖边反向闭包,再与可消减集求交。
124
+ children: dict[str, list[str]] = {}
125
+ for uid in allowed:
126
+ for dep in facts[uid][1]:
127
+ children.setdefault(dep, []).append(uid)
128
+ root_of: dict[str, str] = {}
129
+ blocked: set[str] = set()
130
+ stack: list[str] = list(deferred)
131
+ while stack:
132
+ cur = stack.pop()
133
+ for child in children.get(cur, ()):
134
+ if child in deferred or child in blocked:
135
+ continue
136
+ blocked.add(child)
137
+ root_of.setdefault(child, root_of.get(cur, cur))
138
+ stack.append(child)
139
+ blocked &= reduced
140
+ return SelectionStandstill(
141
+ excluded_uids=tuple(sorted(excluded)),
142
+ blocked_uids=tuple(sorted(blocked)),
143
+ unblocked_uids=tuple(sorted(reduced - blocked)),
144
+ stuck_uids=tuple(sorted(stuck)),
145
+ cycle_uids=tuple(cycle_uids),
146
+ blocked_by=tuple(sorted((uid, root_of.get(uid, "")) for uid in blocked)),
147
+ )
63
148
 
64
149
 
65
150
  @dataclass(frozen=True)
@@ -146,14 +231,12 @@ class DeadlockGovernor:
146
231
  def arbitrate(
147
232
  self,
148
233
  facts: StandstillFacts | None,
149
- store: ArbitrationStore,
150
- *,
151
- selection_machine: SelectionStandstillSource | None = None,
234
+ store: "StateStore",
152
235
  ) -> DeadlockDecision:
153
236
  """自闭环死锁仲裁单一入口。
154
237
 
155
238
  评估停摆事实:
156
- 0. 若传入 selection_machine 且激活,且无已知死锁成因,先做 Kahn 拓扑消减;
239
+ 0. 若当前会话启用排除且无已知死锁成因,先做 Kahn 拓扑消减;
157
240
  若判定为「仅因 Exclude 阻塞」,闭环返回 action="selection_blocked";
158
241
  1. 若 min_wait == inf,直接触发 resolve_deadlock 进行细粒度归因与批量熔断;
159
242
  2. 若 min_wait 为有限值,但处于 waiting_for_dependency 且存在拓扑成环
@@ -164,19 +247,14 @@ class DeadlockGovernor:
164
247
  self.deadlock_gap_rounds = 0
165
248
  return DeadlockDecision(action="none", should_terminate=False, wait_time=0.0)
166
249
 
167
- selection_active = selection_machine is not None and selection_machine.is_active
250
+ session = store.session
251
+ selection_active = session.has_exclusions
168
252
  selection_standstill = (
169
- selection_machine.partition_standstill()
170
- if selection_active and selection_machine is not None
171
- else None
253
+ partition_standstill(store.state, session) if selection_active else None
172
254
  )
173
255
 
174
256
  # 0. 执行选择先验判定:无明确死锁成因时先检查是否仅因 Exclude 阻塞
175
- if (
176
- selection_active
177
- and selection_machine is not None
178
- and not facts.attribution.has_deadlock_causes
179
- ):
257
+ if selection_active and not facts.attribution.has_deadlock_causes:
180
258
  if (
181
259
  selection_standstill is not None
182
260
  and selection_standstill.only_blocked_by_exclusion
@@ -193,11 +271,10 @@ class DeadlockGovernor:
193
271
  return self._resolve_deadlock(
194
272
  facts,
195
273
  store=store,
196
- selection_machine=selection_machine,
197
274
  selection_standstill=selection_standstill,
198
275
  )
199
276
 
200
- if facts.waiting_for_dependency and store.state is not None:
277
+ if facts.waiting_for_dependency:
201
278
  cycle_uids: Sequence[str]
202
279
  if selection_active:
203
280
  cycle_uids = (
@@ -216,11 +293,9 @@ class DeadlockGovernor:
216
293
  return self._resolve_deadlock(
217
294
  facts,
218
295
  store=store,
219
- selection_machine=selection_machine,
220
296
  selection_standstill=selection_standstill,
221
297
  )
222
298
 
223
-
224
299
  # 3. 资源等待(包含有限时间等待与未知时长通知等待):不视为死锁缺口
225
300
  if facts.has_resource_waiters:
226
301
  self.deadlock_gap_rounds = 0
@@ -231,7 +306,6 @@ class DeadlockGovernor:
231
306
  return self._resolve_deadlock(
232
307
  facts,
233
308
  store=store,
234
- selection_machine=selection_machine,
235
309
  selection_standstill=selection_standstill,
236
310
  )
237
311
 
@@ -243,35 +317,31 @@ class DeadlockGovernor:
243
317
  def resolve_deadlock(
244
318
  self,
245
319
  facts: StandstillFacts,
246
- store: ArbitrationStore,
247
- *,
248
- selection_machine: SelectionStandstillSource | None = None,
320
+ store: "StateStore",
249
321
  ) -> DeadlockDecision:
250
322
  """直接执行死锁归因,并在入口读取当前选择停摆事实。"""
323
+ session = store.session
251
324
  selection_standstill = (
252
- selection_machine.partition_standstill()
253
- if selection_machine is not None and selection_machine.is_active
254
- else None
325
+ partition_standstill(store.state, session) if session.has_exclusions else None
255
326
  )
256
327
  return self._resolve_deadlock(
257
328
  facts,
258
329
  store=store,
259
- selection_machine=selection_machine,
260
330
  selection_standstill=selection_standstill,
261
331
  )
262
332
 
263
333
  def _resolve_deadlock(
264
334
  self,
265
335
  facts: StandstillFacts,
266
- store: ArbitrationStore,
336
+ store: "StateStore",
267
337
  *,
268
- selection_machine: SelectionStandstillSource | None,
269
338
  selection_standstill: SelectionStandstill | None,
270
339
  ) -> DeadlockDecision:
271
340
  """以同一停摆快照完成归因与状态提交。"""
272
341
  effective_state = store.state
342
+ session = store.session
273
343
  effective_gap_max = self.deadlock_gap_max_rounds
274
- selection_active = selection_machine is not None and selection_machine.is_active
344
+ selection_active = session.has_exclusions
275
345
 
276
346
  attr = facts.attribution
277
347
  malformed_uids = set(attr.malformed_uids)
@@ -344,13 +414,9 @@ class DeadlockGovernor:
344
414
  self.deadlock_gap_rounds = 0
345
415
 
346
416
  # resolved 但零归档时的选择收敛闭环(如归档全部被选择过滤)
347
- if (
348
- not outcome.failed_uids
349
- and selection_machine is not None
350
- and selection_machine.is_active
351
- ):
417
+ if not outcome.failed_uids and selection_active:
352
418
  # 批量写入可能改变队列;归档为零时再基于当前队列收敛。
353
- standstill = selection_machine.partition_standstill()
419
+ standstill = partition_standstill(effective_state, session)
354
420
  if standstill is not None and standstill.only_blocked_by_exclusion:
355
421
  return DeadlockDecision(
356
422
  action="selection_blocked",
@@ -399,10 +465,9 @@ class DeadlockGovernor:
399
465
 
400
466
 
401
467
  __all__ = [
402
- "ArbitrationStore",
403
- "BulkFailureOutcome",
404
468
  "DEADLOCK_GAP_MAX_ROUNDS",
405
469
  "DeadlockDecision",
406
470
  "DeadlockGovernor",
407
471
  "SelectionStandstill",
472
+ "partition_standstill",
408
473
  ]
@@ -1,37 +1,22 @@
1
1
  """v2 在途作业与生命周期跟踪深模块。
2
2
 
3
3
  统一内敛:
4
- 1. 在途任务条目管理与 PipelineState 状态同步(原子登记/注销,防身份真空);
5
- 2. 活动子进程句柄批量提取与轮询;
6
- 3. 异常/停机时的统一资源安全释放与伪条目合成;
7
- 4. 字典语义 MutableMapping 兼容。
4
+ 1. 在途任务条目管理与 PipelineState 状态同步(原子登记/注销/清空,防身份真空);
5
+ 2. 活动子进程句柄批量提取;
6
+ 3. 异常/停机时的统一资源安全释放;
7
+ 4. 只读 Mapping 视图(禁止绕过 PipelineState 同步的裸写入口)。
8
8
  """
9
9
  from __future__ import annotations
10
10
 
11
- from collections.abc import MutableMapping
11
+ from collections.abc import Iterator, Mapping
12
12
  from dataclasses import dataclass, field
13
- from typing import Any, Iterator, Mapping, Protocol, TYPE_CHECKING
13
+ from typing import Any, TYPE_CHECKING
14
14
 
15
15
  if TYPE_CHECKING:
16
16
  from ..models.state import PipelineState
17
17
  from .resource import ResourceManager
18
18
 
19
- class InFlightStateIndex(Protocol):
20
- """在途登记/注销同步的内存状态索引契约。
21
-
22
- PipelineState(直持索引)满足;注册与注销是六集合互斥不变式的
23
- 单一维护点(调用方传 ``store.state``)。
24
- """
25
-
26
- @property
27
- def in_flight_uids(self) -> frozenset[str]: ...
28
-
29
- def register_in_flight(self, job_uid: str) -> None: ...
30
-
31
- def unregister_in_flight(self, job_uid: str) -> None: ...
32
-
33
19
  from ..models.job import Job
34
- from .resource import NullResourceLease, ResourceLease
35
20
  from .types import JobHandle
36
21
 
37
22
 
@@ -39,7 +24,7 @@ from .types import JobHandle
39
24
  class InFlightJob:
40
25
  """已进入 running、尚未提交结果的执行上下文。
41
26
 
42
- 资源租约或 acquired 列表由 release_resources 幂等归还。
27
+ acquired 列表由 release_resources 幂等归还。
43
28
  handle 为 None 时没有 worker,可携带前置操作失败时已获取的资源;
44
29
  有 worker 时以 started_monotonic 和句柄期限驱动超时判定。
45
30
  """
@@ -50,7 +35,6 @@ class InFlightJob:
50
35
  acquired: list[tuple[str, float]] = field(default_factory=list)
51
36
  handle: JobHandle | None = None
52
37
  started_monotonic: float | None = None
53
- lease: ResourceLease | None = None
54
38
  # 完整执行身份随 running 登记,结算时用于追加 Attempt。
55
39
  execution_id: str | None = None
56
40
  attempt_no: int = 1
@@ -60,31 +44,16 @@ class InFlightJob:
60
44
  active_files: dict[str, Any] = field(default_factory=dict)
61
45
  active_file_sources: dict[str, Any] = field(default_factory=dict)
62
46
 
63
- def __post_init__(self) -> None:
64
- if self.lease is None:
65
- if not self.acquired:
66
- self.lease = NullResourceLease(job_uid=self.job_uid)
67
- elif not self.acquired:
68
- self.acquired = list(self.lease.acquired)
69
-
70
- @property
71
- def is_pseudo(self) -> bool:
72
- """是否没有关联的 worker 句柄。"""
73
- return self.handle is None
74
-
75
47
  def release_resources(self, resource_mgr: ResourceManager | None = None) -> None:
76
- """释放关联的资源租约或 acquired 列表(幂等归还)。"""
77
- if self.lease is not None:
78
- self.lease.release()
79
- self.acquired = []
80
- elif self.acquired:
48
+ """释放关联的已获取资源列表(幂等归还)。"""
49
+ if self.acquired:
81
50
  acquired, self.acquired = self.acquired, []
82
51
  if resource_mgr is not None:
83
52
  resource_mgr.release_all(acquired, job_uid=self.job_uid)
84
53
 
85
54
 
86
- class InFlightTracker(MutableMapping[str, InFlightJob]):
87
- """统一在途任务生命周期跟踪器深模块。"""
55
+ class InFlightTracker(Mapping[str, InFlightJob]):
56
+ """统一在途任务生命周期跟踪器深模块(对外只读 Mapping,写操作必经同步出口)。"""
88
57
 
89
58
  def __init__(self, entries: Mapping[str, InFlightJob] | None = None) -> None:
90
59
  self._entries: dict[str, InFlightJob] = dict(entries) if entries is not None else {}
@@ -92,12 +61,6 @@ class InFlightTracker(MutableMapping[str, InFlightJob]):
92
61
  def __getitem__(self, job_uid: str) -> InFlightJob:
93
62
  return self._entries[job_uid]
94
63
 
95
- def __setitem__(self, job_uid: str, entry: InFlightJob) -> None:
96
- self._entries[job_uid] = entry
97
-
98
- def __delitem__(self, job_uid: str) -> None:
99
- del self._entries[job_uid]
100
-
101
64
  def __iter__(self) -> Iterator[str]:
102
65
  return iter(self._entries)
103
66
 
@@ -110,28 +73,27 @@ class InFlightTracker(MutableMapping[str, InFlightJob]):
110
73
  def get(self, job_uid: str, default: InFlightJob | None = None) -> InFlightJob | None: # type: ignore[override]
111
74
  return self._entries.get(job_uid, default)
112
75
 
113
- def pop(self, job_uid: str, default: InFlightJob | None = None) -> InFlightJob | None: # type: ignore[override]
114
- return self._entries.pop(job_uid, default)
115
-
116
76
  @property
117
77
  def uids(self) -> frozenset[str]:
118
78
  """当前在途作业 UID 集合的不可变快照(单一真相源)。"""
119
79
  return frozenset(self._entries.keys())
120
80
 
121
- def clear(self) -> None:
81
+ def clear_all(self, *, state: "PipelineState") -> None:
82
+ """清空全部在途条目并同步注销内存状态中的在途索引。"""
83
+ for uid in list(self._entries.keys()):
84
+ if uid in state.in_flight_uids:
85
+ state.unregister_in_flight(uid)
122
86
  self._entries.clear()
123
87
 
124
88
  def track(
125
89
  self,
126
90
  entry: InFlightJob,
127
91
  *,
128
- state: "InFlightStateIndex | None" = None,
92
+ state: "PipelineState | None" = None,
129
93
  ) -> InFlightJob:
130
94
  """登记在途作业条目(单一真相源入口)。
131
95
 
132
- ``state`` 为内存状态索引(``InFlightStateIndex`` 契约,
133
- PipelineState 满足,调用方传 ``store.state``),非 None 时同步
134
- 内存 in-flight 索引。
96
+ ``state`` 非 None 时同步登记内存 in-flight 索引,维护六集合互斥不变式。
135
97
  """
136
98
  self._entries[entry.job_uid] = entry
137
99
  if state is not None:
@@ -142,7 +104,7 @@ class InFlightTracker(MutableMapping[str, InFlightJob]):
142
104
  self,
143
105
  job_uid: str,
144
106
  *,
145
- state: "InFlightStateIndex | None" = None,
107
+ state: "PipelineState | None" = None,
146
108
  ) -> InFlightJob | None:
147
109
  """语义化结算接缝:注销在途任务并同步内存状态(单一真相源出口)。"""
148
110
  entry = self._entries.pop(job_uid, None)
@@ -155,7 +117,7 @@ class InFlightTracker(MutableMapping[str, InFlightJob]):
155
117
  return entry
156
118
 
157
119
  def active_handles(self) -> list[JobHandle]:
158
- """收集所有活动的真实子进程句柄(排除 handle=None 的伪条目)。"""
120
+ """收集所有活动的真实子进程句柄(排除 handle=None 的无 worker 条目)。"""
159
121
  return [
160
122
  entry.handle for entry in self._entries.values()
161
123
  if entry.handle is not None
@@ -165,19 +127,6 @@ class InFlightTracker(MutableMapping[str, InFlightJob]):
165
127
  """收集所有在途任务的 uid 列表。"""
166
128
  return list(self._entries.keys())
167
129
 
168
- def classify_aborted(
169
- self, completed_map: Mapping[str, Any]
170
- ) -> tuple[list[InFlightJob], list[tuple[InFlightJob, Any]]]:
171
- """将当前在途任务分类为(已取消列表, 已完成待提交列表)。"""
172
- cancelled_entries: list[InFlightJob] = []
173
- done_entries: list[tuple[InFlightJob, Any]] = []
174
- for entry in self._entries.values():
175
- if entry.job_uid in completed_map:
176
- done_entries.append((entry, completed_map[entry.job_uid]))
177
- else:
178
- cancelled_entries.append(entry)
179
- return cancelled_entries, done_entries
180
-
181
130
  def release_all_resources(
182
131
  self,
183
132
  resource_mgr: ResourceManager | None = None,
@@ -186,23 +135,6 @@ class InFlightTracker(MutableMapping[str, InFlightJob]):
186
135
  for entry in self._entries.values():
187
136
  entry.release_resources(resource_mgr)
188
137
 
189
- @staticmethod
190
- def create_pseudo_entry(
191
- job_uid: str,
192
- job_snapshot: dict,
193
- job: Job,
194
- ) -> InFlightJob:
195
- """合成安全伪条目(用于崩溃恢复或 abort 结果提交)。"""
196
- return InFlightJob(
197
- job_uid=job_uid,
198
- job_snapshot=job_snapshot,
199
- job=job,
200
- acquired=[],
201
- handle=None,
202
- started_monotonic=None,
203
- lease=NullResourceLease(job_uid=job_uid),
204
- )
205
-
206
138
 
207
139
  __all__ = [
208
140
  "InFlightJob",