Skip to content

fix(bootstrap): inject app_profile on the first turn of a new app session - #71

Merged
cryptolir merged 1 commit into
mainfrom
fix/app-profile-first-turn
Jun 17, 2026
Merged

cryptolir merged 1 commit into
mainfrom
fix/app-profile-first-turn

Conversation

@cryptolir

Copy link
Copy Markdown
Owner

Problem

New users — and anyone refreshing or starting a fresh chat — were greeted with "what's your name?" even though the per-user app_profile (Phase 3, #68) holds their name. The profile injection worked from the second message onward, but never on the first.

Root cause

appendAppProfileBootstrapFile resolves the user via resolveAppUserId, which reads appUserId from the persisted session entry. chat.send writes that id with updateSessionStoreEntry, which no-ops when the entry doesn't exist yet (config/sessions/store.ts: if (!existing) return null). On the first turn of a brand-new session the entry doesn't exist, so the id isn't persisted until the run creates the entry — i.e. only from turn 2 onward. The first message therefore runs with no APP_PROFILE.md injected.

Reproduced on prod life (v2026.06.17.1): turn 1 of a new session → "what's your name?"; turn 2 of the same session → "Yes, Liran, I remember you." The session store confirms it: single-turn app sessions have appUserId=null, multi-turn ones have it set.

Fix

Add appUserIdFromSessionKey() as a fallback. When the persisted entry has no appUserId yet, derive it from the session key — the second-to-last :-segment after :app: (valid for both the namespaced app:havaya:<userId>:<conv> and legacy app:<userId>:<conv> forms, since the conversationId is always the final colon-free segment). Read-only and same-user (the id comes from this very session's key), so it cannot surface another user's profile, and it leaves the shared resolveAppUserId — and thus the workspace jail + save_user_section — untouched.

Also braces the guard-returns in this file to satisfy oxlint curly; it was the only file with project lint errors (pre-existing), so pnpm lint is now green repo-wide.

Testing

  • appUserIdFromSessionKey unit cases (4-part / 3-part / bare / lowercasing / non-app / no-userId / undefined)
  • first-turn fallback integration test (temp users/<id>.md, no persisted entry → injects APP_PROFILE.md)
  • vitest 22/22, pnpm lint 0/0, oxfmt clean

🤖 Generated with Claude Code

…sion

resolveAppUserId reads appUserId from the persisted session entry, but
chat.send only writes it onto an EXISTING entry (updateSessionStoreEntry no-ops
when the entry is missing). On the first turn of a brand-new session the entry
doesn't exist yet, so the id isn't available and the APP_PROFILE.md injection
no-ops — the agent asks the user their name even though we know it. Every new
app conversation (e.g. a page refresh / new chat) starts a fresh session and
hit this; from turn 2 on the entry exists and the profile injects correctly.

Fix: add appUserIdFromSessionKey() as a fallback. When the persisted entry has
no appUserId yet, derive it from the session key itself — the second-to-last
":"-segment after ":app:", valid for both the namespaced 4-part form
(app:havaya:<userId>:<conv>) and the legacy 3-part form (app:<userId>:<conv>),
since the conversationId is always the final colon-free segment. Read-only and
same-user (the id comes from this very session's key) — it cannot surface
another user's profile, and it leaves the shared resolveAppUserId (and thus the
workspace jail + save_user_section) untouched.

Also brace the guard-returns in this file to satisfy oxlint `curly` — it was
the only file with project lint errors (pre-existing from #68's --admin merge),
so this greens `pnpm lint` repo-wide.

Tests: appUserIdFromSessionKey unit cases (4-part / 3-part / bare / lowercasing
/ non-app / no-userId / undefined) + a first-turn fallback integration test
(temp users/<id>.md, no persisted entry). vitest 22/22, lint 0, format clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cryptolir
cryptolir merged commit d4ae215 into main Jun 17, 2026
16 of 24 checks passed
@cryptolir
cryptolir deleted the fix/app-profile-first-turn branch June 17, 2026 16:29
cryptolir added a commit that referenced this pull request Jun 17, 2026
) (#73)

STATUS.md: append the #71 first-turn fix + v2026.06.17.2 roll to the 2026-06-17
entry, with prod verification (fresh-session "Hi" now greets by name).
INFRASTRUCTURE.md: bump the life-ahead drift note to v2026.06.17.2.

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
cryptolir pushed a commit that referenced this pull request Jun 17, 2026
…v 2)

Address the four findings + open-question answers on PR #72:
- [P1] confine each load against the matched entry's own trusted root (baseDir),
  not a hardcoded <home>/skills/, so multi-root (bundled/managed) skills resolve.
- [P1] tool allowlist = the same filtered, prompt-visible snapshot, not raw
  loadWorkspaceSkillEntries (no hidden-skill side channel).
- [P2] gate on a resolved app user via the #71 resolveAppUserId ??
  appUserIdFromSessionKey fallback (turn-1-safe); exclude _no-app-user.
- [P2] drop the sibling files list from v1.
Plus: trim+exact name match, 24KB cap with truncated flag, remove the dead
life-access-scope carve-out and commit that hook to git, normal-session prompt
snapshot regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
cryptolir added a commit that referenced this pull request Jun 18, 2026
…oad_skill #74) (#75)

Record the load_skill roll: #74 merged, gateway v2026.06.18.1 (sourceSha
09a99e4) pinned to life only — ships the full per-user stack to prod (writer
#65/#66 + injection #68 + first-turn #71 + load_skill #74). Bump the
INFRASTRUCTURE life-ahead tag to v2026.06.18.1 and note the US-host disk cleanup
(97% to 67%, removed 8 unused/unreferenced gateway tags).

Co-authored-by: Liran Peretz <[email protected]>
Co-authored-by: Claude Opus 4.8 <[email protected]>
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