ms-tau-sdk 2.0.30.dev93__tar.gz → 2.0.31.dev94__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 (95) hide show
  1. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/CHANGELOG.md +11 -0
  2. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/PKG-INFO +1 -1
  3. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/pyproject.toml +1 -1
  4. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/client.py +25 -0
  5. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/local.py +129 -0
  6. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/manager.py +64 -13
  7. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/.gitignore +0 -0
  8. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/README.md +0 -0
  9. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/__init__.py +0 -0
  10. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/app.py +0 -0
  11. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/cli.py +0 -0
  12. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/config.py +0 -0
  13. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/env_file.py +0 -0
  14. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/logs.py +0 -0
  15. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/proxy.py +0 -0
  16. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/state.py +0 -0
  17. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/static/BULMA-LICENSE.txt +0 -0
  18. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/static/app.js +0 -0
  19. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/static/board.css +0 -0
  20. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/static/bulma.min.css +0 -0
  21. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/packages/tau-board/src/ms_tau_board/static/index.html +0 -0
  22. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/__init__.py +0 -0
  23. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/SKILL.md +0 -0
  24. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/agents/openai.yaml +0 -0
  25. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/references/metatables-example.html +0 -0
  26. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/tau_a2a_runtime_adapter/SKILL.md +0 -0
  27. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/tau_local_development/SKILL.md +0 -0
  28. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/tau_project_customization/SKILL.md +0 -0
  29. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/tau_repository_integration/SKILL.md +0 -0
  30. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/agent_skills/tau_security_and_access/SKILL.md +0 -0
  31. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/__init__.py +0 -0
  32. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/a2a.py +0 -0
  33. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/chat.py +0 -0
  34. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/conversations.py +0 -0
  35. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/dependencies.py +0 -0
  36. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/health.py +0 -0
  37. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/inspection.py +0 -0
  38. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/local_chat.py +0 -0
  39. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/models.py +0 -0
  40. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/request_identity.py +0 -0
  41. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/api/sessions.py +0 -0
  42. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/app.py +0 -0
  43. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/application.py +0 -0
  44. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/__init__.py +0 -0
  45. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/assertions.py +0 -0
  46. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/auth.py +0 -0
  47. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/hydrate_endpoint.py +0 -0
  48. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/mcp.py +0 -0
  49. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/models.py +0 -0
  50. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/release_access.py +0 -0
  51. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/routes.py +0 -0
  52. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/backend/team_memberships.py +0 -0
  53. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/cli.py +0 -0
  54. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/errors.py +0 -0
  55. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/logging.py +0 -0
  56. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/__init__.py +0 -0
  57. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/a2a_failure.py +0 -0
  58. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/a2a_message.py +0 -0
  59. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/a2a_roles.py +0 -0
  60. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/assistant_ui.py +0 -0
  61. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/caller_context.py +0 -0
  62. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/chat_history.py +0 -0
  63. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/protocols/strict_json.py +0 -0
  64. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/providers/__init__.py +0 -0
  65. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/providers/definitions.py +0 -0
  66. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/providers/factory.py +0 -0
  67. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/providers/tau_compat.py +0 -0
  68. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/resources/SYSTEM.md +0 -0
  69. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/resources/__init__.py +0 -0
  70. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/resources/context_compat.py +0 -0
  71. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/resources/loader.py +0 -0
  72. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/resources/prompts/review-code-repository.md +0 -0
  73. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/resources/selection.py +0 -0
  74. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/__init__.py +0 -0
  75. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/deployment_health.py +0 -0
  76. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/events.py +0 -0
  77. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/extensions.py +0 -0
  78. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/failures.py +0 -0
  79. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/live_turns.py +0 -0
  80. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/observability.py +0 -0
  81. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/provenance.py +0 -0
  82. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/requester.py +0 -0
  83. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/session.py +0 -0
  84. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/snapshots.py +0 -0
  85. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/runtime/task_context.py +0 -0
  86. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/sessions/__init__.py +0 -0
  87. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/sessions/storage.py +0 -0
  88. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/settings.py +0 -0
  89. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/skills.py +0 -0
  90. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/tools/__init__.py +0 -0
  91. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/tools/mainsequence_mcp.py +0 -0
  92. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/tools/mcp_applications.py +0 -0
  93. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/tools/mcp_connection.py +0 -0
  94. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/tools/skill_read.py +0 -0
  95. {ms_tau_sdk-2.0.30.dev93 → ms_tau_sdk-2.0.31.dev94}/src/ms_tau_sdk/tools/task_control.py +0 -0
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.31 — 2026-11-10
4
+
5
+ - **A local session changes model without hydrating the model it leaves.** Selecting a model for a
6
+ session that is not loaded (`PUT /api/chat/session-model`) used to load it on its previous
7
+ selection first, which for a new session is `TAU_LOCAL_PROVIDER`'s, and hydrate that. A custom
8
+ hydrate endpoint that had recorded the session on the new model refused it, so the change
9
+ failed. Now an unloaded session is created or switched on the requested selection and loaded
10
+ once, so only that selection is hydrated, with or without a custom endpoint. A refused
11
+ selection restores the previous one without hydrating it, deletes a session created for the
12
+ change, and answers the refusal. A loaded session still switches only while idle.
13
+
3
14
  ## 2.0.30 — 2026-11-10
4
15
 
5
16
  - **Provider credentials can come from an application's own hydrate endpoint.** An application
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: ms-tau-sdk
3
- Version: 2.0.30.dev93
3
+ Version: 2.0.31.dev94
4
4
  Summary: Workspace-bound Tau application primitives for Main Sequence projects
5
5
  Project-URL: Changelog, https://github.com/mainsequence-sdk/ms-tau-sdk/blob/development/CHANGELOG.md
6
6
  Project-URL: Documentation, https://github.com/mainsequence-sdk/ms-tau-sdk/tree/development/docs
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "ms-tau-sdk"
7
- version = "2.0.30.dev93"
7
+ version = "2.0.31.dev94"
8
8
  description = "Workspace-bound Tau application primitives for Main Sequence projects"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13"
@@ -579,6 +579,31 @@ class MainSequenceClient:
579
579
  raise BackendError("Backend did not select the requested configured provider")
580
580
  return session
581
581
 
582
+ async def select_session_model(
583
+ self,
584
+ session_uid: str,
585
+ *,
586
+ provider: str,
587
+ model: str,
588
+ thinking_level: str | None,
589
+ holder_id: str,
590
+ custom_id: str | None = None,
591
+ ) -> AgentSession | None:
592
+ """Record the selection of a session that is not loaded, without hydrating it."""
593
+
594
+ del session_uid, provider, model, thinking_level, holder_id, custom_id
595
+ raise LocalModeUnsupportedError("Model selection requires TAU local mode")
596
+
597
+ async def restore_session_model(
598
+ self,
599
+ session_uid: str,
600
+ previous: AgentSession | None,
601
+ ) -> None:
602
+ """Undo ``select_session_model`` without hydrating."""
603
+
604
+ del session_uid, previous
605
+ raise LocalModeUnsupportedError("Model selection requires TAU local mode")
606
+
582
607
  async def get_agent_card(self, session_uid: str) -> AgentCardEnvelope:
583
608
  data = await self._request(
584
609
  "GET",
@@ -760,6 +760,135 @@ class LocalDevelopmentBackend(MainSequenceClient):
760
760
  await self._run(operation)
761
761
  return await self.get_session(session_uid)
762
762
 
763
+ async def select_session_model(
764
+ self,
765
+ session_uid: str,
766
+ *,
767
+ provider: str,
768
+ model: str,
769
+ thinking_level: str | None,
770
+ holder_id: str,
771
+ custom_id: str | None = None,
772
+ ) -> AgentSession | None:
773
+ """Record the selection of a session this process has not loaded, without hydrating it.
774
+
775
+ The session's next load then hydrates only this selection, so neither its previous
776
+ selection nor the configured one is ever hydrated for the change. A session that does not
777
+ exist is created on the selection. An existing one keeps its credential binding when the
778
+ provider stays the same and no configured credential is named, as
779
+ ``update_session_config`` does; otherwise it is bound again by its next load. Returns the
780
+ session as it was, or None when it did not exist, for ``restore_session_model``.
781
+ """
782
+
783
+ if not provider or not model:
784
+ raise BackendConflictError("A provider and model are required")
785
+ selection = (provider, model, thinking_level)
786
+
787
+ def operation() -> AgentSession | None:
788
+ now = _utcnow()
789
+ with closing(self._connect()) as connection, connection:
790
+ connection.execute("BEGIN IMMEDIATE")
791
+ row = connection.execute(
792
+ "SELECT * FROM sessions WHERE uid = ?", (session_uid,)
793
+ ).fetchone()
794
+ if row is None:
795
+ # As if created on the configured selection and then switched.
796
+ retained = custom_id is None and provider == self.settings.local_provider
797
+ connection.execute(
798
+ """
799
+ INSERT INTO sessions(
800
+ uid, provider, model, thinking, runtime_config_sha256,
801
+ custom_id, created_at, updated_at
802
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
803
+ """,
804
+ (
805
+ session_uid,
806
+ *selection,
807
+ self._runtime_config_sha256(selection),
808
+ self.settings.local_custom_id if retained else custom_id,
809
+ _iso(now),
810
+ _iso(now),
811
+ ),
812
+ )
813
+ return None
814
+ if row["runtime_activity"] == "working":
815
+ raise BackendConflictError("Cannot change a model while the session is working")
816
+ lease = connection.execute(
817
+ "SELECT * FROM leases WHERE session_uid = ?", (session_uid,)
818
+ ).fetchone()
819
+ foreign_lease = (
820
+ lease is not None
821
+ and _from_iso(str(lease["expires_at"])) > now
822
+ and str(lease["holder_id"]) != holder_id
823
+ )
824
+ if row["active_task_attempt_uid"] and (lease is None or foreign_lease):
825
+ raise BackendConflictError(
826
+ "Local Task turn recovery is pending before lease replacement"
827
+ )
828
+ if foreign_lease:
829
+ raise BackendConflictError("Local session is owned by another running process")
830
+ previous = self._session_from_row(row)
831
+ retained = custom_id is None and previous.active_provider == provider
832
+ connection.execute(
833
+ "UPDATE sessions SET provider = ?, model = ?, thinking = ?, "
834
+ "runtime_config_sha256 = ?, updated_at = ?, custom_id = ?, "
835
+ "model_provider_credential_uid = ? WHERE uid = ?",
836
+ (
837
+ *selection,
838
+ self._runtime_config_sha256(selection),
839
+ _iso(now),
840
+ previous.custom_id if retained else custom_id,
841
+ previous.model_provider_credential_uid if retained else None,
842
+ session_uid,
843
+ ),
844
+ )
845
+ return previous
846
+
847
+ return await self._run(operation)
848
+
849
+ async def restore_session_model(
850
+ self,
851
+ session_uid: str,
852
+ previous: AgentSession | None,
853
+ ) -> None:
854
+ """Undo ``select_session_model`` after the load of the new selection failed.
855
+
856
+ Nothing is hydrated. A session the selection created is removed again while it holds no
857
+ entries; an existing one gets back its selection and credential binding.
858
+ """
859
+
860
+ def operation() -> None:
861
+ with closing(self._connect()) as connection, connection:
862
+ connection.execute("BEGIN IMMEDIATE")
863
+ if previous is None:
864
+ connection.execute(
865
+ "DELETE FROM sessions WHERE uid = ? AND next_sequence = 0",
866
+ (session_uid,),
867
+ )
868
+ return
869
+ selection = (
870
+ previous.active_provider or "",
871
+ previous.active_model or "",
872
+ previous.active_thinking,
873
+ )
874
+ connection.execute(
875
+ "UPDATE sessions SET provider = ?, model = ?, thinking = ?, "
876
+ "runtime_config_sha256 = ?, updated_at = ?, custom_id = ?, "
877
+ "model_provider_credential_uid = ?, "
878
+ "organization_environment_uid = ? WHERE uid = ?",
879
+ (
880
+ *selection,
881
+ self._runtime_config_sha256(selection),
882
+ _iso(_utcnow()),
883
+ previous.custom_id,
884
+ previous.model_provider_credential_uid,
885
+ previous.organization_environment_uid,
886
+ session_uid,
887
+ ),
888
+ )
889
+
890
+ await self._run(operation)
891
+
763
892
  async def get_agent_card(self, session_uid: str) -> AgentCardEnvelope:
764
893
  context_id = self.settings.local_session_uid(session_uid)
765
894
  agent_uid = self.settings.local_agent_uid
@@ -2407,7 +2407,15 @@ class SessionRuntimeManager:
2407
2407
  thinking_level: str | None,
2408
2408
  custom_id: str | None = None,
2409
2409
  ) -> None:
2410
- """Switch an idle session and reload it with backend-authorized evidence."""
2410
+ """Switch an idle session and reload it with backend-authorized evidence.
2411
+
2412
+ A session this process has not loaded is never loaded on its previous selection, or on the
2413
+ configured one when it does not exist yet: its selection is recorded without hydrating,
2414
+ and one load hydrates only the new selection. A custom hydrate endpoint may refuse any
2415
+ other (ADR 0027), and without one the old selection's hydrate is wasted work. When that
2416
+ load fails, the previous selection is put back without hydrating it, and the caller gets
2417
+ the new selection's failure.
2418
+ """
2411
2419
  if not self.settings.local_mode:
2412
2420
  raise BackendConflictError("Board model selection requires local mode")
2413
2421
  async with self._registry_lock:
@@ -2415,7 +2423,14 @@ class SessionRuntimeManager:
2415
2423
  async with load_lock:
2416
2424
  runtime = self._runtimes.get(session_uid)
2417
2425
  if runtime is None:
2418
- runtime = await self._load(session_uid)
2426
+ await self._select_unloaded_session_model(
2427
+ session_uid,
2428
+ provider=provider,
2429
+ model=model,
2430
+ thinking_level=thinking_level,
2431
+ custom_id=custom_id,
2432
+ )
2433
+ return
2419
2434
  async with runtime.lock:
2420
2435
  if runtime.coding_session.is_running or runtime.runtime_activity == "working":
2421
2436
  raise BackendConflictError("Cannot change a model while the session is working")
@@ -2441,17 +2456,9 @@ class SessionRuntimeManager:
2441
2456
  await self._load(session_uid)
2442
2457
  except Exception:
2443
2458
  try:
2444
- await self.backend.update_session_config(
2445
- session_uid,
2446
- provider=previous.active_provider,
2447
- model=previous.active_model,
2448
- thinking_level=previous.active_thinking,
2449
- **(
2450
- {"custom_id": previous.custom_id}
2451
- if previous.custom_id is not None
2452
- else {}
2453
- ),
2454
- )
2459
+ # The previous selection and binding are put back as they were, without a
2460
+ # hydrate of their own; reloading the session it was running hydrates them.
2461
+ await self.backend.restore_session_model(session_uid, previous)
2455
2462
  await self._load(session_uid)
2456
2463
  except Exception:
2457
2464
  logger.exception(
@@ -2467,6 +2474,50 @@ class SessionRuntimeManager:
2467
2474
  thinking_level=thinking_level,
2468
2475
  )
2469
2476
 
2477
+ async def _select_unloaded_session_model(
2478
+ self,
2479
+ session_uid: str,
2480
+ *,
2481
+ provider: str,
2482
+ model: str,
2483
+ thinking_level: str | None,
2484
+ custom_id: str | None,
2485
+ ) -> None:
2486
+ """Change the model of a session that is not loaded, under its load lock.
2487
+
2488
+ Its selection is recorded without hydrating, a new session being created on it, and one
2489
+ load hydrates only that selection. When the load fails the previous selection is put back
2490
+ without hydrating or loading it, since the session was not loaded, and the load's failure
2491
+ is raised.
2492
+ """
2493
+
2494
+ previous = await self.backend.select_session_model(
2495
+ session_uid,
2496
+ provider=provider,
2497
+ model=model,
2498
+ thinking_level=thinking_level,
2499
+ holder_id=self.holder_id,
2500
+ **({"custom_id": custom_id} if custom_id is not None else {}),
2501
+ )
2502
+ try:
2503
+ await self._load(session_uid)
2504
+ except Exception:
2505
+ try:
2506
+ await self.backend.restore_session_model(session_uid, previous)
2507
+ except Exception:
2508
+ logger.exception(
2509
+ "runtime.session.model_change_rollback_failed",
2510
+ session_uid=session_uid,
2511
+ )
2512
+ raise
2513
+ logger.info(
2514
+ "runtime.session.model_changed",
2515
+ session_uid=session_uid,
2516
+ provider=provider,
2517
+ model=model,
2518
+ thinking_level=thinking_level,
2519
+ )
2520
+
2470
2521
  async def _evict_with_context(self, session_uid: str, *, force: bool = False) -> None:
2471
2522
  runtime = self._runtimes.get(session_uid)
2472
2523
  if runtime is None or (runtime.evicting and not force):