Skip to content

fix(cli, workspace): Store a conversation only when a turn starts - #1178

Open
JeanMertz wants to merge 3 commits into
mainfrom
empty-prompt
Open

JeanMertz wants to merge 3 commits into
mainfrom
empty-prompt

Conversation

@JeanMertz

Copy link
Copy Markdown
Collaborator

Quitting the editor without typing anything leaves no trace. jp q -n
prints "Query is empty, ignoring." and the conversation it was about to
start is gone: nothing on disk, and the session still points at
whatever it pointed at before. Abandoning a query on an existing
conversation the same way leaves its metadata and events.json
untouched.

Every flag that shapes the conversation waits for the request now.
--tmp stamped the expiry and flushed it while the conversation was
being created, --fork wrote the whole fork before the prompt was
composed, --compact wrote its compaction events, and --title wrote
the title, all before anyone knew whether there would be a turn. The
same holds for a run that fails on the way to the turn, such as a
missing API key or an editor that will not spawn.

ConversationMut::discard_on_drop inverts guard-scoped persistence for
a single scope: flush becomes the only thing that writes, and every
other way out leaves storage alone. jp query stages its whole
pre-turn phase in one such scope and flushes it once the request is
known to be non-empty. fork_conversation hands its scope back
unflushed, so the flush in jp c fork is what creates a fork, and a
multi-source run that fails part-way no longer leaves an unreported
conversation behind.

`jp query --fork` has never run: it panicked while clap parsed its own
arguments, before the command did any work, with or without a turn
count. Forking from a query works now: `jp q "..." --fork` forks the
active conversation and starts a turn on the fork, and `jp q --fork=2
"..."` gives the fork only the source's last two turns. A bare `--fork`
takes the next word as its count, so the prompt goes first, or the
count is attached with `=`.

The flag paired `default_missing_value = ""` with a `value_parser`
returning `Option<usize>`, so clap registered the value under one type
and the derived reader asked for another. Without the default, clap's
own `Option<Option<T>>` handling reports a bare `--fork` as
`Some(None)`, the same "keep every turn" the empty string stood for,
and the parser is left handling only the counts a user actually writes.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
Quitting the editor without typing anything leaves no trace. `jp q -n`
prints "Query is empty, ignoring." and the conversation it was about to
start is gone: nothing on disk, and the session still points at
whatever it pointed at before. Abandoning a query on an existing
conversation the same way leaves its metadata and `events.json`
untouched.

Every flag that shapes the conversation waits for the request now.
`--tmp` stamped the expiry and flushed it while the conversation was
being created, `--fork` wrote the whole fork before the prompt was
composed, `--compact` wrote its compaction events, and `--title` wrote
the title, all before anyone knew whether there would be a turn. The
same holds for a run that fails on the way to the turn, such as a
missing API key or an editor that will not spawn.

`ConversationMut::discard_on_drop` inverts guard-scoped persistence for
a single scope: `flush` becomes the only thing that writes, and every
other way out leaves storage alone. `jp query` stages its whole
pre-turn phase in one such scope and flushes it once the request is
known to be non-empty. `fork_conversation` hands its scope back
unflushed, so the flush in `jp c fork` is what creates a fork, and a
multi-source run that fails part-way no longer leaves an unreported
conversation behind.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
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