Skip to content

fix(models): preserve session selection across fallback turns - #119325

Merged
vincentkoc merged 82 commits into
openclaw:mainfrom
VACInc:feat/model-here-session-scope
Aug 7, 2026
Merged

vincentkoc merged 82 commits into
openclaw:mainfrom
VACInc:feat/model-here-session-scope

Conversation

@VACInc

@VACInc VACInc commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What problem this solves

Session model selection had split ownership and persistence semantics:

  • bare owner/admin /model could claim a configured-default write even when immutable config skipped it or an async write failed;
  • Telegram's callback picker remained session-only while help and docs described owner/admin default updates;
  • fallback retries could lose the authoritative selected model/auth profile;
  • context-engine completion could receive unprojected host-only parameters and durable completion was not recovered through one canonical lifecycle.

The result was operator-visible scope drift: acknowledgements, docs, fallback behavior, and the actual persisted state could disagree.

Canonical fix

Maintainer decision: retain the combined ContextEngine transcript/commitTurn contract in this PR. The additive SQLite lifecycle and legacy-engine behavior are accepted as the permanent owner boundary, with exact-head fault/recovery, projection, and channel proof below.

  • Keeps -s / --session as the explicit public session-only model scope, including configured aliases and session reset.
  • Reports configured-default persistence truthfully: requested, immutable/unchanged, or failed, without pretending best-effort mutation completed.
  • Keeps Telegram callback-picker selection explicitly session-only in runtime copy, help, docs, and tests.
  • Preserves selected model and auth-profile provenance across fallback turns; automatic auth-failure skips are keyed to the selected profile and model.
  • Moves context-engine turn completion through the canonical attempt/outbox lifecycle. commitTurn now receives the same constrained host-param projection as other guarded methods.
  • Uses an additive, lazily ensured SQLite outbox table in the per-agent database. No schema-version bump and no parallel file store.
  • Removes the connected duplicate finalization/transcript paths instead of layering another fallback.

ClawSweeper findings resolved

  • Actual configured-default write outcome is reflected at the owning boundary.
  • Telegram picker scope is accurate in command help and operator docs.
  • Models FAQ temporary-switch examples use -s.
  • Telegram reset notices derive from the applied runtime change.
  • Automatic auth skip isolation rotates profiles correctly without requiring pool membership changes.
  • commitTurn host parameters are projected and regression-tested.
  • Branch-owned changelog entries were removed per repository workflow.

User impact

  • Owners/admins can choose session-only model changes without changing future sessions.
  • Bare direct model changes retain their configured-default update behavior, but acknowledgements no longer overclaim persistence.
  • Telegram picker actions remain session-only and say so.
  • Model and auth selection survive fallback turns without leaking an automatic failure skip to the wrong profile/model.
  • Context-engine completion is durable across restart and receives only allowed host parameters.

Evidence

  • Exact head: 138ca82774a66cbf63b5f3c70beb588d8946ca80
  • Exact tree: 5be96428aac7d4bbf3f69dc98644879783448c0d
  • Exact-head autoreview: Sol/high, 0 accepted/actionable findings, correctness 0.98.
  • Blacksmith Testbox: tbx_01kzdj9chs92k7qa1bw1scs6v1; pnpm check:changed passed in 1,639s. Run: https://github.com/openclaw/openclaw/actions/runs/31158163614
  • Real Gateway proof: 12/12 scenarios passed, including session scope, default reset, writable/immutable/failed configured-default writes, aliases, partial options, authorization, and shared-default targeting. Sanitized artifact SHA-256: 310c639beab7fb4e6df82f126a5b5957ce4f15001d8f061a74319418c8f21569.
  • Telegram integration proof: 2/2 scenarios passed for configured-default reset and non-default session-only selection. Sanitized artifact SHA-256: 6125c3bf8c59045b912ef8e367c6584d57479fbfd02869a6cb2ba98727336988.
  • Focused tests: model fallback 156/156; harness selection 107/107; context-engine host projection 8/8; Telegram bot 137/137.
  • Hosted CI: exact-head run https://github.com/openclaw/openclaw/actions/runs/31158135166 passed, including required openclaw/ci-gate. One untouched src/skills/lifecycle/upload-store.test.ts timing/state assertion failed in the initial 4,375-test shard; the failed-job retry passed without a source change.

Dependency contract check

Direct sibling Codex source was inspected for the exact CLI/app-server/config/turn-history behavior:

  • ../codex/codex-rs/cli/src/main.rs:500-545,1090-1135
  • ../codex/codex-rs/app-server/README.md:72-88,930-940,1350-1405
  • ../codex/codex-rs/config/src/config_toml.rs:345-395
  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/turn.rs:50-175
  • ../codex/codex-rs/app-server-protocol/src/protocol/common.rs:1595-1635
  • ../codex/codex-rs/app-server-protocol/src/protocol/thread_history.rs:1145-1198
  • ../codex/codex-rs/app-server/src/bespoke_event_handling.rs:130-205,1150-1195,1545-1580

Repair metrics

  • Production: +4,839/-1,535 (net +3,304)
  • Tests: +6,650/-788 (net +5,862)
  • Docs: +112/-36 (net +76)

The positive production delta is justified by the permanent public session-scope contract, canonical fallback/session/context-engine ownership, durable SQLite completion recovery, and channel/runtime sibling behavior. The test delta covers the original failure, owner boundary, lifecycle order, recovery, and sibling paths.

The branch merged current main at 1574723997c; later main is a descendant and GitHub's exact-head merge candidate remains conflict-free.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Aug 4, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 7, 2026, 3:39 AM ET / 07:39 UTC.

ClawSweeper review

What this changes

Adds session-scoped model selection while changing model fallback, auth-profile, transcript, context-engine, and channel-picker behavior.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 6 items remain

Keep open for a maintainer decision: the PR now combines a new public context-engine contract with model/fallback repairs, and its supplied runtime proof predates the current head.

Priority: P1
Reviewed head: 138ca82774a66cbf63b5f3c70beb588d8946ca80
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has meaningful validation work, but its latest broad lifecycle changes need exact-head proof and an owner-approved contract boundary.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The supplied Gateway result is useful earlier-head runtime evidence, but it does not demonstrate the latest head's later context-engine, fallback, transcript, Codex, and Copilot behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied Gateway result is useful earlier-head runtime evidence, but it does not demonstrate the latest head's later context-engine, fallback, transcript, Codex, and Copilot behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Repository policy and Codex gate: The root policy requires direct sibling Codex source inspection before a Codex behavior verdict or proof-sufficiency claim. The applicable sibling checkout is absent and DNS prevented cloning it.
Current-main owner boundary: Current main centralizes context-engine guarded method and host-parameter behavior in the registry, while turn finalization remains in the harness lifecycle; main does not contain this PR's durable-turn symbols.
Plugin compatibility risk: The proposed ContextEngine contract adds transcript semantics and an idempotent commit hook, making external context-engine upgrade behavior a maintainer-visible compatibility decision.
Findings None None.
Security None None.

How this fits together

Chat commands and picker callbacks persist model and profile state for a session; that state then drives provider fallback, agent execution, transcript persistence, and context-engine turn handling.

flowchart LR
A[Chat and picker input] --> B[Model selection]
B --> C[Session and profile state]
C --> D[Provider fallback]
D --> E[Agent runtime]
E --> F[Transcript and context engine]
F --> G[Channel acknowledgement]
Loading

Decision needed

Question Recommendation
Should this PR permanently add the ContextEngine transcript-semantics and idempotent commit-turn contract, including its legacy-engine downgrade behavior, as part of the model-selection repair? Split the public contract: Keep the model-selection repair focused and move the context-engine API and durable-turn work to a separately owner-reviewed change.

Why: This is a compatibility-sensitive public plugin API and lifecycle policy; source review cannot choose its long-term contract without owner intent.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied Gateway result is useful earlier-head runtime evidence, but it does not demonstrate the latest head's later context-engine, fallback, transcript, Codex, and Copilot behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - Merging changes the public ContextEngine plugin contract and its legacy-engine downgrade behavior without a demonstrated upgrade path.
  • Resolve merge risk (P2) - The supplied runtime evidence does not cover the latest head's added fallback, transcript, context-engine, Codex, and Copilot changes.
  • Resolve merge risk (P1) - The required direct Codex dependency inspection is unavailable, so Codex-specific behavior and proof cannot be approved in this review.
  • Complete next step (P2) - A maintainer must decide the public context-engine compatibility contract before any automated repair or merge path is safe.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Context-engine public contract 1 optional lifecycle hook and 1 metadata contract added External context-engine plugins need a defined upgrade and legacy behavior before this API expansion can merge.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-agent-context-engine-turn-outbox-schema.test.ts, database schema: src/state/openclaw-agent-context-engine-turn-outbox-schema.ts, database schema: src/state/openclaw-agent-schema.sql, serialized state: extensions/codex/src/app-server/session-history.test.ts, serialized state: extensions/codex/src/app-server/session-history.ts, serialized state: extensions/copilot/src/attempt-transcript-journal.ts, and 32 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Mantis proof suggestion

A Telegram Desktop recording can directly show the changed picker acknowledgement and active-session scope. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify that a model-picker selection updates only the active session and returns the expected acknowledgement.

Merge-risk options

Maintainer options:

  1. Separate and prove the contract (recommended)
    Split the public context-engine contract or provide owner-approved exact-head upgrade and fault-recovery proof before merge.
  2. Accept the combined lifecycle change
    Maintainers may retain the combined design only after explicitly accepting the external-plugin compatibility and durable-session-state risk.

Technical review

Best possible solution:

Separate the public context-engine contract from the session-model repair, or obtain explicit owner approval plus exact-head fault, retry, legacy-plugin, and channel proof for the combined design.

Do we have a high-confidence way to reproduce the issue?

No: the current head could not be inspected or executed locally, and the supplied runtime proof covers an earlier head rather than the current state-lifecycle changes.

Is this the best way to solve the issue?

No: session-scoped selection may be useful, but the current branch entangles it with a permanent plugin API and durable-turn redesign that needs an explicit compatibility decision.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ea4466e5dce5.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: The PR affects active chat model selection, fallback behavior, and persisted session state.
  • merge-risk: 🚨 compatibility: It extends a public ContextEngine contract and changes model-command semantics.
  • merge-risk: 🚨 session-state: It changes model/profile persistence, transcript admission, turn ordering, and fallback state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied Gateway result is useful earlier-head runtime evidence, but it does not demonstrate the latest head's later context-engine, fallback, transcript, Codex, and Copilot behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. The branch changes user-visible Telegram model-picker selection behavior.

Evidence

What I checked:

  • Repository policy and Codex gate: The root policy requires direct sibling Codex source inspection before a Codex behavior verdict or proof-sufficiency claim. The applicable sibling checkout is absent and DNS prevented cloning it. (AGENTS.md:13, ea4466e5dce5)
  • Current-main owner boundary: Current main centralizes context-engine guarded method and host-parameter behavior in the registry, while turn finalization remains in the harness lifecycle; main does not contain this PR's durable-turn symbols. (src/context-engine/registry.ts:45, ea4466e5dce5)
  • Plugin compatibility risk: The proposed ContextEngine contract adds transcript semantics and an idempotent commit hook, making external context-engine upgrade behavior a maintainer-visible compatibility decision. (src/context-engine/types.ts:179, 138ca82774a6)
  • Proof is not exact-head: The supplied Gateway proof names a4a75e1, while the current PR head is 138ca82 and includes later context-engine, transcript, Codex, and Copilot changes. (138ca82774a6)
  • History ownership: Current-main blame for the registry, lifecycle, schema-compatibility, and harness boundaries points to steipete; shallow history limits deeper provenance. (src/agents/harness/context-engine-lifecycle.ts:234, 48ea08918e)

Likely related people:

  • steipete: Current-main history attributes the central context-engine registry, harness lifecycle, and schema-compatibility boundaries to this contributor. (role: current-main area owner; confidence: medium; commits: 48ea08918e; files: src/context-engine/registry.ts, src/agents/harness/context-engine-lifecycle.ts, src/state/openclaw-agent-db-schema-helpers.ts)
  • vincentkoc: The current PR revisions and maintainer re-review requests span the affected model, fallback, context-engine, and channel paths. (role: recent area contributor; confidence: high; commits: 74972938decf, 138ca82774a6; files: src/model-picker/apply-session-model-selection.ts, src/context-engine/registry.ts, extensions/telegram/src/bot-handlers.callback-model.runtime.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide redacted exact-head fault and recovery evidence for fallback, durable turns, and legacy context engines.
  • Obtain an explicit decision on the public ContextEngine contract.
  • Capture exact-head Telegram picker behavior if that channel change remains in scope.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-05T16:20:52.198Z sha 6520c1b :: needs real behavior proof before merge. :: [P2] Preserve session scope in retry guidance | [P2] Update temporary model examples to use session scope
  • reviewed 2026-08-05T18:33:21.494Z sha 6520c1b :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-05T22:41:39.015Z sha f261e80 :: found issues before merge. :: [P2] Honor session scope on configured slash aliases
  • reviewed 2026-08-05T23:34:30.110Z sha a4a75e1 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-06T00:34:39.060Z sha a4a75e1 :: needs changes before merge. :: [P1] Preserve inline model directives through reply routing
  • reviewed 2026-08-06T23:32:31.752Z sha 134ffb6 :: needs real behavior proof before merge. :: [P1] Preserve legacy user auth pins across session resets
  • reviewed 2026-08-07T04:42:20.362Z sha 6dba8b1 :: needs real behavior proof before merge. :: [P1] Preserve the scheduled undeclared-engine host-parameter transition
  • reviewed 2026-08-07T06:35:05.174Z sha 6483561 :: needs real behavior proof before merge. :: [P2] Project host parameters for commitTurn | [P3] Remove release-owned changelog entries

@VACInc VACInc changed the title feat(models): add session-only /model here selection feat(models): add session-only /model -s selection Aug 4, 2026
@clawsweeper clawsweeper Bot added the mantis: telegram-visible-proof Mantis should capture Telegram visible proof. label Aug 4, 2026
@VACInc
VACInc marked this pull request as ready for review August 4, 2026 21:28
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 4, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 4, 2026
@VACInc
VACInc force-pushed the feat/model-here-session-scope branch from d70cef2 to dace4d0 Compare August 4, 2026 22:28
@VACInc

VACInc commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@VACInc

VACInc commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Head 7818562e057c1e2a5e7bd172212677f9f4ec1a3c requires complete -s/--session tokens. Partial lookalikes remain ordinary inline text, and native commands reject them before mutation.

Focused proof: 170 tests passed; targeted Oxlint and git diff --check passed; autoreview clean (0.99).

@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord channel: telegram Channel integration: telegram commands Command implementations docs Improvements or additions to documentation extensions: baseten Extension: baseten extensions: codex extensions: copilot gateway Gateway runtime mantis: telegram-visible-proof Mantis should capture Telegram visible proof. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants