Skip to content

[NO-JIRA] Rolling memory on the state machine: fold older history at turn start (R12) - #30

Merged
johnnymo87 merged 2 commits into
patched/v1.60.2from
r12-rolling-memory
Nov 22, 2026
Merged

johnnymo87 merged 2 commits into
patched/v1.60.2from
r12-rolling-memory

Conversation

@johnnymo87

Copy link
Copy Markdown
Owner

Description

Ports rolling memory onto the v1.60.2 state machine (R12, workstation-6w7i.26.4.3). When a session goes over its budget, the older history is folded into a first-person memory at turn start. stall-watch coordinators turn it on through settings/set rollingMemory.

Stacked on #25 (R8). This PR's first two commits are #25's. I'll rebase onto patched/v1.60.2 once #25 merges. Per the merge order, this merges after R11.

  • Carried from 1.54: context_mgmt/rolling.rs, and the compaction_rolling.md template, byte-identical, since its wording was validated by experiment.
  • New RollingMemoryOperation: a fork-only file, registered before CompactionOperation.
    • It runs at turn start, which means only user messages since the kickoff. Turns started by a slash command count too.
    • It runs once per turn. An operation note on the kickoff guards it, so it never loops.
    • The fold is applied as a standard CompactConversation effect. That effect saves the history, records the memory call once as compaction usage, and emits HistoryReplaced.
    • A failed memory call goes to the usage ledger only, and the session's current usage is left as it was. The turn then proceeds.
  • Proactive auto-compaction and tool-pair summarization are off while rolling is on, as on 1.54. Reactive context-length compaction and /compact still work.
  • settings/set rollingMemory: {budgetTokens, tailTokens} turns it on and null turns it off. It is validated (tail >= 1000, budget >= 10000, tail < budget; errors start invalid rollingMemory: ) and stored per key in extension_data as rolling_memory.v0, which stall-watch reads back.
  • Approximation: the system prompt and tools used for the fold estimate are rebuilt (project and recipe parts plus the session's extension tools). They are not the exact inference request. The calibration ratio absorbs the difference, a few percent at stall-watch's budget. With GOOSE_TOOL_DEFERRAL=lookup the tools are over-counted.
  • Change from 1.54: 1.54 refused the unrolled loop when rolling was on. That loop no longer exists, so the refusal is gone.

Tests: 44 unit tests, 8 integration tests (tests/rolling_memory.rs) and rollingMemory cases in acp_session_settings_test. All are in the patched-ci exact-test list. The integration tests use a temp-dir session store and switch telemetry off for the whole process, so they never open the default goose data dir.

References

  • workstation epic workstation-6w7i.26, bead .26.4.3 (1.54 source: 3eb4f65)

johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…turn start (R12)

Ports rolling memory from the v1.54 legacy loop to the 1.60 state machine
pipeline as RollingMemoryOperation.

Design summary:
- Operation timing: Runs at turn start when `messages_since_kickoff` has
  length 1 (the kickoff user prompt).
- Estimation context: `prepare_system_and_tools` approximates the inference
  system prompt using PromptManager with session recipe instructions and
  project instructions, along with tools resolved via
  `services.current_session_snapshot`. This closely approximates the actual
  inference request for token counting.
- Once-per-turn guard: Combination of durable message metadata operation
  note (`rolling_memory.folded = true`) applied via `SetMessageOperationNote`
  on the kickoff message, plus an in-memory `folded_turns` set on
  `RollingMemoryOperation` that records evaluated kickoff IDs across all paths
  (fold, not needed, under budget, error) to prevent duplicate runs across
  state machine steps or loops in the same turn.
- Compaction gating: Proactive auto-compaction (`ops_compaction.rs`) and tool
  pair summarization (`ops_tool_pair_compaction.rs`) are skipped when rolling
  memory is active (`rolling::is_on(session)`).
- Session settings & ACP: Added `rollingMemory` (budgetTokens, tailTokens)
  to `SetSessionSettingsRequest` in `goose-sdk-types`, `acp-schema.json`, and
  ACP server handlers.

Behaviour changed from v1.54:
- Integrated as a state machine `Operation` returning `GooseEffect`s rather
  than controlling the agent loop directly.
- `rolling::execute_fold` no longer directly saves compacted conversations
  or records metrics; instead, the operation emits `GooseEffect::CompactConversation`
  with usage and `SetMessageOperationNote`, preventing double-counting.
- `session_manager.rs` remains untouched upstream; test inspection of the
  usage ledger connects directly to the sqlite database via `open_test_db()`.

Tests:
- 44 unit tests in `context_mgmt::rolling` and `prompt_template`
- 8 integration tests in `tests/rolling_memory.rs`
- 6 tests in `tests/acp_session_settings_test.rs`
- 9 tests in `goose-sdk-types`
- All tests verified and listed in `.github/workflows/patched-test.yml`

X-Shepherd-Wake: #30
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
… state writes, slash-command turns

* tests/rolling_memory.rs: every test uses a temp-dir SessionManager, and a
  process-wide Once sets GOOSE_PATH_ROOT and GOOSE_TELEMETRY_OFF before the first
  goose call, so telemetry's global SessionManager never opens the default DB.
* A failed memory call is recorded to the usage ledger with the session's current
  usage unchanged (as on 1.54), instead of a RecordUsage effect that overwrote it.
* Rolling state and the settings/set rollingMemory value are written per key with
  set_extension_value, so concurrent extension_data changes are not lost.
* Turn start is "only user messages since the kickoff", so turns that a slash
  command starts (agent-only prompt appended before inference) fold too.

X-Shepherd-Wake: #30
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…turn start (R12)

Ports rolling memory from the v1.54 legacy loop to the 1.60 state machine
pipeline as RollingMemoryOperation.

Design summary:
- Operation timing: Runs at turn start when `messages_since_kickoff` has
  length 1 (the kickoff user prompt).
- Estimation context: `prepare_system_and_tools` approximates the inference
  system prompt using PromptManager with session recipe instructions and
  project instructions, along with tools resolved via
  `services.current_session_snapshot`. This closely approximates the actual
  inference request for token counting.
- Once-per-turn guard: Combination of durable message metadata operation
  note (`rolling_memory.folded = true`) applied via `SetMessageOperationNote`
  on the kickoff message, plus an in-memory `folded_turns` set on
  `RollingMemoryOperation` that records evaluated kickoff IDs across all paths
  (fold, not needed, under budget, error) to prevent duplicate runs across
  state machine steps or loops in the same turn.
- Compaction gating: Proactive auto-compaction (`ops_compaction.rs`) and tool
  pair summarization (`ops_tool_pair_compaction.rs`) are skipped when rolling
  memory is active (`rolling::is_on(session)`).
- Session settings & ACP: Added `rollingMemory` (budgetTokens, tailTokens)
  to `SetSessionSettingsRequest` in `goose-sdk-types`, `acp-schema.json`, and
  ACP server handlers.

Behaviour changed from v1.54:
- Integrated as a state machine `Operation` returning `GooseEffect`s rather
  than controlling the agent loop directly.
- `rolling::execute_fold` no longer directly saves compacted conversations
  or records metrics; instead, the operation emits `GooseEffect::CompactConversation`
  with usage and `SetMessageOperationNote`, preventing double-counting.
- `session_manager.rs` remains untouched upstream; test inspection of the
  usage ledger connects directly to the sqlite database via `open_test_db()`.

Tests:
- 44 unit tests in `context_mgmt::rolling` and `prompt_template`
- 8 integration tests in `tests/rolling_memory.rs`
- 6 tests in `tests/acp_session_settings_test.rs`
- 9 tests in `goose-sdk-types`
- All tests verified and listed in `.github/workflows/patched-test.yml`

X-Shepherd-Wake: #30
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
… state writes, slash-command turns

* tests/rolling_memory.rs: every test uses a temp-dir SessionManager, and a
  process-wide Once sets GOOSE_PATH_ROOT and GOOSE_TELEMETRY_OFF before the first
  goose call, so telemetry's global SessionManager never opens the default DB.
* A failed memory call is recorded to the usage ledger with the session's current
  usage unchanged (as on 1.54), instead of a RecordUsage effect that overwrote it.
* Rolling state and the settings/set rollingMemory value are written per key with
  set_extension_value, so concurrent extension_data changes are not lost.
* Turn start is "only user messages since the kickoff", so turns that a slash
  command starts (agent-only prompt appended before inference) fold too.

X-Shepherd-Wake: #30
…turn start (R12)

Ports rolling memory from the v1.54 legacy loop to the 1.60 state machine
pipeline as RollingMemoryOperation.

Design summary:
- Operation timing: Runs at turn start when `messages_since_kickoff` has
  length 1 (the kickoff user prompt).
- Estimation context: `prepare_system_and_tools` approximates the inference
  system prompt using PromptManager with session recipe instructions and
  project instructions, along with tools resolved via
  `services.current_session_snapshot`. This closely approximates the actual
  inference request for token counting.
- Once-per-turn guard: Combination of durable message metadata operation
  note (`rolling_memory.folded = true`) applied via `SetMessageOperationNote`
  on the kickoff message, plus an in-memory `folded_turns` set on
  `RollingMemoryOperation` that records evaluated kickoff IDs across all paths
  (fold, not needed, under budget, error) to prevent duplicate runs across
  state machine steps or loops in the same turn.
- Compaction gating: Proactive auto-compaction (`ops_compaction.rs`) and tool
  pair summarization (`ops_tool_pair_compaction.rs`) are skipped when rolling
  memory is active (`rolling::is_on(session)`).
- Session settings & ACP: Added `rollingMemory` (budgetTokens, tailTokens)
  to `SetSessionSettingsRequest` in `goose-sdk-types`, `acp-schema.json`, and
  ACP server handlers.

Behaviour changed from v1.54:
- Integrated as a state machine `Operation` returning `GooseEffect`s rather
  than controlling the agent loop directly.
- `rolling::execute_fold` no longer directly saves compacted conversations
  or records metrics; instead, the operation emits `GooseEffect::CompactConversation`
  with usage and `SetMessageOperationNote`, preventing double-counting.
- `session_manager.rs` remains untouched upstream; test inspection of the
  usage ledger connects directly to the sqlite database via `open_test_db()`.

Tests:
- 44 unit tests in `context_mgmt::rolling` and `prompt_template`
- 8 integration tests in `tests/rolling_memory.rs`
- 6 tests in `tests/acp_session_settings_test.rs`
- 9 tests in `goose-sdk-types`
- All tests verified and listed in `.github/workflows/patched-test.yml`

X-Shepherd-Wake: #30
… state writes, slash-command turns

* tests/rolling_memory.rs: every test uses a temp-dir SessionManager, and a
  process-wide Once sets GOOSE_PATH_ROOT and GOOSE_TELEMETRY_OFF before the first
  goose call, so telemetry's global SessionManager never opens the default DB.
* A failed memory call is recorded to the usage ledger with the session's current
  usage unchanged (as on 1.54), instead of a RecordUsage effect that overwrote it.
* Rolling state and the settings/set rollingMemory value are written per key with
  set_extension_value, so concurrent extension_data changes are not lost.
* Turn start is "only user messages since the kickoff", so turns that a slash
  command starts (agent-only prompt appended before inference) fold too.

X-Shepherd-Wake: #30
@johnnymo87
johnnymo87 merged commit e2b5080 into patched/v1.60.2 Nov 22, 2026
13 checks passed
johnnymo87 added a commit that referenced this pull request Nov 22, 2026
…turn start (R12)

Ports rolling memory from the v1.54 legacy loop to the 1.60 state machine
pipeline as RollingMemoryOperation.

Design summary:
- Operation timing: Runs at turn start when `messages_since_kickoff` has
  length 1 (the kickoff user prompt).
- Estimation context: `prepare_system_and_tools` approximates the inference
  system prompt using PromptManager with session recipe instructions and
  project instructions, along with tools resolved via
  `services.current_session_snapshot`. This closely approximates the actual
  inference request for token counting.
- Once-per-turn guard: Combination of durable message metadata operation
  note (`rolling_memory.folded = true`) applied via `SetMessageOperationNote`
  on the kickoff message, plus an in-memory `folded_turns` set on
  `RollingMemoryOperation` that records evaluated kickoff IDs across all paths
  (fold, not needed, under budget, error) to prevent duplicate runs across
  state machine steps or loops in the same turn.
- Compaction gating: Proactive auto-compaction (`ops_compaction.rs`) and tool
  pair summarization (`ops_tool_pair_compaction.rs`) are skipped when rolling
  memory is active (`rolling::is_on(session)`).
- Session settings & ACP: Added `rollingMemory` (budgetTokens, tailTokens)
  to `SetSessionSettingsRequest` in `goose-sdk-types`, `acp-schema.json`, and
  ACP server handlers.

Behaviour changed from v1.54:
- Integrated as a state machine `Operation` returning `GooseEffect`s rather
  than controlling the agent loop directly.
- `rolling::execute_fold` no longer directly saves compacted conversations
  or records metrics; instead, the operation emits `GooseEffect::CompactConversation`
  with usage and `SetMessageOperationNote`, preventing double-counting.
- `session_manager.rs` remains untouched upstream; test inspection of the
  usage ledger connects directly to the sqlite database via `open_test_db()`.

Tests:
- 44 unit tests in `context_mgmt::rolling` and `prompt_template`
- 8 integration tests in `tests/rolling_memory.rs`
- 6 tests in `tests/acp_session_settings_test.rs`
- 9 tests in `goose-sdk-types`
- All tests verified and listed in `.github/workflows/patched-test.yml`

X-Shepherd-Wake: #30
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.

1 participant