Commit Graph

6489 Commits

Author SHA1 Message Date
YeonGyu-Kim 2613de522f fix(prompt-async-gate): timeout isSessionActive to prevent infinite hang on stale SDK status
- Wrap isSessionActive in withDispatchTimeout (capped at 5s) so a
  stuck OpenCode SDK status() call cannot block internal prompts forever.
- Catch the timeout and treat session as inactive so the prompt can
  proceed rather than hanging indefinitely.
- Add regression test: session.status that never resolves now times out
  and allows dispatch instead of hanging the test (and production).

Refs: AGENTS.md internal-message-injection safety note
2026-05-17 03:41:08 +09:00
YeonGyu-Kim 169e61f775 test(audit): allowlist build-team-idle-wake-hint-client.ts in prompt route audit
Red: a43215f24 introduced plugin/build-team-idle-wake-hint-client.ts which
    accesses session.promptAsync for method binding. The audit test flagged it
    as a raw prompt route offender, breaking CI on dev.

Green: Add the narrow client facade to RAW_PROMPT_ALLOWLIST with the same
       justification pattern used for event.ts and recover-unavailable-tool.ts.
       The facade binds SDK methods back to the Session instance and performs
       no direct dispatch itself; all downstream calls flow through the shared
       prompt-async gate.

Verification: bun test src/shared/prompt-async-route-audit.test.ts passes
(6 pass, 0 fail, offenders list empty).
2026-05-17 03:10:02 +09:00
YeonGyu-Kim a43215f24e fix(plugin/event): bind team-idle-wake-hint client methods to SDK Session
The team-mode wiring at `createEventHandler` extracted
`pluginContext.client.session.promptAsync` and `.status` into a fresh
wrapper object. The methods were copied by reference, so the prompt-async
gate's `session.promptAsync.bind(session)` was binding to that plain
wrapper rather than the underlying SDK `Session` instance. The opencode
SDK's `promptAsync` reads `this._client.post(...)`, so production calls
threw `TypeError: undefined is not an object (evaluating 'this._client')`
on the very first dispatch — fingerprinted in /tmp/oh-my-opencode.log as
688 `background-agent-parent-wake`, 47 `model-suggestion-retry`, and 4
`team-idle-wake-hint` failures over the past three days.

Move the wrapper construction into `buildTeamIdleWakeHintClient`, which
preserves the narrow factory contract while binding both methods back to
the SDK `Session` so `_client` survives the dispatch. Cover the contract
with four BDD-style tests including the historical destructure-only
failure mode so any future regression is caught at unit-test time.
2026-05-17 02:06:52 +09:00
YeonGyu-Kim 271878bcea perf(rules-injector): cache full candidates and memoize ancestor scans
The rule scan cache stored a path[] keyed by (projectRoot|startDir|
skipClaudeUserRules), so two issues stacked up on every tracked tool
call:

- Cache hits still ran safeRealpathSync(realpathSync) and re-derived
  isGlobal / distance / isSingleFile for every cached path. That is a
  per-candidate sync syscall plus repeated string-prefix walks.
- Sibling files in the same project landed under different startDir
  keys, so the entire walk-and-recursive-scan chain repeated even
  though every ancestor rule directory was identical.

Store the full RuleFileCandidate[] in the per-call cache so a cache hit
returns immediately with no realpath syscall. Add a separate per-
directory scan cache (getDirScan/setDirScan) keyed by absolute rule
directory path, so two sibling files reuse the same readdir + realpath
work for every shared ancestor.

Microbench (200 files / 20 modules / cached session):
- single sweep: 41.8ms -> 2.5ms (16x)
- 3-pass replay: 88.6ms -> 3.2ms (28x)

Pin the new invariants with two new tests:
- 'does not re-resolve symlinked rule path on cache hit' via a
  retargeted directory symlink.
- 'reuses ancestor directory scan for sibling files in the same
  project' by deleting the source rule file between the two calls.
2026-05-17 02:06:52 +09:00
YeonGyu-Kim c25f75294e perf(rules-injector): cache project root for visited ancestors
findProjectRoot was keyed by exact startPath, so sibling files in the
same project repeated the entire upward marker walk. The walk does one
existsSync per marker per ancestor directory, which adds up on every
read/write/edit/multiedit tool call.

Track every directory visited during the walk and seed the cache with
the resolved root for each of them. Subsequent lookups for any
descendant short-circuit to the cached ancestor without re-running
marker probes. Cache invalidation still happens on session.deleted /
session.compacted, so production semantics are unchanged.

Pin the new contract via a sibling-startpath test, and make the
existing finder.test.ts beforeEach explicit about cache state so the
more aggressive cache does not leak between tests.
2026-05-17 02:06:52 +09:00
YeonGyu-Kim f843f57cf0 Merge pull request #4088 from code-yeongyu/fix/session-agent-map-cleanup
fix(claude-code-session-state): clear session-agent map on delete and sync cleanup
2026-05-17 01:42:03 +09:00
YeonGyu-Kim 2b8782de85 fix(claude-code-session-state): clear session-agent map on delete and sync cleanup
External review on PR #4074 noted that adding setSessionAgent for child
sessions left sessionAgentMap holding entries after the session was
deleted or after the sync call_omo_agent executor cleaned up other
owned state. The map only grows; entries never get reused but they do
accumulate across long-running plugin instances.

Close both gaps:
- BackgroundManager.handleEvent for session.deleted now calls
  clearSessionAgent for the deleted session id on both the early-return
  no-task branch and the cascade tail. This pairs with the existing
  clearDelegatedChildSessionBootstrap and SessionCategoryRegistry.remove
  so all owned session state is dropped together.
- sync-executor finally for createdSessionForExecution now calls
  clearSessionAgent alongside the existing subagentSessions,
  syncSubagentSessions, and deleteSessionTools cleanup so sessions this
  executor created cannot leak their agent mapping.

Adds focused tests:
- BackgroundManager.handleEvent - session.deleted cascade > should
  clear session agent state for deleted sessions to prevent map leak
- executeSync > registers child-session bootstrap and tracked prompt
  state before sync prompt dispatch (extended assertion for cleanup)
2026-05-17 01:28:12 +09:00
YeonGyu-Kim 25d8054192 Merge pull request #4074 from code-yeongyu/fix/delegate-task-spawn
fix(delegate-task): start child prompts reliably
2026-05-17 01:00:03 +09:00
YeonGyu-Kim c9ec11dd51 bump comment-checker to 0.7.1 2026-05-17 00:51:50 +09:00
YeonGyu-Kim d3318617d0 fix(background-agent): clean child session-agent state on pre-start abort and normalize stored agent
Two adjacent gaps cubic flagged on the previous diff:

1. spawner.startTask stored input.agent (potentially prefixed with sort
   marker and ZWSP) in setSessionAgent, but the prompt body used the
   stripped/normalized form. The session-agent registry therefore did
   not match what promptAsync actually dispatched. Capture the
   normalized agent once at the top of startTask and use it for
   setSessionAgent plus the launch log lines.
2. manager.startTask wrote setSessionAgent(sessionID, input.agent)
   before the cancelled and stale-attempt cleanup branches, but those
   branches only cleared subagentSessions and the delegated bootstrap.
   The session->agent mapping survived as orphan state after an aborted
   launch. Call clearSessionAgent inside both early-return paths so
   nothing remains tied to a session we just aborted.

Adds focused tests for both: spawner persistence parity with promptAsync
and manager cancellation cleanup leaving getSessionAgent undefined.
2026-05-17 00:30:50 +09:00
YeonGyu-Kim cc97a023cc test(agents): drop unsafe AgentFactory cast and add typed empty skills
Tests that mock an AgentFactory were using an `as AgentFactory` cast
and a separate mutation of `mockFactory.mode` to satisfy the type.
Replace with Object.assign so the factory type is constructed correctly
without casts. Also type the empty discoveredSkills fixture so its
element type is inferred from the function signature instead of
collapsing to never[].
2026-05-17 00:09:21 +09:00
YeonGyu-Kim 791fbf3e55 refactor(delegate-task): share buildSyncPromptTools between bootstrap and prompt dispatch
Two call sites built the sync delegate tool gate independently:
sync-prompt-sender's prompt body construction and sync-task's bootstrap
registration. Drift between them would let bootstrap claim one tool set
while the actual prompt sent a different one. Extract buildSyncPromptTools
and route both call sites through it so the registered bootstrap and the
dispatched prompt always agree.
2026-05-17 00:09:11 +09:00
YeonGyu-Kim ea5f6ddfd7 fix(call-omo-agent): register bootstrap and session agent before sync prompt dispatch
call_omo_agent sync path created the child OpenCode session and went
straight into promptAsync without registering child session agent,
session tools, or bootstrap state. If first dispatch failed before any
durable user message persisted, runtime fallback could not reconstruct
the original prompt or the agent identity for that child session.

Bind setSessionAgent and setSessionTools to the child session id with
the same tool restrictions that the prompt body sends, register a
delegated child session bootstrap with the prompt text, fallback chain,
and prompt tools, then clean bootstrap + session tools in finally for
sessions this call created.
2026-05-17 00:08:56 +09:00
YeonGyu-Kim 097d7dc547 fix(background-agent): keep delegated skill, permission, and child agent across retries
Three coupled gaps surfaced after the initial spawn fix:

1. fallback-retry-handler dropped task.skillContent and
   task.sessionPermission when rebuilding LaunchInput, so the retried
   background task lost the delegated system prompt and question-deny
   permission rule.
2. manager.startTask never bound the child sessionID to the resolved
   agent via setSessionAgent, leaving runtime fallback and other hooks
   with no idea which agent owned the new child session.
3. The fallback-to-general path in spawner.ts rebuilt the prompt body
   without going through buildFallbackBody, so bootstrap state, session
   tools, and session agent updates drifted apart.

Persist skillContent and sessionPermission on BackgroundTask, bind
setSessionAgent/updateSessionAgent at session creation and on fallback,
and route the FALLBACK_AGENT retry through buildFallbackBody so the
prompt body, bootstrap tools, and session registries all agree.
2026-05-17 00:08:44 +09:00
YeonGyu-Kim ba648685d4 fix(runtime-fallback): carry delegated system and tools through bootstrap retry
When the first prompt fails before any durable user message persists,
runtime fallback retry was rebuilding the request from parts alone and
losing the delegated agent system prompt and tool gates. Now it threads
bootstrap.system and bootstrap.tools into the retry body alongside the
captured retry parts, so the retried prompt keeps the same scope as the
initial delegate launch.
2026-05-17 00:08:30 +09:00
YeonGyu-Kim 761f682add refactor(delegated-bootstrap): accept optional system and tools
Add optional system and tools fields to DelegatedChildSessionBootstrap
so callers can stash the original delegated context alongside retry
parts. Backward compatible - existing callers stay unchanged.
2026-05-17 00:08:19 +09:00
YeonGyu-Kim 4f9813848a feat: add ci test runner, session routing, bash parser, and test fixtures
- script/run-ci-tests.ts: CI test sharding and isolation logic
- script/run-ci-tests.test.ts: tests for CI test target selection
- src/features/background-agent/session-route.ts: session prompt routing for background agents
- src/hooks/interactive-bash-session/parser.ts: interactive bash output parser
- src/hooks/ralph-loop/completion-promise-detector-test-input.ts: test fixture for completion promise detection
2026-05-16 23:51:43 +09:00
github-actions[bot] 166e5de06c @pizzav-xyz has signed the CLA in code-yeongyu/oh-my-openagent#4084 2026-05-16 11:43:47 +00:00
YeonGyu-Kim 80fa177b11 Merge pull request #4075 from code-yeongyu/feature/migrate-sisyphus-to-omo
Migrate legacy workspace state to .omo
2026-05-16 19:55:34 +09:00
YeonGyu-Kim 6573bd9431 chore(workspace): move test discipline rule to omo 2026-05-16 19:27:52 +09:00
YeonGyu-Kim 5a2c3bbba8 fix(workspace): match omo guard paths cross-platform 2026-05-16 19:14:54 +09:00
YeonGyu-Kim b5992b13ec test(shared): stabilize port utility interface check 2026-05-16 18:28:33 +09:00
YeonGyu-Kim cdac0d69bb fix(workspace): report only the active notepad change 2026-05-16 18:12:50 +09:00
YeonGyu-Kim 240a4a17ad fix(workspace): harden omo migration review issues 2026-05-16 18:02:54 +09:00
YeonGyu-Kim fbc5768f9a Merge pull request #3971 from MoerAI/fix/task-examples-add-run-in-background
fix(agents): add run_in_background to category task() examples in prompts (fixes #3960)
2026-05-16 18:02:01 +09:00
YeonGyu-Kim 82ec099c3a fix(atlas): match omo as a path segment 2026-05-16 17:52:28 +09:00
YeonGyu-Kim 63519ec563 docs(workspace): document omo workspace paths 2026-05-16 17:42:06 +09:00
YeonGyu-Kim f10f796318 fix(workspace): keep omo and legacy rules compatible 2026-05-16 17:41:49 +09:00
YeonGyu-Kim 36e373cdbb feat(workspace): point planning guardrails at omo 2026-05-16 17:41:35 +09:00
YeonGyu-Kim a86221b1a9 feat(workspace): store runtime state under omo 2026-05-16 17:40:11 +09:00
YeonGyu-Kim 5dca1a5742 feat(workspace): migrate legacy sisyphus state to omo 2026-05-16 17:39:54 +09:00
YeonGyu-Kim 7c2e2fe1fa fix(background-agent): redact task registry views 2026-05-16 17:12:48 +09:00
YeonGyu-Kim 982fa81367 fix(delegate-task): start child prompts reliably
Preserve delegated child prompt/bootstrap metadata for early runtime fallback before OpenCode has persisted the first user turn. Bind prompt gate calls to the SDK session receiver and keep completed background task lookup visible across plugin manager instances.
2026-05-16 16:27:56 +09:00
YeonGyu-Kim 76e573a920 Merge pull request #4073 from code-yeongyu/fix/team-create-permission-inline-spec
fix(team-mode): accept legacy inline team specs
2026-05-16 15:49:26 +09:00
YeonGyu-Kim d974cd3d3b test(hooks): repair stale retry harnesses 2026-05-16 15:43:15 +09:00
YeonGyu-Kim cf7bf9d02d fix(team-mode): accept legacy inline specs 2026-05-16 15:43:08 +09:00
YeonGyu-Kim a20540579e Merge pull request #4068 from code-yeongyu/feat/pre-publish-fix-v420
v4.2.0: pre-publish review fixes (BLOCKER-1..3, HIGH-5..10, MID-11/12)
2026-05-16 14:50:54 +09:00
YeonGyu-Kim 3f3a63c54d docs(changelog): v4.2.0 entry with known issues and supersession history
Documents the v4.2.0 release window in Keep-a-Changelog format, including prompt gate fixes, internal audits, known issues, and the watchdog supersession history.

Closes LOW-14, LOW-16
2026-05-16 02:13:58 +09:00
YeonGyu-Kim eba17441cf test(mock-module-audit): require lifecycle cleanup for mock.module
New AST-based audit walks all *.test.ts files under src/ and asserts every mock.module(...) call is paired with cleanup. Existing offenders are documented in MOCK_MODULE_LIFECYCLE_ALLOWLIST with TODO references.

Closes HIGH-10
2026-05-16 02:13:11 +09:00
YeonGyu-Kim aaa215c5de docs(release-process): add post-fix repro verification policy
Race-condition and concurrency fixes must include reporter-verified repro confirmation before the originating issue is closed. Adds the checklist and rationale grounded in recent incident examples.

Closes MEDIUM-12
2026-05-16 02:12:28 +09:00
YeonGyu-Kim 3435c9bef2 docs(adr): write prompt-async-gate ADR
Documents the reservation-based duplicate-injection guard introduced in v4.2.0 with accepted status, exported API signatures, release semantics, migration notes, and commit references.

Closes MEDIUM-11
2026-05-16 02:12:01 +09:00
YeonGyu-Kim 102d067022 fix(model-suggestion-retry): release reservation on async error path
The promptWithModelSuggestionRetry async variant did not release the
post-dispatch reservation when the wrapped promptAsync threw. Callers
that immediately retry (such as sendSyncPrompt error toast paths) hit
the gate as reserved and surfaced 'promptAsync skipped by gate: reserved'
instead of the underlying error.

Mirrors the existing sync variant fix from ff1b15d53.

Closes regression introduced by BLOCKER-2 hardening
2026-05-16 01:56:04 +09:00
YeonGyu-Kim 5a8bd05db0 test(prompt-async-gate): replace timer waits with deterministic sync (BLOCKER-3)
Lines 79/142/428 of prompt-async-gate.test.ts used timer-based synchronization, violating .sisyphus/rules/test-discipline.md which forbids time-based test waits. Replace them with explicit dispatch awaits and mocked-time expiry so the assertions do not depend on CI machine speeds.

Closes BLOCKER-3 (Wave 2 cleanup)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-16 01:50:11 +09:00
YeonGyu-Kim 9dd52a0435 docs(changelog): v4.2.0 entry covering BLOCKER + HIGH + KNOWN ISSUES
Closes L14

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-16 01:43:57 +09:00
YeonGyu-Kim 7dbb34cd4f refactor(background-agent): wire ParentWakeNotifier into BackgroundManager
Replace the inlined parent-wake coalescing logic in manager.ts with delegation to the ParentWakeNotifier extracted in c1ccf8d09. The four timer Maps and the related methods now live in their own module with a narrow public API, while BackgroundManager retains the wiring point and the enqueue-callback bridge.

Closes HIGH-9 (step 2: integration)

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-16 01:43:16 +09:00
YeonGyu-Kim 41ff7bca24 fix(background-agent): release prompt gate before agent fallback retry
Release the model-suggestion prompt reservation before the spawner retries with the fallback agent so the immediate retry is not skipped by the gate.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-16 01:42:54 +09:00
YeonGyu-Kim 209063e861 docs(known-issues): document delegate-task early-failure-fallback deferral
PR #3825 introduced a delegated child-session bootstrap to capture first-prompt retry payloads before history is persisted, addressing the empty-history fallback gap. After merge the PR's own regression test failed on clean root bun test (6828 pass / 1 fail), so PR #4044 reverted it. Ship v4.2.0 with the bug documented and a workaround so users have an explicit story for the unfixed delegated child-session early-failure path. Reland will target v4.2.1.

Closes BLOCKER-4 (Path B - reland deferred to v4.2.1)
2026-05-16 01:40:57 +09:00
YeonGyu-Kim 0f8902c49b docs(changelog): v4.2.0 entry
Document all 7+ BLOCKER+HIGH fixes, breaking-change-free additions
(public exports), known issue for delegated child-session fallback
(PR #3825 deferred to v4.2.1), and internal-only changes.

Closes L14
2026-05-16 01:38:59 +09:00
YeonGyu-Kim 4848017219 test(mock-module-audit): require lifecycle cleanup for mock.module
Walk all test files, parse with TypeScript Compiler API, assert every
mock.module(path, factory) invocation has a paired afterEach/afterAll
cleanup. Existing offenders are allowlisted with TODOs for v4.2.1 work.

Closes H10
2026-05-16 01:37:28 +09:00
YeonGyu-Kim 845d862b9b test(prompt-async-gate): replace setTimeout sleeps with deterministic sync
Test-discipline.md forbids setTimeout(resolve, N) and sleep(N) in test bodies. Replace the 3 microtask and expiry sleeps with explicit microtask yields and deterministic clock advancement, preserving the prompt gate invariants without real-time waits.

Closes BLOCKER-3

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-05-16 01:36:57 +09:00