Skip to content

refactor(session): the facts of a run live in one record its tree shares - #1232

Open
debugmcpdev wants to merge 3 commits into
mainfrom
refactor/run-record
Open

debugmcpdev wants to merge 3 commits into
mainfrom
refactor/run-record

Conversation

@debugmcpdev

@debugmcpdev debugmcpdev commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1229: the first three commits listed here are that PR's, and this one is to be read as its last two commits only. It needs a rebase onto main once #1229 merges.

What this is

The storage half of the decision taken for #1214 ("view now, storage next"). How a program was started is a fact of the run, the same for every session of a tree. Those facts were thirteen fields of ManagedSession, written on the launch root and empty on a child, and #1214 and #1222 were readers that asked the session they were handed. #1229 gave such readers a view that walks to the root. This gives the facts storage of their own:

export interface Run {
  attachMode?: boolean;
  programOwnership?: 'owned' | 'borrowed';
  attachLocality?: AttachLocality;
  lastLaunch?: LastLaunchSpec;
  transformedLaunch?: TransformedLaunch;
  launchConfigNotices?: string[];
  toolchainValidation?: ToolchainValidationState;
  effectiveBreakOnExceptions?: ExceptionBreakMode;
  launchExceptionFilters?: { … };
  launchDebuggerOff?: boolean;
  attachDroppedConfigKeys?: string[];
  attachForwardedUnknownConfigKeys?: string[];
  attachTransformNotices?: string[];
}

Every session has run: Run, created with it. Adoption gives a child its parent's by reference (child.run = parent.run). A reader holding any session of a tree reads the same object, so there is no wrong session to ask.

What moved, and what did not change

  • The thirteen fields moved with their comments. logDir stays on the session (the view serves the log path).
  • Every write stays where it was and resets what it reset. The launcher, the proxy launcher and the attach controller write session.run.<field> at the same points. This PR does not turn the scattered per-launch resets into "a new record per launch": a dry run and a failed preparation must leave the record as it was (A dryRunSpawn on a finished session discards that run's output and exit code (it is a launch attempt) #812), and that is easiest to keep true by not moving any reset.
  • Four writes used SessionStore.update together with other fields. They are direct now. The two toolchain-verdict writes still touch the row through the store (updateSession(id, {})): that is what moves updatedAt, and what throws when the session was closed during a long compile, which gives the adapter lease back (the test for that still holds, on the touch instead of on the key).
  • runFactsOf keeps its signature. It reads the session's own record; the root's row still supplies the root id and the run directory.
  • Adoption no longer copies the two arming facts it used to copy.

What a child reads differently

reader a child before a child now meant?
isDebuggerOff (the noDebug sentences, debuggerDisabled in the listing) "not recorded" the run's decision yes: it is the run's. Whether any adapter reports children under an honoured noDebug was not determined. The proof by a verified breakpoint stays each session's own, so a root and its child can answer differently until the child's breakpoints bind
the stop that proves the debugger on (setupProxyEventHandlers) cleared the child's own, empty, field clears the run's decision yes: the proof holds for the run
seeding of launch notices into the output buffer nothing to seed would have seeded the root's notes into every child's output no: guarded to the root, with a test
exception arming (describeLaunchArming) a copy taken at adoption the live record yes: a child adopted before the arming was recorded used to keep an empty copy
everything behind runFactsOf the root's, since #1229 the same unchanged

One thing the compiler did not catch

DebuggerOffView declared launchDebuggerOff? as an optional property, so a session without the field still satisfied the type and the decision silently read as "on". The unit tests caught it. The view now names the record (run?: { launchDebuggerOff? }). I read through the other places in the sources that mention the thirteen names without run.; this was the only one of its kind.

Tests

  • 161 references renamed by position from the compiler's own errors; hand-built sessions in tests give their facts as run: { … }.
  • The run-facts guard (tests/unit/architecture/run-facts-seam.test.ts) is removed: it held readers to the view because a child's own fields were empty, and a child's record is its tree's now.
  • New in session-manager-child-sessions.test.ts: a child's record is its root's (the same object, and a later write by the root is seen by the child); a session nothing was started on has an empty record of its own; the root's launch notes are not seeded into a child's output. The first and third fail under the two mutations I tried (a copy instead of the reference; seeding without the guard).
  • One existing expectation changed, and is right now: a Ruby attach's refused breakpoint re-send has always carried a path hint in production. That test's store is a mock that swallowed the write saying "attached", so the test never saw the hint; the record is written directly.
  • runFactsOf and isDebuggerOff require the record. My first commit let them accept a row without one, for the minimal stand-ins the server tests hand over; the review pointed out that this is the same silent "nothing started" that the DebuggerOffView bug was, waiting for the next caller. About 120 stand-ins carry run: {} now.
  • The launch-after-attach reset (run.attachMode = false in the launcher, [FEATURE] restart_debugging tool — relaunch the current session in one call #238) had no test before or after the move; it has one now.

The launch-shaped operations refuse a child at the session layer

Until now only the tool handlers refused a child id (childSessionRefusal), and the session layer was safe by accident: a child had no lastLaunch to replay and no ownership to be judged by. With the tree's record on the child, restartDebugging(childId) would have found the root's launch and detachFromProcess(childId) the root's ownership. refuseChildSession (in the in-flight guard that all four operations pass) gives the handlers' answer to any caller. Nothing reaches these with a child id today except through the handlers.

Review

One independent review with a mutation pass on the hand-edited lines (18 mutants, 15 killed). It found the move neutral for roots, the child-side changes real and deliberate, and nothing critical or important in the commit. Its points are answered in the second commit: the strict readers, the session-layer refusal, the reset test, and corrections to what the docs claimed (the core also writes the record, at a stop that proves the debugger on; a failed real start has already reset what it resets, only a dry run leaves the record as it was; the record is mutated in place). Of the three surviving mutants, one is the reset that now has a test, and two are equivalent in production (the attachMode fall-back in borrowsProgram, and clearing attachLocality at a launch, whose readers are all gated on attached).

The integration run found what neither the compiler nor the unit suite could: the self-debugging test evaluates an expression inside the debugged server that named the old field. The reviewer then searched tests, docs, skills, tools and scripts for other names reached at run time and found none.

It also came across a bug that predates this work, filed as #1231: after the proxy worker dies as a process, a relaunch keeps the previous run's child rows, and the root's wait_for_stop can answer with one of them.

Not done here

  • "A new record per launch" in place of the per-field resets.
  • No changelog fragment: nothing a caller sees changes except the rows marked "yes" above. I added the no-changelog label; say if you would rather have a fragment.

Gates

typecheck:all, lint, check-docs. The pre-push run on the pushed commit (Windows 11, Node 24.14.1): unit 438 files, 9602 passed and 7 skipped; integration 47 files, 245 passed and 1 skipped, the self-debugging and the JavaScript and Python tree suites among them. A vitest worker's stop on this build still carries no stale-build note and its breakpoint is verified with the adapter's id (the #1214 and #1211 rows of #1229, re-run).

🤖 Generated with Claude Code

@debugmcpdev debugmcpdev added the no-changelog PR needs no CHANGELOG fragment (refactor, CI-internal, or otherwise not user-visible) label Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

cynarlab and others added 3 commits November 23, 2026 00:34
How a program was started is a fact of the run, the same for every session
of the tree: launch or attach, where an attach's target lives, the launch
the adapter's transform produced, the request a restart replays, the
exception arming, the debugger-off decision, the notes and the toolchain
verdict of the start. They were thirteen fields of ManagedSession, written
on the root and empty on a child, and #1214 and #1222 were readers that
asked the session they were handed. The previous change gave those readers
a view that walks to the root. This one gives the facts storage of their
own: a Run record (session.run), created with the session, which adoption
hands to the child by reference (child.run = parent.run). A reader holding
any session of a tree reads the same object.

What moved and how:
- The thirteen fields, with their comments, from ManagedSession into Run.
- Every write stays where it was and resets what it reset: the launcher, the
  proxy launcher and the attach controller write session.run.<field>. Four
  writes went through SessionStore.update with other fields; they are direct
  now, and the two toolchain-verdict writes still touch the row through the
  store, which is what moves updatedAt and what throws when the session was
  closed during a long compile.
- runFactsOf keeps its signature and reads the session's record; the root's
  row still supplies the root id and the run directory.
- Adoption no longer copies the two arming facts it used to copy.

What a child reads differently, reader by reader:
- isDebuggerOff: the run's decision, where a child read "not recorded".
- A stop in a child that proves the debugger on clears the run's decision.
- The seeding of launch notices into the output buffer stays the root's:
  guarded, with a test, because a child now holds the same notes.
- Everything else already went through the view.

One thing the compiler did not catch: DebuggerOffView declared the moved
field as optional, so a session without it still satisfied the type and the
decision silently read as "on". The view now names the record. The other
optional-field views in the sources were read through; this was the only
one.

Tests: hand-built sessions give their facts as `run: { ... }`; the run-facts
guard is removed (there is no wrong session to read any more); three new
cases hold the sharing, the per-session empty record and the root-only
notes. One existing expectation changed, and is right now: a Ruby attach's
refused breakpoint re-send always carried a path hint in production, which
that test's mocked store hid by swallowing the write that said "attached".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…for a row without one

An independent review with a mutation pass (18 mutants on the hand-edited
lines) found the storage move neutral for roots and nothing critical or
important in it. What it asked for, and what the integration run found:

- The two readers that tolerated a row without a record (runFactsOf, the
  debugger-off view) require one now. The tolerance existed for hand-built
  sessions in the unit tests; a real session always has a record, and the
  next caller to hand in a projection would have read "nothing started" or
  "debugger on" in silence, which is the kind of bug the first commit had to
  fix in the debugger-off view. About 120 stand-ins in the tests carry
  `run: {}` instead.
- The launch-shaped operations refuse a child session at the session layer
  too (refuseChildSession, in the in-flight guard every one of them passes).
  Until now only the tool handlers refused, and the session layer was safe
  by accident: a child had no lastLaunch to replay and no ownership to judge
  by. With the tree's record on the child, restart would have found the
  root's launch and detach the root's ownership. No caller reaches them
  today except through the handlers.
- A test for the reset the launcher does when a launch supersedes an attach
  (a mutant that dropped it survived): the session is a launch again and
  restart replays it (#238).
- The self-debugging integration test evaluates an expression inside the
  debugged server that named the old field; it names the record now. Nothing
  else reaches the moved fields by name at run time.
- Docs and comments: the record is also written by the core (a stop that
  proves the debugger on); a failed real start has already reset what it
  resets, only a dry run leaves the record as it was; it is mutated in
  place, so a child row that outlives its run reads what its root reads;
  the stale mentions of the removed guard and of the old field paths.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…quest (#1214, #1222)

- collectProxyFailureDiagnostics: omit proxyLogPath/proxyLogResource when logOwner still carries parentSessionId (orphan or cycled child), matching runFactsOf (#1222).
- outputOnFor: omit the launch-session pointer when the root walk stopped below the root (orphaned grandchild).
- runFactsOf: clear request alongside launch when attached is true so a prior launch on the root cannot leak into attach-mode readers.
- Add unit coverage for orphan diagnostics, orphaned grandchild outputOnFor, attach runFactsOf.request, and undefined policy in connectionBehaviorOf.
@debugmcpdev debugmcpdev changed the title refactor(session): the facts of a run live in one record its tree shares (stacked on #1229) refactor(session): the facts of a run live in one record its tree shares Nov 23, 2026

@debugmcpdev debugmcpdev left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reviewed #1232 (
efactor/run-record), rebased onto main (5fdbf9b), and pushed 3734c14 after passing the full local pre-push gate (lint, ypecheck:all, clean build, 438/438 unit files, 47/47 integration files):

  • Verified all 13 Run fields across launch, dryRun, cold/hot
    estartDebugging, �ttachToProcess, detachFromProcess, closeSession, isDebuggerOff, and
    efuseChildSession.
  • Added hardening commit 3734c14:
    • collectProxyFailureDiagnostics: guard logOwner.parentSessionId === undefined so orphaned/cycled children never emit a nonexistent proxy-.log path or invalid proxy-log resource URI (#1222).
    • outputOnFor: guard
      eachedRoot so an orphaned grandchild never points at an intermediate child session.

unFactsOf: gate
equest alongside launch when �ttached is rue so a prior launch on the root never leaks into attach-mode readers.

  • Added unit tests covering all three cases plus connectionBehaviorOf with an undefined policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog PR needs no CHANGELOG fragment (refactor, CI-internal, or otherwise not user-visible)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants