Skip to content

feat(coding-agent): persist parent edges and derived depth for all sessions - #584

Merged
snimu merged 5 commits into
feat/lazy-child-hydrationfrom
feat/agent-tree-groundwork
Aug 5, 2026
Merged

snimu merged 5 commits into
feat/lazy-child-hydrationfrom
feat/agent-tree-groundwork

Conversation

@snimu

@snimu snimu commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Every session now records two facts in its file on disk: who spawned it (its parent) and how deep it sits in the spawn tree (a root is depth 0, its children are depth 1, and so on).

Until now we could only guess at this from whatever happened to be in memory, which broke down for sessions that weren't loaded. Now it's stored once, at creation, and read back everywhere — session lists, the saved-session catalog, the UI.

Two rules that matter:

  • Spawning a child stores parent + 1 as its depth.
  • Forking or branching a session copies the original's depth, because a fork of a root is still a root — it's a copy, not a child.

Old session files without these fields still work; we just don't know their depth and fall back to sensible defaults.


This is part 1–7 of a stack (each PR builds on the one before it):

  1. feat(coding-agent): lazy child session hydration #583 — don't load finished subagents until someone needs them
  2. feat(coding-agent): persist parent edges and derived depth for all sessions #584 — record each session's parent and depth on disk
  3. feat(coding-agent): /rlm-max-depth session command #585 — new /rlm-max-depth command to control how deep agents can nest
  4. feat(coding-agent): recursive scoped agents view #586 — browse the agent tree in the agents view
  5. feat(coding-agent): delete child-agent inspector; one subagent summary line #587 — replace the child-agent inspector with one summary line
  6. feat(coding-agent): whole-tree idle eviction #588 — shut down worker processes whose sessions have all gone idle
  7. feat(coding-agent): intra-tree child session passivation #589 — quietly unload idle child sessions inside a running worker

Tests: the full suite at the top of the stack fails only on tests that already fail on the base branch. Each branch in the stack also passes checks and its own tests independently.

Note

Persist parent edges and derived depth in session headers for all session types

  • All new sessions now write rlmDepth to their headers: root sessions default to 0 (or the RLM_DEPTH env var), child sessions increment from their parent's persisted depth.
  • Resumed sessions read rlmDepth from their persisted header rather than the environment, so depth is stable across restarts.
  • Fork, branch, and materialize paths carry the source rlmDepth forward consistently.
  • Session listings (active and inactive) now include rlmDepth, and daemon protocol is bumped to schema revision 10.
  • Serialization/deserialization of SavedSessionInfo is consolidated into a new shared saved-session-info.ts module.
  • Risk: invalid RLM_DEPTH env values now throw at root session creation instead of being silently ignored.

Changes since #584 opened

  • Changed SessionInfo.rlmDepth from optional to required and introduced resolveSessionRlmDepth utility function that computes depth from persisted header value, defaults to 0 for root sessions, or infers depth by counting nested sub-* directory segments in the session file path [6a1950b]
  • Updated all session creation and loading code paths in SessionManager to compute and persist rlmDepth using resolveSessionRlmDepth, including scanSessionInfo, open, constructor existing-file handling, materializeSessionFile, createBranchedSession, and forkFrom [6a1950b]
  • Updated AgentDaemon.buildPassiveRlmSubagentRequest to rely solely on SessionInfo.rlmDepth and modified AgentDaemon.createRuntime to infer rlmDepth using resolveSessionRlmDepth when resuming from existing session files [6a1950b]
  • Updated test helpers in agents-view-state.test.ts, daemon-session-list.test.ts, and their makeSessionInfo functions to default rlmDepth to 0, and added comprehensive test coverage in file-operations.test.ts and daemon-mode.test.ts validating depth inference from path structure [6a1950b]
  • Modified resolveSessionRlmDepth utility to derive child depth from parent session header when available and refined path-based depth inference [08c8870]
  • Updated AgentDaemon.buildSessionListWithPassiveRlmSubagents method to prefer registry entry depth over session info depth [08c8870]
  • Added test coverage for depth resolution precedence and path-based inference behavior [08c8870]
  • Implemented recursive parent-based session depth resolution with cycle detection and selective depth increment [748b47c]
  • Added test coverage for depth backfilling behavior in legacy forked sessions [748b47c]
  • Modified resolveLegacySessionRlmDepth function in coding-agent to resolve parent session paths relative to each session file's directory [121ae3d]
  • Added test case validating relative parent path resolution in legacy session depth calculation [121ae3d]

Macroscope summarized 842927d.


Note

Medium Risk
Changes session header semantics, fork/branch depth rules, and daemon wire schema; invalid RLM_DEPTH now throws at root session creation, and legacy depth inference could mis-rank edge-case trees.

Overview
Persists RLM spawn depth (rlmDepth) in session file headers and threads it through spawn, fork, branch, and resume so nesting limits no longer depend on in-memory state or RLM_DEPTH alone.

New and child sessions write parentSession + rlmDepth at creation (children get parent depth + 1; forks/branches copy the source depth). AgentSession resolves depth from config → persisted header → env, and exposes rlmDepth. resolveSessionRlmDepth backfills legacy files (parent chain, sub-* path segments, open-time rewrite) and makes SessionInfo.rlmDepth required for listings.

Daemon / UI: saved-session and session-list DTOs include rlmDepth (schema revision 10); passive subagent rows use registry depth when present; serialization moves to saved-session-info.ts. Subagent runtime creation passes explicit rlmDepth into newSession.

Reviewed by Cursor Bugbot for commit 121ae3d. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread packages/coding-agent/src/core/agent-session-runtime.ts
Comment thread packages/coding-agent/src/core/agent-session-runtime.ts
Comment thread packages/coding-agent/src/core/session-manager.ts
Comment thread packages/coding-agent/src/core/session-manager.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
snimu added a commit that referenced this pull request Aug 3, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
@snimu
snimu force-pushed the feat/agent-tree-groundwork branch from 865918d to 405c88a Compare August 3, 2026 12:05
snimu added a commit that referenced this pull request Aug 3, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
Comment thread packages/coding-agent/src/core/agent-session.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
Comment thread packages/coding-agent/src/core/agent-session-runtime.ts
snimu added a commit that referenced this pull request Aug 3, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 3, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
@snimu
snimu force-pushed the feat/agent-tree-groundwork branch from 405c88a to dcae3e4 Compare August 4, 2026 07:49
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
@snimu
snimu force-pushed the feat/agent-tree-groundwork branch from 81a00da to b4881a8 Compare August 4, 2026 20:25
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
@sethkarten
sethkarten self-requested a review August 4, 2026 21:40
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.
Comment thread packages/coding-agent/src/core/session-manager.ts Outdated
Comment thread packages/coding-agent/src/modes/daemon/daemon-mode.ts Outdated
Comment thread packages/coding-agent/src/core/session-manager.ts
@snimu
snimu force-pushed the feat/agent-tree-groundwork branch from 6a1950b to 417eb4c Compare August 4, 2026 22:42
snimu added a commit that referenced this pull request Aug 4, 2026
… parsing, and legacy fallbacks

- Finding 8: new-session parent links were deriving spawn depth; copy the source header depth across the reference edge and add a runtime regression test (origin: PR #584).
- Finding 9: first-entry forks of legacy sessions discarded effective runtime depth; fall back to session.rlmDepth in persisted and in-memory branches and test both (origin: PR #584).
- Finding 10: root RLM_DEPTH parsing accepted malformed and unsafe values; require decimal digits and a valid safe non-negative integer, with probe cases as tests (origin: PR #584).
- Finding 11: child-depth derivation could overflow MAX_SAFE_INTEGER; guard the increment and test the boundary (origin: PR #584).
- Finding 12: daemon children of in-memory parents skipped explicit depth persistence; always create the child header with explicit depth and test --no-session ancestry (origin: PR #584).
- Finding 13: legacy completed subagents rehydrated at root depth; restore the depth-one fallback and test a registry/header pair without depth (origin: PR #584).
snimu added a commit that referenced this pull request Aug 4, 2026
…ots, and depth ingestion

- preserve daemon routable IDs for passive children (origin: PR #583)
- recheck guarded passive hydration and heartbeat restores (origin: PR #583)
- repair wrong-kind pending hydration joins (origin: PR #583)
- fence passive hydration during update restart preparation (origin: PR #583)
- validate persisted RLM depth before constructor ingestion (origin: PR #584)
- retry attach child snapshots across session replacement (origin: PR #587)
- retain effective depth for legacy parented new sessions (origin: PR #589)
- coordinate parent passivation with child hydration publication (origin: PR #589)
snimu added a commit that referenced this pull request Aug 4, 2026
…on entries

The legacy-entry rehydration fallback (entry.rlmDepth ?? 1) is passed as
config, which outranks the opened transcript header in AgentSession — so a
nested legacy child whose header carried a deeper persisted depth woke at
depth 1, weakening the host recursion gate. Registry depth stays
authoritative when present; otherwise the validated header depth wins and 1
remains the last-resort default for fully legacy children.

origin: PR #584 fallback restored in round-1 triage; surfaced by post-rebase
bot review of PR #589.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 08c8870. Configure here.

Comment thread packages/coding-agent/src/core/session-manager.ts
snimu added 3 commits August 5, 2026 01:14
…ssions

Groundwork for the recursive agent tree (Track A PR 2): every session -
live, passive, or saved-only - carries its tree position without a runtime
and without inference.

- additive rlmDepth field in the session JSONL header (no format bump; old
  readers ignore it); surfaced through SessionInfo, the saved-session
  catalog, SessionSummary, and agent-connection types
- spawn edges derive child depth = parent depth + 1 at creation; fork and
  branch COPY the source depth (reference edges, not structural parents):
  a forked root stays a root
- RLM_DEPTH env seeds fresh parentless sessions; persisted header wins for
  resumed sessions; legacy children resolve depth via the subagent registry
  fallback, never chain walks at scan time
- one shared saved-session-info serializer (deduped from daemon-mode/
  daemon-supervisor); DAEMON_SCHEMA_REVISION 9 with regenerated id

Track A PR 2 of the recursive-agent-harness plan.
- Infer legacy session depth from nested subagent artifact directories.
- Persist inferred depth when opening sessions while keeping listings read-only.
- Use resolved file metadata for passive rows and daemon subagent rehydration.
- Derive legacy child depth from its parent header before using anchored path inference.
- Preserve authoritative registry depth for passive legacy subagents.
Comment thread packages/coding-agent/src/core/session-manager.ts
- Copy the recursively resolved source depth across legacy fork and branch reference edges.
- Increment legacy spawn depth only for structural subagent artifact paths while retaining safe cycle and unreadable-parent fallbacks.
Comment thread packages/coding-agent/src/core/session-manager.ts
- Resolve relative parentSession paths from the current legacy session directory during RLM depth traversal.
- Add regression coverage for relative-linked legacy sessions when the process cwd differs.
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.

2 participants