Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ class Session(BaseModel):

- ✓ Bounded OpenCode capture and launch-proven native identity (itdove/devaiflow#648)
- Retains created IDs and persists them before `daf open` starts the child, avoiding post-exit rediscovery of known IDs
- Shares a two-second fallback query deadline across polling, version detection, and subprocess execution, with content-free failure diagnostics
- Shares a bounded fallback query deadline across polling, version detection, and subprocess execution, with content-free failure diagnostics
- Refuses unresolved pending/missing-ID reopen instead of silently replacing conversations; preserves project scoping, ambiguity, and clone guards

- ✓ Retry cancelled first OpenCode setup without weakening identity guards (itdove/devaiflow#650)
Expand All @@ -1860,7 +1860,7 @@ class Session(BaseModel):
- Revalidates session/worktree/source identity and active process use before removal

- ✓ Kilo interactive native session capture budget (itdove/devaiflow#693)
- Gives Kilo version detection and session-list startup a bounded 10-second budget independent of OpenCode's 2-second budget
- Gives Kilo version detection and session-list startup its own bounded 10-second budget
- Preserves exact project-scoped ID capture, post-exit DAF title updates, and fail-closed timeout/ambiguity handling
- Adds slow-query, timeout, title, project-scope, and reopen-budget regression coverage

Expand All @@ -1881,6 +1881,12 @@ class Session(BaseModel):
- Documents that manual Git operations do not complete sessions or update status/time tracking
- Verifies completion skips redundant commit/push work for pre-committed and pre-pushed changes

- ✓ Bounded OpenCode lookup and verified reopen recovery (itdove/devaiflow#699)
- Gives fallback capture and reopen verification a bounded 10-second budget for slow successful queries
- Preserves saved identity and metadata on timeout or failed/ambiguous verification; never launches a replacement
- Shows recovery steps tied to the recorded project/worktree path and verified native ID
- Adds slow-reopen, timeout, and metadata-preservation regression coverage

## Release Management

### Overview
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- **Bounded OpenCode session lookup and verified reopen recovery** (#699)
- Extends fallback capture and reopen verification to a bounded 10-second query budget
- Keeps timeouts and failed/ambiguous verification fail-closed without replacing saved identity
- Shows recovery guidance using the recorded project/worktree path and verified `daf update` flow
- **Issue-aware completed worktree cleanup** (#675)
- Requires explicit issue-closure approval and a fresh tracker-confirmed closed status before `daf complete` removes a worktree
- Adds `daf worktree clean <issue-key>` to retry cleanup for completed sessions without repeating completion operations
Expand Down
7 changes: 3 additions & 4 deletions devflow/agent/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,9 @@
PENDING_CAPTURE_PLACEHOLDER = "pending-capture"
_SESSION_CAPTURE_POLL_ATTEMPTS = 10
_SESSION_CAPTURE_POLL_INTERVAL = 0.1
OPENCODE_CAPTURE_TIMEOUT = 2.0
# Kilo session queries include version detection and a fresh CLI startup. Keep
# that backend-specific startup allowance separate from OpenCode's tighter
# fallback-capture budget.
OPENCODE_CAPTURE_TIMEOUT = 10.0
# Keep separate backend budgets so startup-latency changes for one CLI do not
# silently change the other adapter's bounded session-capture behavior.
KILO_CAPTURE_TIMEOUT = 10.0


Expand Down
43 changes: 31 additions & 12 deletions devflow/cli/commands/open_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
)



class _JsonAwareConsole:
"""Suppress Rich output while a command is producing JSON."""

Expand Down Expand Up @@ -360,25 +359,40 @@ def _extract_repository_from_issue_key(issue_key: str, issue_tracker: Optional[s


def _refuse_unverified_opencode_session(
session_name: str, reason: str, output_json: bool, backend: str = "opencode"
session_name: str,
reason: str,
output_json: bool,
backend: str = "opencode",
project_path: Optional[str] = None,
) -> NoReturn:
"""Preserve unresolved native identity instead of silently launching a replacement."""
if backend == "kilo":
agent_name = "Kilo"
list_guidance = "Kilo's `kilo session list --format json --all`"
else:
agent_name = "OpenCode"
list_guidance = "OpenCode's session list"
list_guidance = (
"`opencode session list --format json` (add `--standalone` on v2)"
)
recorded_location = (
f"the recorded project/worktree `{project_path}`"
if project_path
else "the recorded project/worktree"
)
message = (
f"Cannot safely resume {agent_name}: {reason}. No replacement conversation was launched. "
"If a native conversation exists, verify its ID and project directory with "
f"{list_guidance}, then run "
f"`daf update {session_name} --session-id VERIFIED_ID` outside the agent session. "
f"If a native conversation exists, from a regular terminal in {recorded_location}, "
f"inspect {list_guidance} and verify its ID and project directory. Then run "
f"`daf update {session_name} --session-id VERIFIED_ID` outside the agent session "
f"and retry `daf open {session_name}`. "
"To explicitly archive this record and start over (even without a saved branch), "
f"use `daf open {session_name} --new-conversation`."
)
if output_json:
emit_json(success=False, error={"code": "AGENT_SESSION_UNVERIFIED", "message": message})
emit_json(
success=False,
error={"code": "AGENT_SESSION_UNVERIFIED", "message": message},
)
else:
console.print(f"[yellow]{escape(message)}[/yellow]")
raise click.exceptions.Exit(1)
Expand Down Expand Up @@ -617,8 +631,6 @@ def refuse(message: str) -> bool:
return True




@require_outside_claude
@_json_output_scope
def open_session(
Expand Down Expand Up @@ -1085,6 +1097,11 @@ def open_session(
"or explicit never-launched provenance; automatic recovery is unavailable",
output_json,
backend=effective_agent_backend,
project_path=(
active_conv.temp_directory
or active_conv.worktree_path
or active_conv.project_path
),
)

if (
Expand All @@ -1096,6 +1113,7 @@ def open_session(
# Check if the session exists using the agent-aware check
# This handles both Claude (.jsonl file) and OpenCode (database query) correctly
from devflow.agent import create_agent_client

agent_client = create_agent_client(effective_agent_backend)
agent_name = agent_client.get_agent_name()

Expand All @@ -1118,7 +1136,8 @@ def open_session(
else OPENCODE_CAPTURE_TIMEOUT
)
conversation_exists = (
active_conv.ai_agent_session_id in agent_client.get_existing_sessions(
active_conv.ai_agent_session_id
in agent_client.get_existing_sessions(
check_path, timeout=capture_timeout, strict=True
)
)
Expand All @@ -1128,13 +1147,15 @@ def open_session(
str(exc),
output_json,
backend=effective_agent_backend,
project_path=check_path,
)
if not conversation_exists:
_refuse_unverified_opencode_session(
session.name,
"the saved native ID was not found in this project",
output_json,
backend=effective_agent_backend,
project_path=check_path,
)
else:
conversation_exists = agent_client.session_exists(active_conv.ai_agent_session_id, check_path)
Expand Down Expand Up @@ -4762,8 +4783,6 @@ def _handle_temp_directory_for_ticket_creation(session, session_manager, config=
return True




def _display_conflict_resolution_help(project_path: str, session_name: str, agent_name: str = "Claude Code") -> None:
"""Display detailed help for resolving merge conflicts.

Expand Down
11 changes: 7 additions & 4 deletions devflow/cli_skills/daf-workflow/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,15 @@ session metadata are preserved on refusal.

OpenCode retains native IDs returned by titled launch rather than rediscovering
them on exit; `daf open` saves that identity before starting the child. Fallback
capture has a two-second total query deadline and fails closed on query errors or
same-project ambiguity. A legacy `pending-capture` reopen cannot prove ownership
capture and saved-ID reopen verification use a bounded 10-second total query
deadline and fail closed on query errors or same-project ambiguity. A legacy
`pending-capture` reopen cannot prove ownership
without a saved launch ID/baseline, so it stops with verification guidance rather
than silently replacing the conversation. The user can verify the native ID and
canonical directory, then run `daf update <session-name> --session-id <verified-id>`
outside the agent, or deliberately use `daf open <session-name> --new-conversation`.
canonical directory from the recorded project/worktree path, then run
`daf update <session-name> --session-id <verified-id>` outside the agent and retry
`daf open <session-name>`, or deliberately use
`daf open <session-name> --new-conversation`.
Do not guess an ID from ordering/titles or edit backend storage to recover it.

Cancelled first-open setup is retryable with ordinary `daf open` when DAF saved
Expand Down
18 changes: 11 additions & 7 deletions docs/guides/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -1928,9 +1928,10 @@ If you can't resolve the issue:

DAF retains IDs returned by titled creation and `daf open` saves them before
starting OpenCode. Known IDs are not rediscovered after exit. When fallback
discovery is necessary, a two-second deadline covers queries, version detection,
and polling sleeps, rather than allowing ten independent ten-second queries.
This deadline does not bypass completion's directory-holder checks.
discovery or saved-ID reopen verification is necessary, a bounded 10-second
deadline covers queries, version detection, and polling sleeps, rather than
allowing ten independent queries. This deadline does not bypass completion's
directory-holder checks.

Warnings distinguish a failed query (timeout, CLI exit, invalid JSON, or version
detection), no new project-scoped sessions, and multiple new candidates. A failed
Expand All @@ -1954,11 +1955,14 @@ a replacement. A missing saved native ID or failed verification also stops safel

From a regular terminal, after exiting the agent:

1. If a native conversation exists, inspect `opencode session list --format json --standalone` on v2 (omit
`--standalone` on v1). Verify the intended ID and canonical project directory;
do not infer ownership from timestamps or titles alone.
1. A timeout is not proof that the saved session is missing. In the exact
project/worktree path recorded for the DAF conversation, inspect
`opencode session list --format json --standalone` on v2 (omit `--standalone`
on v1). Verify the intended ID and canonical project directory; do not infer
ownership from timestamps or titles alone.
2. Restore a verified association with
`daf update <session-name> --session-id <verified-native-id>`, then reopen.
`daf update <session-name> --session-id <verified-native-id>`, then retry
`daf open <session-name>`.
3. If you deliberately want a fresh conversation instead, run
`daf open <session-name> --new-conversation`. This archives the previous
conversation and its identity/history metadata; it is not recovery of the
Expand Down
5 changes: 3 additions & 2 deletions docs/reference/ai-agent-support-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,9 @@ ID after their title is synchronized to the current DAF session name.
Native IDs returned by titled creation are retained instead of being rediscovered
after exit. `daf open` persists that launch-proven ID before starting the child.
Known IDs are never replaced by polling results. Fallback discovery has a
two-second total deadline, including CLI execution and lazy version detection;
query errors, empty results, and ambiguity have different content-free diagnostics.
bounded 10-second total deadline, including CLI execution and lazy version
detection; query errors, empty results, and ambiguity have different content-free
diagnostics.
An unavailable pre-launch snapshot cannot be treated as an empty baseline.

Commit-message generation also adapts the `run` flags by major version: v1
Expand Down
13 changes: 8 additions & 5 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1252,13 +1252,16 @@ inactive sessions alone do not prove exclusive workspace ownership. See
[temporary-clone troubleshooting](../guides/troubleshooting.md#temporary-clone-still-in-use-after-agent-exit).

OpenCode launch-proven native IDs are retained rather than rediscovered on exit;
`daf open` saves them before starting the child. Fallback post-exit capture has a
two-second total query deadline and distinguishes query failure, no new sessions,
and ambiguous same-project candidates. Legacy `pending-capture` reopen, missing
`daf open` saves them before starting the child. Fallback capture and saved-ID
reopen verification use a bounded 10-second total query deadline, distinguishing
query failures, no new sessions, and ambiguous same-project candidates. Legacy `pending-capture` reopen, missing
native IDs, and failed verification stop without selecting a replacement
(`AGENT_SESSION_UNVERIFIED` in JSON). Verify the ID and directory before using
(`AGENT_SESSION_UNVERIFIED` in JSON). Verify the ID and directory in the recorded
project/worktree path, then use
`daf update <session-name> --session-id <verified-native-id>` outside the agent,
or explicitly archive/start fresh with `daf open <session-name> --new-conversation`.
and retry `daf open <session-name>`. Use `--standalone` to inspect the session list
on OpenCode v2. Alternatively, explicitly archive/start fresh with
`daf open <session-name> --new-conversation`.
This explicit start-over also supports OpenCode records without a saved branch;
the old identity/history is archived and initial branch setup runs for the new
conversation. New first-open setup records carry explicit never-launched
Expand Down
5 changes: 3 additions & 2 deletions tests/test_kilo_capture_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def advance(seconds):
def test_slow_kilo_queries_capture_project_session_with_backend_budget(
monkeypatch, clock
):
"""Version detection and slow listing stay within Kilo's larger bounded budget."""
"""Version detection and slow listing stay within Kilo's bounded budget."""
agent = KiloAgent()
list_calls = 0
list_timeouts = []
Expand Down Expand Up @@ -91,7 +91,8 @@ def launch(**kwargs):
)
assert list_calls == 3
assert list_timeouts[1] == pytest.approx(KILO_CAPTURE_TIMEOUT)
assert KILO_CAPTURE_TIMEOUT > OPENCODE_CAPTURE_TIMEOUT
assert KILO_CAPTURE_TIMEOUT == 10.0
assert KILO_CAPTURE_TIMEOUT >= OPENCODE_CAPTURE_TIMEOUT
assert clock.now < KILO_CAPTURE_TIMEOUT + 1


Expand Down
Loading
Loading