Skip to content

fix(labs/claude-code-style): title sessions with the generator, not the first message - #4819

Merged
jhoffner merged 3 commits into
mainfrom
fix/claude-code-style-session-title
Nov 6, 2026
Merged

jhoffner merged 3 commits into
mainfrom
fix/claude-code-style-session-title

Conversation

@jhoffner

@jhoffner jhoffner commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • The Claude-style lab's sessions list titled every session by the first line of its first message, and never read the title the session stored. Nothing wrote one either: the main worker's flow had no title generator.
  • The lab's agent flow now runs core's `utility.sessionTitleGenerator` as its `afterAnswer` step, which is a sidechain of each turn (`agent-worker-flow.ts` applies it with `.sideChain`).
  • A row shows the stored title when one exists. Until then it falls back to the first message's first line, as before. `New session` is used only when there is no message.

Why the adapter change

The adapter's title cache held the first line forever, so a generated title could never replace it. The cache now holds only the first line it read, and the title rule lives in `src/lib/session-title.ts` as a pure function.

Tests

  • `labs/claude-code-style/test/session-title.test.ts`: the title rule (generated title wins, blank title counts as none, fallback width).
  • `packages/workforce/test/agent-session-title.test.ts`: one turn through `testFlow` (the server's `runAction`, which drains sidechains). A generator result lands on the stored session title. A generator that fails output validation leaves the session untitled, and the turn still completes with its answer.
  • Lab suite: 31 files, 212 tests pass. Lab typecheck passes.
  • Not verified: a live model turn. The generator's output is tested through mocks only.

Known limits

  • A failed title is not recorded anywhere. The lab can only see that a session has no title, so a failed generation shows the first-message fallback indefinitely.
  • The generator runs after every turn, not only the first, so each turn costs one small-model call. The generator's prompt tells the model to keep a good title.

🤖 Generated with Claude Code

jhoffner and others added 3 commits November 5, 2026 17:58
…he first message

The lab's sessions list titled every session by the first line of its
first message, and never read the title the session stored. The main
worker's flow also ran no title generator, so nothing ever wrote one.

- fsdev.config.mts: the `agent` flow runs core's sessionTitleGenerator as
  its afterAnswer step, on the utility model the lab already names.
- adapter.ts: a row reads the stored title first. The first message is a
  fallback only once a turn has ended with no title, and never while a
  turn runs. The first-line cache holds only what it read.
- src/lib/session-title.ts: the title rule as a pure function, with tests
  that pin the rule (generated wins, no raw message mid-turn, blank title
  counts as none, fallback width).

Not verified end to end: no live model run. Generation failures are
inferred from "turn ended, still untitled", since the side chain's
failure is not recorded on the session.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
… title lands

Per review: the first message's first line stays the title whenever no
generated title exists, as the lab showed before. The "only after a turn
ends" gate is dropped. Titling already runs as a sidechain (afterAnswer
is wired with .sideChain), so no flow change is needed.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
…idechain

The lab titles sessions with core's sessionTitleGenerator as the agent
flow's afterAnswer. Nothing tested that path, so a regression would leave
sessions on the first-message fallback without any failing check.

The new test runs one turn through testFlow (the server's runAction, which
drains side chains) and checks two things: a generator result lands on the
stored session title, and a generator that fails validation leaves the
session untitled while the turn still completes with its answer. The
failure case was confirmed from the trace: auto-title and the after-answer
rescue both report failed.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flow-state-dev-docs Ready Ready Preview Nov 5, 2026 11:00pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
flow-state-dev-ui Ignored Ignored Preview Nov 5, 2026 11:00pm UTC
flow-state-dev-build-site Skipped Skipped Nov 5, 2026 11:00pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T23:03:33.560714Z e0b99a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment on lines +67 to +75
it("leaves the session untitled when generation fails, and the turn still completes with its answer", async () => {
const failing = mockGenerator({ name: "auto-title:generate", script: [{ text: "not a title object" }] });

const { result, session, answer } = await runTurn(failing);

expect(result.status).toBe("completed");
expect(answer.calls).toHaveLength(1);
expect(session?.title).toBeUndefined();
});

@gitar-bot gitar-bot Bot Nov 5, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Failure-path test passes even if the title generator never runs

The second test in agent-session-title.test.ts checks that session.title is undefined and that the turn completed. It never checks that the failing generator was actually called. If the afterAnswer sidechain were skipped, dropped, or wired under the wrong generator name, the session would still have no title and the test would still pass. So it doesn't show what its name claims: that a generation failure is contained and the turn still answers. This is the kind of test CLAUDE.md #5 rules out. Fix: assert failing.calls has length 1, as the first test does for titler.

Assert the failing generator ran, so the test checks that a failure is contained rather than that nothing ran:

expect(result.status).toBe("completed");
expect(answer.calls).toHaveLength(1);
expect(failing.calls).toHaveLength(1);
expect(session?.title).toBeUndefined();

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 closed / 1 findings

🟡 Medium risk · Running the title generator after every agent turn adds recurring model cost and could delay turn completion while its sidechain drains.

Titles sessions with the stored generator result, falling back to the first message's first line until one lands. Approved with a suggestion: the failure-path test in packages/workforce/test/agent-session-title.test.ts should also assert that the failing generator was called, so it proves the sidechain ran and the turn still answers.

💡 Quality: Failure-path test passes even if the title generator never runs

📄 packages/workforce/test/agent-session-title.test.ts:67-75

The second test in agent-session-title.test.ts checks that session.title is undefined and that the turn completed. It never checks that the failing generator was actually called. If the afterAnswer sidechain were skipped, dropped, or wired under the wrong generator name, the session would still have no title and the test would still pass. So it doesn't show what its name claims: that a generation failure is contained and the turn still answers. This is the kind of test CLAUDE.md #5 rules out. Fix: assert failing.calls has length 1, as the first test does for titler.

Assert the failing generator ran, so the test checks that a failure is contained rather than that nothing ran
expect(result.status).toBe("completed");
expect(answer.calls).toHaveLength(1);
expect(failing.calls).toHaveLength(1);
expect(session?.title).toBeUndefined();
🤖 Prompt for agents
Code Review: Titles sessions with the stored generator result, falling back to the first message's first line until one lands. Approved with a suggestion: the failure-path test in `packages/workforce/test/agent-session-title.test.ts` should also assert that the failing generator was called, so it proves the sidechain ran and the turn still answers.

1. 💡 Quality: Failure-path test passes even if the title generator never runs
   Files: packages/workforce/test/agent-session-title.test.ts:67-75

   The second test in `agent-session-title.test.ts` checks that `session.title` is undefined and that the turn completed. It never checks that the failing generator was actually called. If the `afterAnswer` sidechain were skipped, dropped, or wired under the wrong generator name, the session would still have no title and the test would still pass. So it doesn't show what its name claims: that a generation failure is contained and the turn still answers. This is the kind of test CLAUDE.md #5 rules out. Fix: assert `failing.calls` has length 1, as the first test does for `titler`.

   Fix (Assert the failing generator ran, so the test checks that a failure is contained rather than that nothing ran):
   expect(result.status).toBe("completed");
   expect(answer.calls).toHaveLength(1);
   expect(failing.calls).toHaveLength(1);
   expect(session?.title).toBeUndefined();

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

jhoffner commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Second look + architecture review

Verdict: the approach is right. It reuses core's utility.sessionTitleGenerator through the existing afterAnswer slot, and moving the title rule into a pure function is the right size. There is no better shape to switch to. The points below are for the implementer to weigh, most important first.

1. A new title may not reach the sessions list (needs checking)

rowOf re-reads a row only on ROW_CHANGES notices (request, board, resource, adapter.ts:261), or on the 3s pollIntervalMs. The title is written by a sidechain after the turn's request settles, and it emits session.metadata.changed. That event isn't in ROW_CHANGES.

  • Nothing here shows a title notice or the 3s poll triggering a re-read. The "live model turn" is also listed as unverified. So a first turn could show the first-line fallback until some later notice.
  • Ask: confirm in fsdev dev that the row flips to the generated title without a reload. If it doesn't, the fix is one line (add the kind the title write emits to ROW_CHANGES), not a new mechanism.
  • If it does flip, add a one-line comment saying which notice carries it. Otherwise the next reader will assume the gap above.

2. Cost: the generator runs on every turn

The PR already notes this. The generator is written to re-title, so it can't simply be stopped after turn 1. But for a lab that wants a title once, afterAnswer could be gated on "session has no title". For example, wrap it in a sequencer with .sideChainIf(ctx => !ctx.session.metadata.title, ...), per BP-036. That removes N-1 model calls per session and also the "model rewrites a good title" risk. Whether re-titling as the conversation drifts is wanted is a product call. Recommend gating unless drift-retitling is a goal, and recording whichever is chosen. At the moment it is only an accident of the prompt.

3. Failure is silent and invisible

A generator that fails validation leaves the session untitled. The test pins this (good), but nothing records it, so the first-line fallback shows forever. Combined with (2), a gated generator would never retry after a failure. That is another reason to prefer "run every turn until a title exists", i.e. gate on no title and not on first turn.

4. Small cleanups (optional)

  • sessionTitle/firstLineOfText are split into two exports plus an adapter-side firstLines cache with its own early undefined. A single firstLineTitle(text) that applies the 60-char cut would remove one caller-side step. At the moment firstLineOfText trims but the slice happens later, and the slice is re-applied on every read.
  • detail.title?.trim() ? undefined : await firstLineOf(...) skips the item read once a title exists. That's a useful saving, and it's worth a short comment saying that is the point, not just a branch.
  • The default "openai/gpt-6-luna" now lives in both fsdev.config.mts (utilityModel) and core's sessionTitleGenerator. It's passed explicitly here, so it's fine. Just don't let a third copy appear.

5. Test placement

packages/workforce/test/agent-session-title.test.ts tests the lab's wiring (afterAnswer: utility.sessionTitleGenerator) and core's generator through workforce's defineAgentWorkerFlow. That is a reasonable home, since it proves the afterAnswer + sidechain-drain contract and not just the lab. Keep the header comment saying so. It would be wrong for the test to be read as covering the lab's fsdev.config.mts itself, which nothing here exercises.

Architecture opportunities

None worth taking in this PR. The adapter's row-building is already one function, and the title rule is now pure and unit-tested. I'd leave ROW_CHANGES and the notice plumbing alone unless (1) shows a real gap.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0b99a90f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

installation,
model,
...answerAgain,
afterAnswer: utility.sessionTitleGenerator({ name: "auto-title", model: utilityModel }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Prevent title-generation errors from failing delegated tasks

When a delegated desk.researcher task returns its result to its filer (the default), a title-model error or invalid structured output now fails an otherwise successful task attempt. afterAnswerStep only rescues failures for resultTo: "conversation"; other failures reach task-request.ts, where ending.backgroundFailures fails the attempt. Repeated title failures can therefore exhaust retries and discard successful research merely because its session could not be titled. Rescue errors around the cosmetic title generator itself so delegated task success does not depend on title generation.

Useful? React with 👍 / 👎.

@jhoffner
jhoffner added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 1d87d9c Nov 6, 2026
23 checks passed
@jhoffner
jhoffner deleted the fix/claude-code-style-session-title branch November 6, 2026 00:16

This branch was successfully deployed

1 active deployment
Preview – flow-state-dev-docs — e0b99a90 Deployed Nov 5, 2026 by vercel[bot]
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