nextloop 0.6.0__tar.gz → 0.7.0__tar.gz

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 (131) hide show
  1. {nextloop-0.6.0/src/nextloop.egg-info → nextloop-0.7.0}/PKG-INFO +9 -7
  2. {nextloop-0.6.0 → nextloop-0.7.0}/README.md +8 -6
  3. nextloop-0.7.0/docs/adr/0008-lease.md +24 -0
  4. {nextloop-0.6.0 → nextloop-0.7.0}/docs/architecture/development-plan.md +1 -1
  5. {nextloop-0.6.0 → nextloop-0.7.0}/docs/architecture/feature-worklist.md +2 -2
  6. {nextloop-0.6.0 → nextloop-0.7.0}/docs/architecture/requirements.md +1 -1
  7. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/architecture.md +3 -3
  8. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/harness.md +6 -0
  9. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/loop-interface.md +3 -2
  10. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/verification-matrix.md +19 -2
  11. {nextloop-0.6.0 → nextloop-0.7.0}/pyproject.toml +1 -1
  12. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/__init__.py +6 -0
  13. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/memory.py +74 -7
  14. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/observing.py +12 -2
  15. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/sqlite.py +131 -16
  16. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/contracts.py +29 -2
  17. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/driver.py +1 -0
  18. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/harness.py +13 -5
  19. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/loop.py +90 -29
  20. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/testing.py +12 -2
  21. {nextloop-0.6.0 → nextloop-0.7.0/src/nextloop.egg-info}/PKG-INFO +9 -7
  22. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop.egg-info/SOURCES.txt +2 -0
  23. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_approval.py +3 -0
  24. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_harness.py +14 -1
  25. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_import_contract.py +3 -0
  26. nextloop-0.7.0/tests/test_lease.py +461 -0
  27. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_skills.py +1 -1
  28. {nextloop-0.6.0 → nextloop-0.7.0}/LICENSE +0 -0
  29. {nextloop-0.6.0 → nextloop-0.7.0}/MANIFEST.in +0 -0
  30. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0001-embeddable-agent-loop.md +0 -0
  31. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0002-dsh-aligned-agent-loop.md +0 -0
  32. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0003-python-and-centralized-contracts.md +0 -0
  33. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0004-event-compatibility.md +0 -0
  34. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0005-pending-input.md +0 -0
  35. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0006-operation-id.md +0 -0
  36. {nextloop-0.6.0 → nextloop-0.7.0}/docs/adr/0007-approval.md +0 -0
  37. {nextloop-0.6.0 → nextloop-0.7.0}/docs/architecture/agent-loop-capability-review.md +0 -0
  38. {nextloop-0.6.0 → nextloop-0.7.0}/docs/architecture/discussion-roadmap.md +0 -0
  39. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/agent-loop.md +0 -0
  40. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/context-builder.md +0 -0
  41. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/react-protocol.md +0 -0
  42. {nextloop-0.6.0 → nextloop-0.7.0}/docs/design/skills.md +0 -0
  43. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-02-dsh-primary-sources.md +0 -0
  44. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-02-loop-evidence-notes.md +0 -0
  45. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-03-hermes-turn-control.md +0 -0
  46. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-03-tool-batch-failures.md +0 -0
  47. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-03-tool-call-validation.md +0 -0
  48. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-03-yomi-turn-control.md +0 -0
  49. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-06-open-source-agent-loops.md +0 -0
  50. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-06-react-tool-event-recovery.md +0 -0
  51. {nextloop-0.6.0 → nextloop-0.7.0}/docs/research/2026-11-10-nextloop-optimization-review.md +0 -0
  52. {nextloop-0.6.0 → nextloop-0.7.0}/examples/basic.py +0 -0
  53. {nextloop-0.6.0 → nextloop-0.7.0}/examples/harness-skills/echo/SKILL.md +0 -0
  54. {nextloop-0.6.0 → nextloop-0.7.0}/examples/harness.toml +0 -0
  55. {nextloop-0.6.0 → nextloop-0.7.0}/examples/live_smoke.py +0 -0
  56. {nextloop-0.6.0 → nextloop-0.7.0}/examples/python_tools.py +0 -0
  57. {nextloop-0.6.0 → nextloop-0.7.0}/examples/skills/coding/SKILL.md +0 -0
  58. {nextloop-0.6.0 → nextloop-0.7.0}/examples/skills_demo.py +0 -0
  59. {nextloop-0.6.0 → nextloop-0.7.0}/examples/workers/cpp_worker.cpp +0 -0
  60. {nextloop-0.6.0 → nextloop-0.7.0}/examples/workers/python_worker.py +0 -0
  61. {nextloop-0.6.0 → nextloop-0.7.0}/examples/workers/rust_worker.rs +0 -0
  62. {nextloop-0.6.0 → nextloop-0.7.0}/setup.cfg +0 -0
  63. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/__init__.py +0 -0
  64. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/_sse.py +0 -0
  65. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/anthropic.py +0 -0
  66. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/adapters/openai.py +0 -0
  67. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/cli.py +0 -0
  68. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/__init__.py +0 -0
  69. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/approval.py +0 -0
  70. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/input.py +0 -0
  71. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/outcome.py +0 -0
  72. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/pending.py +0 -0
  73. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/project.py +0 -0
  74. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/repair.py +0 -0
  75. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/response.py +0 -0
  76. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/trace.py +0 -0
  77. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/events/upcast.py +0 -0
  78. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/__init__.py +0 -0
  79. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/batch.py +0 -0
  80. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/cancellation.py +0 -0
  81. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/cleanup.py +0 -0
  82. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/composite.py +0 -0
  83. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/mcp.py +0 -0
  84. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/model.py +0 -0
  85. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/preview.py +0 -0
  86. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/result_read.py +0 -0
  87. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/stdio.py +0 -0
  88. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/stdio_transport.py +0 -0
  89. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/execute/tools.py +0 -0
  90. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/py.typed +0 -0
  91. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop/skills.py +0 -0
  92. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop.egg-info/dependency_links.txt +0 -0
  93. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop.egg-info/entry_points.txt +0 -0
  94. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop.egg-info/requires.txt +0 -0
  95. {nextloop-0.6.0 → nextloop-0.7.0}/src/nextloop.egg-info/top_level.txt +0 -0
  96. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_aggregate_close.py +0 -0
  97. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_approval_regressions.py +0 -0
  98. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_budgets.py +0 -0
  99. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_cli.py +0 -0
  100. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_compaction_lineage.py +0 -0
  101. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_complexity_regressions.py +0 -0
  102. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_correctness_regressions.py +0 -0
  103. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_events.py +0 -0
  104. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_failures.py +0 -0
  105. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_fault_injection.py +0 -0
  106. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_fault_matrix.py +0 -0
  107. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_harness_injection.py +0 -0
  108. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_loop.py +0 -0
  109. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_mcp.py +0 -0
  110. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_mcp_hardening.py +0 -0
  111. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_observability.py +0 -0
  112. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_observability_close_deadline.py +0 -0
  113. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_operations.py +0 -0
  114. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_pending_inputs.py +0 -0
  115. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_preview.py +0 -0
  116. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_projection_parity.py +0 -0
  117. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_provider_terminal.py +0 -0
  118. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_providers.py +0 -0
  119. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_result_budget_regressions.py +0 -0
  120. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_result_policies.py +0 -0
  121. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_retry_regressions.py +0 -0
  122. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_review_regressions.py +0 -0
  123. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_stdio.py +0 -0
  124. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_stdio_cleanup.py +0 -0
  125. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_stdio_frames.py +0 -0
  126. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_stdio_safety.py +0 -0
  127. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_store_contract.py +0 -0
  128. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_stores.py +0 -0
  129. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_surface_snapshot.py +0 -0
  130. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_upcasting.py +0 -0
  131. {nextloop-0.6.0 → nextloop-0.7.0}/tests/test_worker_conformance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nextloop
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics
5
5
  Author-email: 12bitsD <bis12@163.com>
6
6
  License-Expression: MIT
@@ -35,12 +35,12 @@ nextloop is an embeddable Python AgentLoop for developers who want to build thei
35
35
 
36
36
  **Your agent, your rules. No magic, no black box.**
37
37
 
38
- Current version: **0.6.0**.
38
+ Current version: **0.7.0**.
39
39
 
40
40
  ## Install
41
41
 
42
42
  ```bash
43
- python -m pip install nextloop==0.6.0
43
+ python -m pip install nextloop==0.7.0
44
44
  ```
45
45
 
46
46
  For local development:
@@ -86,8 +86,9 @@ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-ag
86
86
  ```python
87
87
  AgentLoop.run(TurnContext) -> TurnOutcome
88
88
  AgentLoop.steer(session_id, content, *, input_id=None) -> bool
89
+ AgentLoop.steer_result(session_id, content, *, input_id=None) -> SteerResult
89
90
  AgentLoop.cancel(session_id, cause="user_stop") -> bool
90
- AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
91
+ AgentLoop.recover(session_id, store, delivery, *, force=False) -> RecoveryOutcome
91
92
  AgentLoop.pending_inputs(session_id, store) -> tuple[PendingInput, ...]
92
93
  AgentLoop.resume(context, *, decisions=None, reject_all=False, new_input=None) -> TurnOutcome
93
94
  AgentLoop.retry_operation(context, operation_id) -> TurnOutcome
@@ -101,7 +102,8 @@ Core adapter seams are `EventStore`, `ModelProvider`, `ToolRuntime`, and `Delive
101
102
 
102
103
  | Area | Guarantee | Not a guarantee |
103
104
  |---|---|---|
104
- | Accepted input | Accepted inputs are projected from the log by `input_id` and can be queried with `AgentLoop.pending_inputs`. Explicit IDs are non-empty; identical retries deduplicate, conflicting content is rejected without consuming the original. | Automatic deduplication when callers retry with a different or missing ID. |
105
+ | Accepted input | Accepted inputs are projected from the log by `input_id` and can be queried with `AgentLoop.pending_inputs`. Explicit IDs are non-empty; identical retries deduplicate, conflicting content is rejected without consuming the original. `steer_result` exposes structured rejection reasons. | Automatic deduplication when callers retry with a different or missing ID. |
106
+ | Writer lease | Optional owner/epoch/expiry checks with heartbeat, same-owner restart, expiry or forced takeover, and spawn-verified same-host contention. Legacy behavior remains when no owner is configured. | Distributed locks, cross-host leases, or execution after an expired/stale writer check. |
105
107
  | Delivery | Delivery is at least once; DeliveryOwner must deduplicate by stable `final_message_id`. | Exactly-once delivery or delivery without an idempotent owner. |
106
108
  | Tool execution | The library never automatically replays an already dispatched Tool. Explicit reconciliation is limited to READ_ONLY and IDEMPOTENT operations. | No duplicate external effect when a model reissues a call or a Tool is not idempotent. |
107
109
  | Resource locks | Unresolved uncertain results retain declared resources; otherwise NON_IDEMPOTENT uses the Tool name. Successful reconciliation releases all locks associated with the operation. | Global idempotency across different resources or operations, or safe concurrent execution of NON_IDEMPOTENT calls. |
@@ -231,7 +233,7 @@ The release checks cover:
231
233
  - 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
232
234
  - live DeepSeek text + Preview + usage and real Tool Call + Delivery smoke;
233
235
  - a 10,505-event benchmark with cross-Store, incremental, and required-content parity;
234
- - 341 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
236
+ - 357 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
235
237
 
236
238
  Current limits:
237
239
 
@@ -253,7 +255,7 @@ Current limits:
253
255
  - [Development plan](docs/architecture/development-plan.md)
254
256
  - [Contributing](CONTRIBUTING.md) and [Security](SECURITY.md)
255
257
  - [Changelog](CHANGELOG.md)
256
- - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md), [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md), [ADR-0004 Event compatibility](docs/adr/0004-event-compatibility.md), [ADR-0005 Pending Input](docs/adr/0005-pending-input.md), [ADR-0006 Operation identity](docs/adr/0006-operation-id.md), and [ADR-0007 Approval](docs/adr/0007-approval.md)
258
+ - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md), [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md), [ADR-0004 Event compatibility](docs/adr/0004-event-compatibility.md), [ADR-0005 Pending Input](docs/adr/0005-pending-input.md), [ADR-0006 Operation identity](docs/adr/0006-operation-id.md), and [ADR-0007 Approval](docs/adr/0007-approval.md), and [ADR-0008 Owner leases](docs/adr/0008-lease.md)
257
259
 
258
260
  ## Release
259
261
 
@@ -6,12 +6,12 @@ nextloop is an embeddable Python AgentLoop for developers who want to build thei
6
6
 
7
7
  **Your agent, your rules. No magic, no black box.**
8
8
 
9
- Current version: **0.6.0**.
9
+ Current version: **0.7.0**.
10
10
 
11
11
  ## Install
12
12
 
13
13
  ```bash
14
- python -m pip install nextloop==0.6.0
14
+ python -m pip install nextloop==0.7.0
15
15
  ```
16
16
 
17
17
  For local development:
@@ -57,8 +57,9 @@ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-ag
57
57
  ```python
58
58
  AgentLoop.run(TurnContext) -> TurnOutcome
59
59
  AgentLoop.steer(session_id, content, *, input_id=None) -> bool
60
+ AgentLoop.steer_result(session_id, content, *, input_id=None) -> SteerResult
60
61
  AgentLoop.cancel(session_id, cause="user_stop") -> bool
61
- AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
62
+ AgentLoop.recover(session_id, store, delivery, *, force=False) -> RecoveryOutcome
62
63
  AgentLoop.pending_inputs(session_id, store) -> tuple[PendingInput, ...]
63
64
  AgentLoop.resume(context, *, decisions=None, reject_all=False, new_input=None) -> TurnOutcome
64
65
  AgentLoop.retry_operation(context, operation_id) -> TurnOutcome
@@ -72,7 +73,8 @@ Core adapter seams are `EventStore`, `ModelProvider`, `ToolRuntime`, and `Delive
72
73
 
73
74
  | Area | Guarantee | Not a guarantee |
74
75
  |---|---|---|
75
- | Accepted input | Accepted inputs are projected from the log by `input_id` and can be queried with `AgentLoop.pending_inputs`. Explicit IDs are non-empty; identical retries deduplicate, conflicting content is rejected without consuming the original. | Automatic deduplication when callers retry with a different or missing ID. |
76
+ | Accepted input | Accepted inputs are projected from the log by `input_id` and can be queried with `AgentLoop.pending_inputs`. Explicit IDs are non-empty; identical retries deduplicate, conflicting content is rejected without consuming the original. `steer_result` exposes structured rejection reasons. | Automatic deduplication when callers retry with a different or missing ID. |
77
+ | Writer lease | Optional owner/epoch/expiry checks with heartbeat, same-owner restart, expiry or forced takeover, and spawn-verified same-host contention. Legacy behavior remains when no owner is configured. | Distributed locks, cross-host leases, or execution after an expired/stale writer check. |
76
78
  | Delivery | Delivery is at least once; DeliveryOwner must deduplicate by stable `final_message_id`. | Exactly-once delivery or delivery without an idempotent owner. |
77
79
  | Tool execution | The library never automatically replays an already dispatched Tool. Explicit reconciliation is limited to READ_ONLY and IDEMPOTENT operations. | No duplicate external effect when a model reissues a call or a Tool is not idempotent. |
78
80
  | Resource locks | Unresolved uncertain results retain declared resources; otherwise NON_IDEMPOTENT uses the Tool name. Successful reconciliation releases all locks associated with the operation. | Global idempotency across different resources or operations, or safe concurrent execution of NON_IDEMPOTENT calls. |
@@ -202,7 +204,7 @@ The release checks cover:
202
204
  - 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
203
205
  - live DeepSeek text + Preview + usage and real Tool Call + Delivery smoke;
204
206
  - a 10,505-event benchmark with cross-Store, incremental, and required-content parity;
205
- - 341 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
207
+ - 357 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
206
208
 
207
209
  Current limits:
208
210
 
@@ -224,7 +226,7 @@ Current limits:
224
226
  - [Development plan](docs/architecture/development-plan.md)
225
227
  - [Contributing](CONTRIBUTING.md) and [Security](SECURITY.md)
226
228
  - [Changelog](CHANGELOG.md)
227
- - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md), [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md), [ADR-0004 Event compatibility](docs/adr/0004-event-compatibility.md), [ADR-0005 Pending Input](docs/adr/0005-pending-input.md), [ADR-0006 Operation identity](docs/adr/0006-operation-id.md), and [ADR-0007 Approval](docs/adr/0007-approval.md)
229
+ - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md), [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md), [ADR-0004 Event compatibility](docs/adr/0004-event-compatibility.md), [ADR-0005 Pending Input](docs/adr/0005-pending-input.md), [ADR-0006 Operation identity](docs/adr/0006-operation-id.md), and [ADR-0007 Approval](docs/adr/0007-approval.md), and [ADR-0008 Owner leases](docs/adr/0008-lease.md)
228
230
 
229
231
  ## Release
230
232
 
@@ -0,0 +1,24 @@
1
+ # ADR-0008: Optional owner leases and writer-scoped input
2
+
3
+ Status: accepted
4
+
5
+ ## Context
6
+
7
+ Writer epochs reject stale appends but do not express ownership or expiry. A paused process can resume after another instance takes over, and inactive processes currently cannot describe why steer or cancel was rejected. Lease behavior must be optional so existing single-writer deployments do not migrate.
8
+
9
+ ## Decision
10
+
11
+ - `owner_id` is opt-in. Without it, `attach_writer` keeps its existing unconditional epoch increment and writer checks keep their existing semantics.
12
+ - Lease-enabled Stores bind `session_id`, `owner_id`, `writer_epoch`, and `expires_at`. The Store clock decides expiry. Same-owner restart may take over immediately; a different owner waits for expiry or explicit `force=True` takeover. Every takeover increments writer_epoch.
13
+ - `check_writer` and append validate owner, epoch, and expiry for lease-enabled Stores. `renew_writer` extends expiry without changing epoch and cannot revive an expired lease.
14
+ - AgentLoop heartbeat renews independently of event appends, including during long Tools. Heartbeat proves only that the process is scheduled; forced takeover remains available for a stuck main loop. SQLite promises same-host, multi-process behavior only, not distributed locking.
15
+ - Every Tool dispatch keeps a writer check after TOOL_CALL. An expired writer fails its next append and cannot dispatch new Tools. A late external result that cannot be committed is discarded and remains uncertain.
16
+ - `steer() -> bool` remains. `steer_result()` additionally returns `accepted`, `session_missing`, `not_writer`, `turn_closed`, `queue_full`, `invalid_input`, or `approval_pending`. Non-writers never append INPUT_ACCEPTED or cancellation facts.
17
+ - Pending Input remains a pure log projection. The in-memory inbox is bounded by `max_pending_inputs`, while Pending remains recoverable from the log after process restart.
18
+
19
+ ## Consequences
20
+
21
+ - Existing deployments keep legacy behavior unless they configure an owner and lease duration.
22
+ - Ownership, expiry, renewal, and forced takeover are durable facts rather than process-local assumptions.
23
+ - Callers receive machine-readable input rejection reasons without a second input authority.
24
+ - Multi-process input acceptance is limited to the current valid writer; cross-host lease coordination is explicitly excluded.
@@ -1,6 +1,6 @@
1
1
  # nextloop development and verification plan
2
2
 
3
- Current stage: **0.6.0 release verification**. `0.5.0` is published; later milestones are not claimed as implemented.
3
+ Current stage: **0.7.0 release verification**. `0.6.0` is published; later milestones are not claimed as implemented.
4
4
 
5
5
  ## Delivery order
6
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Purpose: distinguish implemented capabilities from remaining work. Executable evidence is owned by the [verification matrix](../design/verification-matrix.md).
4
4
 
5
- ## Implemented in the current 0.6 line
5
+ ## Implemented in the current 0.7 line
6
6
 
7
7
  | Feature | Implementation | Evidence |
8
8
  |---|---|---|
@@ -14,6 +14,7 @@ Purpose: distinguish implemented capabilities from remaining work. Executable ev
14
14
  | Context | Append-only projection, WorkingContext, Compaction, result preview/page/full | Projection parity, compaction, UTF-8 paging, read-back, and capacity tests |
15
15
  | EventStore | Memory and SQLite, atomic conditional append, idempotency, writer checks | Public conformance plus deliberately broken Store rejection |
16
16
  | Event compatibility | Read-only 1.0→1.1 upcasting, raw append comparison | Real 1.0/1.1 SQLite fixtures and unknown-schema negative paths |
17
+ | Owner leases | Optional owner/epoch/expiry, heartbeat, forced takeover, steer_result | Same/different owner, renewal failure, concurrent resume, late results, and spawn-based multiprocess contention |
17
18
  | Operation identity | operation_id, ToolEffect, resource locks, explicit Reconciliation | End-to-end propagation, dynamic locks, repeated/concurrent retry, and no-replay evidence |
18
19
  | Approval | Atomic Intent/request, new-Turn resume, origin pairing, lazy expiry | Zero pre-grant dispatch, crash windows, concurrent resume, rejection, cancellation, and fresh budgets |
19
20
  | Providers | OpenAI-compatible and Anthropic streaming adapters | Recorded protocol streams plus separately identified live-provider smoke |
@@ -25,7 +26,6 @@ Purpose: distinguish implemented capabilities from remaining work. Executable ev
25
26
 
26
27
  | Feature | Target and boundary |
27
28
  |---|---|
28
- | Time-based writer leases | 0.7; opt-in owner identity, heartbeat, expiry, and takeover |
29
29
  | Durable Outbox | 0.8; caller-driven export, persistent acknowledgement, auditable gaps |
30
30
  | Whole-Session deletion | 0.9; tombstones and local derived-state cleanup |
31
31
  | Official OpenAI/Anthropic acceptance | 1.0 hard gate; recorded streams and DeepSeek do not substitute |
@@ -21,7 +21,7 @@ This map records reusable execution requirements and verification ownership. No
21
21
  | L15 | Retry delivery without rerunning model or Tools | [DeliveryOwner](../design/loop-interface.md#deliveryowner) | **Design closed.** `final_message_id`, delivery_unknown, durable handoff and writer-release tests |
22
22
  | L16 | Prove consumer independence through public Adapters | [Loop interface](../design/loop-interface.md) | **Open.** Fake Adapters and public Store conformance are implemented; nika consumer acceptance remains separate |
23
23
  | L18 | Load third-party instruction Skills from directories on demand | [SkillRegistry](../design/skills.md) | **Implemented.** Metadata discovery, current-body loading, duplicate/dependency/version errors, and `skill_view` tests |
24
- | L17 | Package and release only after protocol verification | [Development plan](development-plan.md), [ADR-0003](../adr/0003-python-and-centralized-contracts.md) | **0.6.0 implemented and verified.** The complete fault matrix, benchmark, Python 3.14, import contract, upcasting, operation, approval, and clean package gates pass; publication and later milestones remain separate |
24
+ | L17 | Package and release only after protocol verification | [Development plan](development-plan.md), [ADR-0003](../adr/0003-python-and-centralized-contracts.md) | **0.7.0 implemented and verified.** Fault matrix, benchmark, Python 3.14, import contract, upcasting, operation, approval, owner lease, and clean package gates pass; publication and later milestones remain separate |
25
25
 
26
26
  ## Independence rule
27
27
 
@@ -25,14 +25,14 @@ The Loop coordinates execution; the Store owns ordering and writer fencing. `eve
25
25
 
26
26
  ## Invariants
27
27
 
28
- - Event append checks `writer_epoch` and `expected_seq` atomically. Repeating an append with identical event IDs is idempotent; changing their content is rejected.
28
+ - Event append checks `writer_epoch` and `expected_seq` atomically. With an optional owner lease, it also validates owner identity and expiry in the same transaction. Legacy attach behavior is unchanged when no owner is configured.
29
29
  - TOOL_CALL is committed before Tool dispatch. A second `check_writer()` runs after that commit and immediately before `ToolRuntime.execute()`.
30
30
  - Recovery does not replay a dispatched Tool. Missing results become explicit skipped or uncertain outcomes.
31
31
  - FINAL_MESSAGE and TURN_END are durable before Delivery. Delivery is at least once and owners deduplicate by `final_message_id`.
32
32
  - Pending Input is derived from INPUT_ACCEPTED and USER_MESSAGE by `input_id`. A later Step boundary commits its consumption; the in-memory inbox is only a wake-up signal.
33
33
  - Trace records are projections of committed Events. Export failures cannot change Turn outcomes.
34
34
 
35
- Writer epochs currently fence stale writers; they are not time-based leases. Multi-process coordination, persistent Outbox, and Session deletion are separate later milestones.
35
+ Owner leases are optional. Same-owner restarts take over immediately; different owners require expiry or explicit force. Heartbeat renewal is independent of appends, and the Store clock decides expiry. SQLite promises same-host multi-process contention only, not distributed coordination. Persistent Outbox and Session deletion remain later milestones.
36
36
 
37
37
  ## Complexity boundaries
38
38
 
@@ -50,7 +50,7 @@ The benchmark checks Memory/SQLite Conversation Projection parity, Model/Tool Tr
50
50
 
51
51
  ## Frozen import contract
52
52
 
53
- The root `nextloop` package keeps its existing convenience re-exports. `tests/test_import_contract.py` snapshots all 94 names and rejects accidental additions, removals, and duplicate entries.
53
+ The root `nextloop` package keeps its existing convenience re-exports. `tests/test_import_contract.py` snapshots all 97 names and rejects accidental additions, removals, and duplicate entries.
54
54
 
55
55
  Core integration paths:
56
56
 
@@ -82,6 +82,12 @@ Skills remain instructions only. Their metadata is added to the system prompt, a
82
82
 
83
83
  Exporters may optionally implement `flush()` and `close()`, synchronously or asynchronously. The queue is flushed before Exporter lifecycle calls. Harness closes Exporters created from `[trace]`; runtime-injected Exporters are flushed but not closed. `nextloop.testing.check_event_store(store)` exposes the same basic atomicity, idempotency, fencing, surface, and recovery-read contract used by the built-in Stores.
84
84
 
85
+ ## Store leases and Pending limits
86
+
87
+ `[store]` accepts optional `owner_id` and `lease_seconds`. When `owner_id` is absent, Store construction and writer semantics stay legacy. When configured, same-owner restarts take over immediately, another owner needs expiry or `recover(force=True)`, and active Turns renew through an independent heartbeat. SQLite initialization includes bounded lock backoff for same-host process contention.
88
+
89
+ `loop.max_pending_inputs` bounds the active in-memory inbox (default 100). Pending Input remains recoverable from the Event log; the limit is not a second persistence policy. `steer_result()` reports `session_missing`, `not_writer`, `turn_closed`, `queue_full`, `invalid_input`, or `approval_pending` alongside `accepted`.
90
+
85
91
  ## Tool effects and approval
86
92
 
87
93
  Each `[[tools]]` entry accepts optional `effect = "read_only" | "idempotent" | "non_idempotent"`. The default is NON_IDEMPOTENT, and `nextloop check` reports a migration warning when it is unset. Explicit `resources` still control normal conflict checks; otherwise only uncertain outcomes use the Tool name as a lock.
@@ -1,6 +1,6 @@
1
1
  # Loop interface and ownership
2
2
 
3
- Status: **v1.1 implemented for 0.6.0**, with public contracts in `src/nextloop/contracts.py`.
3
+ Status: **v1.1 implemented for 0.7.0**, with public contracts in `src/nextloop/contracts.py`.
4
4
 
5
5
  ## Independence and version dependency
6
6
 
@@ -11,8 +11,9 @@ This document and `src/nextloop/contracts.py` are the integration dependency bet
11
11
  ```text
12
12
  AgentLoop.run(TurnContext) -> TurnOutcome
13
13
  AgentLoop.steer(session_id, content, *, input_id=None) -> bool
14
+ AgentLoop.steer_result(session_id, content, *, input_id=None) -> SteerResult
14
15
  AgentLoop.cancel(session_id, cause="user_stop") -> bool
15
- AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
16
+ AgentLoop.recover(session_id, store, delivery, *, force=False) -> RecoveryOutcome
16
17
  AgentLoop.pending_inputs(session_id, store) -> tuple[PendingInput, ...]
17
18
  AgentLoop.resume(context, *, decisions=None, reject_all=False, new_input=None) -> TurnOutcome
18
19
  AgentLoop.retry_operation(context, operation_id) -> TurnOutcome
@@ -1,6 +1,6 @@
1
1
  # AgentLoop verification matrix
2
2
 
3
- Status: 0.6.0 release gate. A claim is closed only by the executable evidence named here; test count alone is not evidence.
3
+ Status: 0.7.0 release gate. A claim is closed only by the executable evidence named here; test count alone is not evidence.
4
4
 
5
5
  ## Evidence rules
6
6
 
@@ -77,7 +77,7 @@ Conversation Projection is bounded by the returned Surface and serialized messag
77
77
 
78
78
  ## Public contracts and packaging
79
79
 
80
- - `tests/test_import_contract.py` freezes all 94 root re-exports and the complete `__all__` of `events`, `adapters`, `execute`, and `testing`, plus explicit supported names on other integration modules.
80
+ - `tests/test_import_contract.py` freezes all 97 root re-exports and the complete `__all__` of `events`, `adapters`, `execute`, and `testing`, plus explicit supported names on other integration modules.
81
81
  - `tests/test_store_contract.py` is the third-party Store conformance entrypoint.
82
82
  - Python 3.11, 3.12, 3.13, and 3.14 run CI. Local clean Python 3.11 and 3.14 environments also run the full suite and benchmark before 0.6.0 publication.
83
83
  - `ruff`, format check, strict mypy, wheel/sdist build, Twine, clean wheel installation, examples, and CLI diagnostics are required gates.
@@ -100,6 +100,23 @@ Conversation Projection is bounded by the returned Surface and serialized messag
100
100
 
101
101
  The 0.6 review closed non-boolean grants, lock-delay expiry, duplicate dispatch, concurrent reconciliation, repeated-retry lock leakage, unknown-schema bypass, resource/budget approval bypass, finalization divergence, and input/dedup duplication. Every original counterexample has a regression and incremental Risk verification.
102
102
 
103
+ ## 0.7 lease and input evidence
104
+
105
+ | Claim | Closing evidence |
106
+ |---|---|
107
+ | No-owner behavior remains compatible | Legacy epoch checks and raw 1.0/1.1 fixture bytes remain unchanged; lease tables are opt-in |
108
+ | Same-owner restart and renewal | Immediate takeover, independent renewal during a long Tool, and expiry rejection |
109
+ | Different-owner takeover | Expiry or `recover(force=True)` with increasing epoch and stale-writer rejection |
110
+ | Legacy takeover fences old lease owners | Global epoch plus owner/expiry validation in check/append/has_writer |
111
+ | Heartbeat failure cannot continue silently | Operational RuntimeError cancels execution without CANCELLATION_REQUESTED |
112
+ | Late results never fabricate completion | No result before recovery; recovered result is uncertain_hanging |
113
+ | Lease resume/recovery is idempotent | Concurrent resume has one winner and repeated recover does not duplicate facts |
114
+ | Same-host multiprocess works | Spawn-based simultaneous initialization and contention pass 20 consecutive runs with bounded WAL lock backoff |
115
+ | Renewal cannot silently succeed after expiry | Atomic UPDATE with `rowcount == 1` and has_writer=False afterward |
116
+ | Input rejection is machine-readable | accepted, session_missing, not_writer, turn_closed, queue_full, invalid_input, and approval_pending |
117
+ | Idempotent input is not capacity-rejected | Accepted ID replay precedes queue_full checks; non-writers never append facts |
118
+ | Lease cancellation is writer-scoped | Active stale writers and inactive non-owners are rejected before cancellation append |
119
+
103
120
  ## Review and external evidence
104
121
 
105
122
  Standards, Spec, and Risk reviews run independently. Original counterexamples must become regressions, and fixes receive incremental review. The 0.5.0 review closed stale dispatch, Pending consumption, ID conflicts, Compaction identity, export-contract gaps, wrapper duplication, and erased-content test oracles.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nextloop"
7
- version = "0.6.0"
7
+ version = "0.7.0"
8
8
  description = "An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -47,6 +47,8 @@ from .contracts import (
47
47
  SkillError,
48
48
  SkillSpec,
49
49
  Skipped,
50
+ SteerResult,
51
+ SteerStatus,
50
52
  StoreConfig,
51
53
  SurfaceOp,
52
54
  TimingSource,
@@ -74,6 +76,7 @@ from .contracts import (
74
76
  UncertainSettled,
75
77
  ValidatedCall,
76
78
  ValidationIssue,
79
+ WriterLeaseError,
77
80
  new_id,
78
81
  utc_now,
79
82
  )
@@ -148,6 +151,8 @@ __all__ = [
148
151
  "StdioProtocolError",
149
152
  "StdoutExporter",
150
153
  "StoreConfig",
154
+ "SteerResult",
155
+ "SteerStatus",
151
156
  "SurfaceOp",
152
157
  "TimingSource",
153
158
  "ToolCall",
@@ -177,6 +182,7 @@ __all__ = [
177
182
  "UncertainSettled",
178
183
  "ValidatedCall",
179
184
  "ValidationIssue",
185
+ "WriterLeaseError",
180
186
  "load_harness_spec",
181
187
  "new_id",
182
188
  "project_traces",
@@ -2,8 +2,10 @@ from __future__ import annotations
2
2
 
3
3
  import asyncio
4
4
  import copy
5
+ import time
5
6
  from collections import defaultdict
6
- from collections.abc import Sequence
7
+ from collections.abc import Callable, Sequence
8
+ from dataclasses import dataclass
7
9
 
8
10
  from ..contracts import (
9
11
  Event,
@@ -12,28 +14,94 @@ from ..contracts import (
12
14
  NewEvent,
13
15
  PayloadErasedError,
14
16
  SurfaceOp,
17
+ WriterLeaseError,
15
18
  utc_now,
16
19
  )
17
20
  from ..events.upcast import upcast_event, validate_event_schema
18
21
 
19
22
 
23
+ @dataclass
24
+ class _Lease:
25
+ owner_id: str
26
+ writer_epoch: int
27
+ expires_at: float
28
+
29
+
20
30
  class InMemoryEventStore:
21
- def __init__(self) -> None:
31
+ def __init__(
32
+ self,
33
+ *,
34
+ owner_id: str | None = None,
35
+ lease_seconds: float = 5.0,
36
+ clock: Callable[[], float] = time.time,
37
+ ) -> None:
38
+ if owner_id is not None and not owner_id.strip():
39
+ raise ValueError("owner_id must be non-empty")
40
+ if lease_seconds <= 0:
41
+ raise ValueError("lease_seconds must be positive")
22
42
  self._events: dict[str, list[Event]] = defaultdict(list)
23
43
  self._epochs: dict[str, int] = defaultdict(int)
44
+ self._leases: dict[str, _Lease] = {}
24
45
  self._lock = asyncio.Lock()
46
+ self._owner_id = owner_id
47
+ self.lease_seconds = lease_seconds if owner_id is not None else None
48
+ self._clock = clock
25
49
 
26
- async def attach_writer(self, session_id: str) -> tuple[int, int, int]:
50
+ async def attach_writer(self, session_id: str, *, force: bool = False) -> tuple[int, int, int]:
27
51
  async with self._lock:
52
+ if self.lease_seconds is not None:
53
+ lease = self._leases.get(session_id)
54
+ if (
55
+ lease is not None
56
+ and lease.owner_id != self._owner_id
57
+ and lease.expires_at > self._clock()
58
+ and not force
59
+ ):
60
+ raise WriterLeaseError("Another owner holds an unexpired Session lease")
61
+ self._leases[session_id] = _Lease(
62
+ self._owner_id or "",
63
+ self._epochs[session_id] + 1,
64
+ self._clock() + self.lease_seconds,
65
+ )
28
66
  self._epochs[session_id] += 1
29
67
  events = self._events[session_id]
30
68
  last_turn = max((event.turn for event in events), default=0)
31
69
  return self._epochs[session_id], len(events), last_turn
32
70
 
33
- async def check_writer(self, session_id: str, writer_epoch: int) -> None:
34
- async with self._lock:
71
+ def _check_writer_locked(self, session_id: str, writer_epoch: int) -> None:
72
+ if self.lease_seconds is None:
35
73
  if self._epochs[session_id] != writer_epoch:
36
74
  raise InvariantViolation("Stale writer_epoch")
75
+ return
76
+ lease = self._leases.get(session_id)
77
+ if (
78
+ lease is None
79
+ or lease.owner_id != self._owner_id
80
+ or lease.writer_epoch != writer_epoch
81
+ or lease.expires_at <= self._clock()
82
+ ):
83
+ raise InvariantViolation("Stale writer_epoch")
84
+
85
+ async def check_writer(self, session_id: str, writer_epoch: int) -> None:
86
+ async with self._lock:
87
+ self._check_writer_locked(session_id, writer_epoch)
88
+
89
+ async def renew_writer(self, session_id: str, writer_epoch: int) -> None:
90
+ async with self._lock:
91
+ if self.lease_seconds is None:
92
+ raise InvariantViolation("Writer leases are not configured")
93
+ self._check_writer_locked(session_id, writer_epoch)
94
+ self._leases[session_id].expires_at = self._clock() + self.lease_seconds
95
+
96
+ async def has_writer(self, session_id: str) -> bool:
97
+ async with self._lock:
98
+ if self.lease_seconds is None:
99
+ return False
100
+ try:
101
+ lease = self._leases[session_id]
102
+ except KeyError:
103
+ return False
104
+ return lease.owner_id == self._owner_id and lease.expires_at > self._clock()
37
105
 
38
106
  async def append(
39
107
  self,
@@ -43,8 +111,7 @@ class InMemoryEventStore:
43
111
  events: Sequence[NewEvent],
44
112
  ) -> Sequence[Event]:
45
113
  async with self._lock:
46
- if self._epochs[session_id] != writer_epoch:
47
- raise InvariantViolation("Stale writer_epoch")
114
+ self._check_writer_locked(session_id, writer_epoch)
48
115
  existing = self._events[session_id]
49
116
  if expected_seq != len(existing) + 1:
50
117
  return self._idempotent(existing, events)
@@ -76,8 +76,8 @@ class ObservingEventStore:
76
76
  self._close_lock = asyncio.Lock()
77
77
  self.dropped_count = 0
78
78
 
79
- async def attach_writer(self, session_id: str) -> tuple[int, int, int]:
80
- result = await self._store.attach_writer(session_id)
79
+ async def attach_writer(self, session_id: str, *, force: bool = False) -> tuple[int, int, int]:
80
+ result = await self._store.attach_writer(session_id, force=force)
81
81
  try:
82
82
  async with self._projector_lock:
83
83
  self._projector.advance_seq(session_id, result[1])
@@ -85,9 +85,19 @@ class ObservingEventStore:
85
85
  self._report_error(exc, None)
86
86
  return result
87
87
 
88
+ @property
89
+ def lease_seconds(self) -> float | None:
90
+ return getattr(self._store, "lease_seconds", None)
91
+
88
92
  async def check_writer(self, session_id: str, writer_epoch: int) -> None:
89
93
  await self._store.check_writer(session_id, writer_epoch)
90
94
 
95
+ async def renew_writer(self, session_id: str, writer_epoch: int) -> None:
96
+ await self._store.renew_writer(session_id, writer_epoch)
97
+
98
+ async def has_writer(self, session_id: str) -> bool:
99
+ return await self._store.has_writer(session_id)
100
+
91
101
  async def load_surface(self, session_id: str) -> Sequence[Event]:
92
102
  return await self._store.load_surface(session_id)
93
103