Skip to content

feat: tell, then remind, an agent to tend its pinned memory - #47044

Open
buluoray wants to merge 3 commits into
crew/slack/reinforced-memoryfrom
crew/slack/pinned-upkeep-reminder
Open

buluoray wants to merge 3 commits into
crew/slack/reinforced-memoryfrom
crew/slack/pinned-upkeep-reminder

Conversation

@buluoray

@buluoray buluoray commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: With pinned memory on, an agent is told the feature exists and is reminded, on its next turn, to pin before a compaction and to tidy once its pins grow.

With memory.pinned_memory on, no prompt text names the feature: the pinned_memory tool is deferred behind tool search on KAS and kiro-cli, and its description told the agent to "keep it small". Nothing asks the agent to pin as its context fills, or to tidy once the pins near the 30,000 characters one block sends. A bot pinned only because its owner asked it to. This is part 3 of pinned memory; it stacks on #46364 (part 1), which now also carries what was #46450 (part 2).

Why it matters

Pinned memory only protects what the agent pins. If the agent does not know the tool, or is never asked at the moment it matters, the person's rules still drop out at the next compaction, which is the problem the feature exists to fix.

Not a goal

  • Auto-pinning a lesson a person taught (a follow-up PR).
  • Changing what a compaction sends, the 30,000-character guard, or which pins it keeps.
  • Any text shown to the person, or any new setting: everything rides the existing memory.pinned_memory switch.
  • Keeping the counters across a gateway restart.

What changed (motivation → approach → change)

Goal → tell the agent once, remind it at the moments that matter, and let it read how that went → three parts, all behind memory.pinned_memory, none costing an extra model turn.

  • Tell. config/prompt.md gains a {{PINNED_MEMORY_BLOCK}} line in the capability list. context_assembly/agent_spec._resolve_prompt_templates resolves it live through sections.resolve_pinned_memory: the line while the switch is on and pinned_memory.may_pin (the chat_binding rule) accepts the chat, nothing otherwise. The agent prompt takes one path on every harness, at session start and after each compaction, so kiro-cli, KAS and Claude Code all get it the same way. A chat whose prompt was built before the switch went on, by an earlier gateway, or by a custom agent without the token, gets the line once on its next turn (pinned_memory_upkeep.intro_due). A bot's member section gets one sentence (conductor.pinned_memory_item).

  • Remind. pinned_memory_upkeep.py (new). CompactionCoordinator.check_context_usage hands each turn's reading to observe, whatever the backend decides about compacting. The next turn (context_assembly/turn.pinned_upkeep_parts) carries one line at:

    • warn: the warn point, 60% by default (autocompact_pct − CONTEXT_WARN_MARGIN_PCT);
    • last: halfway to the compaction point, 65%;
    • full: the pins at 80% of HARD_CHARS, measured at each pin, unpin and send (pinned_memory.measure, which reads records as the send does);
    • over: the guard leaves pins out; the line names them.

    warn and last fire once per fill. A backend with no reading counts turns instead (40 and 60). One line a turn, the most urgent. A stage armed on a turn that cannot carry it (pinning off, a minimal or read-blocked turn) is not spent. 80% leaves about 13 pins of the ~450 characters seen in real use before anything is left out, and one tidy pass frees about a fifth, which brings the set back under the share.

  • Read back. pinned_memory list reports the block's size against the total and, per fill, the reminders given and the pins and unpins made, so the agent can review its own upkeep without reading a file.

  • Tool description. "Keep it small" is gone: pins are sent whole after every compaction, a fuller set is fine, and the agent tidies when asked.

Docs: memory-skills-hooks.md (Pinned memory).

Backwards compatibility

Compatible: with memory.pinned_memory off (the default) every new path returns nothing, and the prompt line resolves to no line.

Removes nothing: the tool keeps its ops and arguments; only its description text and its list answer grow.

Tests

  • test/test_pinned_memory_upkeep.py (new): each stage's trigger and once-only rule; the turn-count fallback; a rebuild with and without a reading; a stage crossed while off is given once on; full and over, and over naming the left-out pins; the counters; the prompt line present only while on and only for a chat that may pin; the resolver marks a told chat; the intro once for a running chat; nothing on minimal or read-blocked turns; a chat that may not pin is not read again; the bot sentence only while on.
  • test/test_pinned_memory.py: a pin and an unpin are counted and list reports the size.
  • test/test_prompt_compact_contract.py: the new slot.

Proof: not provable -- other: a new feature, so there is no fix to revert; mutation-checked instead (the once-per-fill guard and the route counter each turn tests red).

Manual verification

Pending: a pod with pinned memory on, driving a chat past 60% and 65% and pinning past 80%.

Real-machine verification

Pending, with the manual verification above.

Screenshots / video

N/A -- no frontend file changes; every new line is agent-facing.

Related Issues

Part of #46328

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 163fb750bba1c23dd9b3c1b617e13b1484c01099 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 163fb750bba1c23dd9b3c1b617e13b1484c01099 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: every new path sits behind memory.pinned_memory, the tool's ops and answers only grow, and the per-process state is admitted as a shortcut.

Notes

  • The reminder counters are fed from three places: session_compaction, the turn_message rebuild, and pinned_memory._send and _upkeep. That keeps the fill-boundary logic in observe and rebuilt hard to reason about. If a fourth signal appears, move it to a single event the coordinator emits.
  • Real-machine verification is still pending. It should cover a KAS chat that compacts itself, since the "reading shrank after a re-send" heuristic is the one most likely to miscount a fill.

[DESIGN-REVIEWED] 163fb75

Description read

[DESCRIPTION-READ] e7cbdcf2c1cb386cd0e02b796b393ad6116573b363118f9f50508196ae348e60

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 163fb750bba1c23dd9b3c1b617e13b1484c01099 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: the feature sits behind memory.pinned_memory, which is off by default, and no existing reminder warns the agent before a compaction. The per-fill history in the list answer goes beyond the Goal.

Notes

  • Item 6 — oversized: the Goal is "told … and is reminded". Nothing in it covers reading back history. Yet the change keeps up to 10 earlier fills per chat (_FILLS_KEPT), plus reminder logs and omitted counts. Only one place reads them (mcp_tools/learn._upkeep_lines), and the only reader is the agent itself. Subtraction: delete _Chat.done, _FILLS_KEPT, _REMINDERS_KEPT/omitted and the earlier and reminders fields of summary. Keep the block size chars/total. Clears when: the mechanism is removed, or a human amends the Goal.
  • Item 6 — zero consumers: nothing reads _fill_json's "started" (grepped ["started"] and get("started"): 0 hits in pinned-memory code). Subtraction: delete the started field from _Fill and from _fill_json.
Inventory (9 items) — 7 justified

Intent: when pinned memory is on, the agent learns the tool exists and is asked to pin before a compaction and to tidy as pins grow. ADDITION.

  1. The capability list in the agent prompt gains a pinned_memory line while the switch is on — justified
  2. A chat that started before the switch went on gets that line once on its next turn — justified
  3. A bot's member section gains one sentence about pins while the switch is on — justified
  4. A one-line reminder on the next turn at 60% and 65% context — justified
  5. A reminder when pins reach 80% of 30,000 characters, and when pins get left out (this line names them) — justified
  6. pinned_memory list reports the block size and a history of reminders and pins for each fill — oversized
  7. The tool description drops "Keep it small" and invites a fuller set — justified
  8. Backends with no context reading count turns instead (40 and 60) — justified
  9. The tool-bytes ceilings for codex, opencode, goose and pi each rise by 163 bytes — rides along

[FIRST-PRINCIPLES-REVIEWED] 163fb75

Description read

[DESCRIPTION-READ] 79923c0f4cb6107253c26ebc33d67f19be34e55f955ebc998cf832113ae65ff4

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 5076814 to 589b4b0 Compare December 4, 2026 05:50
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 6.1 flagged blocking issues on 163fb750bba1c23dd9b3c1b617e13b1484c01099; Opus 5.5 adjudication downgraded every one of them. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 1 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

This comment is updated in place on each push.

Review details

BLOCKING -- src/kiro_crew/pinned_memory_upkeep.py:185 -- Attribute post-compaction pin changes to the new fill

if shrunk or (chat.fired and pct < compact_at - warn_margin):
_new_fill(chat)
Trigger: A dashboard chat at 61% is compacted; its next turn calls pinned_upkeep_parts → rebuilt, then successfully pins a memory through the route’s _upkeep. End-of-turn check_context_usage → observe receives the reduced reading.
Outcome: _new_fill archives that post-compaction pin into the previous fill. The next pinned_memory list reports “Since the last compaction” with zero pins instead of one, and incorrectly credits the earlier fill.
Anchor: defect
Fix: Track pin/unpin deltas after rebuilt and assign them to the new fill when the reduced reading confirms compaction; retain them in the current fill otherwise.
Sites: src/kiro_crew/dashboard/handlers/pinned_memory.py:306 (unpin), src/kiro_crew/dashboard/handlers/pinned_memory.py:386 (pin), src/kiro_crew/mcp_tools/learn.py:843 (affected reader).
[BLOCK-MERGE-DOWNGRADED] 163fb75
[GPT-REVIEWED] 163fb75

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 — Harm rung: LOW. The bug requires all of these: a reading-bearing chat, so rebuilt sets resent instead of ending the fill (pinned_memory_upkeep.py:294-295, called from context_assembly/turn.py:400); a pin or unpin during the turn after the re-send, which pin_changed counts into chat.fill (:305-309, via dashboard/handlers/pinned_memory.py:211); and a lower reading at the end of that turn, which then archives the fill (:184-186). The only effect is wrong pinned/unpinned counters in the list answer's "Since the last compaction" and "Fill -n" lines (mcp_tools/learn.py:843-847). The pins themselves are unaffected and nothing depends on the counters, and the next fill counts correctly.
The real fix needs new per-chat state: a buffer of pin deltas made after the re-send, plus branches in pin_changed, observe and _new_fill to move that buffer to the new fill or keep it in the current one. That is a mechanism that exists only to fix the attribution of a diagnostic counter, and every future reader carries it. It costs more than one misattributed count on a rare turn. No blocking: true AUTOSDE rule anchors this finding (it is anchored "defect").

[ADJUDICATION] 163fb750bba1c23dd9b3c1b617e13b1484c01099 total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/pinned_memory_upkeep.py:185 reason=disproportionate-remedy
[GPT-ADJUDICATED] 163fb750bba1c23dd9b3c1b617e13b1484c01099

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 163fb750bba1c23dd9b3c1b617e13b1484c01099 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 163fb750bba1c23dd9b3c1b617e13b1484c01099 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 163fb75

Verdict parsed from the review's SHA-scoped output markers for commit 163fb750bba1c23dd9b3c1b617e13b1484c01099.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 163fb750bba1c23dd9b3c1b617e13b1484c01099 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 589b4b0 to 0b1c0db Compare December 4, 2026 06:19
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from dfb09af to 13009bb Compare December 4, 2026 06:40
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 0b1c0db to b6e9d2c Compare December 4, 2026 07:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from 7da9780 to bec5ec5 Compare December 4, 2026 07:07
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from b6e9d2c to e1286bd Compare December 4, 2026 07:08
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from bec5ec5 to c1d3a59 Compare December 4, 2026 10:34
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from e1286bd to 95ecfe4 Compare December 4, 2026 10:34
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from c1d3a59 to 30bc840 Compare December 4, 2026 11:04
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 95ecfe4 to 05b04eb Compare December 4, 2026 11:04
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 4, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from 3d47e26 to 9a76fd2 Compare December 4, 2026 23:29
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from f182731 to 3d7aa54 Compare December 4, 2026 23:29
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 4, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from 9a76fd2 to a63385b Compare December 5, 2026 06:27
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 3d7aa54 to 211e63a Compare December 5, 2026 06:28
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from a63385b to c0843a1 Compare December 5, 2026 07:07
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 211e63a to 0d28ae4 Compare December 5, 2026 07:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 5, 2026
@buluoray
buluoray marked this pull request as ready for review December 5, 2026 08:12
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners December 5, 2026 08:12
@buluoray
buluoray requested review from cruisercohen and removed request for a team December 5, 2026 08:12
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/pinned-memory-card branch from c0843a1 to 033bc45 Compare December 5, 2026 08:56
@buluoray
buluoray force-pushed the crew/slack/pinned-upkeep-reminder branch from 0d28ae4 to 4432ba2 Compare December 5, 2026 08:56
@buluoray

buluoray commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Dispositions for GPT 6.1 Review on 6429a0f883d. The new head is 0da188dd731.

Finding Verdict What happened
A fill's reminder history has no cap (pinned_memory_upkeep.py:225) Fixed A fill keeps its newest 20 reminders (_REMINDERS_KEPT) and counts the rest in omitted. The list answer prints them as "and N earlier". Tests: test_a_fill_keeps_its_newest_reminders_and_counts_the_rest and test_the_list_answer_counts_the_reminders_not_kept.
A /compact before the warn point never ends the fill (:173, :276) Fixed rebuilt() marks a chat that has a reading as re-sent. The first reading after that, if it is lower than the fill's highest, ends the fill. A rules edit or a resume does not lower the reading, so it still keeps the fill (test_a_rebuild_with_a_reading_keeps_the_fill). Test: test_a_compaction_before_the_warn_point_ends_the_fill.

Each fix was reverted in turn, and each revert turned a test red. The spec paragraph in memory-skills-hooks.md now names both rules.

With pinned memory on, nothing told an agent the feature existed, and
nothing asked it to pin before a compaction or to tidy once the pins
grew: the tool was deferred and its description said to keep it small.

While memory.pinned_memory is on:
- The agent prompt's capability list carries one pinned_memory line,
  and a bot's member section one sentence. Both ride the agent prompt,
  so every harness gets them at session start and after a compaction;
  a chat that started before the switch gets the line once on its next
  turn.
- A chat's next turn carries one line at four stages: the context at
  the warn point (60%) and halfway to compaction (65%), once per fill,
  read from each turn's context reading whatever the backend decides
  (KAS and Claude Code included), or from the turn count when there is
  no reading; the pins at 80% of the 30,000 characters one block sends;
  and the pins over it, naming the ones left out of the next send.
- pinned_memory list reports the block's size and, per fill, the
  reminders given and the pins and unpins made.

The tool description drops "Keep it small": a fuller set is fine, and
the agent tidies when asked.
A fill kept every reminder given, with no cap; it now keeps the newest
20 and counts the rest. A /compact before the warn point never ended
the fill, because only a fired stage did; the first reading after a
context re-send that is lower than the fill's highest now ends it too.
A reset without replay starts a full session under the same key, but
the upkeep state kept told, so a custom agent whose prompt has no
pinned-memory line never got its intro again. A full start now counts
as a context re-send, as a compaction does.
@buluoray

buluoray commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Disposition for GPT 6.1 Review on a277008aee9. The new head is 163fb750bba.

Finding Verdict What happened
A full session start under a known key (a reset with replay=false) keeps upkeep's told, so a custom agent whose prompt has no {{PINNED_MEMORY_BLOCK}} never gets the intro again (context_assembly/turn_message.py:771) Fixed A full session start under a known key now calls pinned_memory_upkeep.rebuilt before the agent prompt is resolved, the same call a compaction makes. A prompt that carries the line marks the chat told again, and a custom prompt gets the intro on the next turn. A slim resume is left as it was. Test: TestFreshSessionStart::test_a_full_start_under_a_known_key_tells_the_chat_again, which is red without the call. The spec's upkeep paragraph names this re-send.

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

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant