Skip to content

⏯️ feat: Enable Graph Subagent Approval and Resume - #599

Open
lia-by-librechat[bot] wants to merge 7 commits into
mainfrom
lia/graph-subagent-hitl
Open

lia-by-librechat[bot] wants to merge 7 commits into
mainfrom
lia/graph-subagent-hitl

Conversation

@lia-by-librechat

@lia-by-librechat lia-by-librechat Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enable foreground graph-subagent approvals through existing checkpoint/replay machinery. Member approvals resume individually or together, including after rebuilding Run. All pending members recover settled results; only addressed interrupts receive approval authority. Completed effects do not repeat, and recovery preserves the designated result.

Resume binds topology, models, instructions, tool schemas/capabilities, member session partitions, termination controls, and optional host configId. Checkpointed pending IDs support either partial-resume order without extra reads. Existing ownership and proposal safeguards remain intact.

Exports GRAPH_SUBAGENT_HITL_VERSION = 1. Graph nesting remains disabled; background work cannot wait for human input. Related host work: LibreChat-AI/LibreChat#16764.

Verification

Head: 3cc511ad44fab9c59865ed70f6096040446c7c89.

  • 21 focused suites, 692 tests passed: approvals, sessions, replay/recovery, lifecycle, questions, cancellation, caller capabilities, and tracing.
  • Real SDK tests cover all decisions, repeated call IDs, simultaneous/partial resume, fresh/in-memory recovery, stale declarations, adapter changes/removal, and completed direct effects beside pending direct/event approvals.
  • npx tsc --noEmit, all PR-touched-file ESLint with zero warnings, and package build passed. CJS feature export verified.
  • Localhost conditional breakpoints reproduced the session, ownership, settled-cache, and partial-map defects before their fixes.
  • Independent source review completed at 3cc511ad44fab9c59865ed70f6096040446c7c89 with no findings. Reviewer runtime and live tracing checks were not run.
  • Current CI: 4 passed, 9 cancelled. Validation is incomplete, not green.
  • Full local suite, live-provider tests, and real Langfuse project inspection were not run.

Finding Ledger

ID Severity Finding Disposition
R1 P1 Registry capability binding Fixed in 6e0f5516
R2 P1 Member session partition binding Fixed in a55b691c
R3 P2 Inline tool-end binding comment Already fixed in a55b691c; replied with evidence
R4 P2 Batched member approval evidence Fixed in e4adb468
R5 P1 Settled records for unresumed members Fixed in 48c821fc
R6 P2 Non-current member interrupt maps Fixed in 48c821fc

| R7 | P2 | Functional edge prompt revision binding | Fixed in 3cc511ad |
| R8 | P2 | Refreshed session grants after restoration | Fixed in 3cc511ad |

No rejected findings. Audited declaration binding, context projection, checkpoints, replay, cancellation, result recovery, and tracing by invariant.

Compatibility

HITL stays opt-in. Hosts retain current authorization and single-winner resume ownership. Optional graph configId tracks implementation changes outside declarative inputs. Functional edge prompts require a host revision when HITL is enabled. Refreshed authorized session seeds merge after restoration. Feature-detect SDK support before enabling graph approvals.

Default-session keys and older manifests remain readable. Older custom-partition snapshots without partition identity fail closed. No publication, version bump, or LibreChat dependency/UI change. Host follow-up must verify resume-time graph-member authorization before removing its warning.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head c66dc21: foreground graph subagents use regular approval/replay machinery with member attribution and graph-definition binding. Parallel approvals, rebuilt-run recovery, question interrupts, decision handling, and cancellation are covered. All 460 focused tests, SDK typecheck, scoped lint, and build pass. Fresh independent review follows this head.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head 704f27c: updates the pre-existing graph host-argument rejection assertion to account for optional graph revisions. Production code is unchanged. Host-argument, graph-normalization, and real graph-HITL cases pass, as do typecheck and scoped lint. Fresh CI and exact-head independent review follow.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head 6e0f551: fixes review R1/P1 by binding canonical registry capabilities, executable map schemas, and direct-tool modes into graph resume identity. Stale programmatic approvals fail closed; unchanged reordered registries resume. All 521 focused tests across 17 suites pass, along with SDK typecheck, scoped lint, and build. Fresh exact-head independent review and CI follow.

@danny-avila

Copy link
Copy Markdown
Collaborator

@codex review the latest head, final review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 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-05T22:07:08.162367Z 3cc511a Manual request
ℹ️ 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: 6e0f5516b3

ℹ️ 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 +446 to +452
members: config.agents.map((agent) => ({
id: agent.agentId,
provider: agent.provider,
model: resolveClientOptionsModel(agent.clientOptions),
instructions: agent.instructions,
additionalInstructions: agent.additional_instructions,
maxContextTokens: agent.maxContextTokens,

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 Include toolEnd in the graph resume fingerprint

When a pending graph approval is resumed after a rebuild where a member's toolEnd setting changed, this member projection produces the same definition ID, so isResumeExecutionCompatible accepts the new graph. However, Graph.ts uses agentContext.toolEnd to compile the tool-node edge to either END or the agent node, meaning the approved call can resume into a different control flow and terminate the member prematurely instead of returning to the model. Add toolEnd to the fingerprint so this configuration change fails closed like the model, instructions, topology, and tool-schema changes already covered here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Already covered in a55b691: the member fingerprint includes normalized toolEnd, and the real graph-HITL regression rejects a changed tool-end setting before approved execution. No additional patch is needed.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head a55b691: fixes R2/P1 by binding declared and effective member session partitions across rebuilt and in-memory resume, including context-adapter removal. The invariant sweep also binds tool-end and summarize-only controls. Default legacy session keys remain compatible. All 599 focused tests across 19 suites pass, with SDK typecheck, PR-touched-file lint, and build. R1/P1 remains fixed in 6e0f551. Fresh exact-head review and CI follow.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head e4adb46: fixes R4/P2 by restoring checkpoint evidence for each resumed member independently. Simultaneous approvals, mixed decisions, partial resume, and a follow-up question pass without replaying completed siblings. Existing owner, proposal, principal, and conversation checks remain intact. All 662 focused tests across 21 suites pass, with SDK typecheck, all touched-file lint, and package build. Fresh exact-head independent review and CI follow.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head 48c821f: fixes R5/P1 by restoring settled records for every pending member while granting approval evidence only to addressed interrupts. Also fixes R6/P2: checkpointed pending IDs let Run.resume recognize a non-current member’s interrupt map without extra reads. The new real SDK tests cover either partial order, both decisions, fresh/in-memory resume, and completed direct effects beside direct/event approvals. Boundary checks, typecheck, and lint passed; final focused checks/build are running alongside CI. Fresh exact-head independent review follows.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Independent review completed at head 48c821f: no findings. R1–R6 remain fixed or already covered; no rejected findings. All 683 focused tests, SDK typecheck, touched-file lint, and build passed. CI: 12 passed; Anthropic summarization is running. Reviewer verification was source-only. Full local suite, live-provider tests, and real Langfuse inspection were not run. No publication or LibreChat dependency/UI change.

@danny-avila

Copy link
Copy Markdown
Collaborator

@codex review the latest head, final review

@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: 48c821fc3e

ℹ️ 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 thread src/tools/subagent/SubagentExecutor.ts Outdated
maxTurns: config.maxTurns,
entry: config.entryAgentId,
result: config.resultAgentId,
edges: config.edges,

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 Bind functional edge prompts to the resume identity

When a graph uses a function-valued edge.prompt and a rebuilt run supplies a different callback without changing the optional configId, both definitions receive the same fingerprint: stableStringify ultimately applies JSON.stringify to the function, which yields undefined. The pending approval is therefore accepted even though the resumed graph can invoke different prompt logic after executing the approved tools. Require a stable revision for functional prompts or otherwise incorporate their executable identity into the compatibility check.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3cc511a. Foreground HITL graphs with function-valued edge prompts require a host configId revision before child execution. The fingerprint distinguishes callback and static prompts. Tests cover changed revisions, unchanged rebuilt callbacks, prompt-kind changes, and non-HITL backwards compatibility.

const member = childPlan.memberInputs.get(agentId);
if (member == null) throw new Error('Unknown subagent context member.');
member.codeSessionKey = sessions.codeSessionKey;
member.initialSessions = sessions.initialSessions;

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 resumed session state consistently across rebuilds

When prepare() returns different initialSessions on resume while keeping the same codeSessionKey, this assignment accepts the new seed, but its effect depends on whether the child graph remained in memory. seedChildGraphSessions merges newly returned files into a cached paused graph, whereas a rebuilt graph is seeded and then restoreSubagentResumeState clears those sessions and restores the checkpoint snapshot, discarding the same files. Consequently, the identical approval resume can execute a code tool with different file grants depending on whether the process rebuilt the Run; reject changed session seeds or apply refreshed authorization after checkpoint restoration consistently.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3cc511a. Current host-authorized initial session seeds are merged after checkpoint restoration, consistently for cached and rebuilt children. Existing execution sessions and generated files remain authoritative; fresh file refs deduplicate by storage identity. Direct/event tests verify identical injected grants and untouched host maps.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Head 3cc511a: fixes Codex R7/P2 (functional prompt revision binding) and R8/P2 (consistent refreshed session grants). All 692 focused tests across 21 suites, SDK typecheck, PR-touched-file lint, and build passed. New exact-head independent review and CI follow.

@lia-by-librechat

Copy link
Copy Markdown
Contributor Author

Independent review completed at 3cc511a: no findings. Codex R7/P2 and R8/P2 are fixed; all earlier findings remain resolved. Local verification: 692 focused tests, SDK typecheck, touched-file lint, and build passed. CI: 9 queued, 4 success. Source-only independent review. Full local suite, live-provider tests, and real Langfuse inspection were not run.

@danny-avila

Copy link
Copy Markdown
Collaborator

@codex review the latest head, final review

@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: 3cc511ad44

ℹ️ 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 +460 to +461
maxContextTokens: agent.maxContextTokens,
toolDefinitions: agent.toolDefinitions,

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 Include discovered tools in graph resume fingerprints

When a paused graph is rebuilt with only a member's discoveredTools changed, this projection produces the same definition ID, so the resume compatibility check accepts it. AgentContext.fromConfig seeds those names into discoveredToolNames, which controls whether deferred registry tools are bound to subsequent model calls; therefore a resume can continue with newly exposed capabilities instead of failing closed like registry and tool-schema changes. Include a normalized discoveredTools set in the member fingerprint.

Useful? React with 👍 / 👎.

Comment on lines +2112 to +2114
pendingInterruptIds: [...new Set(activeRun.pendingInterrupts.flatMap(
(pending) => pending.id == null ? [] : [pending.id]
))],

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 Expose every pending member interrupt payload

When multiple graph members pause in the same superstep, this manifest records only their interrupt IDs. Run still retains only interrupts[0], and getInterrupt() strips the private manifest, so a public caller cannot see the proposal or allowed decisions associated with the remaining IDs and therefore cannot safely construct the supported multi-ID resume map without reading the checkpointer directly, as the new integration tests do. Expose the pending ID/payload pairs through the public interrupt result rather than persisting IDs alone.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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