Skip to content

Don't kill the REPL on /ctx with invalid input#54

Open
superbling wants to merge 1 commit intoantirez:mainfrom
superbling:fix/parse-int-repl-no-exit
Open

Don't kill the REPL on /ctx with invalid input#54
superbling wants to merge 1 commit intoantirez:mainfrom
superbling:fix/parse-int-repl-no-exit

Conversation

@superbling
Copy link
Copy Markdown

Summary

The /ctx command in the interactive REPL called parse_int(), which exits the process via exit(2) on bad input. That is correct for command-line argument parsing at startup, but in the REPL it kills the entire ds4 process — dropping the KV cache and the conversation — on a typo like /ctx abc.

All other failure paths in the REPL already print and continue: /ctx with no argument, /read on a missing file, an unknown command. Only invalid /ctx numeric values exited.

This PR adds a parse_int_repl() twin of parse_int() that prints the same error and returns false instead, and switches the /ctx handler to use it. Behavior on every other path — including a valid /ctx N that fails inside repl_chat_set_ctx() — is unchanged from main.

Test plan

  • make — clean build, no new warnings
  • Piped commands into ./ds4 -c 4096:
    • /ctx abc → prints ds4: invalid value for /ctx: abc, REPL continues (previously: process exit)
    • /ctx 4096 → still works, recreates the session
    • /quit → exits cleanly

Note

There is a sibling PR — focused on a separate, independent failure mode (the chat losing its session when repl_chat_set_ctx() itself fails) — that I will open right after this one. It is intentionally split because it includes a behavioral change worth its own review.

The REPL handler called parse_int(), which exits via exit(2) on bad
input. That is correct for command-line argument parsing, but in the
REPL it drops the KV cache and the entire conversation on a typo
(e.g. /ctx abc).

Add a parse_int_repl() twin that prints the same error and returns
false, and switch the /ctx handler to use it. All other failure paths
in the REPL (unknown command, /read on a missing file, /ctx without
arguments) already print and continue; only invalid /ctx values exited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant