Keep the chat session when /ctx fails to recreate it#55
Open
superbling wants to merge 1 commit intoantirez:mainfrom
Open
Keep the chat session when /ctx fails to recreate it#55superbling wants to merge 1 commit intoantirez:mainfrom
superbling wants to merge 1 commit intoantirez:mainfrom
Conversation
repl_chat_set_ctx() freed the existing session before trying to create the replacement. If creation failed (e.g. allocation error for a larger context size), the old session was already gone and run_repl broke out of the loop, ending the chat. Drop the redundant pre-free; repl_chat_create_session() already keeps the old session intact on failure. With the session preserved, the /ctx handler now prints a warning and lets the user try a smaller value instead of exiting the REPL. Note this is a behavioral change: previously /ctx with a valid number that failed to allocate would terminate the REPL; now it prints a warning and keeps the current context. The parse-error path (e.g. /ctx abc) is independent and not addressed here; it still calls parse_int() which exits via exit(2).
2 tasks
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
repl_chat_set_ctx()freed the existing session before trying to create the replacement:If the new session failed to allocate (e.g. asking for a context size the backend can't satisfy), the old session was already gone and
run_replhad no choice but to break out of the loop, ending the chat.This PR drops the redundant pre-free.
repl_chat_create_session()already has the safe ordering — it tries to create first and only frees the old session on success — so removing the pre-free restores that protection. The/ctxhandler is updated to print a warning and keep the current context on failure rather than exiting the REPL.Heads up: behavioral change
This is not pure cleanup — it changes user-visible behavior:
/ctx Nwith a valid number that fails to allocate terminates the REPL.ds4: /ctx N failed; keeping current ctx Mand stays at the prompt.I think keeping the session is the friendlier default (matches every other REPL failure path), but this is a design call and I'm happy to drop the
run_replchange if you'd rather keep the terminate-on-failure semantics. Therepl_chat_set_ctx()cleanup still stands on its own — it's a real bug regardless of how the caller responds.Relation to #54
Independent of #54. Both touch the
/ctxhandler so they will textually conflict on whichever lands second; happy to rebase. The two PRs address different failure modes:/ctx abc(parse error)/ctx Nwhere N is valid but creation fails (resource error)Test plan
make— clean build, no new warnings/ctx 4096then/quitinto./ds4 -c 4096: session recreated successfully, exits cleanly. The failure path is hard to exercise reliably without injecting an allocation failure intods4_session_create(); relying on inspection for that branch.