Skip to content

fix(ai): distinguish pending turn readback and consolidate conversation APIs - #354

Open
ice-black-tea wants to merge 2 commits into
masterfrom
fix/history-session-turn-pending
Open

ice-black-tea wants to merge 2 commits into
masterfrom
fix/history-session-turn-pending

Conversation

@ice-black-tea

@ice-black-tea ice-black-tea commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  • An exact History.session_turn() read of an authorized, admitted, still-active turn can now report SESSION_TURN_PENDING when its timeline commit has not been published yet. An absent admission, a missing terminal commit and recovery-required storage retain their existing behavior.
  • Releasing the exact active execution after publishing an admitted terminal turn now advances the session revision even if there is no continuation checkpoint. Mere occupancy changes, missing admission and idempotent release do not advance it. This lets state observers identify a newly published terminal turn even if they did not see its active interval.
  • No new read is required to classify the pending case; release reuses the existing committed-turn lookup. No schema changes.

Original turn-publication verification

20 tests passed across test_session_timeline.py, test_session_timeline_repository_ownership.py and test_session_timeline_recovery.py. Covers access checks, pending versus unadmitted and recovery, terminal consistency, and revision advancement exactly once. git diff --check passed.

Public API and ownership

  • Keep History.session_detail(...).timeline for a history page and History.session_turn(...) for an exact published turn. Remove the forwarding History.session_timeline(...) method. Keep the distinct live Runtime timeline and observer interfaces.
  • Keep one Chat SSE mode, /api/session/events?session_id=…&view=chat. Remove Chat mode from /api/executions/{id}/events; that endpoint remains dedicated to diagnostics. Requests with the retired selector are rejected rather than silently switched to a more detailed stream. Exact Web readback no longer substitutes the latest page for the requested execution.
  • SessionService is owned and exported by linktools.ai.session, not linktools.ai.execution. Keep project_event_payload at linktools.ai.execution.events, and keep the live tool projector public; materializing stored transcript tool history stays private to History.
  • Remove persistence.objects.runtime_domain_uses_object_store: every real persistence domain is object-capable. Keep input validation and actual storage-route/retention decisions at their respective boundaries.

Focus: conversation-facing SDK, Web, and directly related persistence contracts. No DDL, wire-storage, authorization, execution diagnostics, coordination, or provider API changes. The separately documented Runtime.attach alias is not removed here.

Cleanup verification

Candidate fef6e3e56910: 248 tests passed in the focused History, persistence and ownership suite; 75 passed and one skipped in the Web/CLI suite (the suites overlap). The pending-read DOM scenario passed independently. The package architecture gate, configured Ruff rule selection, JavaScript syntax check and git diff --check passed. Full merge CI is separate.

File-by-file review

Changed = in the combined PR diff; Reviewed = source/contract inspected; References = call sites or exports searched; Verification = read or exercised for a regression. This table reports the actual review scope, not every file in the package.

File Review Decision
AGENTS.md Reviewed Repository export, dependency and verification rules.
linktools-ai/AGENTS.md Reviewed Package ownership, public export and durable contracts.
linktools-ai/docs/capability-ownership.md References Names the session service as lifecycle owner; no old import example.
linktools-ai/docs/domain-composition.md Reviewed Documents the Runtime.attach compatibility alias; keep this separately documented migration surface for now.
linktools-ai/docs/runtime-capabilities.md References Refers to the session service role, not its former import.
linktools-ai/docs/runtime-history.md Reviewed History API and history-vs-runtime boundary; no stale call.
linktools-ai/docs/storage-cache-design.md Changed The example uses one session_detail read, not separate metadata and timeline reads.
linktools-ai/docs/storage-caching.md References Describes max_age and the custom session service contract; unchanged.
linktools-ai/docs/web-console.md Changed Separate the session Chat stream from execution diagnostics.
linktools-ai/linktools.yml Reviewed SDK dependencies, test matrix and normal gates; unchanged.
linktools-ai/pyproject.toml Reviewed Package metadata and minimum Python version; unchanged.
linktools-ai/src/linktools/ai/__init__.py Reviewed Root composition exports remain intentionally narrow.
linktools-ai/src/linktools/ai/acp.py References Live tool projection and session detail remain valid callers.
linktools-ai/src/linktools/ai/errors.py Changed Introduce SESSION_TURN_PENDING for admitted, still-active exact reads.
linktools-ai/src/linktools/ai/execution/__init__.py Changed Remove the noncanonical SessionService re-export; leave existing request and view contracts intact.
linktools-ai/src/linktools/ai/execution/_service.py References Existing durable commit reader retains strict recovery behavior.
linktools-ai/src/linktools/ai/execution/_service_api.py Changed Stop owning the session lifecycle protocol in the execution domain.
linktools-ai/src/linktools/ai/execution/events.py Reviewed Remain the single public owner of project_event_payload.
linktools-ai/src/linktools/ai/execution/handle.py Reviewed Keep execution-bound control, read and watch operations.
linktools-ai/src/linktools/ai/execution/tree.py References Keep the canonical execution.events import.
linktools-ai/src/linktools/ai/history/__init__.py Changed Remove the second export of project_event_payload.
linktools-ai/src/linktools/ai/history/_history.py Changed Keep session_detail for the page and session_turn for an exact committed turn; remove the trivial History.session_timeline wrapper.
linktools-ai/src/linktools/ai/history/_session_timeline.py Changed Own saved transcript tool projection locally; classify pending publication without changing membership authorization.
linktools-ai/src/linktools/ai/migrate/_database.py Changed Provision default SQL objects for any valid nonempty domain set; validate actual enum members.
linktools-ai/src/linktools/ai/persistence/__init__.py References Checked the public persistence composition exports; unchanged.
linktools-ai/src/linktools/ai/persistence/_conversation_repositories.py Changed Distinguish classified pending reads, keep strict commit checks otherwise, and advance revision once for a released published turn.
linktools-ai/src/linktools/ai/persistence/_materializer.py Changed Derive object metadata from storage routing rather than an always-true domain predicate.
linktools-ai/src/linktools/ai/persistence/_object_router.py Changed Route object stores over the actual domain enum without the redundant predicate.
linktools-ai/src/linktools/ai/persistence/_plan.py Changed Use durable_domains for plan validation; remove the always-true capability query.
linktools-ai/src/linktools/ai/persistence/_retention.py References Retention commit-reader calls remain strict.
linktools-ai/src/linktools/ai/persistence/_root.py References The typed pending-turn coordination and the advanced host composition seam are separate; unchanged.
linktools-ai/src/linktools/ai/persistence/_runtime_commands.py References Command commit-reader calls stay strict; no behavior widening.
linktools-ai/src/linktools/ai/persistence/_runtime_state.py Changed Use all actual domains when building the snapshot's object-store map.
linktools-ai/src/linktools/ai/persistence/contracts.py Changed Repository boundary opts into pending reads explicitly; default remains strict.
linktools-ai/src/linktools/ai/persistence/objects.py Changed Remove an always-true public predicate; keep validation on the object-key boundary.
linktools-ai/src/linktools/ai/runtime/__init__.py Reviewed Runtime domain façades remain the public runtime entry points.
linktools-ai/src/linktools/ai/runtime/_agent.py Reviewed Keep bound Session.timeline and the separately governed planning entry point.
linktools-ai/src/linktools/ai/runtime/_domains.py Changed Use the session-owned protocol; retain live timeline, observation, wait and owned publication operations.
linktools-ai/src/linktools/ai/runtime/_factory.py References Uses internal assembly-facing History adapters; not duplicate caller endpoints.
linktools-ai/src/linktools/ai/runtime/_local.py References Keep live producer notice and tool-delta projection.
linktools-ai/src/linktools/ai/runtime/_runtime_service.py Changed Use the owning session protocol; do not change lifecycle behavior or the documented attach alias.
linktools-ai/src/linktools/ai/runtime/_session.py Reviewed Live pending and committed-only History views are not interchangeable.
linktools-ai/src/linktools/ai/runtime/agent_execution.py Changed Import the dependency annotation from its session owner.
linktools-ai/src/linktools/ai/session/__init__.py Changed Export SessionService from its owner; retain only the live public process projector.
linktools-ai/src/linktools/ai/session/_contracts.py Reviewed Keep the independently owned DTOs and session history contracts.
linktools-ai/src/linktools/ai/session/_process.py Changed Leave live tool events here; move committed raw transcript projection to History.
linktools-ai/src/linktools/ai/session/_service.py Changed Own the existing 15-method SessionService protocol unchanged.
linktools-ai/src/linktools/ai/storage/__init__.py References Generic storage and extension primitives remain distinct; unchanged.
linktools-ai/src/linktools/ai/storage/_database.py References Generic SQL provisioning remains separate from Runtime domain choices.
linktools-ai/src/linktools/ai/storage/_route.py References Keep storage-route retention and backend semantics.
linktools-ai/src/linktools/ai/storage/_turn.py References Keep the typed coordination pieces; they have distinct host uses.
linktools-ai/src/linktools/ai/web/_app.py Changed Use one ordinary page read and exact committed lookups, retire only the duplicate per-execution Chat mode, retain diagnostics and occupancy observation.
linktools-ai/src/linktools/ai/web/assets/app.js Changed Pending exact read keeps live preview and waits for stream progress or reconnect, without extra polling.
linktools-ai/src/linktools/commands/ai/_common.py References CLI consumes observe_turns; keep it separate from occupancy observation.
manage.py Reviewed Project check runner and supported test tiers; unchanged.
scripts/check/ai/__main__.py Reviewed Architecture gate entry; unchanged.
tests/ai/AGENTS.md Reviewed Retain distinct behavior and failure coverage.
tests/ai/_measure_sync_session_io.py References IO measurement consumers of session observation, unchanged.
tests/ai/test_architecture.py Verification Run package-boundary checks against the new owner imports.
tests/ai/test_archive_object_router.py Verification Run object-store routing regressions.
tests/ai/test_chat_tool_process.py Changed Preserve separate live and saved tool-projection assertions.
tests/ai/test_cli_turn_sync.py Verification Run cross-client and notice synchronization regressions.
tests/ai/test_conversation_output_retention.py Changed Retain history continuity, pagination, authorization and retention assertions on canonical session_detail.timeline.
tests/ai/test_conversation_turn_codec.py Changed Verify round-trip output against session_detail.timeline.
tests/ai/test_live_history_projection.py References Already imports the canonical execution.events projection.
tests/ai/test_retention_publication_proof.py Changed Keep fail-closed publication assertions on session_detail.
tests/ai/test_runtime_session_inactivity.py References Independent wait and inactivity semantics.
tests/ai/test_session_actor_identity.py Changed Preserve owner/peer projection checks on session_detail.timeline.
tests/ai/test_session_timeline.py Verification Run session timeline behavior regression suite.
tests/ai/test_session_timeline_recovery.py Verification Run recovery and release regression suite.
tests/ai/test_session_timeline_repository_ownership.py Changed Cover pending versus missing/recovery and exact-once revision; migrate existing assertions to the canonical page.
tests/ai/test_session_timeline_runtime.py Changed Retain Runtime and History parity, pagination and publication boundaries.
tests/ai/test_session_turn_notices.py References Producer turn notifications are separate from occupancy views.
tests/ai/test_session_watch.py References Distinct occupancy watch, unchanged.
tests/ai/test_spec_capability_contracts.py Changed Use actual object-key behavior, not an always-true predicate test.
tests/ai/test_sqlite_history_recovery.py Changed Verify offline SQLite history recovery on canonical session_detail.timeline.
tests/ai/test_storage_resource_contracts.py Verification Run storage resource and lifecycle regressions.
tests/ai/test_structured_output_preview.py References Uses the canonical projection export directly.
tests/ai/test_web_console.py Changed Cover canonical Chat streaming, diagnostic isolation, reconnection and exact pending versus genuine storage failure.
tests/ai/test_web_console_client.py Verification Run static UI and browser-fixture regressions.
tests/ai/test_web_console_startup.py Verification Run startup and existing occupancy SSE regressions.
tests/ai/test_web_console_viewers.py Changed Mock the canonical session_detail binding for viewer behavior.
tests/ai/test_web_local_coordination.py Verification Run local notifier and web coordination regressions.
tests/ai/test_web_session_detail_capture.py Verification Keep and run the one-capture page read assertion.
tests/ai/web_console_dom.mjs Changed Verify pending preserves live process, has no repeated read on a duplicate snapshot, and reads exactly once on reconnect.

@ice-black-tea
ice-black-tea marked this pull request as ready for review November 23, 2026 16:30
@ice-black-tea
ice-black-tea marked this pull request as draft November 23, 2026 16:58
@ice-black-tea ice-black-tea changed the title fix(history): distinguish pending turn publication fix(ai): distinguish pending turn readback and consolidate conversation APIs Nov 23, 2026
@ice-black-tea
ice-black-tea marked this pull request as ready for review November 23, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant