feat(atlas): persist preferred task session reuse#2640
feat(atlas): persist preferred task session reuse#2640code-yeongyu merged 3 commits intocode-yeongyu:devfrom
Conversation
|
I have read the CLA Document and I hereby sign the CLA |
|
All contributors have signed the CLA. Thank you! ✅ |
There was a problem hiding this comment.
2 issues found across 14 files
Confidence score: 3/5
- There is some merge risk here: both reported issues are medium severity (6/10) with high confidence (9/10), and each can cause concrete runtime misbehavior rather than cosmetic problems.
- In
src/hooks/atlas/subagent-session-id.ts, thetask_metadataregex may span closing tags and pick up an incidentalsession_id, which can cause the true metadata session ID to be missed and lead to incorrect session association. - In
src/hooks/atlas/tool-execute-after.ts, early return on background task launches can skippendingTaskRefs.delete(callID), creating a memory-growth risk from stale map entries over time. - Pay close attention to
src/hooks/atlas/subagent-session-id.tsandsrc/hooks/atlas/tool-execute-after.ts- session ID parsing correctness andpendingTaskRefscleanup on background launches.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/hooks/atlas/subagent-session-id.ts">
<violation number="1" location="src/hooks/atlas/subagent-session-id.ts:2">
P2: `task_metadata` regex can cross closing tags, causing extraction of incidental `session_id` outside metadata and skipping the real metadata session ID.</violation>
</file>
<file name="src/hooks/atlas/tool-execute-after.ts">
<violation number="1" location="src/hooks/atlas/tool-execute-after.ts:84">
P2: `pendingTaskRefs` entries are not cleaned up on background task launches because the function returns before `pendingTaskRefs.delete(callID)` executes, causing unbounded map growth over time.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
Thanks — I addressed the 2 issues identified by cubic and pushed a follow-up commit ( What changed:
Fresh verification after the fix: bun run typecheck
bun run build
bun test src/features/boulder-state/storage.test.ts src/hooks/atlas/subagent-session-id.test.ts src/hooks/atlas/index.test.ts src/hooks/start-work/index.test.ts src/tools/delegate-task/sync-continuation.test.ts src/tools/delegate-task/background-continuation.test.ts src/tools/delegate-task/tools.test.ts src/agents/atlas/atlas-prompt.test.tsResult: @cubic-dev-ai re-run review please. |
@HaD0Yun I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 14 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: Defensive implementation with backward compatibility for boulder state, extensive regression tests, and targeted logic that improves session continuity without breaking existing flows.
code-yeongyu
left a comment
There was a problem hiding this comment.
Hey @HaD0Yun! 👋 Thanks for putting this together — the core idea of persisting task-scoped session reuse for Atlas is really solid, and I can see you've thought carefully about the edge cases (plan advancement, explicit resume guard, backward compat). Tests are comprehensive and all green (116 pass).
That said, I found a few issues that I think we should address before merging. I've left inline comments on each file — please take a look!
TL;DR — 3 blocking issues:
- Explicit resume path leaks the wrong preferred session into reminders (
tool-execute-after.ts) - Parallel
task()calls all bind to the same task key (tool-execute-before.ts) - Session ID parsed from model output is trusted without validation (
subagent-session-id.ts→storage.ts)
Everything else looks great. The type design, backward compat handling, and test coverage are all well done. Let's get these three sorted and this is good to go! 🚀
📁
|
📁
|
📁
|
📁
|
📁
|
📁
|
📁
|
📁 Tests (
|
|
Thanks for the careful review — I pushed a follow-up that addresses the blocking points you called out. Changes in this update:
I also added regressions for each case and re-ran:
|
Summary
Changes
task_sessionsso Atlas can remember a preferred reusable subagent session per current top-level plan tasktask()completestask(session_id=...)continuations, so old-session follow-ups do not poison the new task's preferred session<task_metadata>block instead of incidental body texttask_sessionsbackward compatibilityTesting
Targeted local verification run before opening this PR:
bun run typecheck bun run build bun test src/features/boulder-state/storage.test.ts src/hooks/atlas/subagent-session-id.test.ts src/hooks/atlas/index.test.ts src/hooks/start-work/index.test.ts src/tools/delegate-task/sync-continuation.test.ts src/tools/delegate-task/background-continuation.test.ts src/tools/delegate-task/tools.test.ts src/agents/atlas/atlas-prompt.test.tsResults:
bun run typecheck✅bun run build✅bun test ...command above →242 pass, 0 failRelated Issues
This PR is intentionally scoped as a narrow Atlas continuity improvement rather than a broad session-architecture redesign.
Continuation metadata lineage
Boulder / session storage concurrency lineage
Atlas handoff / contract / structured-plan lineage
Atlas execution-quality background
Why this change is needed
Atlas already has the primitive needed for continuation:
task(session_id=...)can resume an existing delegated session with preserved context. The missing piece is persistence and preference at the current top-level plan-task boundary. Today, persisted Atlas / boulder state is plan-wide, while task-scoped reuse depends too heavily on transient session output, in-memory bookkeeping, and the orchestrator reusing the rightsession_idat the right moment.That gap shows up in two concrete ways:
This PR addresses that gap without trying to redesign Atlas into a general per-plan / per-session state machine.
Scope / non-goals
Persist and prefer the last subagent session for the current top-level plan task; fall back to a fresh session when no reusable session exists or reuse would cross task boundaries; explicitly not a broad per-plan/per-session redesign.
Here, “top-level plan task” is kept conservative: the current task unit Atlas is executing from its todo-list / structured-plan flow, not a broader undocumented global task graph.
Summary by cubic
Persist and prefer the last reusable subagent session for the current top‑level Atlas task, now hardened with lineage validation and ambiguity guards to improve continuity without cross‑task bleed. Preferred sessions are surfaced in continuation, completion, and verification prompts, with a safe fresh‑session fallback.
New Features
task_sessionsinboulder.jsonand exposegetTaskSessionState/upsertTaskSessionState.task()start and persist on completion, even if the plan advances.task(session_id=...)is used or when multiple in‑flight calls claim the same task.Bug Fixes
<task_metadata>block, ignore body text, and handle missing IDs with a placeholder.Written for commit 8859da5. Summary will update on new commits.