Skip to content

fix: do not persist new-session model picks into global defaults - #871

Merged
agegr merged 4 commits into
agegr:mainfrom
luwanglin:fix/no-persist-startup-model-defaults
Sep 29, 2026
Merged

agegr merged 4 commits into
agegr:mainfrom
luwanglin:fix/no-persist-startup-model-defaults

Conversation

@luwanglin

@luwanglin luwanglin commented Sep 16, 2026 •

Copy link
Copy Markdown

Summary

  • New Pi Web chats that pick an explicit model were rewriting ~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a one-off selection (e.g. DeepSeek flash) silently became the CLI/global default.
  • Make that helper a no-op (session-scoped only), aligned with the TUI where setModel only persists when options.persist is true. Keep the helper as the hook for a future explicit "Save as default" action.
  • Update AGENTS.md + unit tests accordingly.

Test plan

  • npm test (1027 pass, including startup-preferences / rpc-manager startup assertions)
  • Live check against patched 0.9.1: POST /api/agent/new with an alternate provider/model leaves /api/models defaultModel and settings mtime unchanged

Selecting a model for a single Pi Web chat was rewriting
~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a
one-off DeepSeek/flash pick silently became the CLI/global default.
Align with the TUI: session-scoped selection unless the user explicitly
opts into persist (future "Save as default").
@luwanglin
luwanglin force-pushed the fix/no-persist-startup-model-defaults branch from e9bbb5c to c882aa0 Compare September 16, 2026 04:07
agegr and others added 3 commits September 29, 2026 22:33
With new-session picks now session-scoped, pi-web had no way left to change
the default model or reasoning level. Add the Web counterpart of the TUI's
Ctrl+S: a star on each row of the model selector and the reasoning menu.

- PUT /api/models/default writes defaultProvider/defaultModel or
  defaultThinkingLevel, only for models the selector can offer, and refuses
  with 409 when a trusted project's .pi/settings.json overrides the key.
- The star saves the default and selects it for the current chat.
- Menu rows use SelectorRow, styled like session-list rows: the save star
  floats on hover/focus (always visible on touch), the default gets an
  inline marker.
- Remove the no-op startup-preferences helper and its call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the session-list accent bar on the active row and the inline star
after the default's name. The default row now shows a small static grey
star in the right gutter, the same spot where the save button floats in
on hover or focus, so an idle menu carries a single marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit 6a1246e into agegr:main Sep 29, 2026
2 checks passed
dreadster3 added a commit to dreadster3/pi-web that referenced this pull request Sep 30, 2026
…ence fix + default-CWD folders (#12)

* fix: do not persist new-session model picks into global defaults (agegr#871)

* fix: do not persist new-session model picks into global defaults

Selecting a model for a single Pi Web chat was rewriting
~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a
one-off DeepSeek/flash pick silently became the CLI/global default.
Align with the TUI: session-scoped selection unless the user explicitly
opts into persist (future "Save as default").

* feat: explicit save-as-default for model and reasoning level

With new-session picks now session-scoped, pi-web had no way left to change
the default model or reasoning level. Add the Web counterpart of the TUI's
Ctrl+S: a star on each row of the model selector and the reasoning menu.

- PUT /api/models/default writes defaultProvider/defaultModel or
  defaultThinkingLevel, only for models the selector can offer, and refuses
  with 409 when a trusted project's .pi/settings.json overrides the key.
- The star saves the default and selects it for the current chat.
- Menu rows use SelectorRow, styled like session-list rows: the save star
  floats on hover/focus (always visible on touch), the default gets an
  inline marker.
- Remove the no-op startup-preferences helper and its call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: simpler default marker in model and reasoning menus

Drop the session-list accent bar on the active row and the inline star
after the default's name. The default row now shows a small static grey
star in the right gutter, the same spot where the save button floats in
on hover or focus, so an idle menu carries a single marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

* feat(default-cwd): create dated folders under ~/pi-cwd using the local date (agegr#996)

"Use default directory" now opens ~/pi-cwd/YYYYMMDD instead of scattering
~/pi-cwd-YYYYMMDD folders across home. The date still keeps a first-time user
out of folders that hold their own data and gives a fresh scratch cwd per day.

The stamp is the local calendar date; toISOString() gave the UTC one, so in
UTC+8 the folder was named after yesterday until 08:00.

The default directory is now selected exactly like any other directory.
/api/default-cwd only creates the folder and returns its path; the sidebar
then passes it to commitCustomPath(), so /api/cwd/validate checks it, adds it
to the file allow-list, and resolves its project identity. The only difference
is remember: false, so it does not replace the custom-path picker's last path.

With that, the allow-list no longer scans home for default cwds at all. Older
~/pi-cwd-YYYYMMDD folders with sessions are ordinary session cwds, and
selecting any dated folder again goes through /api/cwd/validate.

Co-authored-by: Claude Opus 5.5 <[email protected]>

* fix(sidebar): keep handleDefaultCwd next to the worktree handlers

The fork's branch quick-switch added `handleUseBranch` right after
`handleDefaultCwd`, so the source slice the project-identity test reads
(handleDefaultCwd → handleCreateWorktree) swallowed a `setSelectedCwd`
call and the assertion failed. Move `handleUseBranch` above
`handleDefaultCwd` instead: `handleCreateWorktree` closes over it, so
moving it below would trip the temporal dead zone.

Functionally neutral — no body change, only declaration order. Follow-up
to upstream 433d09e, which added the test and the commitCustomPath
`remember` param the slice also asserts on.

* chore(demo): mirror the upstream model-default selectors byte-identically

Port the byte-identical mirrors from upstream 6a1246e so the demo copies
stay byte-identical mirrors of the root files as they were before the
merge: ChatInput, ModelSelector, useAgentSession, models-cache and the
three i18n message files, plus the new SelectorRow both selectors import.

* chore(demo): port upstream's feature hunks into the adapted copies

ChatWindow and SessionSidebar are pre-adapted demo copies, so they get the
feature hunks from 6a1246e (defaultModel/savedDefaultThinkingLevel props
into ChatInput) and 433d09e (commitCustomPath's remember param plus the
handleDefaultCwd -> commitCustomPath hand-off) rather than a byte copy.
Their divergence from the root is unchanged, 3 and 39 diff lines.

* chore(demo): stub PUT /api/models/default in the mock

The model and reasoning selectors' star now writes the global default
through PUT /api/models/default (upstream 6a1246e); the demo has no real
models.json, so the mock records the pick in memory and serves it back as
`defaultModel` / `savedDefaultThinkingLevel` from GET /api/models, the
same way the other mutable settings panels work in the demo.

POST /api/default-cwd already exists and needs no change: 433d09e only
made the client select its result through /api/cwd/validate, which the
mock's cwdRoute already answers for SCRATCH_ROOT.

* chore(demo): validate default-model mock like the real route

Fold-in from review: reject empty provider/modelId and validate the
thinking level set, mirroring app/api/models/default/route.ts 400s.

---------

Co-authored-by: luck <[email protected]>
Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…gr#871)

* fix: do not persist new-session model picks into global defaults

Selecting a model for a single Pi Web chat was rewriting
~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a
one-off DeepSeek/flash pick silently became the CLI/global default.
Align with the TUI: session-scoped selection unless the user explicitly
opts into persist (future "Save as default").

* feat: explicit save-as-default for model and reasoning level

With new-session picks now session-scoped, pi-web had no way left to change
the default model or reasoning level. Add the Web counterpart of the TUI's
Ctrl+S: a star on each row of the model selector and the reasoning menu.

- PUT /api/models/default writes defaultProvider/defaultModel or
  defaultThinkingLevel, only for models the selector can offer, and refuses
  with 409 when a trusted project's .pi/settings.json overrides the key.
- The star saves the default and selects it for the current chat.
- Menu rows use SelectorRow, styled like session-list rows: the save star
  floats on hover/focus (always visible on touch), the default gets an
  inline marker.
- Remove the no-op startup-preferences helper and its call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: simpler default marker in model and reasoning menus

Drop the session-list accent bar on the active row and the inline star
after the default's name. The default row now shows a small static grey
star in the right gutter, the same spot where the save button floats in
on hover or focus, so an idle menu carries a single marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 6a1246e)
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
上游已合并的 agegr#884/agegr#871/agegr#996 我们已同步(代码与上游一致),agegr#892 已回退,
四行都不再是取舍信息,删掉;保留的都是上游仍未合并(我们领先)或被我们
拒绝的 PR。顺带修掉 agegr#907 的理由措辞:状态列里出现「已摘取」会让
scripts/prs.sh 把它误判成已摘取。
Kano-u pushed a commit to Kano-u/pi-web that referenced this pull request Oct 2, 2026
…#907 agegr#941 agegr#946 agegr#961 agegr#968 agegr#969 agegr#1007 agegr#1008 agegr#1009 agegr#1010)

上游已把我们提前摘取的 agegr#884 / agegr#871 / agegr#996 / agegr#961 原样合并(agegr#961 逐字节相同),
agegr#967 与 agegr#963 由上游的 agegr#1009 / agegr#1008 接管。

冲突解决:
- demo/ 对齐上游 fe288c0,撤销 agegr#963 对 demo 的两处改动(`@/lib/chat-phase-label`
  在 demo/lib 下不存在,会打断 Pages 构建)。
- AGENTS.md:保留我们的 default-project 条目,open-folder 换成上游的
  open-in-explorer。
- MessageView.tsx / SessionSidebar.tsx / FileExplorer.tsx:以上游为准,
  DismissButton 采用上游的独立文件,保留我们的思考卡片与文件管理改动。
- SessionSidebar 移除引用已删函数的旧 agegr#951 工作区按钮(agegr#951 的其他入口另行收尾)。
lclichen added a commit to lclichen/pi-web that referenced this pull request Oct 9, 2026
- @earendil-works/{pi-agent-core,pi-ai,pi-coding-agent,pi-tui} 1.0.0 → 1.1.0.
  No API breaks for pi-web (coding-agent 1.1.0 additive; Terminal interface
  untouched — pi-web implements no pi-tui Terminal).
- Replace the pre-merge prompt continuations (prepareNextTurnWithContext
  monkey-patch + readonly state assignments) with the pi >= 0.86 supported
  host path: one RpcPromptPolicy shared between the wrapper and a hidden
  before_agent_start extension (exact / forced-empty / web-addendum), with
  chat-only exact prompts composing the addendum at the exactSystemPromptRef.
  Upstream source-shape tests now pass unmodified.
- fork_branch guard narrowed to the bash-specific refusal (matches upstream
  agegr#1023 fork-while-streaming semantics); abortBash call sites made
  mock-tolerant.
- rpc-manager test agegr#22 gated: fork keeps persistExplicitStartupPreferences
  (fork feature; upstream removed theirs in agegr#871).
GreyLi813 pushed a commit to GreyLi813/pi-web that referenced this pull request Oct 13, 2026
The merge left local code that upstream had already replaced, and its
resolution dropped a few imports. tsc --noEmit is clean again.

- rpc-manager.ts: drop the pre-0.86 exact-system-prompt path
  (applyExactSystemPrompt and a prepareNextTurnWithContext patch). Upstream
  sends the exact prompt from an inline `before_agent_start` handler
  (lib/exact-system-prompt.ts) and its shutdown suite asserts the agent
  hook stays undefined. Also drop the startup-preferences write upstream
  removed in agegr#871 for silently rewriting the global model defaults, and
  read the listener count from the Set.
- subagent-runtime.ts: send the profile prompt the same way instead of
  rewriting the transcript; the file is now byte-identical to upstream.
- SessionSidebar.tsx: remove the local row-rendering cluster that upstream
  replaced with SessionTree plus lib/session-tree.ts. No render path
  referenced it.
- route.ts: restore the SUBAGENT_META_TYPE import.
- pi-types.ts: drop unused type imports.
- rpc-manager.test.mjs: keep the local disposition regression test in step
  with the new prompt handler, and guard the exact-prompt behaviour.
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…gr#871)

* fix: do not persist new-session model picks into global defaults

Selecting a model for a single Pi Web chat was rewriting
~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a
one-off DeepSeek/flash pick silently became the CLI/global default.
Align with the TUI: session-scoped selection unless the user explicitly
opts into persist (future "Save as default").

* feat: explicit save-as-default for model and reasoning level

With new-session picks now session-scoped, pi-web had no way left to change
the default model or reasoning level. Add the Web counterpart of the TUI's
Ctrl+S: a star on each row of the model selector and the reasoning menu.

- PUT /api/models/default writes defaultProvider/defaultModel or
  defaultThinkingLevel, only for models the selector can offer, and refuses
  with 409 when a trusted project's .pi/settings.json overrides the key.
- The star saves the default and selects it for the current chat.
- Menu rows use SelectorRow, styled like session-list rows: the save star
  floats on hover/focus (always visible on touch), the default gets an
  inline marker.
- Remove the no-op startup-preferences helper and its call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: simpler default marker in model and reasoning menus

Drop the session-list accent bar on the active row and the inline star
after the default's name. The default row now shows a small static grey
star in the right gutter, the same spot where the save button floats in
on hover or focus, so an idle menu carries a single marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…gr#871)

* fix: do not persist new-session model picks into global defaults

Selecting a model for a single Pi Web chat was rewriting
~/.pi/agent/settings.json via persistExplicitStartupPreferences, so a
one-off DeepSeek/flash pick silently became the CLI/global default.
Align with the TUI: session-scoped selection unless the user explicitly
opts into persist (future "Save as default").

* feat: explicit save-as-default for model and reasoning level

With new-session picks now session-scoped, pi-web had no way left to change
the default model or reasoning level. Add the Web counterpart of the TUI's
Ctrl+S: a star on each row of the model selector and the reasoning menu.

- PUT /api/models/default writes defaultProvider/defaultModel or
  defaultThinkingLevel, only for models the selector can offer, and refuses
  with 409 when a trusted project's .pi/settings.json overrides the key.
- The star saves the default and selects it for the current chat.
- Menu rows use SelectorRow, styled like session-list rows: the save star
  floats on hover/focus (always visible on touch), the default gets an
  inline marker.
- Remove the no-op startup-preferences helper and its call site.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* style: simpler default marker in model and reasoning menus

Drop the session-list accent bar on the active row and the inline star
after the default's name. The default row now shows a small static grey
star in the right gutter, the same spot where the save button floats in
on hover or focus, so an idle menu carries a single marker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: luwanglin <[email protected]>
Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants