Recover a session's context from the CLI's own file
A restarted server has been told nothing, so a Claude session that has not taken a turn since reported its context as unknown -- which was true, and useless, since the CLI had written the figure down at the time and it was sitting in the session's file the whole while. It now reads it from there at load, over the session's transport, in the background: the same three input fields the import list already reads, so it is a measurement rather than a guess. Only when nothing else has answered, and only for a provider that keeps such a file. A clear needs no special case even though it makes the last usage in a file stale, because clearing gives the CLI a new session id -- so the lookup lands on a file with no usage yet and answers unknown, which is what it is.
This commit is contained in:
1 parent
bc0a48799c
commit
0d623b7073
3 files changed
+76
No files matched your search
@@ -1299,6 +1299,32 @@ fn launch(
|
||||
written: Mutex::new(0),
|
||||
});
|
||||
|
||||
// Nothing here has measured this session's context: the transcript
|
||||
// predates the figure being recorded, or the last turn happened before
|
||||
// this server was watching. The CLI wrote it down at the time, so ask
|
||||
// its file rather than leaving the row saying "unknown" until somebody
|
||||
// sends a message. In the background, because it is a file read on a
|
||||
// machine that may be at the other end of an ssh connection, and a
|
||||
// server start must not wait on one.
|
||||
if provider.kind == DriverKind::ClaudeCli
|
||||
&& shared.context_tokens.lock().unwrap().is_none()
|
||||
&& let Some(session_id) = claude::read_resume_token(&dir)
|
||||
{
|
||||
let transport = Transport::for_setup(setup);
|
||||
let shared = Arc::clone(&shared);
|
||||
tokio::spawn(async move {
|
||||
if let Some(context) = import::context_of(&transport, &session_id).await {
|
||||
// Only if nothing else has answered in the meantime: a turn
|
||||
// that finished while this was in flight measured the
|
||||
// context after the one this read.
|
||||
let mut held = shared.context_tokens.lock().unwrap();
|
||||
if held.is_none() {
|
||||
*held = Some(context);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// An imported session shares its transcript file with the CLI --
|
||||
// `--resume` appends to the same one rather than forking, measured
|
||||
// rather than assumed -- so work done at a terminal belongs in this
|
||||
|
||||
Reference in new issue
Block a user