Skip to content

fix(core): govern forks as children of their source session - #775

Merged
dezren39 merged 1 commit into
mainfrom
queue/2725-505-fork-governance
Oct 28, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/2725-505-fork-governance

Conversation

@dezren39

@dezren39 dezren39 commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes #505

Forking a child session laundered it out of ancestor governance: the projector inserts a fork with parent_id: null (keeping only fork_session_id and a copy of the source's own subagent_policy), and every governance walk followed parentID only — so a fork escaped every policy above its source, its own switchAgent/switchModel were unchecked (top-level gate), and its descendants were governed only by the copied policy. Spec specs/2026-10-25-subsession-model-governance.md §6.2 already decided the opposite: "Session.fork creates a child whose parent is the source session."

Shape (governance-link, projection untouched)

The fork stays projected top-level (parent_id still null, listing/projection unchanged); governance now treats the fork source as the fork's governance parent:

  • packages/core/src/session/model-governance.ts — the assertAllowed ancestor walk follows parentID ?? fork.sessionID, so ancestor session policies above the source bind the fork, its switches (via the creation/fork checks that call it), and its descendants' creation.
  • packages/core/src/session/session.ts — switchAgent/switchModel gate on the governance parent (parentID ?? fork.sessionID) instead of parentID alone, so a fork's own switches are checked against its source's chain; genuinely top-level sessions remain unchecked.
  • packages/core/src/session/subagent-depth.ts — the depth walk follows the same link, so max_depth caps above the source bind the fork's subtree (a fork hop counts as one level, as a child would).

Tests

New regression test in packages/core/test/session-governance.test.ts: a grandchild is forked under a grandparent policy of test/haiku only — the fork (projected top-level, parentID undefined) cannot switchModel to test/opus, cannot launch children on test/opus, and can launch children on test/haiku. Existing fork governance tests (fork-of-policy-denied, permitted fork copies policy) and the session-governance suite run in CI.

Verification is CI-only per fleet policy; the unit suites on this PR are the evidence.

Queue task 2725.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4bc7d85d-ac0a-4067-bb60-80562e28aa76
Commits

Reviewing files that changed from the base of the PR and between f1878bd and 72ceef6.

Files selected for processing: 4
  • packages/core/src/session/model-governance.ts
  • packages/core/src/session/session.ts
  • packages/core/src/session/subagent-depth.ts
  • packages/core/test/session-governance.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T22:00:01.416079Z 72ceef6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72ceef6a66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +151 to +153
const governanceParentID = session.parentID ?? session.fork?.sessionID
if (governanceParentID) {
const parent = yield* get(governanceParentID)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve fork governance when the source session is deleted

After a user forks a session and deletes the source, the surviving fork can no longer switch models or agents, create children, or be forked again: these operations now require loading the deleted source. Session.remove in packages/core/src/session.ts recursively removes only sessions returned by list({ parentID: sessionID }), and SessionStore.list filters on parent_id, so top-level-projected forks survive deletion with a dangling fork.sessionID. The new governance walks then fail with NotFoundError or Parent session not found, even when no model restrictions were configured. Coordinate source deletion with the new governance relationship so surviving forks retain usable, enforceable governance rather than depending on a row that can be removed.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown

The following comment was made by an LLM, it may be inaccurate:

@github-actions

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@dezren39
dezren39 merged commit a9452a1 into main Oct 28, 2026
14 of 18 checks passed
@dezren39
dezren39 deleted the queue/2725-505-fork-governance branch November 1, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant