Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions crates/webcodex-tool-contracts/src/registry/output_schemas/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,177 @@ use super::common::{
validation_delta_schema, wrapped_output_schema,
};

fn session_handoff_goal_context_schema() -> Value {
let nullable = |schema: Value| json!({"anyOf": [schema, {"type": "null"}]});
let excerpt = |max_length: usize, description: &str| {
json!({
"type": "object",
"description": description,
"additionalProperties": false,
"properties": {
"excerpt": nullable(json!({"type": "string", "maxLength": max_length})),
"truncated": {"type": "boolean"}
},
"required": ["excerpt", "truncated"]
})
};
let candidate = json!({
"type": "object",
"additionalProperties": false,
"properties": {
"goal_id": {"type": "string", "maxLength": 128},
"title": {"type": "string", "maxLength": 256},
"title_truncated": {"type": "boolean"},
"lifecycle": {"type": "string", "const": "active"},
"revision": {"type": "integer", "minimum": 1}
},
"required": ["goal_id", "title", "title_truncated", "lifecycle", "revision"]
});
let condition_list = json!({
"type": "object",
"additionalProperties": false,
"properties": {
"items": {
"type": "array",
"maxItems": 8,
"items": {"type": "string", "maxLength": 256}
},
"total": {"type": "integer", "minimum": 0},
"returned": {"type": "integer", "minimum": 0, "maximum": 8},
"truncated": {"type": "boolean"},
"content_truncated": {"type": "boolean"}
},
"required": ["items", "total", "returned", "truncated", "content_truncated"]
});
let step_list = json!({
"type": "object",
"additionalProperties": false,
"properties": {
"items": {
"type": "array",
"maxItems": 32,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {"type": "string", "maxLength": 32},
"title": {"type": "string", "maxLength": 128},
"title_truncated": {"type": "boolean"},
"status": {"type": "string", "enum": ["pending", "in_progress", "completed"]}
},
"required": ["id", "title", "title_truncated", "status"]
}
},
"total": {"type": "integer", "minimum": 0},
"returned": {"type": "integer", "minimum": 0, "maximum": 32},
"truncated": {"type": "boolean"}
},
"required": ["items", "total", "returned", "truncated"]
});
let goal = json!({
"type": "object",
"description": "One exact caller-owned active Goal already explicitly correlated to the recovered Workflow Session. This is read-only recovery context and grants no authority.",
"additionalProperties": false,
"properties": {
"goal_id": {"type": "string", "maxLength": 128},
"title": {"type": "string", "maxLength": 256},
"title_truncated": {"type": "boolean"},
"lifecycle": {"type": "string", "const": "active"},
"revision": {"type": "integer", "minimum": 1},
"objective": excerpt(1024, "Bounded redacted Goal objective for recovery only."),
"plan": {
"type": "object",
"additionalProperties": false,
"properties": {
"completion_conditions": condition_list,
"steps": step_list,
"current_step_id": nullable(json!({"type": "string", "maxLength": 32})),
"checkpoint": {
"type": "object",
"additionalProperties": false,
"properties": {
"summary": excerpt(512, "Bounded latest Goal checkpoint/progress summary."),
"at_unix_ms": nullable(json!({"type": "integer"}))
},
"required": ["summary", "at_unix_ms"]
}
},
"required": ["completion_conditions", "steps", "current_step_id", "checkpoint"]
}
},
"required": [
"goal_id", "title", "title_truncated", "lifecycle", "revision",
"objective", "plan"
]
});

json!({
"type": "object",
"description": "Optional read-only durable Goal recovery context selected only through an existing explicit Workflow Session correlation. Zero correlated active Goals omit this field; multiple active Goals remain selection_required and never expose one Goal as selected.",
"additionalProperties": false,
"properties": {
"version": {"type": "integer", "const": 1},
"source": {"type": "string", "const": "explicit_workflow_session_correlation"},
"status": {"type": "string", "enum": ["available", "selection_required", "unavailable"]},
"reason_code": nullable(json!({
"type": "string",
"enum": ["multiple_active_goals", "store_unavailable"]
})),
"truncated": {"type": "boolean"},
"goal": nullable(goal),
"candidates": {
"type": "array",
"maxItems": 8,
"items": candidate
}
},
"required": ["version", "source", "status", "reason_code", "truncated", "goal", "candidates"],
"allOf": [
{
"if": {
"properties": {"status": {"const": "available"}},
"required": ["status"]
},
"then": {
"properties": {
"reason_code": {"type": "null"},
"truncated": {"const": false},
"goal": {"not": {"type": "null"}},
"candidates": {"maxItems": 0}
}
}
},
{
"if": {
"properties": {"status": {"const": "selection_required"}},
"required": ["status"]
},
"then": {
"properties": {
"reason_code": {"const": "multiple_active_goals"},
"goal": {"type": "null"},
"candidates": {"minItems": 2}
}
}
},
{
"if": {
"properties": {"status": {"const": "unavailable"}},
"required": ["status"]
},
"then": {
"properties": {
"reason_code": {"const": "store_unavailable"},
"truncated": {"const": false},
"goal": {"type": "null"},
"candidates": {"maxItems": 0}
}
}
}
]
})
}

pub(super) fn output_schema_for_tool(name: &str) -> Option<Value> {
match name {
"record_external_observation" => Some(wrapped_output_schema(vec![
Expand Down Expand Up @@ -706,6 +877,10 @@ pub(super) fn output_schema_for_tool(name: &str) -> Option<Value> {
"continuation_feedback",
continuation_feedback_schema("Deterministic continuation feedback retained only in diagnostic=true handoff output. A read-only attempt summary plus validation delta over existing handoff evidence; never an LLM summary, never an Agent loop, never a new verdict, and it never re-runs validation, mutates the ledger, refreshes activity, or consumes guidance."),
),
(
"goal_context",
session_handoff_goal_context_schema(),
),
(
"handoff_brief",
handoff_brief_schema("Compact deterministic task handoff for a new window, new Agent, or human receiver. It includes a bounded read-only external_report section with explicit incomplete capture coverage, separate from native Session, validation, and Job evidence; it is not Session replay and never restores hidden model context."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ pub(super) const DEFINITIONS: &[ToolDefinition] = &[
super::ToolActivityPresentation::Support,
super::ToolActivityInteraction::Meaningful,
),
"Explicit read-only recovery for genuinely missing task context or an explicit handoff; requires the exact session_id or its returned session_ref selector. Do not use as routine progress/status polling or to establish a Session baseline when current context is coherent. Defaults to identity plus deterministic handoff_brief, hard-bounded at 8 KiB: task instructions, workspace, progress, validation, jobs, collaboration attention, bounded external reports, next actions and basis completeness. External reports retain exact source IDs and unknown outcomes, with incomplete capture coverage; they are not native execution or validation. Omitted project uses the authorized Session Project. diagnostic=true adds detailed ledger and closeout evidence. A concurrent Session change marks the basis incomplete; re-observe before dependent work. No checkpoint allocation, ACK token, or authority grant.",
).with_gpt_action_description("Recover missing task context or perform an explicit handoff for the exact session_id or returned session_ref. Avoid routine status polling or baseline creation. Returns bounded handoff_brief; diagnostic=true adds evidence. Check basis completeness before dependent work. Read-only.")),
"Explicit read-only recovery for missing task context or an explicit handoff; requires exact session_id/session_ref and is not routine status polling. Returns deterministic 8 KiB handoff_brief with task, workspace, progress, validation, Jobs, collaboration/external-report evidence, next actions and basis completeness. If the same owner has active Goals explicitly correlated to the Session, optional bounded goal_context is returned separately: zero omit it and multiple remain selection_required. Goal context is read-only: no inference, Goal mutation, liveness refresh, scheduling or authority grant. External reports retain unknown outcomes/incomplete coverage and are not native execution/validation. Omitted project uses the authorized Session Project; diagnostic=true adds ledger/closeout evidence. Concurrent Session change makes basis incomplete; re-observe before dependent work.",
).with_gpt_action_description("Recover missing task context or perform an explicit handoff for the exact session_id or returned session_ref. Avoid routine status polling or baseline creation. Returns bounded handoff_brief plus optional read-only goal_context only from an existing explicit Session↔Goal correlation; multiple Goals remain unselected. diagnostic=true adds evidence. Check basis completeness before dependent work. Read-only.")),
16,
),
requires_explicit_business_session(
Expand Down
8 changes: 8 additions & 0 deletions docs/agent/goal-workflow-continuity-dogfood.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ projection is not evidence that the Session has no active Goal. This normal re-e
path prevents a new model turn from creating a duplicate Goal merely because it lost
the earlier Goal identity.

Explicit `session_handoff_summary` recovery follows the same identity boundary but may
return a richer bounded sibling `goal_context` for an already-correlated active Goal:
Goal identity/lifecycle/revision, objective, current plan and checkpoint context. Zero
active correlations omit it; multiple active correlations remain `selection_required`
and expose only candidate identities until a caller chooses explicitly. This recovery
read never establishes a new correlation, refreshes Goal liveness, records Goal
progress, schedules continuation, or grants Goal/Session/Project authority.

Use `checkpoint_goal` at recoverable milestones: exact Goal revision and idempotency
key, atomic completed-step ids and optional current step, and a bounded recovery
summary. Complete all steps and freshly verify/review before explicitly completing
Expand Down
16 changes: 13 additions & 3 deletions integrations/codex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This integration records bounded **external reports** in an explicitly selected
WebCodex Workflow Session. It does not install Hooks, change trust, create a
Session/Goal, execute commands, or migrate a conversation. The Server now projects
these claims read-only in `session_handoff_summary`. The optional read-only local
consumer and optional automatic entry below can inspect that brief; export and
Goal linkage remain follow-up work. This does not establish real
two-sided UI acceptance.
consumer and optional automatic entry below can inspect that brief and the optional
read-only Goal recovery context described below; export remains follow-up work. This
does not establish real two-sided UI acceptance.

## Server contract

Expand Down Expand Up @@ -134,6 +134,16 @@ unknown operations before continuing. The command does not select a Session by
directory or recency, bind the new local conversation, mark work complete, replay
an operation, install a Hook, or write a handoff file.

When the exact Workflow Session already has one caller-owned active Goal linked by an
explicit Workflow Session↔Goal correlation, the Server may also return sibling
`goal_context`. This projection is separate from the 8 KiB `handoff_brief` and contains
bounded Goal identity/lifecycle/revision, objective, current plan and checkpoint
context. Zero correlated active Goals omit it. Multiple active Goals return only a
bounded `selection_required` candidate set and never choose or expose one Goal as the
default. Reading this context does not create or associate a Goal, checkpoint/update/
complete progress, refresh Goal liveness, schedule work, or grant Goal/Session/Project
authority.

`read_handoff.py` itself remains a deliberate recovery command.
It requires an already selected Workflow Session and the normal authorized
credential; a new local Codex conversation must not inherit an old conversation's
Expand Down
Loading
Loading