nextloop 1.1.0__tar.gz → 1.1.0rc1__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.
- {nextloop-1.1.0/src/nextloop.egg-info → nextloop-1.1.0rc1}/PKG-INFO +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/architecture/development-plan.md +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/architecture/requirements.md +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/architecture.md +2 -2
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/loop-interface.md +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/tutorial.md +11 -3
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/harness.toml +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/pyproject.toml +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/capabilities.py +7 -2
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/memory.py +29 -3
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/observing.py +74 -9
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/sqlite.py +68 -18
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/contracts.py +26 -18
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/driver.py +34 -16
- nextloop-1.1.0rc1/src/nextloop/events/codec.py +155 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/pending.py +2 -17
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/project.py +9 -70
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/preview.py +13 -2
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/tools.py +9 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/testing.py +9 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1/src/nextloop.egg-info}/PKG-INFO +1 -1
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop.egg-info/SOURCES.txt +1 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_events.py +13 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_execution_races.py +4 -2
- nextloop-1.1.0rc1/tests/test_validation_cache.py +33 -0
- nextloop-1.1.0/src/nextloop/events/codec.py +0 -63
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/LICENSE +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/MANIFEST.in +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/README.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0001-embeddable-agent-loop.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0002-dsh-aligned-agent-loop.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0003-python-and-centralized-contracts.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0004-event-compatibility.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0005-pending-input.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0006-operation-id.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0007-approval.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0008-lease.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0009-outbox.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0010-session-deletion.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/adr/0011-live-provider-acceptance.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/architecture/agent-loop-capability-review.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/architecture/discussion-roadmap.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/architecture/feature-worklist.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/agent-loop.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/context-builder.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/guarantees.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/harness.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/react-protocol.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/skills.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/design/verification-matrix.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-02-dsh-primary-sources.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-02-loop-evidence-notes.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-03-hermes-turn-control.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-03-tool-batch-failures.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-03-tool-call-validation.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-03-yomi-turn-control.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-06-open-source-agent-loops.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-06-react-tool-event-recovery.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/docs/research/2026-11-10-nextloop-optimization-review.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/basic.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/harness-skills/echo/SKILL.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/live_smoke.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/python_tools.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/skills/coding/SKILL.md +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/skills_demo.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/workers/cpp_worker.cpp +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/workers/python_worker.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/examples/workers/rust_worker.rs +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/setup.cfg +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/__init__.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/__init__.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/_http.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/_sqlite.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/_sse.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/anthropic.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/openai.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/adapters/outbox.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/cli.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/__init__.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/approval.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/input.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/outcome.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/repair.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/response.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/trace.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/trace_ids.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/events/upcast.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/__init__.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/batch.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/cancellation.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/cleanup.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/composite.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/mcp.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/model.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/result_read.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/stdio.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/execute/stdio_transport.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/harness.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/loop.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/py.typed +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop/skills.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop.egg-info/dependency_links.txt +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop.egg-info/entry_points.txt +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop.egg-info/requires.txt +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/src/nextloop.egg-info/top_level.txt +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_aggregate_close.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_approval.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_approval_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_budgets.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_cli.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_compaction_lineage.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_complexity_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_correctness_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_deletion.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_execution_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_failures.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_fault_injection.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_fault_matrix.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_finalizer_races.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_harness.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_harness_delegation.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_harness_injection.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_import_contract.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_lease.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_loop.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_mcp.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_mcp_hardening.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_observability.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_observability_close_deadline.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_operations.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_outbox.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_outbox_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_pending_inputs.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_preview.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_projection_parity.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_provider_terminal.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_providers.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_result_budget_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_result_policies.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_retry_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_review_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_skills.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_sqlite_safety.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_stdio.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_stdio_cleanup.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_stdio_frames.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_stdio_safety.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_store_contract.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_store_regressions.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_stores.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_surface_snapshot.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_upcasting.py +0 -0
- {nextloop-1.1.0 → nextloop-1.1.0rc1}/tests/test_worker_conformance.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# nextloop development and verification plan
|
|
2
2
|
|
|
3
|
-
Current stage: **1.1.
|
|
3
|
+
Current stage: **1.1.0rc1 release verification**. `1.0.0` is published; the maintainer-selected DeepSeek live gate is defined by ADR-0011.
|
|
4
4
|
|
|
5
5
|
## Delivery order
|
|
6
6
|
|
|
@@ -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) | **1.1.
|
|
24
|
+
| L17 | Package and release only after protocol verification | [Development plan](development-plan.md), [ADR-0003](../adr/0003-python-and-centralized-contracts.md) | **1.1.0rc1 implemented; release verification in progress.** Fault matrix, benchmark, Python 3.14, import contract, upcasting, operation, approval, owner lease, durable Outbox, whole-Session deletion, DeepSeek live scenarios, and package gates are required; official OpenAI/Anthropic acceptance is not claimed under ADR-0011 |
|
|
25
25
|
|
|
26
26
|
## Independence rule
|
|
27
27
|
|
|
@@ -36,9 +36,9 @@ Owner leases are optional. Same-owner restarts take over immediately; different
|
|
|
36
36
|
|
|
37
37
|
## Complexity boundaries
|
|
38
38
|
|
|
39
|
-
Conversation projection loads the current Surface once per Turn and uses the pure projection fold for each model request.
|
|
39
|
+
Conversation projection loads the current Surface once per Turn and uses the pure projection fold for each model request. Rejected batches, approval-result anchors, Pending inputs, and WorkingContext are collected in one facts pass before messages are built. Surface storage advances by append without repeatedly copying the event tuple, and Compaction snapshots the committed Surface before awaiting a summary so concurrent steer cannot alter its source range. An incremental message-cache prototype was not retained because its 100-Step improvement did not meet the required 50% threshold on both Store backends.
|
|
40
40
|
|
|
41
|
-
Pending Input requires an ordered log scan. A new Turn performs that scan once; it is not an O(1) operation. Trace replay is linear in processed events and payload size. Incremental and whole-history Trace projection use the same fold.
|
|
41
|
+
Pending Input requires an ordered log scan. A new Turn performs that scan once; it is not an O(1) operation. Canonical request bytes are cached per immutable `CandidateRequest`, and the Memory Store maintains an event-ID index without copying the historical ID set on each append. Trace replay is linear in processed events and payload size. Incremental and whole-history Trace projection use the same fold.
|
|
42
42
|
|
|
43
43
|
Run the 10,505-event parity benchmark with:
|
|
44
44
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Loop interface and ownership
|
|
2
2
|
|
|
3
|
-
Status: **v1.1 implemented for 1.1.
|
|
3
|
+
Status: **v1.1 implemented for 1.1.0rc1**, with public contracts in `src/nextloop/contracts.py`.
|
|
4
4
|
|
|
5
5
|
## Independence and version dependency
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ You do not need an API key. A scripted Provider stands in for a hosted model so
|
|
|
9
9
|
nextloop requires Python 3.11 or later.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
python -m pip install nextloop==1.1.
|
|
12
|
+
python -m pip install nextloop==1.1.0rc1
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## 2. Create the example
|
|
@@ -126,7 +126,7 @@ When you are ready for a hosted model, `Harness` can assemble the same Loop from
|
|
|
126
126
|
|
|
127
127
|
```toml
|
|
128
128
|
schema = "nextloop.harness/v1"
|
|
129
|
-
min_nextloop = "1.1.
|
|
129
|
+
min_nextloop = "1.1.0rc1"
|
|
130
130
|
|
|
131
131
|
[provider]
|
|
132
132
|
protocol = "openai"
|
|
@@ -153,7 +153,10 @@ from nextloop import Harness
|
|
|
153
153
|
async def main():
|
|
154
154
|
harness = Harness.load("harness.toml")
|
|
155
155
|
try:
|
|
156
|
-
outcome = await harness.run(
|
|
156
|
+
outcome = await harness.run(
|
|
157
|
+
"Say hello in one short sentence.",
|
|
158
|
+
input_id="hello-request-1",
|
|
159
|
+
)
|
|
157
160
|
assert outcome.status == "succeeded", outcome.error
|
|
158
161
|
print(harness.delivery.messages[-1].content)
|
|
159
162
|
finally:
|
|
@@ -166,9 +169,14 @@ if __name__ == "__main__":
|
|
|
166
169
|
|
|
167
170
|
The default Harness DeliveryOwner keeps messages in memory. Inject your own Delivery adapter when your application needs to send them somewhere else.
|
|
168
171
|
|
|
172
|
+
A stable `input_id` makes retries idempotent. Calling `run()` again with the same ID and content after a successful Turn returns the original `TurnOutcome` without repeating Model calls, Tool execution, or Delivery. Reusing that ID with different content is rejected. `Harness` also accepts an optional `PreviewSink` through `preview=`.
|
|
173
|
+
|
|
169
174
|
## Next steps
|
|
170
175
|
|
|
171
176
|
- [Harness configuration, Tools, MCP, Skills, and Observability](design/harness.md)
|
|
172
177
|
- [Public API and adapter contracts](design/loop-interface.md)
|
|
173
178
|
- [Execution architecture](design/architecture.md)
|
|
174
179
|
- [Guarantees and non-guarantees](design/guarantees.md)
|
|
180
|
+
- [Pending Input, approval resume, reconciliation, and resource locks](design/harness.md#pending-input)
|
|
181
|
+
- [Durable Trace replay with SQLiteOutbox](design/harness.md#durable-outbox)
|
|
182
|
+
- [Recovery and whole-Session deletion](design/harness.md#whole-session-deletion)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nextloop"
|
|
7
|
-
version = "1.1.
|
|
7
|
+
version = "1.1.0rc1"
|
|
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"
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
from collections.abc import Awaitable, Callable, Sequence
|
|
4
4
|
from typing import Protocol, cast, runtime_checkable
|
|
5
5
|
|
|
6
|
-
from ..contracts import Event, EventStore
|
|
6
|
+
from ..contracts import Event, EventStore, NewEvent
|
|
7
7
|
|
|
8
8
|
HistoryCheck = Callable[[Sequence[Event]], None]
|
|
9
9
|
|
|
@@ -32,6 +32,7 @@ class CheckedAttachEventStore(Protocol):
|
|
|
32
32
|
check: HistoryCheck,
|
|
33
33
|
*,
|
|
34
34
|
force: bool = False,
|
|
35
|
+
initial_events: Sequence[NewEvent] = (),
|
|
35
36
|
) -> tuple[int, int, int, Sequence[Event]]: ...
|
|
36
37
|
|
|
37
38
|
|
|
@@ -70,14 +71,18 @@ async def attach_writer_with_check(
|
|
|
70
71
|
check: HistoryCheck,
|
|
71
72
|
*,
|
|
72
73
|
force: bool = False,
|
|
74
|
+
initial_events: Sequence[NewEvent] = (),
|
|
73
75
|
) -> tuple[int, int, int, Sequence[Event]]:
|
|
74
76
|
checked_attach = getattr(store, "attach_writer_checked", None)
|
|
75
77
|
if callable(checked_attach):
|
|
76
78
|
return cast(
|
|
77
79
|
tuple[int, int, int, Sequence[Event]],
|
|
78
|
-
await checked_attach(session_id, check, force=force),
|
|
80
|
+
await checked_attach(session_id, check, force=force, initial_events=initial_events),
|
|
79
81
|
)
|
|
80
82
|
history = await store.load_recovery(session_id)
|
|
81
83
|
check(history)
|
|
82
84
|
epoch, last_seq, last_turn = await store.attach_writer(session_id, force=force)
|
|
85
|
+
if initial_events:
|
|
86
|
+
committed = await store.append(session_id, epoch, last_seq + 1, initial_events)
|
|
87
|
+
last_seq, last_turn = committed[-1].seq, committed[-1].turn
|
|
83
88
|
return epoch, last_seq, last_turn, history
|
|
@@ -82,8 +82,11 @@ class InMemoryEventStore:
|
|
|
82
82
|
check: HistoryCheck,
|
|
83
83
|
*,
|
|
84
84
|
force: bool = False,
|
|
85
|
+
initial_events: Sequence[NewEvent] = (),
|
|
85
86
|
) -> tuple[int, int, int, Sequence[Event]]:
|
|
86
|
-
return await self._attach_writer(
|
|
87
|
+
return await self._attach_writer(
|
|
88
|
+
session_id, force=force, check=check, initial_events=initial_events
|
|
89
|
+
)
|
|
87
90
|
|
|
88
91
|
async def _attach_writer(
|
|
89
92
|
self,
|
|
@@ -91,6 +94,7 @@ class InMemoryEventStore:
|
|
|
91
94
|
*,
|
|
92
95
|
force: bool,
|
|
93
96
|
check: HistoryCheck | None = None,
|
|
97
|
+
initial_events: Sequence[NewEvent] = (),
|
|
94
98
|
) -> tuple[int, int, int, Sequence[Event]]:
|
|
95
99
|
async with self._lock:
|
|
96
100
|
self._ensure_active(session_id)
|
|
@@ -116,6 +120,28 @@ class InMemoryEventStore:
|
|
|
116
120
|
)
|
|
117
121
|
self._epochs[session_id] += 1
|
|
118
122
|
events = self._events[session_id]
|
|
123
|
+
if initial_events:
|
|
124
|
+
first_seq = len(events) + 1
|
|
125
|
+
committed = [
|
|
126
|
+
Event(
|
|
127
|
+
session_id=session_id,
|
|
128
|
+
seq=first_seq + offset,
|
|
129
|
+
turn=draft.turn,
|
|
130
|
+
step=draft.step,
|
|
131
|
+
attempt=draft.attempt,
|
|
132
|
+
writer_epoch=self._epochs[session_id],
|
|
133
|
+
event_id=draft.event_id,
|
|
134
|
+
event_type=draft.event_type,
|
|
135
|
+
surface_op=draft.surface_op,
|
|
136
|
+
payload=copy.deepcopy(dict(draft.payload)),
|
|
137
|
+
occurred_at=utc_now(),
|
|
138
|
+
)
|
|
139
|
+
for offset, draft in enumerate(initial_events)
|
|
140
|
+
]
|
|
141
|
+
if any(event.event_id in self._event_ids[session_id] for event in committed):
|
|
142
|
+
raise InvariantViolation("Event ID reused with different content")
|
|
143
|
+
events.extend(committed)
|
|
144
|
+
self._event_ids[session_id].update((event.event_id, event) for event in committed)
|
|
119
145
|
last_turn = max((event.turn for event in events), default=0)
|
|
120
146
|
return self._epochs[session_id], len(events), last_turn, history
|
|
121
147
|
|
|
@@ -170,10 +196,10 @@ class InMemoryEventStore:
|
|
|
170
196
|
if expected_seq != len(existing) + 1:
|
|
171
197
|
return self._idempotent(existing, events)
|
|
172
198
|
known_ids = self._event_ids[session_id]
|
|
173
|
-
batch_ids = set(
|
|
199
|
+
batch_ids: set[str] = set()
|
|
174
200
|
committed = []
|
|
175
201
|
for offset, draft in enumerate(events):
|
|
176
|
-
if draft.event_id in batch_ids:
|
|
202
|
+
if draft.event_id in known_ids or draft.event_id in batch_ids:
|
|
177
203
|
raise InvariantViolation("Event ID reused with different content")
|
|
178
204
|
batch_ids.add(draft.event_id)
|
|
179
205
|
event = Event(
|
|
@@ -141,10 +141,18 @@ class ObservingEventStore:
|
|
|
141
141
|
check: HistoryCheck,
|
|
142
142
|
*,
|
|
143
143
|
force: bool = False,
|
|
144
|
+
initial_events: Sequence[NewEvent] = (),
|
|
144
145
|
) -> tuple[int, int, int, Sequence[Event]]:
|
|
145
146
|
async with self._activity_lock:
|
|
146
147
|
epoch, last_seq, last_turn, history = await attach_writer_with_check(
|
|
147
|
-
self._store, session_id, check, force=force
|
|
148
|
+
self._store, session_id, check, force=force, initial_events=initial_events
|
|
149
|
+
)
|
|
150
|
+
committed = (
|
|
151
|
+
await self._store.append(
|
|
152
|
+
session_id, epoch, last_seq - len(initial_events) + 1, initial_events
|
|
153
|
+
)
|
|
154
|
+
if initial_events
|
|
155
|
+
else ()
|
|
148
156
|
)
|
|
149
157
|
try:
|
|
150
158
|
async with self._projector_lock:
|
|
@@ -153,6 +161,9 @@ class ObservingEventStore:
|
|
|
153
161
|
self._seeded_sessions.add(session_id)
|
|
154
162
|
else:
|
|
155
163
|
self._projector.advance_seq(session_id, last_seq)
|
|
164
|
+
records = self._projector.feed(committed)
|
|
165
|
+
for record in records:
|
|
166
|
+
self._enqueue(record)
|
|
156
167
|
except Exception as exc:
|
|
157
168
|
self._report_error(exc, None)
|
|
158
169
|
return epoch, last_seq, last_turn, history
|
|
@@ -230,20 +241,23 @@ class ObservingEventStore:
|
|
|
230
241
|
async def _worker(self) -> None:
|
|
231
242
|
while True:
|
|
232
243
|
record = await self._queue.get()
|
|
244
|
+
records = [record]
|
|
245
|
+
while True:
|
|
246
|
+
try:
|
|
247
|
+
records.append(self._queue.get_nowait())
|
|
248
|
+
except asyncio.QueueEmpty:
|
|
249
|
+
break
|
|
233
250
|
async with self._export_lock:
|
|
234
251
|
self._in_flight = record
|
|
235
252
|
try:
|
|
236
|
-
if record.session_id in self._deleted_sessions:
|
|
237
|
-
self.dropped_count += 1
|
|
238
|
-
continue
|
|
239
253
|
for exporter in self._exporters:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
self._report_error(exc, record)
|
|
254
|
+
self.dropped_count += await export_trace_batch(
|
|
255
|
+
exporter, records, self._deleted_sessions, self._report_error
|
|
256
|
+
)
|
|
244
257
|
finally:
|
|
245
258
|
self._in_flight = None
|
|
246
|
-
|
|
259
|
+
for _ in records:
|
|
260
|
+
self._queue.task_done()
|
|
247
261
|
|
|
248
262
|
def _report_error(self, error: Exception, record: TraceRecord | None) -> None:
|
|
249
263
|
try:
|
|
@@ -346,6 +360,57 @@ async def export_trace(exporter: TraceExporterInput, record: TraceRecord) -> Non
|
|
|
346
360
|
await result
|
|
347
361
|
|
|
348
362
|
|
|
363
|
+
async def export_trace_batch(
|
|
364
|
+
exporter: TraceExporterInput,
|
|
365
|
+
records: list[TraceRecord],
|
|
366
|
+
deleted_sessions: set[str],
|
|
367
|
+
on_error: TraceErrorHandler,
|
|
368
|
+
) -> int:
|
|
369
|
+
export = getattr(exporter, "export", None)
|
|
370
|
+
callback = export if callable(export) else cast(Callable[[TraceRecord], Any], exporter)
|
|
371
|
+
deleted = 0
|
|
372
|
+
if inspect.iscoroutinefunction(callback):
|
|
373
|
+
for record in records:
|
|
374
|
+
if record.session_id in deleted_sessions:
|
|
375
|
+
deleted += 1
|
|
376
|
+
continue
|
|
377
|
+
try:
|
|
378
|
+
result = callback(record)
|
|
379
|
+
if inspect.isawaitable(result):
|
|
380
|
+
await result
|
|
381
|
+
except Exception as exc:
|
|
382
|
+
on_error(exc, record)
|
|
383
|
+
return deleted
|
|
384
|
+
outcomes = await asyncio.to_thread(_export_sync_batch, callback, records, deleted_sessions)
|
|
385
|
+
for record, error, result, was_deleted in outcomes:
|
|
386
|
+
if was_deleted:
|
|
387
|
+
deleted += 1
|
|
388
|
+
elif error is not None:
|
|
389
|
+
on_error(error, record)
|
|
390
|
+
elif inspect.isawaitable(result):
|
|
391
|
+
await result
|
|
392
|
+
return deleted
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def _export_sync_batch(
|
|
396
|
+
callback: Callable[[TraceRecord], Any],
|
|
397
|
+
records: list[TraceRecord],
|
|
398
|
+
deleted_sessions: set[str],
|
|
399
|
+
) -> list[tuple[TraceRecord, Exception | None, Any, bool]]:
|
|
400
|
+
outcomes: list[tuple[TraceRecord, Exception | None, Any, bool]] = []
|
|
401
|
+
for record in records:
|
|
402
|
+
if record.session_id in deleted_sessions:
|
|
403
|
+
outcomes.append((record, None, None, True))
|
|
404
|
+
continue
|
|
405
|
+
try:
|
|
406
|
+
result = callback(record)
|
|
407
|
+
except Exception as exc:
|
|
408
|
+
outcomes.append((record, exc, None, False))
|
|
409
|
+
else:
|
|
410
|
+
outcomes.append((record, None, result, False))
|
|
411
|
+
return outcomes
|
|
412
|
+
|
|
413
|
+
|
|
349
414
|
async def exporter_lifecycle(exporter: TraceExporterInput, method: str) -> None:
|
|
350
415
|
callback = getattr(exporter, method, None)
|
|
351
416
|
if not callable(callback):
|
|
@@ -195,9 +195,12 @@ class SQLiteEventStore:
|
|
|
195
195
|
check: HistoryCheck,
|
|
196
196
|
*,
|
|
197
197
|
force: bool = False,
|
|
198
|
+
initial_events: Sequence[NewEvent] = (),
|
|
198
199
|
) -> tuple[int, int, int, Sequence[Event]]:
|
|
199
200
|
with self._lock, write_transaction(self._connection):
|
|
200
|
-
return self._attach_writer_locked(
|
|
201
|
+
return self._attach_writer_locked(
|
|
202
|
+
session_id, force=force, check=check, initial_events=initial_events
|
|
203
|
+
)
|
|
201
204
|
|
|
202
205
|
def _attach_writer_locked(
|
|
203
206
|
self,
|
|
@@ -205,6 +208,7 @@ class SQLiteEventStore:
|
|
|
205
208
|
*,
|
|
206
209
|
force: bool,
|
|
207
210
|
check: HistoryCheck | None = None,
|
|
211
|
+
initial_events: Sequence[NewEvent] = (),
|
|
208
212
|
) -> tuple[int, int, int, Sequence[Event]]:
|
|
209
213
|
self._ensure_active_locked(session_id)
|
|
210
214
|
history: Sequence[Event] = ()
|
|
@@ -250,7 +254,40 @@ class SQLiteEventStore:
|
|
|
250
254
|
"FROM session_events WHERE session_id = ?",
|
|
251
255
|
(session_id,),
|
|
252
256
|
).fetchone()
|
|
253
|
-
|
|
257
|
+
last_seq = int(tail["last_seq"])
|
|
258
|
+
last_turn = int(tail["last_turn"])
|
|
259
|
+
for offset, draft in enumerate(initial_events):
|
|
260
|
+
self._connection.execute(
|
|
261
|
+
"""
|
|
262
|
+
INSERT INTO session_events (
|
|
263
|
+
session_id, seq, turn, step, attempt, writer_epoch, event_id,
|
|
264
|
+
event_type, surface_op, payload_json, occurred_at, schema_version
|
|
265
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
266
|
+
""",
|
|
267
|
+
(
|
|
268
|
+
session_id,
|
|
269
|
+
last_seq + offset + 1,
|
|
270
|
+
draft.turn,
|
|
271
|
+
draft.step,
|
|
272
|
+
draft.attempt,
|
|
273
|
+
epoch,
|
|
274
|
+
draft.event_id,
|
|
275
|
+
draft.event_type.value,
|
|
276
|
+
draft.surface_op.value,
|
|
277
|
+
json.dumps(
|
|
278
|
+
draft.payload,
|
|
279
|
+
ensure_ascii=False,
|
|
280
|
+
sort_keys=True,
|
|
281
|
+
separators=(",", ":"),
|
|
282
|
+
),
|
|
283
|
+
utc_now(),
|
|
284
|
+
EVENT_SCHEMA_VERSION,
|
|
285
|
+
),
|
|
286
|
+
)
|
|
287
|
+
if initial_events:
|
|
288
|
+
last_seq += len(initial_events)
|
|
289
|
+
last_turn = initial_events[-1].turn
|
|
290
|
+
return epoch, last_seq, last_turn, history
|
|
254
291
|
|
|
255
292
|
def _check_writer_locked(self, session_id: str, writer_epoch: int) -> None:
|
|
256
293
|
self._ensure_active_locked(session_id)
|
|
@@ -260,6 +297,9 @@ class SQLiteEventStore:
|
|
|
260
297
|
).fetchone()
|
|
261
298
|
if row is None or int(row["writer_epoch"]) != writer_epoch:
|
|
262
299
|
raise InvariantViolation("Stale writer_epoch")
|
|
300
|
+
self._check_lease_locked(session_id, writer_epoch)
|
|
301
|
+
|
|
302
|
+
def _check_lease_locked(self, session_id: str, writer_epoch: int) -> None:
|
|
263
303
|
if self.lease_seconds is None:
|
|
264
304
|
return
|
|
265
305
|
lease = self._connection.execute(
|
|
@@ -274,6 +314,19 @@ class SQLiteEventStore:
|
|
|
274
314
|
):
|
|
275
315
|
raise InvariantViolation("Stale writer_epoch")
|
|
276
316
|
|
|
317
|
+
def _check_writer_and_tail_locked(self, session_id: str, writer_epoch: int) -> int:
|
|
318
|
+
self._ensure_active_locked(session_id)
|
|
319
|
+
row = self._connection.execute(
|
|
320
|
+
"SELECT (SELECT writer_epoch FROM session_writers WHERE session_id = ?) "
|
|
321
|
+
"AS writer_epoch, COALESCE(MAX(seq), 0) AS last_seq "
|
|
322
|
+
"FROM session_events WHERE session_id = ?",
|
|
323
|
+
(session_id, session_id),
|
|
324
|
+
).fetchone()
|
|
325
|
+
if row["writer_epoch"] is None or int(row["writer_epoch"]) != writer_epoch:
|
|
326
|
+
raise InvariantViolation("Stale writer_epoch")
|
|
327
|
+
self._check_lease_locked(session_id, writer_epoch)
|
|
328
|
+
return int(row["last_seq"])
|
|
329
|
+
|
|
277
330
|
@offload
|
|
278
331
|
def check_writer(self, session_id: str, writer_epoch: int) -> None:
|
|
279
332
|
with self._lock:
|
|
@@ -331,14 +384,7 @@ class SQLiteEventStore:
|
|
|
331
384
|
self._ensure_active_locked(session_id)
|
|
332
385
|
return ()
|
|
333
386
|
with write_transaction(self._connection):
|
|
334
|
-
self.
|
|
335
|
-
last_seq = int(
|
|
336
|
-
self._connection.execute(
|
|
337
|
-
"SELECT COALESCE(MAX(seq), 0) AS last_seq "
|
|
338
|
-
"FROM session_events WHERE session_id = ?",
|
|
339
|
-
(session_id,),
|
|
340
|
-
).fetchone()["last_seq"]
|
|
341
|
-
)
|
|
387
|
+
last_seq = self._check_writer_and_tail_locked(session_id, writer_epoch)
|
|
342
388
|
if expected_seq != last_seq + 1:
|
|
343
389
|
existing = []
|
|
344
390
|
for draft in events:
|
|
@@ -351,15 +397,10 @@ class SQLiteEventStore:
|
|
|
351
397
|
committed = verify_idempotent_append(existing, events)
|
|
352
398
|
return committed
|
|
353
399
|
committed = []
|
|
400
|
+
rows: list[tuple[object, ...]] = []
|
|
354
401
|
for offset, draft in enumerate(events):
|
|
355
402
|
occurred_at = utc_now()
|
|
356
|
-
|
|
357
|
-
"""
|
|
358
|
-
INSERT INTO session_events (
|
|
359
|
-
session_id, seq, turn, step, attempt, writer_epoch, event_id,
|
|
360
|
-
event_type, surface_op, payload_json, occurred_at, schema_version
|
|
361
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
362
|
-
""",
|
|
403
|
+
rows.append(
|
|
363
404
|
(
|
|
364
405
|
session_id,
|
|
365
406
|
expected_seq + offset,
|
|
@@ -378,13 +419,22 @@ class SQLiteEventStore:
|
|
|
378
419
|
),
|
|
379
420
|
occurred_at,
|
|
380
421
|
EVENT_SCHEMA_VERSION,
|
|
381
|
-
)
|
|
422
|
+
)
|
|
382
423
|
)
|
|
383
424
|
committed.append(
|
|
384
425
|
self._event_from_draft(
|
|
385
426
|
session_id, expected_seq + offset, writer_epoch, draft, occurred_at
|
|
386
427
|
)
|
|
387
428
|
)
|
|
429
|
+
self._connection.executemany(
|
|
430
|
+
"""
|
|
431
|
+
INSERT INTO session_events (
|
|
432
|
+
session_id, seq, turn, step, attempt, writer_epoch, event_id,
|
|
433
|
+
event_type, surface_op, payload_json, occurred_at, schema_version
|
|
434
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
435
|
+
""",
|
|
436
|
+
rows,
|
|
437
|
+
)
|
|
388
438
|
return committed
|
|
389
439
|
|
|
390
440
|
def _read_rows_locked(self, statement: str, parameters: Sequence[str]) -> list[sqlite3.Row]:
|
|
@@ -10,7 +10,7 @@ from datetime import UTC, datetime
|
|
|
10
10
|
from enum import StrEnum
|
|
11
11
|
from typing import Any, Literal, Protocol
|
|
12
12
|
|
|
13
|
-
API_VERSION = "1.1.
|
|
13
|
+
API_VERSION = "1.1.0rc1"
|
|
14
14
|
EVENT_SCHEMA_VERSION = "1.1"
|
|
15
15
|
HARNESS_SCHEMA = "nextloop.harness/v1"
|
|
16
16
|
STDIO_PROTOCOL_VERSION = "nextloop.stdio/v1"
|
|
@@ -419,6 +419,20 @@ class PreviewSink(Protocol):
|
|
|
419
419
|
def publish(self, event: PreviewEvent) -> None: ...
|
|
420
420
|
|
|
421
421
|
|
|
422
|
+
def canonical_message_data(message: Message) -> dict[str, Any]:
|
|
423
|
+
return {
|
|
424
|
+
"role": message.role,
|
|
425
|
+
"content": message.content,
|
|
426
|
+
"tool_calls": [
|
|
427
|
+
{"call_id": call.call_id, "name": call.name, "arguments": call.arguments}
|
|
428
|
+
for call in message.tool_calls
|
|
429
|
+
],
|
|
430
|
+
"tool_call_id": message.tool_call_id,
|
|
431
|
+
"name": message.name,
|
|
432
|
+
"provider_data": dict(message.provider_data),
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
|
|
422
436
|
@dataclass(frozen=True)
|
|
423
437
|
class CandidateRequest:
|
|
424
438
|
session_id: str
|
|
@@ -426,31 +440,25 @@ class CandidateRequest:
|
|
|
426
440
|
step: int
|
|
427
441
|
messages: tuple[Message, ...]
|
|
428
442
|
tools: tuple[ToolSpec, ...]
|
|
443
|
+
_canonical_bytes_cache: bytes | None = field(
|
|
444
|
+
default=None, init=False, repr=False, compare=False
|
|
445
|
+
)
|
|
429
446
|
|
|
430
447
|
def canonical_bytes(self) -> bytes:
|
|
448
|
+
if self._canonical_bytes_cache is not None:
|
|
449
|
+
return self._canonical_bytes_cache
|
|
431
450
|
data = {
|
|
432
451
|
"tools": [
|
|
433
452
|
{"name": t.name, "description": t.description, "parameters": dict(t.parameters)}
|
|
434
453
|
for t in self.tools
|
|
435
454
|
],
|
|
436
|
-
"messages": [
|
|
437
|
-
{
|
|
438
|
-
"role": message.role,
|
|
439
|
-
"content": message.content,
|
|
440
|
-
"tool_calls": [
|
|
441
|
-
{"call_id": call.call_id, "name": call.name, "arguments": call.arguments}
|
|
442
|
-
for call in message.tool_calls
|
|
443
|
-
],
|
|
444
|
-
"tool_call_id": message.tool_call_id,
|
|
445
|
-
"name": message.name,
|
|
446
|
-
"provider_data": dict(message.provider_data),
|
|
447
|
-
}
|
|
448
|
-
for message in self.messages
|
|
449
|
-
],
|
|
455
|
+
"messages": [canonical_message_data(message) for message in self.messages],
|
|
450
456
|
}
|
|
451
|
-
|
|
452
|
-
"
|
|
453
|
-
)
|
|
457
|
+
canonical = json.dumps(
|
|
458
|
+
data, ensure_ascii=False, sort_keys=True, separators=(",", ":")
|
|
459
|
+
).encode("utf-8")
|
|
460
|
+
object.__setattr__(self, "_canonical_bytes_cache", canonical)
|
|
461
|
+
return canonical
|
|
454
462
|
|
|
455
463
|
|
|
456
464
|
@dataclass(frozen=True)
|
|
@@ -237,6 +237,7 @@ class ExecutionFrame:
|
|
|
237
237
|
self.writer_epoch = 0
|
|
238
238
|
self.last_seq = 0
|
|
239
239
|
self.last_turn = 0
|
|
240
|
+
self._begun = False
|
|
240
241
|
|
|
241
242
|
async def __aenter__(self) -> ExecutionFrame:
|
|
242
243
|
if not self.context.input_id.strip():
|
|
@@ -259,7 +260,12 @@ class ExecutionFrame:
|
|
|
259
260
|
self.last_seq,
|
|
260
261
|
self.last_turn,
|
|
261
262
|
self.history,
|
|
262
|
-
) = await checked_attach(
|
|
263
|
+
) = await checked_attach(
|
|
264
|
+
self.context.session_id,
|
|
265
|
+
check,
|
|
266
|
+
initial_events=self._initial_events(),
|
|
267
|
+
)
|
|
268
|
+
self._begun = True
|
|
263
269
|
else:
|
|
264
270
|
(
|
|
265
271
|
self.writer_epoch,
|
|
@@ -272,7 +278,7 @@ class ExecutionFrame:
|
|
|
272
278
|
actor=self.actor,
|
|
273
279
|
writer_epoch=self.writer_epoch,
|
|
274
280
|
seq=self.last_seq,
|
|
275
|
-
turn=self.last_turn + 1,
|
|
281
|
+
turn=self.last_turn if self._begun else self.last_turn + 1,
|
|
276
282
|
resource_locks=set(active_resource_locks(self.history)),
|
|
277
283
|
)
|
|
278
284
|
self.execution = execution
|
|
@@ -303,22 +309,26 @@ class ExecutionFrame:
|
|
|
303
309
|
execution.heartbeat_task = asyncio.create_task(self._heartbeat(execution, interval / 3))
|
|
304
310
|
return execution
|
|
305
311
|
|
|
312
|
+
def _initial_events(self) -> tuple[NewEvent, NewEvent]:
|
|
313
|
+
turn = max((event.turn for event in self.history), default=0) + 1
|
|
314
|
+
return (
|
|
315
|
+
NewEvent(
|
|
316
|
+
event_type=EventType.INPUT_ACCEPTED,
|
|
317
|
+
turn=turn,
|
|
318
|
+
step=0,
|
|
319
|
+
payload={
|
|
320
|
+
"input_id": self.context.input_id,
|
|
321
|
+
"content": self.context.initial_input,
|
|
322
|
+
},
|
|
323
|
+
),
|
|
324
|
+
NewEvent(event_type=EventType.TURN_START, turn=turn, step=0),
|
|
325
|
+
)
|
|
326
|
+
|
|
306
327
|
async def begin(self) -> None:
|
|
328
|
+
if self._begun:
|
|
329
|
+
return
|
|
307
330
|
execution = self._require_execution()
|
|
308
|
-
await execution.append(
|
|
309
|
-
[
|
|
310
|
-
NewEvent(
|
|
311
|
-
event_type=EventType.INPUT_ACCEPTED,
|
|
312
|
-
turn=execution.turn,
|
|
313
|
-
step=0,
|
|
314
|
-
payload={
|
|
315
|
-
"input_id": self.context.input_id,
|
|
316
|
-
"content": self.context.initial_input,
|
|
317
|
-
},
|
|
318
|
-
),
|
|
319
|
-
NewEvent(event_type=EventType.TURN_START, turn=execution.turn, step=0),
|
|
320
|
-
]
|
|
321
|
-
)
|
|
331
|
+
await execution.append(self._initial_events())
|
|
322
332
|
|
|
323
333
|
async def begin_step(self) -> None:
|
|
324
334
|
execution = self._require_execution()
|
|
@@ -903,6 +913,14 @@ async def run_approval_resume(
|
|
|
903
913
|
or {item.operation_id for item in current.items} != expected
|
|
904
914
|
):
|
|
905
915
|
raise InvariantViolation("Approval changed; reload decisions")
|
|
916
|
+
closed_turns = {event.turn for event in events if event.event_type == EventType.TURN_END}
|
|
917
|
+
if any(
|
|
918
|
+
event.event_type == EventType.TURN_START
|
|
919
|
+
and event.turn != request.origin_turn
|
|
920
|
+
and event.turn not in closed_turns
|
|
921
|
+
for event in events
|
|
922
|
+
):
|
|
923
|
+
raise InvariantViolation("Approval dispatch already started; recover first")
|
|
906
924
|
if any(
|
|
907
925
|
event.event_type == EventType.TOOL_CALL
|
|
908
926
|
and event.payload.get("operation_id") in expected
|