Skip to content

RFC: Handoff session rollover - #1783

Open
AlexStocks wants to merge 14 commits into
oceanbase:masterfrom
AlexStocks:codex/handoff-session-rollover-rfc
Open

AlexStocks wants to merge 14 commits into
oceanbase:masterfrom
AlexStocks:codex/handoff-session-rollover-rfc

Conversation

@AlexStocks

@AlexStocks AlexStocks commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Which issue or RFC does this PR close?

No tracking issue is assigned. This PR proposes RFC #1783 and includes the initial compatible Handoff implementation.

Rationale for this change

Long Agent sessions can accumulate stale assumptions, noisy context, and compaction loss. PowerContext already has Handoff as the evidence-backed work-continuity boundary, so this PR treats long-session rollover as a Handoff lifecycle event rather than transcript compaction, a new Notes family, or automatic Memory creation.

The implementation follows the RFC's compatibility constraint: rollover reasons are advisory preparation inputs. They can guide draft generation toward a fresh-session checkpoint, but they do not become committed Handoff content identity, do not authorize commit or execution, and do not change Continue or Memory semantics.

What changes are included in this PR?

  • Adds the English RFC at docs/en/rfcs/1783-handoff-session-rollover.md.
  • Adds the synchronized Chinese RFC translation at docs/zh/rfcs/1783-handoff-session-rollover.md.
  • Defines Rollover Handoff scope, quality requirements, host integration levels, and boundaries with Memory, Source, PreparedContext, and provider-specific context-window behavior.
  • Adds optional rollover_reasons to Handoff prepare and activation requests.
  • Propagates rollover reasons through the existing Handoff trigger, service, and generation input path.
  • Updates Handoff generation instructions so non-empty rollover reasons ask for a fresh-session checkpoint without relying on the old transcript.
  • Regenerates checked-in HTTP models/schema from openapi/powercontext.yaml.
  • Adds tests for reason validation, service propagation, generation input exposure, and the fact that reasons are not persisted into Handoff content.

Are there any user-facing changes?

Yes. Handoff prepare and activation HTTP requests now accept optional advisory rollover_reasons values:

  • user_requested
  • host_context_budget
  • host_compaction
  • context_quality
  • delegation
  • manual_checkpoint

Existing requests remain compatible because the field defaults to an empty list.

How was this change tested?

  • uv run --no-sync pytest tests/builtin/artifacts/handoff/test_models.py tests/builtin/artifacts/handoff/test_generation.py tests/builtin/artifacts/handoff/test_service.py tests/test_api_contract.py -q
  • make contract-test
  • uv run --no-sync ruff check <changed Python files>
  • uv run --no-sync ruff format --check <changed Python files>
  • uv run --no-sync ty check --python-version 3.11 <changed Python files>
  • git diff --check
  • Verified English and Chinese RFC heading counts match: 28 headings each.

AI usage statement

Used OpenAI Codex to draft the bilingual RFC, review it against the existing Handoff implementation, implement the compatible rollover-reason path, and run local validation.

Add advisory rollover reasons to Handoff prepare and activation so hosts can request fresh-session checkpoints without changing Handoff content identity.

Constraint: reasons flow through request and generation input only; commit, continue, Memory, and Artifact identity semantics stay unchanged.

Tested: uv run --no-sync pytest tests/builtin/artifacts/handoff/test_models.py tests/builtin/artifacts/handoff/test_generation.py tests/builtin/artifacts/handoff/test_service.py tests/test_api_contract.py -q

Tested: make contract-test

Tested: uv run --no-sync ruff check <changed Python files>

Tested: uv run --no-sync ruff format --check <changed Python files>

Tested: uv run --no-sync ty check --python-version 3.11 <changed Python files>

@PsiACE PsiACE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I support using Handoff for session rollover. Since RFC 0048 already covers transfer and Continue, I suggest focusing this RFC on the host contract for window replacement and recovery.

Comment thread docs/en/rfcs/1783-handoff-session-rollover.md
Comment thread docs/en/rfcs/1783-handoff-session-rollover.md
Comment thread docs/en/rfcs/1783-handoff-session-rollover.md Outdated
Comment thread docs/en/rfcs/1783-handoff-session-rollover.md
@AlexStocks
AlexStocks requested a balanced review from Copilot and removed request for Teingi October 10, 2026 11:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Custom Handoff prompts currently bypass the fresh-session rollover generation requirement.

1 open finding
What changed in this PR

Adds RFC 1783 and initial session-rollover support through advisory Handoff preparation reasons.

Changes:

  • Defines bilingual rollover semantics and boundaries.
  • Propagates validated reasons through HTTP, triggers, and generation.
  • Adds contract and runtime tests.
File Description
docs/​en/​rfcs/​1783-handoff-session-rollover.md Defines the English RFC.
docs/​zh/​rfcs/​1783-handoff-session-rollover.md Adds the Chinese RFC translation.
openapi/​powercontext.yaml Adds rollover request fields and enum.
src/​powercontext/​http/​_generated/​models.py Adds generated request models and enum.
src/​powercontext/​http/​_generated/​schema.py Updates the generated schema.
src/​powercontext/​http/​__init__.py Exports the rollover enum.
src/​powercontext/​server/​mapping.py Maps transport reasons into runtime actions.
src/​powercontext/​builtin/​triggers/​handoff.py Forwards reasons through activation.
src/​powercontext/​builtin/​artifacts/​handoff/​models.py Defines and validates runtime reasons.
src/​powercontext/​builtin/​artifacts/​handoff/​generation.py Exposes reasons to generation.
src/​powercontext/​builtin/​artifacts/​handoff/​service.py Propagates reasons into generation requests.
src/​powercontext/​builtin/​artifacts/​handoff/​prompts.py Adds fresh-session generation guidance.
src/​powercontext/​builtin/​artifacts/​handoff/​__init__.py Exports the runtime reason type.
src/​powercontext/​builtin/​artifacts/​prompt/​builtin.py Updates Handoff prompt invariants.
tests/​test_api_contract.py Tests the public request contract.
tests/​builtin/​artifacts/​handoff/​test_models.py Tests reason validation.
tests/​builtin/​artifacts/​handoff/​test_generation.py Tests generation exposure and non-persistence.
tests/​builtin/​artifacts/​handoff/​test_service.py Tests service propagation.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/powercontext/builtin/artifacts/prompt/builtin.py
Copilot AI balanced review requested due to automatic review settings October 10, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Custom prompts miss required rollover behavior and accept demonstration inputs outside the runtime contract.

1 open finding
Previously missed (3)

In code that hasn't changed since last review

Medium severity Expose rollover_reasons in supported Handoff tool schemas

openapi/​powercontext.yaml:4703

Possible capability gap (non-blocking): the supported Pi, OpenCode, DSH, and Hermes Handoff tools still expose fixed prepare/activate argument schemas without rollover_reasons (for example, integrations/pi/plugins/powercontext/src/tools.ts:508-524,607-620 and integrations/hermes/plugins/powercontext/commands.py:731-760). Agents using those advertised Handoff surfaces therefore cannot discover or send this new input, even though the HTTP/MCP contract supports it. Update the adapters or track the missing host support explicitly.

Medium severity Validate rollover reason constraints in custom prompt demonstrations

src/​powercontext/​builtin/​artifacts/​handoff/​generation.py:59

HandoffGenerationInput is also the schema used to validate custom prompt demonstrations, but this new field does not carry the six-item or uniqueness constraints from HandoffGenerationRequest. The secondary validation in prompt/validation.py reconstructs PrepareHandoff without forwarding these reasons, so demonstrations containing duplicates or more than six reasons are accepted even though no real generation request can produce them. Mirror the request constraints here or pass this field through the demonstration validator.

Medium severity Preserve fresh-session checkpoint requirements in custom prompts

src/​powercontext/​builtin/​artifacts/​prompt/​builtin.py:176

Custom handoff.generate prompts replace the default instructions with these invariants plus scope-owned guidance. This line only says that reasons are advisory; it omits the new behavior in HANDOFF_GENERATION_INSTRUCTIONS requiring a self-contained fresh-session checkpoint. Consequently, a supported custom prompt receives rollover_reasons but is never told to avoid old-transcript references or make the first safe action explicit. Keep that conditional requirement in the invariant contract as well.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 10, 2026 12:19
@AlexStocks

Copy link
Copy Markdown
Contributor Author

CI failures on the previous head were cross-branch contract drift: master added the Dify integration, desktop contract checks, and skill-up OpenAPI validation after this branch was cut, and the PR's new rollover_reasons parameter had not been propagated to the derived artifacts.

Fixed in 4fde3a6 (on top of a master merge):

  • integrations/dify: registered rollover_reasons in generate_contract.py PARAMETERS and regenerated contract.json and both tool YAMLs (make dify-test generate step passes).
  • desktop: regenerated ui/src/generated/api.d.ts, ui/src/generated/operations.ts, and src-tauri/src/transport/operations.json with the pinned generator versions (openapi-typescript 7.13.0 / yaml 2.9.0); generate.mjs --check passes.
  • evaluation/skills/skill-up: refreshed the tool argument reference via validate_suite.py --write-tool-contract; the suite passes.

Preserve fresh-session rollover rules for custom Handoff Prompts and correct Dify Chinese labels.

Constraint: Rollover reasons remain advisory preparation context only.

Scope-risk: Host adapter parity is tracked in oceanbase#1931 rather than included in this RFC PR.

Tested: targeted Python and Dify regression tests; Dify generation; Ruff; ty.
Copilot AI balanced review requested due to automatic review settings October 11, 2026 03:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The default Auto generation prompt omits the advisory non-content constraint applied to custom prompts.

1 open finding
3 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Add advisory-only rule to v2 default handoff instructions

src/​powercontext/​builtin/​artifacts/​handoff/​prompts.py:30

The Auto selection uses only HANDOFF_GENERATION_INSTRUCTIONS (definitions.py:111-112), so it does not receive the advisory-only rule added to the custom-prompt invariants. This leaves the default generator free to present a rollover reason as committed Handoff content, contrary to the RFC compatibility constraint. Include the same advisory/non-content rule in the v2 default instructions.

🧠 Review effort: Balanced

@knqiufan knqiufan left a comment

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.

Reviewed commit 1508074 using Open Code Review and a public API reproduction. One reproducible contract violation remains in custom handoff.generate demonstration validation; please address the inline finding before merging.

Comment thread src/powercontext/builtin/artifacts/handoff/generation.py Outdated

@hidb4ai hidb4ai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Constraint: Keep rollover_reasons bounded to six unique advisory values across runtime requests and custom Prompt demonstrations.
Scope-risk: Limits only generation-input validation and aligns Auto instructions with the existing custom Prompt invariant; no committed Handoff content changes.
Tested: python -m pytest tests/builtin/artifacts/prompt/test_prompt_validation.py tests/builtin/artifacts/prompt/test_prompt_content.py tests/builtin/artifacts/handoff/test_generation.py -q; python -m ruff check src/powercontext/builtin/artifacts/handoff/generation.py src/powercontext/builtin/artifacts/handoff/prompts.py tests/builtin/artifacts/prompt/test_prompt_validation.py tests/builtin/artifacts/prompt/test_prompt_content.py; python -m ruff format --check src/powercontext/builtin/artifacts/handoff/generation.py src/powercontext/builtin/artifacts/handoff/prompts.py tests/builtin/artifacts/prompt/test_prompt_validation.py tests/builtin/artifacts/prompt/test_prompt_content.py; python -m ty check --python .venv-py311 src/powercontext/builtin/artifacts/handoff/generation.py src/powercontext/builtin/artifacts/handoff/prompts.py tests/builtin/artifacts/prompt/test_prompt_validation.py tests/builtin/artifacts/prompt/test_prompt_content.py
Copilot AI balanced review requested due to automatic review settings October 11, 2026 05:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The advisory input is consistently validated, propagated, documented, tested, and excluded from durable Handoff identity.

1 open finding

🧠 Review effort: Balanced

…-review

# Conflicts:
#	desktop/src-tauri/src/transport/operations.json
#	desktop/ui/src/generated/operations.ts
Copilot AI balanced review requested due to automatic review settings October 11, 2026 11:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@AlexStocks AlexStocks added 1.4.0 v1.4.0 release tracking and removed 1.3.0 labels Oct 11, 2026
Deterministic validation for rollover drafts (RFC 1783 quality requirements):
reject generated drafts that omit the next action without disposition
complete, and reject transcript-dependent wording. Rollover reasons stay
preparation context: they never change content identity, so commit
idempotency and CAS semantics are unchanged.
Copilot AI balanced review requested due to automatic review settings October 12, 2026 04:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Expose the advisory rollout reasons on Pi, OpenCode, DSH, and Hermes Handoff prepare and activate tools, while omitting the field for existing callers that do not supply it. Regenerate the checked-in OpenCode and DSH package outputs and cover each host boundary.

Constraint: rollover reasons remain optional preparation context and do not change Handoff content identity or commit semantics.

Scope-risk: automatic rollover policy, context-pressure detection, and provider window control remain out of scope.

Tested: pnpm --dir integrations/pi/plugins/powercontext test -- tests/tools.spec.ts; pnpm --dir integrations/opencode/plugins/powercontext test -- tests/plugin.spec.ts; pnpm --dir integrations/dsh/plugins/powercontext test -- tests/tools.spec.ts; uv run --no-sync pytest tests/builtin/artifacts/handoff/test_models.py tests/builtin/artifacts/handoff/test_generation.py tests/builtin/artifacts/handoff/test_service.py tests/builtin/artifacts/prompt/test_prompt_content.py tests/builtin/artifacts/prompt/test_prompt_validation.py tests/test_api_contract.py tests/integrations/test_hermes_provider.py -q; pnpm --dir integrations/pi/plugins/powercontext typecheck; pnpm --dir integrations/opencode/plugins/powercontext typecheck; pnpm --dir integrations/opencode/plugins/powercontext build; pnpm --dir integrations/dsh/plugins/powercontext build; uv run --no-sync ruff check integrations/hermes/plugins/powercontext/commands.py tests/integrations/test_hermes_provider.py; uv run --no-sync ruff format --check integrations/hermes/plugins/powercontext/commands.py tests/integrations/test_hermes_provider.py; uv run --no-sync ty check --python-version 3.11 integrations/hermes/plugins/powercontext/commands.py tests/integrations/test_hermes_provider.py; git diff --check
Copilot AI balanced review requested due to automatic review settings October 12, 2026 05:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Remove the maxItems constraint from DSH rollover reason schemas because the host value-schema DSL rejects it during plugin loading. Retain the array and enum constraints in the adapter; the API contract remains authoritative for the six-item limit.

Constraint: rollover reasons remain optional, advisory preparation input; the server continues to enforce its public request limit.

Scope-risk: this only restores DSH runtime compatibility and does not add automatic rollover policy or change Handoff content identity.

Tested: pnpm.cmd --dir integrations/dsh/plugins/powercontext test; pnpm.cmd --dir integrations/dsh/plugins/powercontext build; node --test --test-concurrency=1 --test-name-pattern 'documented setup installs the matched plugin' runtime.test.mjs; git diff --check
Copilot AI balanced review requested due to automatic review settings October 12, 2026 05:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Reject rollover drafts whose next action depends on the old session through continue-above wording. This preserves the RFC fresh-session quality floor.

Constraint: rollover reasons remain advisory preparation input and do not change Handoff identity or commit semantics.

Scope-risk: no host rollover policy, session-window control, or durable content behavior changes.

Tested: uv run --no-sync pytest tests/builtin/artifacts/handoff/test_models.py tests/builtin/artifacts/handoff/test_generation.py tests/builtin/artifacts/handoff/test_service.py tests/builtin/artifacts/prompt/test_prompt_content.py tests/builtin/artifacts/prompt/test_prompt_validation.py tests/test_api_contract.py -q (175 passed); uv run --no-sync ruff check src/powercontext/builtin/artifacts/handoff/service.py tests/builtin/artifacts/handoff/test_service.py; uv run --no-sync ruff format --check src/powercontext/builtin/artifacts/handoff/service.py tests/builtin/artifacts/handoff/test_service.py; uv run --no-sync ty check --python-version 3.11 src/powercontext/builtin/artifacts/handoff/service.py tests/builtin/artifacts/handoff/test_service.py; git diff --check
Copilot AI balanced review requested due to automatic review settings October 12, 2026 07:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

1.4.0 v1.4.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants