fix(session): preserve logical thread continuity#393
Conversation
fro-bot
left a comment
There was a problem hiding this comment.
Summary
This PR correctly implements the fix for session title persistence identified in the post-ship audit. The root cause — OpenCode auto-renaming session titles after prompts — is addressed by re-asserting the title after each prompt attempt.
Key Changes
1. New title-reassert.ts module — Best-effort session title restoration
The implementation is well-designed:
- Null-safe early return when title is undefined
- Try/catch wrapper with warning-level logging (failures don't abort execution)
- Uses SDK's typed
session.updateendpoint
2. Integration in execution.ts — Correct placement in finally block
const result = await (async () => {
try {
return await sendPromptToSession(...)
} finally {
await reassertSessionTitle(client, sessionId, config?.sessionTitle, logger)
}
})()This ensures title re-assertion happens after every prompt attempt (including retries), which is the correct behavior.
3. Test coverage — Two new tests verify the behavior:
're-asserts session title with SDK update payload after prompt attempts''re-asserts session title even when prompt attempt fails'
Both tests pass ✅.
Quality Assessment
✅ Tests pass — All 1068 tests pass including the new ones
✅ Type check clean — No TypeScript errors
✅ Lint clean — Only warnings in unrelated test files (pre-existing)
✅ Follows project patterns — Uses Logger injection, Result pattern would be overkill for best-effort operation
✅ Correct layering — New module in services/session/ where storage operations belong
✅ Documentation — Audit document clearly explains the fix
Minor Observations
-
as Record<string, unknown>cast — The type assertion on line 17 oftitle-reassert.tsis acceptable given the SDK's untyped endpoint, though a more precise type could be added if the SDK exposes the shape in the future. -
Test mock coverage — The
session.updatemock is already present increateMockClient()at line 113 of the test file, which is good reuse of the test infrastructure.
Verdict
This is a targeted, correct fix for the identified root cause. The implementation is minimal, well-tested, and follows established patterns. The audit document provides excellent traceability from problem to fix.
Recommended action: Merge after CI passes.
Run Summary
| Field | Value |
|---|---|
| Event | pull_request |
| Repository | fro-bot/agent |
| Run ID | 23686153603 |
| Cache | hit |
| Session | ses_2cb6115dbffeuLRGFT6r9OoaMl |
No description provided.