Staff session staffId persistence#609
Merged
Merged
Conversation
…ation Staff sessions lost their staffId association across server restart / in-place respawn because StaffManager set `session.staffId = id` only in memory \u2014 SessionManager.createSession() never accepted `staffId` in its opts, so plan.staffId stayed undefined and persistOnce wrote no staffId to disk. On respawn, restoreSession read ps.staffId = undefined \u2192 no BOBBIT_STAFF_ID env \u2192 defaults/tools/inbox/extension.ts gated all three inbox tools off \u2192 staff agent could no longer mark entries complete. Fix: - Thread staffId through createSession opts \u2192 plan \u2192 persistOnce, so it lands in PersistedSession at spawn time and survives any respawn path. - Add a one-shot startup backfill (src/server/agent/staff-backfill.ts) that heals existing broken sessions by matching title + worktreePath against the staff registry, with a loud warn log on every match (spec req #4). Wired from server.ts boot via sessionManager.backfillStaffIds(staffManager). Regression test: tests/staff-session-staffid-persistence.test.ts \u2014 Tests 1 and 3 fail on master, pass after fix. Source guards pin the read side (restoreSession), the write side (persistOnce), and the new plan-builder wiring (createSession opts \u2192 plan). Co-authored-by: bobbit-ai <bobbit@bobbit.ai>
Co-authored-by: bobbit-ai <bobbit@bobbit.ai>
Co-authored-by: bobbit-ai <bobbit@bobbit.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Staff sessions silently lost their
staffIdassociation across server restart / agent CLI respawn. The three inbox tools (inbox_list,inbox_complete,inbox_dismiss) are gated byBOBBIT_STAFF_IDin the agent process env, set on every (re)spawn fromPersistedSession.staffId. Pre-fix,StaffManagermutatedsession.staffIdonly in memory —SessionManager.createSession()didn't acceptstaffIdin its opts, soplan.staffIdstayed undefined andpersistOncewrote nothing to disk. On respawn,restoreSessionreadps.staffId = undefined→ no env var → inbox tools refused to register → staff agent could never mark entries complete, and pending entries re-fired forever.Root cause
StaffManager.createStaff/ensureSessionForStaffsetsession.staffId = idaftercreateSession()returned — purely in memory.SessionManager.createSessionhad nostaffIdfield in its inlineoptstype, so the field never reached either plan-builder.persistOnce()faithfully writesstaffId: plan.staffId— but withplan.staffIdalways undefined for staff sessions, the persisted record on disk was always missingstaffId.Fix
staffId?: stringtoSessionManager.createSessionopts; threadedstaffId: opts?.staffId,into both plan-builder literals (worktree branch and normal branch).staffId: idin bothcreateSessioninvocations.src/server/agent/staff-backfill.tsruns at server boot, finds sessions with nostaffIdwhosetitlematches a staffnameAND whoseworktreePath/cwdmatches the staff's worktree, and heals them with a loud warn log. Conservative — refuses title-only matches.Regression test
tests/staff-session-staffid-persistence.test.ts— 7 tests across 3 describe blocks:staffId: opts?.staffId,plan-builder lines, fails on master, passes after fix) + behavioural round-trip viapersistOnce.staffIdround-trip throughstore.put.restoreSessionenv wiring andpersistOncewrite.All 7 pass on this branch; coder confirmed they fail on master when the source fix is stashed.
Documentation
docs/debugging.md— new symptom entry "Staff inbox tools missing after restart / [INBOX] completion silently fails" withjqdiagnostic, expected warn log, the four spawn-path wires, and a pointer to the pinning test.staff-backfill.tsand one-liner comments on the load-bearing plan-builder and call-site lines, all pointing to the regression test.Verification
npm run check— passnpm run test:unit— 1101 passnpm run test:e2e— 1111 pass, 11 flaky-retry passes, 8 skippedOut of scope (deferred to follow-ups)
BOBBIT_STAFF_IDis missing (spec Enforce PR-only master policy in team-lead prompt #5). The fix means this state never happens for new sessions and the backfill heals existing ones, so the original motivation evaporated.BOBBIT_GOAL_ID/BOBBIT_TASK_ID— investigation shows those already work correctly viaplan.goalId/plan.taskId.🤖 Generated with Bobbit