Skip to content

Compaction throws TypeError when another plugin has already removed event.tools #668

Closed

Description

@yunuserenm

delete event.tools.compress throws when another plugin has already removed event.tools

Version: @tarquinen/opencode-dcp 3.2.0
OpenCode: V2 (2.2.5) on Windows 11
Related plugin: opencode-runtime-fallback 0.3.1

Summary

When DCP's compaction handler runs after a plugin that clears event.tools, DCP throws a TypeError and the whole compaction fallback is aborted.

Where

dist/index.js, lines ~8363 and ~8366 (3.2.0 build):

delete event.tools.compress;

If a preceding context/compaction hook mutated the event and set event.tools to undefined, the delete expression dereferences undefined and throws:

TypeError: Cannot convert undefined or null to object
    at deleteProperty ...

Result in the OpenCode server log:

level=ERROR message="Failed to drain Session"
Compaction fallback failed

Why it happens here

opencode-runtime-fallback 0.3.1 registers a context/compaction hook that does:

delete event.tools;

Hook order is not guaranteed, so DCP can receive an event whose tools field no longer exists.

Minimal fix

if (event.tools) delete event.tools.compress;

or, keeping it one line:

delete event.tools?.compress;

(delete on undefined?.x is valid and a no-op.)

Why it matters

It is a hard failure, not a graceful degradation: the fallback compaction pass never completes and the session stays over the context limit. Any plugin that touches event.tools can trigger it, not only the fallback plugin.

Priority

Low code complexity, but it turns a benign plugin interaction into a broken session. Defensive guard seems worth adding.

Activity

  1. Tarquinen commented on Nov 16, 2026

    @Tarquinen
    Owner

    Fixed in #678 (merged into dev). It will ship in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions