Skip to content

feat(harness): re-anchor after session compaction#53

Open
pablontiv wants to merge 3 commits into
Gentleman-Programming:mainfrom
pablontiv:feat/compaction-reanchor
Open

feat(harness): re-anchor after session compaction#53
pablontiv wants to merge 3 commits into
Gentleman-Programming:mainfrom
pablontiv:feat/compaction-reanchor

Conversation

@pablontiv

@pablontiv pablontiv commented Jun 16, 2026

Copy link
Copy Markdown

Re-land of #42 (approved, then closed; head branch deleted, so this is a fresh PR with the same commit). Rebased onto current main (1c218795). Opened as draft for now.

What changed vs the original #42: rebased cleanly — no textual conflict. Composes with #46's autonomous runtime guard (both touch session-level behavior; no double-injection or ordering conflict). The harness logic is byte-identical to the approved commit.

Stacked on #41; cumulative diff until predecessors merge.

Part of #39. Stacked on #41 (review the last commit only).

Summary

  • Registers session_compact: sets a one-shot flag so the next context-event reminder carries a post-compaction block (re-check SDD/OpenSpec state on disk, restate scope and acceptance criteria before continuing).
  • The flag resets when consumed and at session_start, preventing leakage across sessions.

Changes

File Change
extensions/gentle-ai.ts compactionPending flag, session_compact handler, post-compaction block in buildContextReminder(), reset at session_start
tests/gentle-ai.test.ts One-shot semantics, flag reset through applyHarnessReminder, multi-turn integration scenario

Test plan

  • pnpm test green at this commit on current main: 166 pass, 0 fail. Original count on the older base was 65.

Notes

Deliberately minimal v1: no session_before_compact interception and no custom CompactionResult. Those stay open as a possible follow-up if this direction lands well.

Summary by CodeRabbit

  • New Features

    • Added a “gentle-harness” reminder that’s injected into outgoing context messages to improve continuity across multi-turn conversations.
  • Improvements

    • Updated orchestrator prompt handling to load on demand (no caching) with safe fallback when the prompt file can’t be read.
    • Enhanced reminder logic with compaction-aware, one-time “just compacted” messaging and automatic deduplication so only one reminder is present per turn.
  • Tests

    • Expanded unit tests for prompt reload behavior, reminder structure/content, deduplication, and compaction state transitions.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a0c2eacc-8bd3-4544-8993-26079de6cc04

📥 Commits

Reviewing files that changed from the base of the PR and between 2287f9e and 9fa4557.

📒 Files selected for processing (2)
  • extensions/gentle-ai.ts
  • tests/gentle-ai.test.ts

📝 Walkthrough

Walkthrough

Replaces the cached orchestrator prompt reader with a fresh-read helper (getOrchestratorPromptImpl) that falls back to an empty string on missing files. Adds a compactionPending flag, buildContextReminder, and applyHarnessReminder that inject and deduplicate a harness-reminder message in Pi context events, with the flag set on session_compact and cleared on session_start. New test suite covers all helpers.

Changes

Harness reminder injection and orchestrator prompt refresh

Layer / File(s) Summary
Orchestrator prompt fresh-read helper
extensions/gentle-ai.ts, tests/gentle-ai.test.ts
Replaces orchestratorPromptCache with getOrchestratorPromptImpl(pathOverride?) that reads the markdown file on every call and returns "" on error; exposed via __testing. Tests verify repeated reads reflect disk changes and missing paths return "" without throwing.
Reminder construction and deduplication logic
extensions/gentle-ai.ts, tests/gentle-ai.test.ts
Adds reminder content constants, compactionPending flag, buildContextReminder() (conditionally appending a compaction note), and applyHarnessReminder(messages) (filters prior reminders, appends a fresh one). Tests assert correct role/type, required phrases, no mutation of original array, deduplication, mid-array removal, and last-position placement.
Session and context event wiring
extensions/gentle-ai.ts
Resets compactionPending at session_start, sets it on session_compact, and transforms outgoing messages via applyHarnessReminder on each context event.
Compaction state and multi-turn reminder tests
tests/gentle-ai.test.ts
Tests setCompactionPending/getCompactionPending toggling, a multi-turn scenario confirming exactly one fresh reminder persists across turns, and that applyHarnessReminder resets the pending flag and injects compaction-specific content when pending.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(harness): re-anchor after session compaction' directly describes the main functionality change—reanchoring the harness after session compaction—which is the core objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@extensions/gentle-ai.ts`:
- Around line 1923-1932: The global `compactionPending` variable causes race
conditions across concurrent sessions because multiple sessions can read and
write to it simultaneously without isolation. Replace the single global
`compactionPending` flag with a session-scoped approach: either use a Map keyed
by session identifier (e.g., `compactionPendingBySessionId`) if the `context`
event object contains a stable session/context identifier, or refactor
`buildContextReminder()` and `applyHarnessReminder()` to accept
`compactionPending` as a parameter that is threaded through from session-scoped
state rather than relying on shared global mutable state. Ensure that the
`session_start` reset logic and the `session_compact` event handler are also
updated to work with the session-scoped state instead of the global variable.

In `@tests/gentle-ai.test.ts`:
- Around line 59-64: The test for __testing.getOrchestratorPrompt with a missing
file uses a hardcoded absolute path that is environment-dependent and
unreliable. Instead of using "/nonexistent/path/orchestrator.md", create a
temporary directory dynamically and construct a path to a guaranteed-missing
child file within that temp directory. This ensures the test is deterministic
and works reliably across different environments. Use that
dynamically-constructed missing path when calling
__testing.getOrchestratorPrompt in the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b91eb2f9-4f22-4020-b4ad-551936660f38

📥 Commits

Reviewing files that changed from the base of the PR and between 1c21879 and 3aba486.

📒 Files selected for processing (2)
  • extensions/gentle-ai.ts
  • tests/gentle-ai.test.ts

Comment thread extensions/gentle-ai.ts
Comment thread tests/gentle-ai.test.ts Outdated
@pablontiv
pablontiv force-pushed the feat/compaction-reanchor branch from 3aba486 to 2287f9e Compare June 16, 2026 18:33
Registers pi.on("context") handler that injects a gentle-harness-reminder message before each LLM call, ensuring the orchestrator pattern, TDD discipline, and artifact-driven decisions are reinforced at every interaction point — not just at agent start.

The handler returns a new message array with the reminder appended as the last message. It deduplicates if a reminder is already present (defensive for chained extensions). The reminder content is a single source of truth module constant and includes all el Gentleman discipline markers.

Pure logic exposed via __testing for verification. Full suite green (58/58 pass, runtime harness exit 0).
@pablontiv
pablontiv force-pushed the feat/compaction-reanchor branch from 2287f9e to 9fa4557 Compare June 16, 2026 20:13
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