Skip to content

Persist brain-inline initial prompt (fixes empty chat + Log on automation sessions)#286

Open
ishaan-berri wants to merge 1 commit into
mainfrom
ishaan/brain-inline-persist-initial-prompt
Open

Persist brain-inline initial prompt (fixes empty chat + Log on automation sessions)#286
ishaan-berri wants to merge 1 commit into
mainfrom
ishaan/brain-inline-persist-initial-prompt

Conversation

@ishaan-berri
Copy link
Copy Markdown
Contributor

Automation (and any brain-inline claude-code-brain-inline) sessions showed nothing in the chat OR the Log once the live thread was gone.

Root cause

Automations create sessions via the standard create-session route with initial_prompt. The general path runs the prompt through runInitialPrompt, which persists the turn (appendUserMessage + completeAssistantMessage) and snapshots the thread to Session.history. But the brain-inline fast path fired a bare harnessSendMessage and persisted nothing — so the durable log + Session.history stayed empty, and both the chat (DB fallback) and the Log (reads DB) were blank after the live thread ended.

Fix

Brain-inline now runs its initial prompt through the same runInitialPrompt path as every other harness — so it records the turn and snapshots history. One file. (Also picks up initial_attachments handling for free.)

Testing — ran LAP locally (no k8s), brain-inline pointed at a local harness

Created a brain-inline session with an initial_prompt, confirmed it persisted (durable_rows=2, history=2 — was 0/NULL before), then killed the harness (simulated reap) and reopened the session. Both panels render from the DB:

brain-inline

Left = chat (user → thinking → haiku → DONE); right = Session Log (created → user → thinking → response, 6.6s · 295 tok). Harness was dead — served entirely from Session.history.

tsc + eslint clean.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 22, 2026

Greptile Summary

Brain-inline sessions (used by automations) now run their initial_prompt through the shared runInitialPrompt helper instead of a fire-and-forget harnessSendMessage, so the user turn and assistant reply are persisted to the DB and Session.history is snapshotted — fixing blank chat and Log panels once the live harness thread ends.

  • Replaces the bare harnessSendMessage call (no persistence) with runInitialPrompt (calls appendUserMessage, completeAssistantMessage, and snapshotThreadToHistory), making the brain-inline path consistent with finishBringUp.
  • Widens the trigger condition from body.initial_prompt to also fire when body.initial_attachments is non-empty, matching the condition already used in finishBringUp (line 449).

Confidence Score: 5/5

Safe to merge. The brain-inline path now mirrors the well-tested finishBringUp path, the error-handling contract of runInitialPrompt is already self-contained, and the change touches exactly one code block in one file.

The fix is a targeted one-block substitution that aligns an outlier code path with the pattern used everywhere else in the same file. runInitialPrompt already swallows its own errors (try/catch + best-effort DB write), so the absence of an explicit .catch() at the new call site is safe. The attachment-trigger widening is consistent with the identical condition already present in finishBringUp. No new async state, no new DB columns, no auth changes.

No files require special attention.

Important Files Changed

Filename Overview
src/app/api/v1/managed_agents/agents/[agent_id]/session/route.ts Brain-inline initial prompt now routes through runInitialPrompt instead of a bare harnessSendMessage, fixing missing persistence for automation sessions. Change is minimal and consistent with the existing finishBringUp path.

Reviews (1): Last reviewed commit: "fix(sessions): persist brain-inline init..." | Re-trigger Greptile

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