fix(session): preserve identity and stable instructions across headless resume - #926
fix(session): preserve identity and stable instructions across headless resume#926breedx wants to merge 7 commits into
Conversation
…nflicting initialization
Persist durable body, rules and model preparation in message metadata. Keep temporary policy outside the frozen prefix and share preparation across first turns and subagents. Invalidate cached agents when restored durable state changes.
…ural-prompt-prefix
…nstructions Keep ordinary resume frozen, but let /cd intentionally rebuild the durable project contract without dropping history or identity. Read stored prepared system text for compaction and context accounting; avoid replaying live hooks or double-counting rules.
|
The new resume regressions pass in upstream CI, but the full suite hits an existing midnight-sensitive session-browser assertion. I reproduced the same failure on unpatched
The CI test environment is Python 3.14.7 despite its 3.13 label; local controls were Python 3.13.13. Deprecation/resource/coroutine warnings were inspected, but not all CI warnings have independent base controls. The full suite is not claimed green. #926 remains a dependent draft awaiting #925 acceptance and subsequent requalification. |
|
Consolidated the identity and structural-prefix proposals here so reviewers can evaluate reliable headless resume in one place. #925 is now closed as superseded; there is no longer a separate prerequisite PR. The head remains aeef90c and all seven commits are unchanged. This PR is ready for review, not a claim of green CI: the previously documented midnight-sensitive session-browser assertion remains the only recorded full-suite failure. |
Resuming a saved headless conversation should preserve both the agent's identity and its durable instructions. Restore them together from structured message metadata so fresh processes continue the same conversation without rebuilding the prompt from changing hooks or rules, while temporary runtime instructions still expire.
Related upstream work
AssembledInstructionsas a delivery capability. This proposal determines which durable instructions are restored and reused, not the delivery mechanism. Constructor/subagent seams overlap; reconcile them if refactor: promote system-prompt delivery to an AssembledInstructions capability #832 lands first. It is not an assumed dependency.PromptPreparation. The first-turn/subagent preparation paths overlap; preserve the durable/temporary boundary and saved preparation when integrating. Its capability refactor is not bundled here.BaseAgent.iddoes not equate it with every hook run/session ID or implement that propagation.Change
Conversation identity
ModelRequest.metadata, preserving unrelated metadata.set_message_history: a saved ID wins over a random process default; conflicting explicit identities fail before replacing active history./quick-resumeand/load_contexterror boundaries, with tests for the interactive picker boundary too.Durable prompt prefix
/cdrefreshes the project's durable contract without discarding history or identity; ordinary resume remains frozen.The existing command changes correct load-error handling and explicit project transitions, not new CLI functionality. Given the plugin-first guidance, please coordinate the preferred supported seams before landing, particularly with #832/#839.
Review structure
The existing seven commits remain intact, with no new code introduced by this consolidation. Review identity through
f119b757, then the incremental prefix rangef119b757..aeef90cc. The latter includes the structural prefix implementation and the reviewed project-transition/accounting correction. The combined head remainsaeef90cc, targetingmainfrom basece1fe372(0.0.827).Validation
Local qualification used Linux / Python 3.13.13 and unchanged upstream dependencies in a dedicated environment. HOME/XDG were disposable, no credentials inherited, and socket connect/DNS/bind blocked, including subprocess fixtures. Model calls use local Pydantic
FunctionModelfixtures./cdand live-hook accounting that underestimated saved instructions. Both added regressions fail before correction and pass at the reviewed head.TODAYassertion, reproduced on unpatched upstream.Current CI evidence
On the unchanged combined head, quality and Windows encoding checks passed. The full macOS job reported 7,871 passed, 1 failed, 14 skipped, 28 warnings. Its only failure is
test_open_project_and_select_session: the fixture subtracts one/two hours from the current time, then requiresTODAY, which fails immediately after midnight when both entries are correctly yesterday. This PR does not modify that test or hide the failure.The CI job is labeled Python 3.13 but its test environment shows Python 3.14.7. Stream/CLI coroutine warnings reproduce locally on base; the existing autosave setter remains deprecated. CI warning categories were inspected, but not all have independent base controls. Marking this ready for review does not mean CI is green or authorize a merge.
Compatibility and boundaries
Metadata-free histories retain the current/default identity and rebuild the durable prompt once; the next checkpoint persists that state. No old identity or unsafe durable/temporary boundary is parsed from prose. Existing old messages are not rewritten or repaired, and session filenames, serialization formats and migration policy are unchanged.
Prompt hooks and project rules become durable conversation state: later edits do not silently replace the saved contract. Start/reset a conversation to adopt a new contract, or explicitly use
/cdto refresh it for the selected project. Successful/cdintentionally changes the prefix. Model preparation is keyed by model and main/subagent scope; temporary suffixes and subagent execution context remain per-run.No retry/history-custody fix, MCP change, dependency/package-version change, live-provider cache validation or measured cost-saving claim is included. This proposal preserves stable bytes; provider cache reuse remains provider-dependent.