Skip to content

Expose enableOnDemandInstructionDiscovery across all SDK SessionConfig types#1323

Merged
stephentoub merged 4 commits into
mainfrom
tmeszaros/sdk-on-demand-instruction-discovery
May 29, 2026
Merged

Expose enableOnDemandInstructionDiscovery across all SDK SessionConfig types#1323
stephentoub merged 4 commits into
mainfrom
tmeszaros/sdk-on-demand-instruction-discovery

Conversation

@examon
Copy link
Copy Markdown
Contributor

@examon examon commented May 18, 2026

Exposes the new enableOnDemandInstructionDiscovery configuration flag across all five in-repo SDKs (Node, Python, Go, .NET, Rust). Mirrors the precedent set by #1044 (enableConfigDiscovery) and #1295 (remoteSession).

The runtime change shipped in github/copilot#7759 and is available in @github/copilot@^1.0.49-1.

Cross-language consistency matrix

SDK Public field Wire key Create Resume Unset behavior Explicit-false behavior
Node enableOnDemandInstructionDiscovery?: boolean enableOnDemandInstructionDiscovery omitted wire false
Python enable_on_demand_instruction_discovery: bool | None = None enableOnDemandInstructionDiscovery omitted wire false
Go EnableOnDemandInstructionDiscovery *bool enableOnDemandInstructionDiscovery omitted (nil) wire false
.NET bool? EnableOnDemandInstructionDiscovery enableOnDemandInstructionDiscovery omitted (null) wire false
Rust enable_on_demand_instruction_discovery: Option<bool> enableOnDemandInstructionDiscovery omitted (None) wire false

Runtime-gated availability

When set to true, the SDK asks the runtime to discover custom instruction files on demand after the agent successfully reads or views files. The option is runtime-gated: it takes effect only when custom instructions are enabled and the connected runtime supports and enables on-demand custom instruction discovery. Otherwise the runtime accepts the option but performs no on-demand discovery (silent no-op, no error or warning).

The SDK does not attempt to detect runtime gating; it forwards the option unconditionally. On session.resume, omitting the option leaves the existing session setting unchanged, and passing an explicit false disables future on-demand discovery for that resumed session.

Trust and security

Enable only for trusted repositories or workspaces. Discovered instruction files are treated as model instructions, may affect agent behavior, and may be stored or replayed with session history. Do not enable for untrusted content, CI jobs processing untrusted forks, or directories writable by untrusted users or processes.

Go shape

Uses *bool (not bool) on both SessionConfig and ResumeSessionConfig so callers can disable a previously-enabled session on resume. Reuses the precedent already set by EnableSessionTelemetry *bool and IncludeSubAgentStreamingEvents *bool. This PR does not retrofit the existing EnableConfigDiscovery bool field — that would be a separate breaking source change with broader blast radius.

Tests

Each SDK adds tests for the new field on both session.create and session.resume, asserting that explicit false is serialized on the wire and that omission drops the key entirely. Mirrors the test patterns already in place for enable_session_telemetry, include_sub_agent_streaming_events, and enable_config_discovery.

  • Node: extends nodejs/test/e2e/client_options.e2e.test.ts happy-path; adds 2 unit tests in nodejs/test/client.test.ts (create + resume, explicit false).
  • Python: extends python/e2e/test_client_options_e2e.py happy-path; adds 2 unit tests in python/test_client.py (create + resume, explicit False).
  • Go: extends go/internal/e2e/client_options_e2e_test.go happy-path; adds 6 wire-format unit tests in go/client_test.go (create + resume; Bool(true), Bool(false), and omitted).
  • .NET: adds 2 serialization tests in dotnet/test/Unit/SerializationTests.cs (create + resume; true, false, omitted) and 4 clone tests in dotnet/test/Unit/CloneTests.cs covering the copy-ctor.
  • Rust: adds 2 wire-format tests in rust/tests/session_test.rs (create + resume; Some(true), Some(false), omitted) and extends the existing builder unit-tests in rust/src/types.rs to call the new .with_enable_on_demand_instruction_discovery(...) method on both SessionConfig and ResumeSessionConfig.

Documentation

The new field is documented inline in each SDK's typed config surface using the language-appropriate doc-comment style (JSDoc, Google-style, godoc, XML, Rustdoc). README and CHANGELOG are intentionally not updated, matching the precedent of #1044 and #1295.

Notes for reviewers

  • go/types.go shows ~170 line changes; the bulk is gofmt-driven struct-tag column re-alignment because the new field name is longer than any existing field. The only semantic changes are the additions of EnableOnDemandInstructionDiscovery to SessionConfig, ResumeSessionConfig, and the two wire-request structs.
  • The existing enableConfigDiscovery docstring statement that custom instruction files "are always loaded from the working directory regardless of this setting" remains accurate — the new option adds on-demand discovery on top of the up-front load; it does not replace it.
  • python/copilot/session.py TypedDicts do not include the new field. They are also missing existing fields (enable_config_discovery, remote_session); closing those gaps is best handled in a follow-up so this PR stays narrow.

Copilot AI review requested due to automatic review settings May 18, 2026 16:55
@examon examon requested a review from a team as a code owner May 18, 2026 16:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new session configuration flag (enableOnDemandInstructionDiscovery) across the in-repo SDKs so consumers can opt into (or explicitly disable) runtime on-demand custom-instruction discovery via the JSON-RPC wire key enableOnDemandInstructionDiscovery.

Changes:

  • Exposes the new flag on SessionConfig + ResumeSessionConfig surfaces (and forwards it on session.create/session.resume) for Node, Python, Go, .NET, and Rust.
  • Adds/extends unit + E2E coverage to verify true/false serialization and key omission when unset.
  • Adds inline API documentation for the new option in each language’s config surface.
Show a summary per file
File Description
rust/tests/session_test.rs Adds serde wire-format tests for enableOnDemandInstructionDiscovery on SessionConfig/ResumeSessionConfig.
rust/src/types.rs Adds enable_on_demand_instruction_discovery: Option<bool> + builder methods + debug/default updates and unit-test coverage.
python/test_client.py Adds forwarding tests ensuring explicit False is sent on create/resume.
python/e2e/test_client_options_e2e.py Extends E2E options propagation test to include the new flag.
python/copilot/client.py Adds new kwargs to create/resume APIs, docs, and wire payload serialization.
nodejs/test/e2e/client_options.e2e.test.ts Extends E2E options propagation test to assert the new flag is present.
nodejs/test/client.test.ts Adds unit tests verifying forwarding on session.create and session.resume.
nodejs/src/types.ts Adds enableOnDemandInstructionDiscovery?: boolean to SessionConfig and includes it in ResumeSessionConfig pick.
nodejs/src/client.ts Forwards the new flag in create/resume request payloads.
go/types.go Adds *bool config fields and wires them into create/resume request structs (plus gofmt alignment).
go/internal/e2e/client_options_e2e_test.go Extends Go E2E options propagation assertions to include the new flag.
go/client.go Forwards EnableOnDemandInstructionDiscovery into create/resume wire requests.
go/client_test.go Adds wire-format unit tests for explicit true/false and omission behavior.
dotnet/test/Unit/SerializationTests.cs Adds serialization tests validating true/false/omitted behavior for create/resume requests.
dotnet/test/Unit/CloneTests.cs Ensures SessionConfig/ResumeSessionConfig clone operations copy/preserve the new nullable property.
dotnet/src/Types.cs Adds bool? EnableOnDemandInstructionDiscovery to SessionConfig/ResumeSessionConfig and copies it in clone constructors.
dotnet/src/Client.cs Threads the new option through Create/Resume request construction and record types.

Copilot's findings

  • Files reviewed: 17/17 changed files
  • Comments generated: 2

Comment thread python/copilot/client.py Outdated
Comment thread go/types.go Outdated
@github-actions

This comment has been minimized.

Tomas Meszaros and others added 2 commits May 19, 2026 14:24
Mirrors the existing enableConfigDiscovery and remoteSession precedents
(PRs #1044 and #1295). Exposes the SDK option that lets the runtime
discover custom instruction files on demand after the agent reads or
views files, complementing the existing up-front load of
`.github/copilot-instructions.md`, `AGENTS.md`, etc.

Wire key (camelCase, identical across all 5 SDKs):
  enableOnDemandInstructionDiscovery

Type shapes:
  Node    enableOnDemandInstructionDiscovery?: boolean
  Python  enable_on_demand_instruction_discovery: bool | None = None
  Go      EnableOnDemandInstructionDiscovery *bool
  .NET    bool? EnableOnDemandInstructionDiscovery
  Rust    Option<bool> with #[serde(skip_serializing_if = "Option::is_none")]

Wire semantics: when set, the wire payload carries the literal value
(including explicit `false`); when omitted, the key is dropped.
Applies to both session.create and session.resume so callers can
toggle the setting on a resumed session.

Runtime-gated. The runtime honors the option only when custom
instructions are enabled and the connected runtime supports on-demand
custom instruction discovery; otherwise the option is accepted but
no-ops. The SDK does not attempt to detect the runtime gate. Requires
@github/copilot ^1.0.49-1 (the runtime change shipped in
github/copilot#7759).

Security: discovered instruction files are treated as model
instructions and may be stored or replayed with session history.
Docstrings caution against enabling for untrusted content, CI jobs
processing untrusted forks, or directories writable by untrusted
users or processes.

Go shape note: uses *bool (not bool) so consumers can disable a
previously-enabled session on resume. Reuses the precedent already
set by EnableSessionTelemetry *bool and IncludeSubAgentStreamingEvents
*bool. Does not retrofit the existing EnableConfigDiscovery bool field
(that would be a separate breaking source change).

Tests: each SDK adds tests for the new field on both create and
resume, asserting that explicit `false` is serialized as `false` and
that omission drops the key from the payload. Mirrors the test
patterns already in place for enable_session_telemetry,
include_sub_agent_streaming_events, and enable_config_discovery.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addresses review feedback on PR #1323: the create-session API docs for
enable_on_demand_instruction_discovery / EnableOnDemandInstructionDiscovery
should not include resume-specific behavior. That note already lives on
the resume-side configs (Python resume_session and Go ResumeSessionConfig).
@examon examon force-pushed the tmeszaros/sdk-on-demand-instruction-discovery branch from 07bfd0a to e9e961a Compare May 19, 2026 14:28
@github-actions

This comment has been minimized.

Comment thread dotnet/src/Types.cs Outdated
public bool? EnableConfigDiscovery { get; set; }

/// <summary>
/// When <see langword="true"/>, requests on-demand discovery of custom instruction
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What does "on-demand discovery" actually mean? Demanded by what / when, discovered where, etc.

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.

@stephentoub thanks for feedback. I improved the docs so they explain how the on-demand discovery works and how the customer instructions are injected into the context 8586e6a

Explain the concrete discovery mechanic (directory walk from the accessed
file up to the repo root, applyTo glob filtering, once-per-session delivery)
and align the runtime-gating and security wording across all five SDKs.

Addresses review feedback on PR #1323.
@stephentoub stephentoub self-assigned this May 29, 2026
…nd-instruction-discovery

# Conflicts:
#	dotnet/src/Client.cs
#	dotnet/src/Types.cs
#	dotnet/test/Unit/CloneTests.cs
#	dotnet/test/Unit/SerializationTests.cs
#	go/client.go
#	go/types.go
#	nodejs/src/client.ts
#	nodejs/src/types.ts
#	python/copilot/client.py
#	rust/src/types.rs
@examon
Copy link
Copy Markdown
Contributor Author

examon commented May 29, 2026

Resolved the merge conflicts by merging latest main.

Heads up for reviewers: the enableOnDemandInstructionDiscovery implementation already landed independently in #1474 ("granular per-session flags for multitenancy hardening") across all five SDKs (public field + wire serialization on create/resume). I resolved every conflict by taking main's implementation, so all production source files are now byte-identical to main.

As a result, the remaining diff of this branch against main is test-only regression coverage:

  • Node/Python/Go/.NET: added create/resume serialization + clone tests for the flag (kept alongside the tests main added at the same spots).
  • Rust: main made SessionConfig/ResumeSessionConfig non-Serialize and moved wire conversion to the crate-private into_wire, so the original integration tests that called serde_json::to_value(&config) no longer compile. I relocated that wire-format coverage into the in-crate *_into_wire_serializes_bucket_b_fields unit tests and kept the builder-method assertions.

Verified locally: Rust (lib + session integration), Node (field tests + full typecheck), Python (field tests), and .NET (Clone/Serialization suites) all pass; go vet and the Go unit tests pass.

Since the implementation is now superseded by #1474, this PR is effectively test-only. Maintainers may want to either merge it for the added regression coverage or close it as superseded.

@github-actions
Copy link
Copy Markdown
Contributor

SDK Consistency Review ✅

This PR adds enableOnDemandInstructionDiscovery consistently across Node.js, Python, Go, .NET, and Rust. The cross-language consistency matrix in the PR description confirms aligned behavior across all five SDKs.

Java SDK: Not included in this PR, but the Java SDK (java/src/main/java/com/github/copilot/rpc/SessionConfig.java and ResumeSessionConfig.java) already has enableOnDemandInstructionDiscovery with getter/setter/clear methods and copy-constructor support — so Java is already in parity.

No cross-SDK consistency issues found. 🎉

Generated by SDK Consistency Review Agent for issue #1323 · ● 3M ·

Copy link
Copy Markdown
Collaborator

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

3 participants