Don't kill the REPL on /ctx with invalid input#54
Open
superbling wants to merge 1 commit intoantirez:mainfrom
Open
Don't kill the REPL on /ctx with invalid input#54superbling wants to merge 1 commit intoantirez:mainfrom
superbling wants to merge 1 commit intoantirez:mainfrom
Conversation
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.
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The
/ctxcommand in the interactive REPL calledparse_int(), which exits the process viaexit(2)on bad input. That is correct for command-line argument parsing at startup, but in the REPL it kills the entireds4process — dropping the KV cache and the conversation — on a typo like/ctx abc.All other failure paths in the REPL already print and continue:
/ctxwith no argument,/readon a missing file, an unknown command. Only invalid/ctxnumeric values exited.This PR adds a
parse_int_repl()twin ofparse_int()that prints the same error and returnsfalseinstead, and switches the/ctxhandler to use it. Behavior on every other path — including a valid/ctx Nthat fails insiderepl_chat_set_ctx()— is unchanged frommain.Test plan
make— clean build, no new warnings./ds4 -c 4096:/ctx abc→ printsds4: invalid value for /ctx: abc, REPL continues (previously: process exit)/ctx 4096→ still works, recreates the session/quit→ exits cleanlyNote
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.