cc-continuity 0.3.70__tar.gz → 0.3.72__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/PKG-INFO +1 -1
  2. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/README.md +2 -2
  3. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/__init__.py +1 -1
  4. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/overflow.py +6 -1
  5. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/watchdogd.py +11 -2
  6. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity.egg-info/PKG-INFO +1 -1
  7. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/pyproject.toml +1 -1
  8. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_overflow.py +85 -0
  9. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_watchdogd.py +46 -0
  10. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/LICENSE +0 -0
  11. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/__main__.py +0 -0
  12. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/atomic.py +0 -0
  13. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/blink.py +0 -0
  14. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/blink_watch.py +0 -0
  15. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/bootstrap.py +0 -0
  16. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/checkpoint.py +0 -0
  17. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/cli.py +0 -0
  18. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/config.py +0 -0
  19. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/daemon_supervisor.py +0 -0
  20. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/doctor.py +0 -0
  21. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/gitsnap.py +0 -0
  22. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/__init__.py +0 -0
  23. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/common.py +0 -0
  24. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/pre_compact.py +0 -0
  25. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/pre_tool_use.py +0 -0
  26. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/session_end.py +0 -0
  27. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/session_start.py +0 -0
  28. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/stop.py +0 -0
  29. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/task.py +0 -0
  30. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/tool_use.py +0 -0
  31. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hooks/user_prompt.py +0 -0
  32. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/hosting.py +0 -0
  33. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/install.py +0 -0
  34. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/launch.py +0 -0
  35. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/ledger.py +0 -0
  36. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/lock.py +0 -0
  37. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/managed.py +0 -0
  38. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/naming.py +0 -0
  39. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/notify.py +0 -0
  40. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/paths.py +0 -0
  41. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/power_plug.py +0 -0
  42. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/progress_pane.py +0 -0
  43. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/project.py +0 -0
  44. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/redact.py +0 -0
  45. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/rotator.py +0 -0
  46. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/settings_merge.py +0 -0
  47. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/skills.py +0 -0
  48. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/state.py +0 -0
  49. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/statusline.py +0 -0
  50. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/thresholds.py +0 -0
  51. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/transcript.py +0 -0
  52. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/validate.py +0 -0
  53. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/watchdog.py +0 -0
  54. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity/watchdog_digest.py +0 -0
  55. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity.egg-info/SOURCES.txt +0 -0
  56. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity.egg-info/dependency_links.txt +0 -0
  57. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity.egg-info/entry_points.txt +0 -0
  58. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/cc_continuity.egg-info/top_level.txt +0 -0
  59. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/setup.cfg +0 -0
  60. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_atomic.py +0 -0
  61. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_blink.py +0 -0
  62. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_blink_watch.py +0 -0
  63. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_bootstrap.py +0 -0
  64. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_changelog_notes.py +0 -0
  65. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_checkpoint.py +0 -0
  66. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_cli.py +0 -0
  67. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_cli_ledger.py +0 -0
  68. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_cli_log.py +0 -0
  69. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_config.py +0 -0
  70. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_daemon_supervisor.py +0 -0
  71. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_doctor.py +0 -0
  72. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_gitsnap.py +0 -0
  73. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_common.py +0 -0
  74. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_pre_compact.py +0 -0
  75. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_pre_tool_use.py +0 -0
  76. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_session_end.py +0 -0
  77. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_session_start.py +0 -0
  78. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_stop.py +0 -0
  79. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_task.py +0 -0
  80. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_tool_use.py +0 -0
  81. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hooks_user_prompt.py +0 -0
  82. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hosting.py +0 -0
  83. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_hygiene.py +0 -0
  84. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_install.py +0 -0
  85. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_integration_phase5.py +0 -0
  86. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_integration_phase6.py +0 -0
  87. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_integration_phase7.py +0 -0
  88. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_launch.py +0 -0
  89. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_ledger.py +0 -0
  90. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_lock.py +0 -0
  91. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_managed.py +0 -0
  92. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_naming.py +0 -0
  93. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_notify.py +0 -0
  94. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_notify_integration.py +0 -0
  95. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_paths.py +0 -0
  96. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_power_plug.py +0 -0
  97. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_progress_pane.py +0 -0
  98. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_project.py +0 -0
  99. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_readme_badges.py +0 -0
  100. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_readme_gif.py +0 -0
  101. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_redact.py +0 -0
  102. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_rotator.py +0 -0
  103. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_settings_merge.py +0 -0
  104. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_skills.py +0 -0
  105. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_state.py +0 -0
  106. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_status.py +0 -0
  107. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_statusline.py +0 -0
  108. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_statusline_cache.py +0 -0
  109. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_thresholds.py +0 -0
  110. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_tmux_host.py +0 -0
  111. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_transcript.py +0 -0
  112. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_transcript_finalize.py +0 -0
  113. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_uninstall.py +0 -0
  114. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_validate.py +0 -0
  115. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_watchdog.py +0 -0
  116. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_watchdog_digest.py +0 -0
  117. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_watchdog_integration.py +0 -0
  118. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_wsl_doctor.py +0 -0
  119. {cc_continuity-0.3.70 → cc_continuity-0.3.72}/tests/test_wsl_install.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.70
3
+ Version: 0.3.72
4
4
  Summary: Zero-touch session rotation for Claude Code (local large-context model)
5
5
  Classifier: Development Status :: 5 - Production/Stable
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -41,12 +41,12 @@ The five most recent updates, newest first. Each line links to its
41
41
  commit, so you can see what changed lately without digging through the
42
42
  log:
43
43
 
44
+ - **2026-11-26**: The hard-limit brick self-heal now fires in production. v0.3.71 admitted HANDOFF_REQUESTED to the context-400 recovery gates, but the watchdog tick loop only dispatched the scan for sessions its classifier judged ALIVE, TURN_DEAD, STALLED or FROZEN, and the classifier SKIPs everything outside ACTIVE/WARNED, so the hard-limit brick never reached the gate and the fix stayed unreachable code; the SKIP branch now carries HANDOFF_REQUESTED into recovery next to CHECKPOINT_VERIFIED, with one test written first ([commit](https://github.com/pqant/claude-continuity/commit/63ec16e)).
45
+ - **2026-11-26**: A hard-limit context-400 brick now self-heals. The hard-limit gate parks the session in HANDOFF_REQUESTED and the model writes the handoff draft, but when the next API call 400s (input plus requested output over the window) the turn dies without a Stop hook and nothing finalized the draft: the deterministic context-400 recovery refused to run for exactly this state although its own route starts from it; both state gates now include HANDOFF_REQUESTED so the watchdog verifies the draft and restarts the pane on its own, two tests written first ([commit](https://github.com/pqant/claude-continuity/commit/fe8032a)).
44
46
  - **2026-11-26**: An adopted successor no longer keeps the off marking of its abandoned startup. When Claude Code native auto-resume abandons a fresh startup the SessionEnd hook marks that record off (by design, so dead startups stop posing as live); the same record can later be revived as the live session by successor adoption, which refreshed the session id and state but not the off flag, so hooks, the rotator and the watchdog all ignored a real attached pane and the status line showed off instead of the usage segment; both adoption branches now clear off in the same write, abandoned startups stay off exactly as before, and two tests were written first ([commit](https://github.com/pqant/claude-continuity/commit/06c48c1)).
45
47
  - **2026-11-24**: A claim no longer skips a successor that died after attaching. The dead ACTIVE record used to force a fresh `max(counter)+1` name while the corpse kept looking live in the session list; the claim now probes the candidate's recorded pane (`tmux_session` against `tmux list-sessions`) and, only when that pane is gone, adopts the record at its same index and resets it to BOOTSTRAPPING so the SessionStart hook drives it like a fresh claim; the probe is conservative by construction (no recorded pane, tmux missing or any error means the candidate is treated as live), so a live pane is never hijacked, with eight tests written first ([commit](https://github.com/pqant/claude-continuity/commit/fa9b972)).
46
48
  - **2026-11-24**: Resuming now opens with a one-line at-a-glance preview. The SessionStart bootstrap block starts with the checkpoint number, the predecessor session, the VALIDATION result and the first Next Atomic Action item, so you can see what is being resumed without waiting for the first reply; the line is parsed display-only from the handoff text, silently omitted when nothing parses, and the block otherwise stays exactly the old format, with six tests written first ([commit](https://github.com/pqant/claude-continuity/commit/96341cb)).
47
49
  - **2026-11-24**: Handoff search is now a first-class surface. `cc-continuity search <query>` takes the search phrase directly, without typing `history` first, and the new `/continuity-search <phrase>` skill makes the invocation argument itself the query (invoked bare it asks for the keyword once); both reuse the read-only keyword engine from v0.3.66 verbatim, the `--nnn` and `--since`/`--until` filters keep working and `cc-continuity history <query>` continues to work unchanged, with four tests written first ([commit](https://github.com/pqant/claude-continuity/commit/b05b31c)).
48
- - **2026-11-24**: `cc-continuity history` now searches the checkpoint archive. `cc-continuity history <query>` finds every handoff whose text contains the keyword (case-insensitive substring) and prints session number, creation date, the first objective line and the matched line; `--nnn` and `--since`/`--until` filter the result, and the `/continuity-history` skill teaches the same usage; the search is read-only and deterministic, the checkpoint write path and the session index are untouched, and eight tests were written first ([commit](https://github.com/pqant/claude-continuity/commit/be179fe)).
49
- - **2026-11-24**: A rotation no longer splits the successor identity. The rotator predicted the next session name as strict `nnn+1` while the claim mints `max(counter, old_nnn) + 1`, so once stale records had advanced the counter the pane title and the old session's ledger froze a name the claim never minted (seen live: the ledger said connector-259 while the real successor session was connector-267); the prediction now mirrors the claim allocator, the completion paths reconcile the ledger entry and log line with the claimed record before writing them, and a claim whose own never-attached `BOOTSTRAPPING` successor already exists adopts it at the same index instead of minting a second name, with three tests written first to pin all three fixes ([commit](https://github.com/pqant/claude-continuity/commit/b60c518)).
50
50
  ## How it works
51
51
 
52
52
  The whole flow in one picture: the automatic session loop, the optional
@@ -4,4 +4,4 @@ Spec: docs/PRD.md (v1.0). Platform facts verified in docs/VERIFICATION.md.
4
4
  Standard library only at runtime; pytest is dev-only.
5
5
  """
6
6
 
7
- __version__ = "0.3.70"
7
+ __version__ = "0.3.72"
@@ -50,7 +50,12 @@ _INPUT_RE = re.compile(r"at least (\d+) input tokens")
50
50
 
51
51
  #: The states recovery may drive (anything else - a rotation already in
52
52
  #: flight, a terminal session - is a no-op skip).
53
- _RECOVERABLE_STATES = frozenset({"BOOTSTRAPPING", "ACTIVE", "WARNED"})
53
+ # Issue #100 (connector-280 live): HANDOFF_REQUESTED joins the set - the
54
+ # hard-limit gate parks the session there, the model writes the draft and
55
+ # the turn then dies on a 400 (no Stop hook); recover_400's documented
56
+ # route starts from exactly this state (advance() is idempotent there).
57
+ _RECOVERABLE_STATES = frozenset({"BOOTSTRAPPING", "ACTIVE", "WARNED",
58
+ "HANDOFF_REQUESTED"})
54
59
 
55
60
 
56
61
  def _log(detail: str) -> None:
@@ -1462,8 +1462,13 @@ def tick(ctx: TickCtx) -> dict:
1462
1462
  # semantics); _try_recover_400's own gate (full_auto/state/
1463
1463
  # rec400-dedup/400-scan + overflow.recover_400's fresh-prompt
1464
1464
  # check) stays the single source of truth.
1465
+ # Issue #100: HANDOFF_REQUESTED joins this dispatch - classify
1466
+ # SKIPs everything outside ACTIVE/WARNED, so the hard-limit brick
1467
+ # (gate entry + draft written + turn 400'd, no Stop hook) was
1468
+ # unreachable despite the _try_recover_400 gate admitting it.
1465
1469
  if (outcome == "SKIP" and rec.get("turn_active")
1466
- and rec.get("state") == "CHECKPOINT_VERIFIED"
1470
+ and rec.get("state") in ("CHECKPOINT_VERIFIED",
1471
+ "HANDOFF_REQUESTED")
1467
1472
  and _try_recover_400(ctx, key, nnn, rec, target, line)):
1468
1473
  continue
1469
1474
 
@@ -1559,8 +1564,12 @@ def _try_recover_400(ctx: TickCtx, key: str, nnn: int, rec: dict,
1559
1564
  # check lives ONLY in overflow.recover_400 (single source) - a stale
1560
1565
  # verified checkpoint still returns "skipped:CHECKPOINT_VERIFIED".
1561
1566
  if not (bool(ctx.cfg.get("full_auto", True))
1567
+ # Issue #100: HANDOFF_REQUESTED (hard-limit brick) joins the
1568
+ # gate; recover_400 owns the state checks, this is only the
1569
+ # dispatch permit.
1562
1570
  and rec.get("state") in ("BOOTSTRAPPING", "ACTIVE", "WARNED",
1563
- "CHECKPOINT_VERIFIED")
1571
+ "CHECKPOINT_VERIFIED",
1572
+ "HANDOFF_REQUESTED")
1564
1573
  and sid400 and target not in ctx.rec400):
1565
1574
  return False
1566
1575
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.70
3
+ Version: 0.3.72
4
4
  Summary: Zero-touch session rotation for Claude Code (local large-context model)
5
5
  Classifier: Development Status :: 5 - Production/Stable
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cc-continuity"
7
- version = "0.3.70"
7
+ version = "0.3.72"
8
8
  description = "Zero-touch session rotation for Claude Code (local large-context model)"
9
9
  requires-python = ">=3.11"
10
10
  classifiers = [
@@ -228,6 +228,60 @@ def test_recover_400_state_gate(cc_home, tmp_path, monkeypatch):
228
228
  assert calls == []
229
229
 
230
230
 
231
+ def test_recover_400_verified_checkpoint_with_fresh_prompt(
232
+ cc_home, tmp_path, monkeypatch):
233
+ # BUG-3 (cp-258 live): re-attached pane sits CHECKPOINT_VERIFIED while
234
+ # a fresh user_prompt and a trailing 400 prove the user is back. The
235
+ # checkpoint is already verified, so recovery must skip the finalize
236
+ # walk and drive rotator.spawn + ROTATING directly.
237
+ import time
238
+ key = _mk(cc_home, tmp_path)
239
+ for step in ("ACTIVE", "ROTATION_PENDING",
240
+ "HANDOFF_REQUESTED", "HANDOFF_FAILED",
241
+ "CHECKPOINT_WRITING", "CHECKPOINT_VERIFIED"):
242
+ state.transition(key, 1, step)
243
+ ledger.append(paths.session_dir(key, 1),
244
+ {"type": "user_prompt", "text": "go",
245
+ "ts": time.time() + 10})
246
+ spawns = []
247
+ monkeypatch.setattr(overflow.rotator, "spawn",
248
+ lambda *a: spawns.append(a) or 4242)
249
+ monkeypatch.setattr(
250
+ overflow.checkpoint, "finalize",
251
+ lambda *a, **k: pytest.fail("finalize must not rerun on verified"))
252
+ info = {"window": W, "input_tokens": W - 32000, "text_head": "API Error"}
253
+ res = overflow.recover_400(key, 1, "sid-a", "proj:cc.0",
254
+ dict(config.DEFAULTS), tmp_path, info)
255
+ assert res == "recovered"
256
+ rec = state.load_state(key, 1)
257
+ assert rec["state"] == "ROTATING"
258
+ assert spawns == [("sid-a", "proj:cc.0", rec["rotation_id"])]
259
+ evs = [e for e in ledger.read(paths.session_dir(key, 1))
260
+ if e.get("type") == "context400_recovered"]
261
+ assert len(evs) == 1
262
+
263
+
264
+ def test_recover_400_verified_checkpoint_without_fresh_prompt(
265
+ cc_home, tmp_path, monkeypatch):
266
+ # Stale verified checkpoint (rotation deferred, user gone): recovery
267
+ # must stay gated - no fresh user_prompt after the checkpoint stamp.
268
+ key = _mk(cc_home, tmp_path)
269
+ for step in ("ACTIVE", "ROTATION_PENDING", "HANDOFF_REQUESTED",
270
+ "HANDOFF_FAILED", "CHECKPOINT_WRITING",
271
+ "CHECKPOINT_VERIFIED"):
272
+ state.transition(key, 1, step)
273
+ calls = []
274
+ monkeypatch.setattr(overflow.rotator, "spawn",
275
+ lambda *a: calls.append(a))
276
+ monkeypatch.setattr(
277
+ overflow.checkpoint, "finalize",
278
+ lambda *a, **k: pytest.fail("finalize must not run"))
279
+ res = overflow.recover_400(key, 1, "sid-a", "proj:cc.0",
280
+ dict(config.DEFAULTS), tmp_path, None)
281
+ assert res == "skipped:CHECKPOINT_VERIFIED"
282
+ assert calls == []
283
+
284
+
231
285
  def test_recover_400_clears_turn_active_like_stop(
232
286
  cc_home, tmp_path, monkeypatch):
233
287
  # BUG-7 (connector-258 live): the 400 killed the turn without a Stop
@@ -306,3 +360,34 @@ def test_recover_400_verified_checkpoint_survives_deferred_restamp(
306
360
  evs = [e for e in ledger.read(paths.session_dir(key, 1))
307
361
  if e.get("type") == "context400_recovered"]
308
362
  assert len(evs) == 1
363
+
364
+
365
+ # --- issue #100: hard-limit brick recovery (HANDOFF_REQUESTED) ------------
366
+
367
+
368
+ def test_recover_400_from_handoff_requested(cc_home, tmp_path, monkeypatch):
369
+ # issue #100 (connector-280 live): the hard-limit gate parked the
370
+ # session in HANDOFF_REQUESTED, the model wrote the draft, then the
371
+ # turn died on a 400 (input+32000 > window) and the Stop hook never
372
+ # fired. recover_400's own route starts from HANDOFF_REQUESTED
373
+ # (advance() is idempotent there), so the frozenset must include it.
374
+ key = _mk(cc_home, tmp_path)
375
+ state.update_fields(key, 1, state="ACTIVE")
376
+ state.transition(key, 1, "WARNED")
377
+ state.transition(key, 1, "ROTATION_PENDING")
378
+ state.transition(key, 1, "HANDOFF_REQUESTED")
379
+ spawns = []
380
+ monkeypatch.setattr(overflow.rotator, "spawn",
381
+ lambda sid, pane, rid: spawns.append(
382
+ (sid, pane, rid)) or 4242)
383
+ monkeypatch.setattr(overflow.checkpoint, "finalize", _fake_finalize)
384
+ info = {"window": W, "input_tokens": W - 32000, "text_head": "API Error"}
385
+ res = overflow.recover_400(key, 1, "sid-a", "proj:cc.0",
386
+ dict(config.DEFAULTS), tmp_path, info)
387
+ assert res == "recovered"
388
+ rec = state.load_state(key, 1)
389
+ assert rec["state"] == "ROTATING"
390
+ assert spawns == [("sid-a", "proj:cc.0", rec["rotation_id"])]
391
+ evs = [e for e in ledger.read(paths.session_dir(key, 1))
392
+ if e.get("type") == "context400_recovered"]
393
+ assert len(evs) == 1
@@ -2873,3 +2873,49 @@ def test_try_recover_400_skip_does_not_arm_rec400(cc_home, tmp_path,
2873
2873
  assert watchdogd._try_recover_400(ctx, "proj-a", 1, rec,
2874
2874
  "cc-proj-a-0a9b", line) is True
2875
2875
  assert len(calls) == 2 and "cc-proj-a-0a9b" in ctx.rec400
2876
+
2877
+
2878
+ # --- issue #100: hard-limit brick gate (HANDOFF_REQUESTED) ----------------
2879
+
2880
+
2881
+ def test_try_recover_400_accepts_hard_limit_brick(cc_home, tmp_path,
2882
+ monkeypatch):
2883
+ # issue #100 (connector-280 live): the hard-limit gate parked the
2884
+ # session in HANDOFF_REQUESTED, the model wrote the draft, the turn
2885
+ # 400'd and Stop never fired - the ONLY exit is recover_400, whose
2886
+ # documented route starts from HANDOFF_REQUESTED. The tick gate must
2887
+ # hand it over like the other brick states.
2888
+ io = FakeIO(sessions=["cc-proj-a-0a9b"])
2889
+ _mk(st="HANDOFF_REQUESTED", turn_active=True)
2890
+ calls = _patch400(monkeypatch, tmp_path)
2891
+ ctx = _ctx(io, now=10_000.0)
2892
+ rec = state.load_state("proj-a", 1)
2893
+ line = {"events": []}
2894
+ assert watchdogd._try_recover_400(ctx, "proj-a", 1, rec,
2895
+ "cc-proj-a-0a9b", line) is True
2896
+ assert calls == [("proj-a", 1, "sid-proj-a-1", "cc-proj-a-0a9b")]
2897
+ assert any(ev.endswith(":recovered") for ev in line["events"])
2898
+ assert "cc-proj-a-0a9b" in ctx.rec400
2899
+
2900
+
2901
+ def test_tick_context400_handoff_requested_triggers_recovery(
2902
+ cc_home, tmp_path, monkeypatch):
2903
+ # issue #100 (connector-280 live, third gate): classify() SKIPs
2904
+ # everything outside ACTIVE/WARNED, so the hard-limit brick
2905
+ # (gate entry + draft written + turn 400'd, no Stop hook) never
2906
+ # reached _try_recover_400 even after its gate admitted the state -
2907
+ # the tick loop's SKIP dispatch only carried CHECKPOINT_VERIFIED
2908
+ # (BUG-6 precedent). SKIP + HANDOFF_REQUESTED + turn_active must
2909
+ # reach the gate too (full_auto/state/dedup/400-scan/fresh-prompt
2910
+ # checks stay inside _try_recover_400 - single source of truth).
2911
+ pushes = _capture_pushes(monkeypatch)
2912
+ io = FakeIO(pane=PROMPT_PANE, sessions=["cc-proj-a-0a9b"])
2913
+ sdir = _mk(st="HANDOFF_REQUESTED", turn_active=True)
2914
+ _stale_prompt(sdir) # age is moot: row 7 SKIP dominates eligibility
2915
+ calls = _patch400(monkeypatch, tmp_path)
2916
+ ctx = _ctx(io, now=10_000.0)
2917
+ line = watchdogd.tick(ctx)
2918
+ assert line["sessions"][0]["outcome"] == "SKIP"
2919
+ assert calls == [("proj-a", 1, "sid-proj-a-1", "cc-proj-a-0a9b")]
2920
+ assert any(e.startswith("context400:") for e in line["events"])
2921
+ assert io.sends == [] and pushes == []
File without changes
File without changes