GeezerVison is showing github.com — fix(cli,core,tui): restore the thinking level on session/load and fix two review leftovers by zy1233 · Pull Request #146 · zy1233/zycode
Conversation
zy1233
commented
Nov 22, 2026
•
edited by cursor
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
This PR fixes the agent-side leftovers of the review of #144. It has three items. The commits are numbered 1 to 12 in the order of git log --reverse origin/main..HEAD. Rounds 2 and 3 (commits 5 to 12) answer the review findings N31 to N34, B1, NB1 and NB3.
- Item 1 (the thinking level on
session/load): commits 1, 2, 5, 6, 8 and 10. The owner can drop them together. Commits 2 and 6 write the thinking-level text in CHANGELOG.md beside the bash entry of item 2, so dropping them can need a small manual merge in that file.
- Item 2 (the bash output limit): commits 3, 7, 9, 11 and 12.
- Item 3 (the TUI field): commit 4.
| # |
Item |
Commit |
| 1 |
1 |
aaf90da fix(cli): restore the thinking level saved in a chat on session/load and session/resume. Code and tests (finding N22). |
| 2 |
1 |
f5b9e42 docs(cli,vscode): say that session/load restores the thinking level of the chat. The texts that said "does not restore" are true again (root AGENTS.md, packages/pi-agent-cli/AGENTS.md, vscode/README.md, the vscode/src/core/thinking.ts comment, docs/specs/2026-11-04-vscode-extension-design.md). |
| 3 |
2 |
5e7f099 fix(core): count the output of a bash call after the command ended. The flaky test_bash_output_limit_does_not_apply_to_a_call_that_gets_no_limits is a real race in bash.py, not a weak test. |
| 4 |
3 |
79c9d5e refactor(tui): remove the unused usage_cost_currency field of AgentView. |
| 5 |
1 (N31) |
c0c532e docs(cli): say in agent.example.toml that a saved chat level wins over thinking_level. Also the CliConfig.thinking_level comment. |
| 6 |
1 (N32) |
0b5e39d docs(cli): tell the live thinking level as one Added entry in the changelog. One ### Added entry in [Unreleased] for the thinking_level option, its save in the chat file and its restore (1.0.1 has none of them). It replaces the ### Fixed entry about the thinking level. The bash entry stays in ### Fixed. |
| 7 |
2 (N33) |
10417e6 fix(core): tell the model when a bash command had already ended at the output limit. For the late path only, a second sentence says that the command had already ended, with its exit code. The first sentence and the in-flight kill text are unchanged. |
| 8 |
1 (N34) |
06ee78e test(cli): cover that the restored thinking level is the one on the branch. The leaf is moved back before a later level change. |
| 9 |
2 |
62e9374 test(core): make the late-path bash tests independent of the order of event loop tasks. Fixes the Python 3.11 failure of my first N33 test: the tests now patch asyncio.Event.wait, so the limit watcher never fires. |
| 10 |
1 (B1) |
6ce5d7c docs(cli): say that reasoning = false keeps every chat at the thinking_level line. The exception is in agent.example.toml, the CliConfig comment, vscode/README.md and the design record (section 7c). |
| 11 |
2 (NB1) |
57f5f2c docs(core): word the bash race measurement in the changelog as one run. |
| 12 |
2 (NB3) |
2ef5ebf fix(core): name the signal when a bash command killed by one had already ended at the output limit. In the late path, a negative return code reads "killed by signal N"; 0 and above keep "exit code N". The normal path is unchanged. |
Item 1: restore the level on session/load
PiAcpAgent._restored_thinking_level reads the latest thinking_level_change entry of the chat branch. _bind_session gives it to create_session_harness(thinking_level=...), the same way it gives the saved model. load_session and resume_session both use _bind_session.
- The level is set when the harness is built. Nothing is written to the chat file, so there is no duplicate entry and the order of
session/list does not change.
- The level is used only if the chat has a saved level,
reasoning is not false, and the thinking_level option offers the level. Otherwise the level of agent.toml stays and no error is raised. With reasoning = false the option is not offered, and every chat starts at the thinking_level line. A new chat starts at the level of agent.toml, as before.
Model.reasoning follows the restored level, as it follows a live change (invariant 5). reasoning in agent.toml still wins when it is set.
configOptions of the load response show the restored level as currentValue.
- Agents up to 1.0.1 save no level: the texts say so.
Item 2: the flaky bash test
- Cause: a real race in the tool. The output limit is enforced by a watcher that the output pump sets. When the command ends first (a loaded machine),
exit_task finishes before the watcher runs, no kill happens, and a call that printed more than the limit passes.
- Fix: after the output is drained,
bash.py compares the counted bytes with the limit and fails the call with the same Command stopped: its output passed the limit text. For this path only, the text adds that the command had already ended, with its exit code, or with the signal number if a signal ended it.
Item 3: usage_cost_currency
- The Cost segment of the status line writes dollars only (
$0.37), so a cost in another currency shows nothing by design. The smaller change was to remove the dead field. The behaviour is the same: a non-USD cost clears the USD figure. The tests no longer read the removed field, and the spec says what zypi does with a non-USD cost.
What ran
- Item 1 tests:
packages/pi-agent-cli/tests/test_thinking_level_restore.py, 11 tests: the reviewer scenario, last level wins, saved off beats agent.toml, no saved level, new chat, reasoning = false, a level the option does not offer, no write on load or resume (bytes, mtime and session/list order), resume, a level set after a restore, and the branch rule. Revert check: with the source of main, 7 of the 11 fail. The other 4 guard the "do not apply" cases (no saved level, new chat, reasoning = false, a level the option does not offer) and pass without the fix by design, so each was checked by breaking its own condition in the code (4 mutations, each fails the matching tests). A mutation that writes the entry on load fails the no-write test. The branch test fails when _restored_thinking_level reads the whole file (checked in a scratch worktree).
- Item 2 repro, before the fix: 12 busy processes on 4 cores, 300 runs of the test body. In my run, 145 of 300 failed with
DID NOT RAISE (the reviewer measured 107, 123 and 125 of 300; the share changes from run to run). With the fix: 300 of 300 passed. Without load: 0 of 200 failed, so the race needs load.
- Item 2 tests in
pi_agent_core/tests/test_coding_tools_bash.py (49 tests, all pass): three late-path tests (a command that ended first; seq 1 2000; exit 3; seq 1 2000; kill -9 $$, skipped on Windows because a signal is not an exit code there). They patch asyncio.Event.wait, so the late path is the only one that can see the limit. The first two fail against the tool of main; the third fails when the signal text is removed (it reads "exit code -9").
- Stability of the late-path tests and the original flaky test, 150 runs each on Python 3.11.18, 3.12.3 and 3.13.18: 0 failures, with no load and with 12 busy processes on 4 cores.
.venv/bin/ruff check . and .venv/bin/ruff format --check .: clean.
- Full
.venv/bin/python -m pytest (Linux, Python 3.12) at the head 2ef5ebf: 6401 passed, 38 skipped, 31 deselected. pytest packages/pi-agent-cli/tests pi_agent_core/tests: 4725 passed, 25 skipped, 31 deselected.
- Rust (item 3, run at commit 4; no Rust file changed after it):
cargo check -p pi-pager-bin --tests passes. cargo nextest run -p pi-pager -E 'test(acp_handler) | test(status_line)': 254 passed, 0 failed (with env -u PI_HOME -u NO_COLOR; two colour tests fail on this VM if NO_COLOR=1 is set, which is not related to this change).
- CI runs the whole pytest on Linux (Python 3.11, 3.12, 3.13). The Windows and macOS jobs run only the sandbox, auth-method, setup-command and frozen-provider tests, so the changed bash and thinking-level tests do not run there.
What did not run
- I did not run Python or Rust on Windows or macOS myself.
- The new signal test on macOS (
kill -9 $$ in the macOS bash): no CI job runs it there.
cd vscode && npm run check: vscode/node_modules is not installed on the VM. Under vscode/ only README.md and one code comment changed (src/core/thinking.ts).
python scripts/tui_baseline.py test (the full TUI suite): left to the TUI CI.
Not verified
- A real model and a real provider: the tests use the scripted mock model. The restore was not run in a real VS Code or
zypi session.
- That the CI machines show the bash race: the race was reproduced here with CPU load only.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…and session/resume
A loaded or resumed chat started at thinking_level of agent.toml, although the
harness saves a thinking_level_change entry. The level is now given to the harness
when it is built, as the model is, so nothing is written to the chat file. It is
used only when the chat has a saved level, the model can think (reasoning is not
false) and the thinking_level option offers the level. Model.reasoning follows the
restored level as it follows a live change.
The output limit was checked by a watcher that the pump of the output sets. When
the command ended first (a loaded machine), the exit was seen before the limit,
the watcher never ran, and a call with too much output passed the limit. The
tool now compares the counted output with the limit after the drain as well.
Under 12 busy processes on 4 cores the flaky test failed in 145 of 300 runs
before and 0 of 300 after. A new test slows the pump on purpose and fails
without the fix every time.
The field was set from usage_update and never read. The Cost segment of the status
line shows dollars only, so a cost in another currency shows nothing by design.
The tests now check the dollar figure that the status line reads. The spec says
what zypi does with a non-USD cost.
Review result: no blocking issues (0 blocking, 4 non-blocking)
Reviewed head: 79c9d5ea6403b1daca23a8734f15129e60e9ffae (base main at f611243, same as merge-base; 4 commits, 16 files). The head did not move during the review (checked at the start and at the end). All CI jobs are green on this head, including cargo nextest (Linux x86_64).
Checks run
All runs are on Linux (Python 3.12, .venv), on the head and on origin/main. I used my own scripts, not the numbers of the worker report.
1. Thinking level restore (own script, mock stream, real PiAcpAgent, new agent object for each load):
- Old scenario (set
high, prompt, session/load in a new agent): head reads high; origin/main reads off. session/resume: high on the head, off on main.
- A new chat with
thinking_level = "low" in agent.toml starts at low (head and main).
- A chat with no saved level keeps the
agent.toml level (medium) and Model.reasoning is true.
reasoning = false: no option, level off, Model.reasoning false, the stream gets no reasoning. A saved level turbo and a saved empty level: the agent.toml level (low) stays, no error.
- Branch: a chat with
high, then low. After move_to the entry before low, a new agent loads high (the leaf is persisted; the entry on the other branch is not used). With the leaf at the root: off (no entry on the branch). main gives off in both cases.
- No write: after load, resume and a prompt, the chat file still has only the
high entry. A live change to off after the restore adds exactly one entry (high, off). A new agent then loads off.
- Compaction (a real
harness.compact() on a chat with 8 long messages): level stays high, Model.reasoning stays true, no new entry, a later load gives high, the next prompt sends reasoning=high.
- Saved
off with agent.toml high: restored off, Model.reasoning false (the head gives off; main gave high).
- Invariant 5: after a restored
high the stream gets Model.reasoning=True and reasoning="high"; after a restored off it gets False and None. With reasoning = true in agent.toml and a saved off the level gate stays closed (no params). I called _apply_reasoning_params for the DeepSeek API (no base_url): high and reasoning true gives thinking: enabled with reasoning_effort: high; off, and also high with reasoning false, give thinking: disabled. replay_reasoning uses the same gate (langchain_stream.py:569).
- The new test file: 10 pass on the head. With
agent.py and factory.py of main, 6 fail and 4 pass (the 4 are the "do not apply" guards, by design).
2. VS Code extension interplay: read vscode/src/core/chat-controller.ts (thinkingState, applyThinkingLevel, readConfigOptions), thinking.ts, section 7c of the design; ran ZYCODE_REAL_AGENT=1 npx vitest run test/real-thinking.test.ts against the head agent (3 pass).
3. Docs truth: rg over the whole tree (not docs/reviews/, not node_modules, not target) for "does not restore", "no code reads", "not read it back", "level of agent.toml", "past chat", "loaded chat", thinking_level_change and similar. Read the diff of every changed doc.
4. Bash race: 12 busy python3 -c "while True: pass" processes on 4 cores, 300 calls of seq 1 2000 with a 1000-byte limit per run (the test body of the flaky test, in a loop). bash.py of main: 107 of 300 and 125 of 300 passed the limit (bug). bash.py of the head: 0 of 300 and 0 of 300 (all other errors: 0). Without load: 0 of 200 on both (the race needs load). The new deterministic test passes on the head and fails with bash.py of main (test_coding_tools_bash.py:578). Whole file: 47 passed. I also compared the error path (see "Checked and fine").
5. usage_cost_currency: read the diff; rg usage_cost_currency finds no reader or writer left (code, docs, tests). rg for the other readers of usage_cost_usd: one reader (status_line_policy.rs:253 to status_line.rs:119 to the Cost segment, segments.rs:107, "${usd:.2}"). Local run (warm cache): cargo nextest run -p pi-pager for acp_handler and the two colour tests with NO_COLOR=1: 153 passed, 2 failed (script_background_survives_the_pane_fill, text_the_script_did_not_colour_is_muted_and_never_blinks). With the 4 changed tui files of origin/main (same command): the same 2 tests fail, 0 passed. So the two failures are not from this PR.
6. Whole PR: ruff check . and ruff format --check . clean (335 files formatted). pytest packages/pi-agent-cli/tests pi_agent_core/tests: 4722 passed, 25 skipped. Whole pytest: 6398 passed, 38 skipped, 31 deselected (matches the worker). Gmail count over origin/main..HEAD: 0 for author, committer and message, and 0 in the added lines of the diff. No version bump: no change to any pyproject.toml, package.json, Cargo.toml/Cargo.lock; vscode/CHANGELOG.md is not touched; CHANGELOG.md changes only the ## [Unreleased] block. CI: all jobs SUCCESS (Python 3.11, 3.12, 3.13 pytest, Windows and macOS test jobs, cargo nextest, VSIX), merge state CLEAN.
Not run
Windows and macOS (pytest, the bash race, the restore; the CI jobs named Tests (windows-2022) and Tests (macos-*) ran, but I did not read their logs for the bash test). A real VS Code window and a real zypi session. A real model or provider (the DeepSeek check calls the adapter function, not the API). The bash race with a real VS Code or Auto session.
Findings (all non-blocking)
N31. agent.example.toml does not say that a saved chat level wins. packages/pi-agent-cli/agent.example.toml:27 shows thinking_level = "off" # off | minimal | … with no note. After this PR, a chat that had a live change keeps its saved level on session/load and session/resume, whatever the file says. A user who edits the line and opens an old chat in any ACP client sees the old level (the VS Code README says it; the example file and the agent texts a zypi user reads do not). Fix: add one comment line above or after the key, for example "A chat that you changed with the thinking_level option keeps that level when you open it again; this line is the level of a new chat and of a chat with no saved level."
N32. The CHANGELOG.md line is a "Fixed" entry for a feature that no release has. CHANGELOG.md:10-13. The live thinking_level option (PR #144, after 1.0.1) is not in [Unreleased] at all, and 1.0.1 has no option and saves no level. So "Before, a loaded chat always started at thinking_level of agent.toml" is true only for a build from main, and a release reader sees a fix of something they never had. Fix: put the option and its restore in one ### Added line (the option, the save in the chat file, the restore on session/load and session/resume), or word the entry for the build from main.
N33. The late-path error says "stopped" for a command that has ended. pi_agent_core/coding_tools/bash.py:503-504 uses the message at bash.py:532 for a command that ran to its end (any exit code, side effects done). I measured seq 1 2000; exit 3 with a 1000-byte limit: the text is the same as the in-flight kill ("Command stopped: its output passed the limit of 1000B"), and the exit code is lost. A model that reads "stopped" can run a command again that already did its work. This follows the documented rule ("stops … when its output passes the limit"), so it is not a break. Fix (optional): add the fact for this path only, for example "The command had ended before the limit was seen", and keep the first sentence (tests match on it).
N34. No test for the branch rule. packages/pi-agent-cli/tests/test_thinking_level_restore.py has no case for a chat whose leaf was moved back (the PR text and the code comment say "the branch"). I ran it by hand (see 1) and it works, and move_to persists the leaf. Fix: add one test: set high, prompt, set low, prompt, session.move_to the entry before low, load in a new agent, expect high.
Checked and fine
- Restore code (
packages/pi-agent-cli/pi_agent_cli/agent.py:852-868, factory.py:307-312, agent.py:1015-1028): the last ThinkingLevelChangeEntry of session.get_branch() is used, not the whole file. new_session, load_session, resume_session and the blank-reopen path all go through _bind_session. The level is given to the harness constructor, so no entry is written. Model.reasoning follows the level (level != "off") unless reasoning is set in agent.toml; this is the same rule as the live set_config_option (agent.py:583). headless.py and the benchmark evaluator pass no level and are unchanged.
- The option and the restore have the same gate:
_config_options adds thinking_level when reasoning is not False (agent.py:809), and _restored_thinking_level returns None when reasoning is False.
- Extension interplay (item 2). The extension takes the "edit
agent.toml, restart, reopen the chat" path only when liveThinkingLevel is undefined, that is, when the agent does not advertise thinking_level (chat-controller.ts:277, :337; readConfigOptions sets it from the option). An agent that restores a level always advertises the option for that chat (same condition, see above), so the saved level cannot win over a line that the extension just wrote: for an agent with the option the extension never writes the file. An agent without the option (every released agent up to 1.0.1, and any agent with reasoning = false) restores nothing, so for it the file path is unchanged and the file level is the chat level, as before. So with a real pair this cannot happen: not with agent 1.0.0 or 1.0.1 (bundled in extension 1.4.0 to 1.8.0; no option, no restore), and not with a later agent (live path). One note: a build from main at version 1.0.1 already has the option and the restore (and the extension chooses by the option, not by the version, so it is correct); the texts say "agents up to 1.0.1" for the old behaviour, which is true for the released agents. The only way to see a level that is not the file's is the documented one: a user edits agent.toml by hand and opens a past chat that has a saved level (N31).
- Docs truth (item 3): after this PR no text in the repo says that
session/load does not restore the level, except where "agents up to 1.0.1" is meant (root AGENTS.md, packages/pi-agent-cli/AGENTS.md, vscode/README.md, the comment in vscode/src/core/thinking.ts, design section 7c "A live level" and "What a new chat, a past chat and a restart start with", the not-built bullet that is now removed, D28, D29). Old-agent statements are kept for old agents ("Such an agent does not save a level in the chat"). I found no other copy (web/, other READMEs, docs/specs/, comments, tests). CHANGELOG.md changes only [Unreleased]; vscode/CHANGELOG.md and all version numbers are untouched.
- Bash (item 4): abort and timeout still win.
seq 1 2000; sleep 5 with a 0.05 s timeout and a 1000-byte limit gives "Command timed out after 0.05 seconds"; abort set before the call gives "Command aborted"; abort set while the late path runs gives "Command aborted" with the output. The check needs kill_reason is None and it comes before the abort override (bash.py:503-507). The error text of the late path equals the in-flight text; both go through _format_output and _append_status. The tail differs only as expected: the late path shows the end of everything that was printed (up to the 50 KB/2000-line cut), and the in-flight path shows the end up to the kill. The boundary is the same as the pump: exactly the limit passes (printf '%01000d' 0 with limit 1000), one byte more fails. The only other readers of BashLimits.max_output_bytes are Auto (auto_mode.py:649-653), the Auto design table (docs/specs/2026-11-02-auto-mode-design.md:485), packages/pi-agent-cli/AGENTS.md:114, agent.example.toml:141 and the CHANGELOG.md entry for Auto; all say "stops … when its output passes the limit", which the new rule keeps true for the case that the command ended first. A call with no limits is unchanged (max_output is None). The new test fails without the fix and passes with it.
usage_cost_currency: no other reader. The new sentence in docs/specs/2026-11-13-agent-context-usage.md (section 5, "Clients") is true: the Cost segment writes ${usd:.2} only (segments.rs:107), a non-USD cost sets usage_cost_usd to None (acp_handler/mod.rs:221), and the agent sends no cost (section 4, item 4). The two NO_COLOR=1 colour failures also fail on origin/main.
- Whole PR: ruff clean, 4722 and 6398 tests pass, no version bump, Gmail count 0, CI green on the pinned head, nothing committed or pushed by me.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…e output limit
A command that ended before its output was counted got the text of an in-flight
stop, and its exit code was lost. The first sentence is unchanged; for this path
only, a second sentence says that the command had already ended, with its exit
code. The in-flight kill text is unchanged.
… event loop tasks
The test for the exit-code sentence failed on Python 3.11: the slowed pump let the
in-flight watcher win there, so the late path was not the one under test. The
limit watcher now waits for ever in these two tests, so only the count after the
command ended can see the limit, on every Python version. Both tests fail
against the tool of main and pass on 3.11 and 3.12.
Re-review result (delta): REQUEST CHANGES (2 blocking, 3 non-blocking)
Reviewed head: 62e9374d2f187fd5bac18272aed6d519b1508e3f (git ls-remote origin refs/pull/146/head at the start and at the end: the head did not move).
Delta: 79c9d5ea6403b1daca23a8734f15129e60e9ffae..62e9374d2f187fd5bac18272aed6d519b1508e3f (5 commits, 6 files), plus the PR body.
The code is right. N33 and N34 are done well, and the changelog text matches the code. The two blocking points are text: one sentence in agent.example.toml and config.py that is false in one case, and some statements in the PR body that are false now.
Blocking
B1. The N31 comment is false when reasoning = false (caused by this PR: c0c532e).
packages/pi-agent-cli/agent.example.toml:27-28 says: "A chat that you changed with the thinking_level option keeps that level when you open it again, whatever this line says." packages/pi-agent-cli/pi_agent_cli/config.py:207-208 says that session/load and session/resume "start a chat at the level saved in it".
This is not true when agent.toml has reasoning = false. PiAcpAgent._restored_thinking_level (packages/pi-agent-cli/pi_agent_cli/agent.py:852) returns None first in that case (line 860), so the chat starts at the level of the thinking_level line. The test test_a_saved_level_is_not_used_when_the_model_cannot_think (packages/pi-agent-cli/tests/test_thinking_level_restore.py:113) shows it: chat saved at high, opened with reasoning = false: the option is absent and harness.thinking_level == "off". A user can get this case by setting reasoning = false after saving chats. The other cases that you asked about are fine: an agent up to 1.0.1 has no option, so there is no "changed with the option" chat; a saved level that the option does not offer cannot come from the option (it offers all 7 levels).
Fix: add the exception to both texts. For agent.example.toml: "...keeps that level when you open it again, whatever this line says, unless reasoning = false below: then every chat starts at this level." For config.py: "... start a chat at the level saved in it (_restored_thinking_level), unless reasoning is False." (packages/pi-agent-cli/AGENTS.md:38 and vscode/README.md already say it with the reasoning condition; the same words are enough.)
B2. The PR body has statements that are false after the second round (caused by this PR: the body was not changed enough).
- Intro (body line 4): "The owner can drop item 1 (commits 1, 2, 4 and 8) without touching the others." Commit 4 is
refactor(tui): remove the unused usage_cost_currency field (item 3). The item 1 commits are 1, 2, 5 (N31), 6 (N32, the Added entry; its ### Fixed bash text is item 2) and 8 (N34). Fix: "commits 1, 2, 5, 6 and 8", and say that commit 6 also changes the text of the bash ### Fixed entry (item 2).
- "What ran", item 2 (body line 38): "Two deterministic tests slow the pump on purpose".
62e9374 removed the pump slowing. The two tests now patch asyncio.Event.wait (pi_agent_core/tests/test_coding_tools_bash.py:560). Fix: "Two tests make the limit watcher wait for ever, so only the count after the command ended can see the limit: they fail on the bash.py of main and pass on the head."
- Commit 9 (
62e9374) is in no table row and no sentence. The body says "a second round ... (commits 5 to 8)". Fix: add a row (for example "CI fix") and say "commits 5 to 9".
- "What ran", item 1 (body line 37): "11 tests ... Revert check: without the fix, 6 fail. Four tests guard the 'do not apply' cases". Six and four are ten tests, and the file has 11. The N34 test also fails without the fix: I set the call in
_bind_session to thinking_level = None and got 7 failed, 4 passed. Fix: "7 fail".
Non-blocking
NB1. The bash measurement is not worded as one measurement (caused by this PR; text). CHANGELOG.md:16 ends with "Measured with 12 busy processes on 4 cores: 145 of 300 calls passed the limit before, 0 of 300 after." A reader takes this as a fixed rate. My runs on the same shape (12 busy processes, 4 cores, limit 1000 B, seq 1 2000) gave 107, 123 and 125 of 300 before the fix and 0 of 300 after it. The order of magnitude (about 35 to 50 percent) agrees. Fix: "In one run on one machine, with 12 busy processes on 4 cores, 145 of 300 calls passed the limit before and 0 of 300 after; the share changes from run to run."
NB2. Text of zypi --reasoning-effort is incomplete (old on main). tui/crates/codegen/pi-pager-bin/src/interactive_flags.rs:99 says "The Python agent gets no reasoning level from the client. Set thinking_level in agent.toml." After this change a client can set the level over ACP, and a level in agent.toml is used only for a new chat and for a chat with no saved level. This is the same sentence that N31 added to agent.example.toml. It is a message of a refused flag, so no change is needed in this PR. Optional fix, in a later PR: "...Set thinking_level in agent.toml (a chat that already has a saved level keeps that level)."
NB3. "exit code -9" for a command that a signal ended (caused by this PR; optional). pi_agent_core/coding_tools/bash.py:535-537. For seq 1 2000; kill -9 $$ the late message is "The command had already ended (exit code -9) when its output was counted." It is true (returncode is the negative signal number) but a model can read -9 as an error code. Optional fix: f"exit code {code}" if code >= 0 else f"killed by signal {-code}". No other text reads the message.
Checks run
1. N31 (c0c532e). Read agent.example.toml, config.py, agent.py:_restored_thinking_level, factory.py, the tests. Cases: reasoning = false (B1), an agent without the option (up to 1.0.1: no select, no restore, so "changed with the option" does not occur), a saved level that the option does not offer (not used; the option offers all of max, xhigh, high, medium, low, minimal, off, so only a hand-edited file can hold one). rg for thinking_level and thinking level in all non-test files: the same fact is already in packages/pi-agent-cli/AGENTS.md:38 (with the reasoning condition), vscode/README.md ("Which level a chat has" and "A model that does not think") and docs/specs/2026-11-04-vscode-extension-design.md (D29). The only text that still lacks it is NB2.
2. N32 (0b5e39d). Compared each sentence with the code and with git diff v1.0.1 origin/main. v1.0.1:agent.py has 0 matches for thinking_level and thought_level, and v1.0.1:CHANGELOG.md does not describe the select, so the ### Added entry is right ("agents up to 1.0.1 have none of this"; the harness had set_thinking_level and the thinking_level_change entry in 1.0.1, but the agent never called it). Facts that match agent.py at the head: new_session, load_session, resume_session return config_options (lines 370, 400, 455); category thought_level; levels list and order max, xhigh, high, medium, low, minimal, off (_THINKING_LEVELS, line 176); no select when reasoning is False (line 809); invalid_params for an unknown level and for a level but off with reasoning = false (lines 573-580); Model.reasoning follows the level when reasoning is not set, also after a model change (lines 582-586 and 598-602); the harness writes the entry in set_thinking_level (agent_harness.py:1541); load and resume write nothing (test test_loading_writes_nothing_to_the_chat_file, and I read _bind_session). The ### Fixed thinking entry is gone and the bash entry stays in ### Fixed (right: the race is in the released code). Category and place are right. The measurement sentence: NB1.
3. N33 (10417e6). exit_task.result() at bash.py:536: ended_before_limit is set only when kill_reason is None after the try. That is only possible when exit_task was in done (the other branch sets kill_reason and awaits exit_task), and wait_exit returns proc.returncode and cannot raise, so result() is ready and cannot raise. If the code is cancelled the lines are not reached. A command that a signal ended gives a negative number: run with seq 1 2000; kill -9 $$ and the late-path patch: "(exit code -9)" (NB3). ended_before_limit is read only in the output_limit branch. If abort fires, kill_reason becomes abort after the flag is set: run with an abort signal set during the call, the message is "Command aborted" with no "already ended". If a timeout watcher fired, it was in done only with exit_task, which was already the old behaviour. The in-flight text is unchanged: Command stopped: its output passed the limit of {size} is the first part in both paths; the late path adds . The command had already ended (exit code N) when its output was counted. The test for the in-flight path now also asserts that "already ended" is absent (test_coding_tools_bash.py:522). rg for the message text: only bash.py, the tests and the CHANGELOG read it. No Auto code reads the text; packages/pi-agent-cli/AGENTS.md:114 describes the limits, not the message.
4. N34 (06ee78e). In a scratch worktree (PYTHONPATH set to it, module paths checked): on the head the 11 tests pass. With _restored_thinking_level reading session.get_entries() (the whole file): the new test fails ('low' == 'high'), 10 pass. With only the last entry of get_entries(): 6 fail (the new test and 5 others), 5 pass. It cannot pass by luck: the default level is off, the expected level is high, and the test first checks that the low entry is in the file. With thinking_level = None in _bind_session (no fix): 7 fail, 4 pass (B2).
5. 62e9374 (_make_the_limit_watcher_lose).
rg for Event and .wait( in bash.py: the only asyncio.Event wait is over_output_limit.wait() at line 460. The other waiters are asyncio.wait and asyncio.sleep. _wait_abort uses the signal's own wait_aborted, which the late-path tests do not pass (no signal).
monkeypatch.setattr restores it: after the bash test file, a check asyncio.Event.wait.__qualname__ == "Event.wait" passes (49 passed with my check test).
- No pending task:
PYTHONASYNCIODEBUG=1 python -X dev -m pytest pi_agent_core/tests/test_coding_tools_bash.py -W default: 48 passed, no "Task was destroyed but it is pending", no "never awaited". Two ResourceWarning: unclosed file ... pi-output-*.log appear; they are the same two on origin/main source and tests, so they are old on main and not from the new tests (each late-path test alone gives 0 warnings). The finally block cancels the watchers (never waits on a future, and the cancel ends it).
- Both late-path tests fail against
bash.py of origin/main (DID NOT RAISE RuntimeError; and the message ends with "Command exited with code 3") and pass on the head.
- Stability: each test 150 times in one session (300 runs): 300 passed with no load, 3 times 300 passed with 12 busy processes on 4 cores, plus the whole bash test file 3 times under that load (48 passed each). Python 3.11.18, 3.12.3 and 3.13.18 (made with
uv): the file plus 300 loop runs: 348 passed on 3.11 and on 3.13, also 300 of 300 under load on 3.11 and 3.13.
- The race itself, 300 calls of
seq 1 2000 with a 1000 B limit under that load: main 123 passed the limit, the head 0 (NB1 has my other numbers).
6. Whole PR. ruff check . and ruff format --check .: clean. pytest packages/pi-agent-cli/tests pi_agent_core/tests on the head: 4724 passed, 25 skipped, 31 deselected (equal to the body). No version change (no pyproject, package.json, Cargo.toml or agent-assets file in the diff, no version = line). vscode/CHANGELOG.md is not touched (the diff has vscode/README.md and vscode/src/core/thinking.ts only, from the first round). Gmail count over origin/main..HEAD (author, committer, messages, added lines): 0. 9 commits. CI is green and the merge state is CLEAN (from your check; the head did not move).
Checked and fine
bash.py late path: first sentence unchanged, in-flight text unchanged, exit_task.result() safe, abort wins over the new text.
- Changelog:
### Added entry and the bash ### Fixed entry match the code and v1.0.1.
- N34 test: fails for the whole-file and last-entry readers; default level excludes a pass by luck.
_make_the_limit_watcher_lose: one Event.wait in the tool; restored; no pending task; the two tests fail on main source and pass on 3.11, 3.12, 3.13, also under load.
- Ruff, 4724 tests, no version bump,
vscode/CHANGELOG.md untouched, Gmail 0.
Not run
Windows and macOS (CI runs them), the TUI Rust tests, cd vscode && npm run check (the delta has no vscode/ file), a real model and provider.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…ady ended at the output limit
The late path printed "exit code -9" for a command that a signal ended. A negative
return code now reads "killed by signal N"; 0 and above keep "exit code N". The
normal path is unchanged.
Re-review result (delta 2): approve (0 blocking, 1 non-blocking)
Reviewed head: 2ef5ebfbf3f5fabea3f5819673ee24cbc0e22726 (checked with git ls-remote at the start and at the end: no change). Delta: 62e9374..2ef5ebf (3 commits, 7 files) and the rewritten PR body. B1, B2, NB1 and NB3 of the first delta review are fixed. NB2 is old on main and is not in this PR, as agreed.
Blocking
None.
Non-blocking
NB1. The last bullet of "What ran" says more than CI does (PR body, line "CI runs pytest on Python 3.11, 3.12 and 3.13 (Linux), and on Windows and macOS"; the first body had the same claim, and I did not flag it before).
.github/workflows/ci.yml runs the whole pytest -v on ubuntu-latest only (3 Python versions).
- The Windows and macOS jobs (
agent-binaries.yml, job Tests (windows-2022 | macos-15 | macos-15-intel)) run only four paths: packages/pi-dynamic-workflows/tests, pi_agent_core/tests/test_frozen_providers.py, packages/pi-agent-cli/tests/test_acp_auth_methods.py, packages/pi-agent-cli/tests/test_setup_command.py. The log of Tests (macos-15) shows 549 passed, 13 skipped; the log of Tests (windows-2022) shows 530 passed, 32 skipped. Neither log has a line from test_coding_tools_bash.py or test_thinking_level_restore.py.
- So the changed bash code and the new tests (all three late-path tests, and the new signal test) run in CI on Linux only. No CI job runs them on macOS or Windows. The sentence is true word for word, but a reader will take it to mean that the changed tests also run there. It does not change the verdict: the late path is plain Python, and the new test is skipped on Windows.
- Fix (text only, PR body): replace the bullet with "CI runs the whole pytest on Linux (Python 3.11, 3.12, 3.13). The Windows and macOS jobs run only the sandbox, auth-method, setup-command and frozen-provider tests, so the changed bash and thinking-level tests do not run there." In "What did not run", add "the new signal test on macOS (
kill -9 $$ in the macOS bash)".
Checks run
- B1 (
6ce5d7c), the case reasoning = false with thinking_level = "high". I made a chat with a saved level low, then loaded it with three configs (script run on this head, PiAcpAgent with a scripted model):
reasoning = false, thinking_level = "high": harness level high, Model.reasoning is False, no thinking_level option in the load response. A new chat: level high, Model.reasoning False. So "the option is not offered, a saved level is not used, and every chat starts at this line" is true. Nothing is sent to the provider, because Model.reasoning is False (invariant 5 and the README sentence "asks no provider to think, whatever the level is").
reasoning not set, thinking_level = "high": loaded chat low (saved level, option shows low), new chat high.
reasoning = true, thinking_level = "high": same as the line above.
- B1, the four texts.
agent.example.toml:29-30 (reasoning is in [model] at line 40, below: true), config.py:209, vscode/README.md:72 ("see the next point" is the bullet "A model that does not think": true), design section 7c (2026-11-04-vscode-extension-design.md:343). All four are true. The README edit was needed: the next bullet only said that the menu is off, not what level a chat has. The agent up to 1.0.1: the README and design text for it is unchanged and still true (no saved level, one level in the file).
- B1, other text that says a chat keeps its level. I searched the repository (
rg on "keeps that level", "saved level", "restores the level", "starts at the level", and so on), outside tests and audit folders. Texts with the condition: packages/pi-agent-cli/AGENTS.md:38, root AGENTS.md:40, design line 334, CHANGELOG.md:12. Texts without the condition: vscode/src/core/thinking.ts:9-11 and design D29. Both are about "an agent that advertises the select" or "an agent with the live option", and with reasoning = false the agent does not advertise it, so they are true in their own scope. No change needed.
- NB1 (
57f5f2c). CHANGELOG.md:16 now says "In one run on one machine, with 12 busy processes on 4 cores, 145 of 300 calls passed the limit before and 0 of 300 after; the share changes from run to run." This is one run, the other measured shares are in my first delta review (107, 123, 125 of 300). True.
- NB3 (
2ef5ebf), the code. bash.py:535-541. exit_task is wait_exit(), which returns proc.returncode only after the loop while proc.returncode is None, so the result is always an int. The late path is reached only when no kill reason is set, that is, when exit_task is done. A negative code gives "killed by signal N"; 0 and above give "exit code N" (same text as before). test_bash_output_limit_says_when_the_command_had_already_ended (seq 1 2000; exit 3) still passes.
- NB3, revert check. Scratch worktree at
2ef5ebf, with the signal branch in bash.py replaced by how = f"exit code {ended_code}": test_bash_output_limit_says_when_the_command_had_already_been_killed fails (the text has "exit code -9"), 48 others pass. Against the bash.py of main: the three late-path tests fail (the body says "the first two fail against the tool of main"; the third fails there too, so the body says less than the facts; not wrong).
- NB3, stability. One process per Python, 150 runs of the three late-path tests and the original flaky test (
pytest.main in a loop), on Python 3.12.3 (.venv), 3.11.18 and 3.13.18 (uv venvs): 0 failures in 150 runs each, with no load, and again with 12 busy processes on 4 cores (3 x 150 more runs, 0 failures).
- NB3, platforms. The skip for
win32 is right: a signal is not a negative return code there. macOS: kill is a bash built-in and $$ is the PID of the shell itself, so the shell kills itself with SIGKILL and asyncio reports return code -9, as on Linux. This is by reading only; no macOS job runs this file (NB1).
- PR body, facts. Commit table: 12 rows, order, hashes and subjects equal
git log --reverse --format='%h %s' origin/main..HEAD. git show --stat: commits 2 (f5b9e42) and 6 (0b5e39d) change CHANGELOG.md; commits 7, 11, 12 change it too, but they are item 2. Item lists 1, 2, 5, 6, 8, 10 / 3, 7, 9, 11, 12 / 4: correct. Counts: 11 tests in test_thinking_level_restore.py; 49 tests in the bash file (49 passed here); with agent.py and factory.py of main, 7 of 11 fail (the 4 that pass are the "do not apply" cases); pytest packages/pi-agent-cli/tests pi_agent_core/tests: 4725 passed, 25 skipped, 31 deselected; full pytest: 6401 passed, 38 skipped, 31 deselected. "No Rust file changed after commit 4": git diff --name-only 79c9d5e..HEAD has 0 lines under tui/ or for .rs and Cargo files. Item 1 text on reasoning = false, the Model.reasoning sentence and "agents up to 1.0.1 save no level": true (see check 1).
- Whole PR.
ruff check .: clean. ruff format --check .: 335 files formatted. No version bump (pyproject.toml, vscode/package.json have no diff) and vscode/CHANGELOG.md is not touched. Count of "gmail" over origin/main..HEAD (author, committer, message, added lines): 0.
- CI at the head. 5 workflow runs, all success (CI: Ruff, pytest 3.11, 3.12, 3.13; Agent binaries: Windows and macOS tests and 6 build jobs; TUI CI; TUI E2E; VS Code extension).
Checked and fine
- B2: the body now matches the real commit list, the item lists, the test counts and the 7 of 11 revert result.
- The design edit (section 7c) and the
agent.example.toml comment are consistent with packages/pi-agent-cli/AGENTS.md:38.
- The signal text change does not touch the in-flight kill text or the normal path (
bash.py:545).
- The new test is POSIX-only and needs bash (
needs_bash), as the neighbours do.
Not run
- Python or Rust on Windows or macOS (Linux only here). The new signal test was not run on macOS; no CI job runs it there.
- The measurement "145 of 300 before, 0 of 300 after" is the implementer's own run (the body says so and gives my other numbers); I did not repeat the 300-call run on this head. My earlier shares are in the first delta review.
cargo check and cargo nextest for item 3 (the body says they ran at commit 4; I confirmed only that no Rust file changed after it). cd vscode && npm run check (the body says node_modules is missing; only README.md and one code comment changed under vscode/).
- A real model, a real VS Code or
zypi session.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|