Skip to content

feat: vf session, compile only when vf edited the draft; sweep round 8 fixes - #62

Open
Bradenream wants to merge 16 commits into
braden/sweep-r7from
braden/sweep-r8
Open

Bradenream wants to merge 16 commits into
braden/sweep-r7from
braden/sweep-r8

Conversation

@Bradenream

Copy link
Copy Markdown
Contributor

Stacked on #61. Adds vf session, a session lifecycle for talking to the agent that compiles only when it has to, and fixes round 7's remaining CLI-owned majors. Each change is its own commit with a test that replays the tester's scenario and fails without it. Each message says what testers saw, the cause and the change (for the session commits: why, the design and the change). Numbers below are round-7 issue numbers.

Sessions

Round 7 compiled the draft before every conversation send, which put ~0.4 s on every turn. This replaces it with an explicit lifecycle. "Session" is Voiceflow's own word: the Chat and Voice agent API docs say creating a session and sending a message are separate actions.

  • vf session start: the launch. Compiles the draft first, sets --var k=v / --variables before the launch, and records the session as the current one for the project and environment.
  • vf session send <message…>: one turn in the current session, or -s <id>. With none going, it starts one and says so. --button <label> presses a button from the last reply.
  • vf session update (session variables), get, end, run-script (--end ends it after the script).
  • end returns the transcript ID, with one transcript search after the end action. So vf evaluation run --session <id> and vf transcript search --session <id> work from the session ID.
  • When vf compiles: when a session starts, and before a turn only when vf itself edited the draft since the last compile. A plain turn never compiles. When the API says a turn ran an older build (an edit vf didn't make), vf compiles after the turn and says so.
    • vf notes its own edits with a hook on every successful write, in ~/.config/vf/sessions.json. A lock file keeps parallel vf commands from losing each other's changes (a coding agent often runs several at once).
  • A session ID is the runtime user ID, since transcripts are filed under it. Generated IDs look like s-7k2p9xq3.
  • At a terminal, vf session start goes on to a chat: You ❯, /end (prints the transcript), /new, Ctrl-D leaves it going with a line to rejoin.
  • vf conversation … still runs, hidden from help, the menu and --usage, and its help points at vf session.
  • The README, docs, help and every Next line that pointed at conversation send now use the session commands.

Round 7's majors

Not in this PR

For the API team

  • end costs a second call to find its transcript: the end action could return transcriptID.
  • Nothing in a turn's answer says whether it compiled; needsRecompile only says it should have.
  • analytics query topics and topic-details (from master) get HTTP 404: the server has no route for them.
  • Still open from earlier rounds: re-running project/test/function/tool create duplicates with exit 0; updates return only {"message": …}.

Testing

  • Per commit: build, gofmt, scripts/vet.sh, go test ./... (including TestEverySuggestedCommandRuns), the TS suite (181) and go.mod unchanged, on all 15 commits. Lint: 0 errors.
  • A scratch merge of master, feat: pin a project and environment to a directory with vf link (COR-14197) #35/feat: summarize a project for coding agents in one call with vf context (COR-14197) #36, docs: name the compile step the quickstart depends on (COR-13656) #30, feat(auth): end login on Voiceflow's own result page (COR-16309) #53 and this branch passes 205/205 TS tests. Three Go meta-tests fail there, on master's new project member / workspace member / workspace invite commands, not on this branch's code: two member deletes don't ask first, three groups keep their generated descriptions, and a suggested --user-id x9 isn't an integer. They need fixes once this stack is rebased on master.
  • Round 8 of the usability sweep ran against that build, live, with 7 testers:
    • Every tester who talked to the agent used vf session; none needed vf conversation.
    • The fix-verifier's eight live checks of sessions all pass: a plain turn doesn't compile (the compile time stayed put through five turns); a turn after a vf edit compiles and follows it, through the agent and through a playbook; end's transcript ID scores with evaluation run --session; a reused -s starts fresh; voice projects; scripts; the old names; parallel commands.
    • Timing: a plain turn's median is 1.49 s (round 7: 1.55 s with a compile each turn; 1.32 s published). The model's reply time (1.17–1.89 s) dwarfs the ~0.4 s saved, so five turns can't show it.
    • Round 7's fixes: 7 Fixed, 3 Partial, none Not fixed or Regressed. 0 blockers, 0 regressions. All six of round 7's CLI-owned majors are closed or now minor.

…s last compile

Why: round 7 made every `conversation send` with the draft compile it
first (3a5542e). It works, but puts a ~0.4 s compile on every message
(draft send 1.55 s median, compile 0.40 s). The owner decided on an
explicit session lifecycle (`vf session start`, `send`, `update`, `get`,
`end`, `run-script`) and compile rule B: compile when a session starts,
and before a turn only when vf itself edited the draft since the last
compile. A conversation isn't pinned to a build: each turn runs the newest
compile (live probe), so an edit reaches an open session once anything
compiles.

Design: internal/sessions keeps one small JSON file beside vf's config,
~/.config/vf/sessions.json, written whole and renamed into place. Per
project and environment it holds the sessions vf started (ID, version,
start time, the last reply's buttons) with the current one, and when vf
last edited and compiled the draft. An edit that names no environment
(a secret, a merge) marks all of the project's. The new package name
keeps internal/session, the home prompt's context, as it is.

The mark is set by one after-success SDK hook, since every request goes
out through the SDK and its operation ID says what the request does. A
successful POST, PUT, PATCH or DELETE marks its project's environment,
but for writes that aren't edits: conversation turns, state and scripts,
publish, test and evaluation runs and records, function and tool
execute/check, knowledge-base query, searches, transcripts, analytics,
workspaces and phone numbers. Any compile, vf's own or `vf environment
compile`, clears it. A dry run's stand-in answer marks nothing. Marking
too much costs one compile; a missed edit is still caught after the turn
by needsRecompile.

Change: internal/sessions (store, IDs s- plus 8 random characters),
sdk/sdkinternal/hooks/editmark.go and one registration line. Tests: the
store, which writes are edits and where project and environment are
read, and real commands against a fake API (edit marks, compile clears,
reads, turns, state, dry runs and refused edits don't).
…ile rule B

Why: talking to an agent took a user ID, the scope, a version and JSON on
every turn, and nothing said which user ID held which conversation or how
to end one and find its transcript (round 7: human-newcomer F2,
agent-migrator F2, human-poweruser F9). Testers reused one user ID across
edits and read replies swayed by the conversation before. And compiling
the draft before every turn put ~0.4 s on each message.

Design: a session is one conversation, and its ID is the runtime's user
ID. start compiles the draft, ends and clears a reused ID's conversation
(end action, then state delete), sets the variables, then launches, the
order the live probe showed works, and records the session as current
for its project and environment. send takes the message as its words,
--action or --button (the last reply's buttons are kept with the
session); with none going it starts one and says so. update and get set
and read the variables; end sends the end action and searches the
transcripts once by session ID, looking again for up to 5 s, and takes
the newest since the session started. Rule B: a turn with the draft
compiles first only when it starts a conversation or vf edited the draft
since its last compile; an edit made elsewhere is caught by
needsRecompile, compiled after, and warned about in one line. conversation
send follows the same rule.

Change: conversation/session*.go hold the group, hooked in with one line
in conversation/root.go; autocompile.go decides by rule B; the Ctrl-C hint
points at vf session get; no_session exits 2. Tests: session_test.go
(rule B across commands, reused ID order, send with no session, buttons,
end's transcript lookup, Next lines run), sessionend_test.go (none yet
then found, giving up, newest since the start), autocompile tests
rewritten for rule B.
…an --end it

Why: a script is the quickest way to put an agent through a conversation
to evaluate, and it lived apart from the session commands: its user ID
went unremembered, so going on from its last turn meant copying the ID,
and evaluating it meant an end action in JSON and a transcript search.

Design: run-script moves into the session group as it was, same flags and
output, and compiles the draft first as start does. -s names the session
beside -u. After the script its session becomes the current one, so
`vf session send` goes on from the last turn. --end ends it after the
script and gives the transcript: the one the script's answer names, or
else the one end's search finds. `vf conversation run-script` is left as
it was.

Change: conversation/sessionscript.go registers run-script under session
and adds -s and --end; runscript.go gets two one-line hooks; end's tail is
shared (endSession, sayEnded) between end and run-script --end. Tests:
sessionscript_test.go.
…nversation running

Why: with both groups listed, a newcomer met two ways to talk to the agent
and picked the one that needs a user ID, a version and JSON on every
turn. The session group does what conversation did.

Design: conversation is hidden from 'vf --help', the home menu and the
--usage listing, and its help, and its send, run-script and state
commands' help, say which session command does the same. Its commands
still run as they did, for the scripts that use them, and the home
prompt still offers a hidden command's flags once it is typed in full.
--usage lists the session group.

Change: retireConversation in conversation/session.go, called from the
existing hook line; prompt/complete.go findChild resolves a hidden
command typed in full. Tests: sessionhide_test.go; the -y count in
--usage and the misspelt-group mistake leave out the hidden group.
…ession

Why: to score a session, you needed its transcript ID: from 'vf session
end', or from a transcript search by a session ID nobody had said was the
user ID (round 7: agent-migrator F2). An evaluation on a conversation
still open said to send an end action in JSON with 'vf conversation
send'. 'vf transcript search --session' failed as an unknown flag.

Design: evaluation run --session (-s) finds the transcript as 'vf session
end' does: the newest with that session ID created since vf started the
session, or the newest of all for a session vf didn't start. -t still
works; both is a usage error. No transcript is not_found (exit 4), with
the search that lists the session's. A dry run doesn't search; its -t
says whose transcript it would be. transcript_not_ended's step is now
'vf session end -s <id> -p <id> -e <alias>', with -v published for a
published transcript, so session end takes -v as session get does.
transcript search takes --session as another name for --session-id.

Change: evaluation/session.go (one hook line in run.go), notended.go's
help and step; transcript/session.go (one hook line in search.go);
session end takes versionMeta; TranscriptWait/TranscriptPoll exported so
tests shorten them; session end's hint uses --session. Tests:
evalsession_test.go, evalnotended_test.go, session_test.go.
…vf session

Why: the README's quickstart, its notes and its command listing, and the
npm README, still talked to the agent with 'vf conversation send', a user
ID, a version and an action in JSON per turn, and said vf compiles the
draft before every turn. Typing "chat", "talk" or "conversation" at the
home prompt found nothing, now that conversation is hidden.

Design: the quickstart starts a session, sends a message and ends it. The
notes give the session's version, the current session, -s and the
--session flags, and compile rule B: a compile when a session starts and
before a turn after vf's own edits; to try an edit cleanly, start a new
session. The listing and docs/vf.md list the session group, with its
pages generated by cmd/gendocs (the other pages are left as they are).
"chat", "talk", "session" and "conversation" find start, send, end and
run-script in the home menu.

Change: README.md, npm/cli/README.md, docs/vf.md, docs/vf_session*.md,
prompt/intents.go. Test: sessionhide_test.go checks the menu for those
words.
Why: trying an agent at a terminal took a command per turn, 'vf session
send -p … -e … "<message>"', retyped around every message.

Design: at a terminal, for a person, 'vf session start', and 'vf session
send' with no message, go on to a 'You ❯' line: each line entered is a
turn, compiled as send's are (rule B), and a line naming a button the
agent just offered presses it. /end ends the session and gives its
transcript; /new ends it and starts a fresh one. Ctrl-D, or Ctrl-C twice
on an empty line, leaves the session going, with one line saying 'vf
session send' goes back to it. A turn's error prints and the chat goes
on; Ctrl-C during a turn leaves. Scripts, agents, --no-interactive and -o
json get the commands' usual output. The line is the home prompt's
editor: prompt.Options gains Text, Footer and Label, so / and ? are typed
as text and the echo reads 'You ❯ …'.

Change: conversation/sessionchat.go; start and send hand to it; send's
turn is talk(), shared with the chat; buttonNamed() shared with --button;
prompt.go's Text/Footer/Label; README and the start/send pages. Tests:
sessionchat_test.go (a fake types the lines), prompt_test.go.
…lared; a failed execute exits 1

What testers saw: agent-migrator:F1: `vf function create --name
lookup_order --code @functions/lookup_order.js` took code that reads
order_id, writes order_status and returns the paths success and error,
with no warning; `function get-schema` then showed `inputs[0]
outputs[0] paths[0]`, and `function execute` printed

  error: "[ERROR]: … Function returned an invalid path 'success' which
  is not one of the expected paths '[]"
  success: false
  exit=0

Cause:
- function create and update sent the code and printed the answer.
  Nothing compared the names the code uses with what the function
  declares, and a new function declares nothing, so the gap showed only
  when it ran.
- runExecuteCmd (function/execute.go) returned output.Result's error,
  which is nil for any 200: `success: false` is a 200 answer, so a run
  that failed exited 0.

Change:
- function/declared.go reads the names the code uses, comments left
  out: args.inputVars.x, inputVars["x"] and `{ x } = args.inputVars`;
  `outputVars: { x }` and outputVars.x = …; `next: { path: "x" }`, both
  sides of a ternary included. Once create's answer has printed, each
  one is undeclared (the function is new); an update that sends code
  reads the function's schema (one GET) and names what it lacks. A
  warning on stderr, a JSON warning in agent mode, names each one with
  the command that declares it: `vf function variable create
  --project-id p1 --environment-alias main --function-id f1 --type input
  --name order_id`, `vf function path create … --name success`. create
  and update take --strict, which makes the same report exit 1 once the
  function is saved, as --strict does for {tokens}. A dry run checks
  nothing.
- function/executeexit.go: once the answer has printed, a run with
  `success: false` exits 1, error type function_run_failed, with a ✗
  line giving the error. An undeclared path is said plainly ("It
  returned the path success, which the function doesn't declare: it
  declares no paths.") with the `vf function path create` that declares
  it. Exit 1, "any other failure", not 6: 6 is a verdict on a test run
  or a check case, and execute expects nothing; the run failed, as a
  program does.
- strict_test.go counts only the {token} --strict, so function's own
  --strict doesn't trip TestStrictIsOfferedWhereATokenCanFailToBind.

Tests: TestFunctionCreateNamesWhatTheCodeUsesUndeclared replays the
tester's create (person, agent mode, --strict, dry run);
TestFunctionUpdateNamesOnlyWhatIsStillUndeclared covers an update
against a partly declared schema; TestAFailedFunctionRunExits1 replays
the tester's execute answer in all three output modes. All three fail
without the hooks. TestTheNamesAFunctionsCodeUsesAreRead covers the
patterns.
…e been applied

What testers saw: agent-ci:F1: `vf test create -p $P -e main -n
"timeout dup" --timeout 70ms` exited 5, and one of the exit-5 creates
existed (`test list` showed it). variable create at 40, 60 and 80 ms:
exit 5, and all three existed. The error said

  "explanation": "Voiceflow didn't answer within --timeout 40ms.",
  "hints": [ "Run it again with a longer timeout, such as '--timeout 2m'", … ]

and the retry of tq_40 failed: 409 "You have a variable defined with the
'tq_40' name".

Cause: explainTransport (output/explain.go) gave every timeout the same
Next, "Run it again with a longer timeout", whatever the method, and
nothing could tell it more: timeoutClient (client/timeout.go) returned
the deadline's error as the transport did, with no sign of whether the
request had been written before the deadline passed. At 20 ms the
deadline passed while connecting (tq_20 didn't exist); from 40 ms it
passed while vf waited for the answer to a request Voiceflow had.

Change:
- client/timeoutsent.go: timeoutClient traces the request
  (httptrace WroteRequest). A deadline that passes after the whole
  request was written, while waiting for the answer or reading it,
  returns an error that still unwraps to the timeout and also says
  SentMethod, the request's method.
- output/timedout.go, hooked into explainTransport's timeout case: when
  the request was sent and the command writes (POST, PUT, PATCH or
  DELETE, but not a read by name such as `transcript search`, nor
  `function check` or an analytics query), the why adds "The request had
  been sent, so it may have been applied all the same." and Next is
  "Check before you run it again: `vf test list --project-id p1
  --environment-alias main`", then "If it wasn't applied, run it again
  with a longer timeout". The check is the group's list after a create,
  the get (or `read-instructions` after `patch-instructions`) after a
  change, given the IDs the write was; one that would need a value the
  write wasn't given is left out, and so is any for publish, execute or
  send, which no read shows, and for the conversation group. A read, and
  a write that timed out before it was sent, keep "Run it again with a
  longer timeout". Exit code stays 5.

Tests: TestATimedOutWriteSaysItMayHaveBeenApplied replays the tester's
`test create … --timeout 70ms` and variable create against a server that
reads the request and answers late, plus an update, a patch and a nested
create, in both modes, and a `test list` that still says to run it
again. TestATimeoutSaysWhetherTheRequestWentOut covers the transport: a
POST that went out, a request still connecting, a deadline mid-answer.
TestEveryTimedOutWriteSuggestsACheckThatRuns times out every command and
holds each check it suggests to cmdcheck (130 lines). All three fail
without the change.
… tool warns

What testers saw: round-7 agent-builder:F1 wrote "Use /lookup_order
when…" and "Hand off to /Returns when…" in `vf agent update
--instructions @instructions.md --strict`, as the editor's docs suggest.
vf printed "Agent updated." and exited 0; both stayed plain text. The
tester learned the right form, `lookup_order` in backticks, from the API
spec: no help in vf says how a mention is written, and --strict's help
said only "Exit 1 when a {token} … binds to nothing".

Cause: the spec's rule ("Backticked `Name` resolves to a tool, playbook,
or workflow reference … braced {name} resolves to a variable") appears in
no flag or command help, and --strict reads only the answer's
unresolvedReferences and unresolvedMentions, which list {tokens} and
backticked names. A /word is neither, so nothing reported it.

Change: cli/mentions.go. The text flags of agent update, agent
patch-prompt, agent patch-instructions, playbook create, playbook update
and playbook patch-instructions, and those commands' help, say a mention
is the name in backticks and a variable the name in braces (in words in
the flag's help, since pflag takes a backticked word there as the
value's name; the command's help shows `lookup_order`). Once the text is
saved, a /word or @word in it that names one of the environment's
playbooks, functions, workflows or API tools, or a built-in tool, is a
warning (plain_text_mentions) naming each and the form to write; with
--strict it is an unresolved_references error that exits 1, as an
unbound {token} is. The lists are read only when the text has such a
word, and stop once every word is matched; a URL's path, an e-mail
address and a dry run are left alone. --strict's help (output/strict.go)
now says how a variable and a mention are written. Hook: one line in
root.go; it runs as PostRunE, so the generated run is untouched.

Tests: TestASlashNameThatNamesAToolIsReported replays the tester's text
in person and agent mode, with and without --strict;
TestAnAtNameAndABuiltInToolAreReported; TestHelpSaysHowToMention. All
three fail without the root.go hook. barehelp_test.go expects the longer
help; TestStrictIsOfferedWhereATokenCanFailToBind matches --strict's help
by prefix.
…nt names a typed flag once

What testers saw: round-7 agent-builder:F2 ran `vf playbook
patch-instructions … --old-string ' Use `issue_refund_label` when asked
for a label.' --new-string '' --strict` to delete a sentence, as the help
promises ("The text to put in its place. May be empty to delete."). vf
said "vf playbook patch-instructions needs --new-string", exit 2, with
the hint "Pass it: 'vf playbook patch-instructions … --new-string \"\"
… --strict --new-string <value>'". `--new-string=`, `agent
patch-instructions` and `function patch-code` failed the same way; the
tester widened --old-string to get round it.

Cause: buildStringField (flagutil/metadata.go) calls
validateRequiredString(m, val), which takes val == "" for a flag never
given, whether or not it was typed. And commandLineWith (cli/
missingflags.go) builds the hint from typedLine(cmd), which keeps every
typed flag, then appends each missing one, so a flag typed empty came
twice.

Change: flagutil/mayempty.go: a required text flag that was typed, and
whose help says it may be empty, sends the empty value (one-line hook in
buildStringField). That is --new-string on agent patch-prompt, agent
patch-instructions, playbook patch-instructions and function patch-code.
Left out, it is still missing; a flag whose help doesn't say so
(`playbook create --name ''`) is still refused. The hint leaves a missing
flag out of the typed line, so it is named once, as `--name <value>`,
and says "--name was given empty, and it needs a value." in place of
"vf didn't ask for it", since vf doesn't ask for a flag that was typed.

Tests: TestATypedEmptyNewStringDeletesTheText replays the tester's line
and both spellings on all four commands, and fails when help says "may
be empty" on a flag it doesn't cover; TestAFlagTypedEmptyIsNotRepeatedInTheHint.
Both fail without the metadata.go and missingflags.go changes.
… read that shows them

What testers saw: round-7 human-newcomer:F1 typed a prompt and
instructions into `agent update`, then ran the suggested Next, "vf agent
get  see it now". It printed some 120 lines of tool, LLM and voice
settings ("… +91 lines") and, of the text, only "promptLineCount: 1".
"A newcomer checking their work sees … no text they typed. They're left
unsure whether the save worked."

Cause: changed() in output/updated.go (from 74a80a7) offers the group's
get after every update, whatever was written. `agent get` answers with
the prompt's and instructions' line counts, not their text; `agent
read-prompt` and `agent read-instructions` show the text.

Change: output/readback.go. After an update that wrote a field a sibling
read-<field> shows, Next is that read, with the scope and ID the update
was given: --prompt gives `vf agent read-prompt`, --instructions `vf
agent read-instructions` and `vf playbook read-instructions --playbook-id
…`, by flag or as a key of --body. The get stays as a further line when
something else was written too, and is the only line otherwise. Hook: one
line in updated.go.

Tests: TestAnUpdateThatWroteTextOffersTheReadThatShowsIt replays the
tester's update and six more (prompt alone, --strict, --body, prompt and
voice, voice alone, playbook instructions, playbook name), each Next line
checked to run with cmdcheck; TestUpdatesAPublishAndASecretEndAsACreateDoes
now expects read-instructions for its --instructions update. Both fail
without the updated.go hook.
…>, is refused, not sent

What testers saw: round-7 human-newcomer:F4 copied `widget
get-snippet`'s "Next: vf environment publish -e main --name <name>" into
the home prompt, and vf answered "✓ Published release <name> to
environment Main (main)". "Newcomers run suggestions exactly as shown.
The release list now has a junk name."

Cause: 928a5e1 put `--name <name>` in the publish lines (snippetcheck.go,
knowledgebase/answer.go, environment/diffcoverage.go), and the
missing-flag hints write `--name <value>`, `--new-string <value>` and the
like. A shell would stop at the < and >, but the home prompt and an agent
running a command's words pass "<name>" on as the value, and nothing in
vf told a placeholder from a value. cmdcheck, which the suggestion tests
hold every line to, takes a <placeholder> as a value of any type, so no
test saw it.

Change: cli/placeholder.go. Once root's own start has run, a flag value
that is a placeholder as vf writes them is refused, exit 2, error type
placeholder_value, before anything is asked or sent: "--name is <name>, a
placeholder … vf doesn't send it as written, so nothing was sent." A
placeholder is the whole value in < and >: words joined by spaces, |, _
or - (<as before>, <webchat|phone-call>), a generic word (<value>,
<name>), or the flag's own name. A tag like <div> or <speak> is still a
value, and an ID or alias (--project-id <id>) is left for the API to
refuse, so a help example's dry run still shows its body. Hook: one line
in root.go.

Tests: TestAPlaceholderFromASuggestionIsRefused replays the tester's line
and four more kinds (person and agent mode, nothing sent), and checks
that tags and ID placeholders pass. TestEverySuggestedCommandRuns now
runs a line of each kind it collects with a placeholder in a free-text
flag (112) and fails on one that runs as written: 42 do without the
root.go hook. TestEveryJSONFlagsHintsHold fills in its examples'
placeholders before its dry runs.
What testers saw: nothing yet; found replaying the new session commands
offline. `vf session start` ends with "Next: vf session send -p … -e main
"<message>"", and running that line as written sent the text "<message>"
to the agent: the fake API logged `text "<message>"`.

Cause: placeholder.go checks flag values only, and send's message is its
positional words, so the guard round 7's #49 fix added never saw it.

Change: a command whose words are a message carries the annotation
vf:args-are-a-message (session send does), and placeholder.go checks its
words as it checks a flag's value: "the message is <message>, a
placeholder", exit 2, nothing sent. A real message in < and > with markup,
or one that isn't a placeholder word, still goes.

Test: TestAPlaceholderFromASuggestionIsRefused gains the session send line,
in person and agent mode; it fails without the annotation.
…the session file

What testers saw: nothing yet; found in review before round 8. sessions.go
said "Two vf processes writing at once can lose one write". A coding agent
often runs several vf commands at once, and every successful edit writes
the file (the edit mark), so a `session start` racing an `agent update`
could lose the new current session: the next `session send` without -s
would then start a fresh session, and the agent would lose the thread.

Cause: change() read the file, changed it and wrote it back with nothing
between two processes. The write was atomic (temp file and rename), so a
reader never saw half a file, but a second process that read before the
first one's rename wrote its own copy over it.

Change: change() holds a lock while it reads and writes:
sessions.json.lock, created with O_EXCL, so it works the same on macOS,
Linux and Windows. A lock older than 10 s is a crashed vf's and is taken
over; a vf that can't get the lock in 2 s goes on without it, since a
lost write costs a compile or a new session and a hang costs more.
TestChangesMadeAtOnceAreAllKept starts 24 sessions at once and fails
without the lock (every session lost); TestAStaleLockIsTakenOver covers a
lock left behind.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical defects can mark unbuilt edits as compiled and select transcripts from the wrong version or a previous conversation.

9 open issues
3 files not reviewed
  • internal/cli/conversation/root.go: Generated file
  • internal/cli/conversation/runscript.go: Generated file
  • internal/cli/conversation/send.go: Generated file
What changed in this PR

This PR replaces compile-on-every-turn behavior from #61 with a session lifecycle that tracks local draft edits and compiles when needed. It also improves CLI validation, failure reporting, and follow-up guidance.

Changes:

  • Adds session commands, interactive chat, persisted session state, and transcript lookup for evaluations.
  • Tracks successful draft writes to avoid unnecessary compilation while preserving legacy conversation commands.
  • Improves function checks, timeout guidance, placeholder rejection, empty-value handling, and documentation.
File Description
README.md Updates quickstart and compile guidance for sessions.
npm/​cli/​README.md Switches package examples to session commands.
internal/​sessions/​sessions.go Stores sessions and edit marks with file locking.
internal/​sessions/​sessions_test.go Tests persistence, edit tracking, and locking.
internal/​sdk/​sdkinternal/​hooks/​registration.go Registers draft-edit tracking.
internal/​sdk/​sdkinternal/​hooks/​editmark.go Records successful writes and compiles.
internal/​sdk/​sdkinternal/​hooks/​editmark_test.go Tests edit classification and scope extraction.
internal/​prompt/​prompt.go Adds labeled plain-text chat input.
internal/​prompt/​prompt_test.go Tests chat input and echo behavior.
internal/​prompt/​intents.go Maps conversation-related searches to sessions.
internal/​prompt/​complete.go Preserves completion for explicitly typed hidden commands.
internal/​output/​updated.go Routes update suggestions to text readback commands.
internal/​output/​updated_test.go Tests prompt and instructions readback suggestions.
internal/​output/​timedout.go Adds safe verification guidance after timed-out writes.
internal/​output/​strict.go Clarifies mention syntax in strict-mode help.
internal/​output/​readback.go Selects readback commands for changed text fields.
internal/​output/​explain.go Integrates sent-write timeout explanations.
internal/​output/​exitcode.go Classifies missing sessions as usage errors.
internal/​flagutil/​metadata.go Accepts explicitly empty supported text values.
internal/​flagutil/​mayempty.go Identifies flags that permit empty values.
internal/​client/​timeoutsent.go Tracks whether timed-out requests were sent.
internal/​client/​timeoutsent_test.go Tests timeout delivery tracking.
internal/​client/​timeout.go Preserves sent-request context through response reads.
internal/​cli/​transcript/​session.go Adds the transcript search --session alias.
internal/​cli/​transcript/​search.go Registers the session alias.
internal/​cli/​timedout_test.go Tests timeout warnings and verification commands.
internal/​cli/​suggested_test.go Checks placeholder rejection in suggested commands.
internal/​cli/​strict_test.go Distinguishes function-specific strict validation.
internal/​cli/​strayargs_test.go Recognizes session message arguments.
internal/​cli/​sessionscript_test.go Tests scripted sessions and transcript output.
internal/​cli/​sessionhide_test.go Tests session discovery and legacy command compatibility.
internal/​cli/​sessionchat_test.go Tests interactive chat lifecycle.
internal/​cli/​root.go Enables mention guidance and placeholder validation.
internal/​cli/​placeholder.go Rejects copied placeholder values.
internal/​cli/​placeholder_test.go Tests placeholder rejection before requests.
internal/​cli/​missingflags.go Explains empty values without duplicating flags.
internal/​cli/​mentions_test.go Tests mention warnings and strict failures.
internal/​cli/​mayempty_test.go Tests intentional empty text and correction hints.
internal/​cli/​jsonhints_test.go Adapts hint tests to placeholder validation.
internal/​cli/​function/​update.go Checks declarations after function updates.
internal/​cli/​function/​executeexit.go Reports failed function execution with exit 1.
internal/​cli/​function/​execute.go Applies execution failure reporting.
internal/​cli/​function/​declared_test.go Tests extraction of function resource references.
internal/​cli/​function/​create.go Checks declarations after function creation.
internal/​cli/​evaluation/​session.go Resolves sessions to transcripts for evaluation.
internal/​cli/​evaluation/​run.go Registers session-based evaluation.
internal/​cli/​evaluation/​notended.go Suggests session commands for ending conversations.
internal/​cli/​evalsession_test.go Tests session-based evaluation and transcript aliases.
internal/​cli/​evalnotended_test.go Updates open-transcript recovery tests.
internal/​cli/​editmark_test.go Tests edit tracking through CLI requests.
internal/​cli/​conversationcancel_test.go Updates cancellation tests for session guidance.
internal/​cli/​conversation/​version.go Revises version help for selective compilation.
internal/​cli/​conversation/​sessionstate.go Adds session variable updates and state reads.
internal/​cli/​conversation/​sessionsend.go Adds message, action, and button sending.
internal/​cli/​conversation/​sessionscript.go Integrates scripts with session persistence and ending.
internal/​cli/​conversation/​sessionend.go Ends sessions and locates transcripts.
internal/​cli/​conversation/​sessionend_test.go Tests transcript polling and selection.
internal/​cli/​conversation/​sessionchat.go Adds interactive session chat.
internal/​cli/​conversation/​send.go Updates the compile-rule comment.
internal/​cli/​conversation/​runscript.go Connects scripts to session lifecycle handling.
internal/​cli/​conversation/​root.go Registers sessions alongside legacy conversations.
internal/​cli/​conversation/​endaction.go Supports session-specific end reasons.
internal/​cli/​conversation/​canceled.go Uses session commands in cancellation guidance.
internal/​cli/​conversation/​autocompile.go Compiles on starts, tracked edits, and stale responses.
internal/​cli/​conversation/​autocompile_test.go Adapts compile tests to launch behavior.
internal/​cli/​confirm_test.go Excludes hidden commands from usage expectations.
internal/​cli/​barehelp_test.go Updates expected mention help.
docs/​vf.md Lists sessions in the command index.
docs/​vf_session.md Documents the session command group.
docs/​vf_session_update.md Documents session variable updates.
docs/​vf_session_start.md Documents session starts and interactive chat.
docs/​vf_session_send.md Documents turns, actions, buttons, and compilation.
docs/​vf_session_run-script.md Documents scripted sessions and optional ending.
docs/​vf_session_get.md Documents session state inspection.
docs/​vf_session_end.md Documents ending sessions and finding transcripts.

Review effort: Balanced

Comment on lines +158 to +161
body := components.StableTranscriptSearchRequestV2{SessionID: &id}
if alias != "" {
body.EnvironmentAlias = &alias
}
}
var newest *components.StableTranscriptSummary
for i, t := range res.StableTranscriptSearchResponseV2.Transcripts {
if t.SessionID != id || (!since.IsZero() && t.CreatedAt.Before(since.Add(-clockSlack))) {
if projectID == "" || env == "" {
return nil
}
return change(func(f *file) { f.scope(projectID, env).CompiledAt = now().UTC() })
Comment on lines +106 to +108
found, err := FindTranscript(client.WithSpinnerMessage(cmd.Context(), "Finding its transcript…"), s, opts, scope.ProjectID, scope.EnvironmentAlias, rec.ID, rec.StartedAt)
if err != nil {
return nil, "", output.Error(cmd, err)
Comment on lines +77 to +78
rec := sessions.Session{ID: id, Version: scope.Version, StartedAt: wait.began}
if err := sessions.Start(scope.ProjectID, scope.EnvironmentAlias, rec); err != nil {
Comment on lines +89 to +90
if !going {
o := startOptions{id: sessions.NewID(), version: "draft"}
Comment on lines +138 to +139
rememberButtons(cmd, scope, rec.ID, t)
return t, compileAfterStaleTurn(cmd, s, rec.Version, t.stale, scope.ProjectID, scope.EnvironmentAlias), nil // autocompile.go: an edit the turn missed
Comment on lines +143 to +144
if client.IsDryRun(cmd) {
return nil
return err
}
return nil
return checkUpdatedCode(cmd, s, req) // declared.go: names what the code uses that the function doesn't declare
@linear-code

linear-code Bot commented Dec 2, 2026

Copy link
Copy Markdown

COR-16419

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.

2 participants