Skip to content

feat(harness): optimize LLM input context and compaction summaries #3690

Closed

Description

@Buktal

Problem

Harness model input currently mixes instructions with changing state, and its compaction input drops information that the summary needs:

  • WorkspaceContextMiddleware renders the date and session ID with stable environment instructions. The skill catalog is appended to the system prompt.
  • Subagent catalogs, async task progress, and team roster/board/notices are rendered with stable system guidance. Updating these facts changes the system message even when the guidance is unchanged.
  • ConversationCompactor supplies tool names without arguments and previews only the first 500 result characters. Paths, commands, trailing errors, and result error identity can be lost before the summary model sees them.
  • The general-purpose subagent identity constant is not used by its factory. Shared tool descriptions do not carry all the recovery instructions that currently live in the coding-agent example.

These are input-layout and information-preservation problems. They do not establish a measured improvement in provider cache hits or model task success.

Proposed review units

Split the implementation into four independent PRs against main, with tests next to each behavior:

Unit Scope Files
1 Render skill catalogs and date/session facts as runtime materials; retain the catalog through history compaction 10
2 Keep stable subagent/team guidance in system and project live catalogs, progress, roster and notices after the conversation 9
3 Retain tool argument names, short values, long-value head/tail previews and result error identity; improve summary extraction and continuation instructions 3
4 Clarify built-in file/delegation tool contracts and general-purpose subagent identity/final delivery 6

Each PR will reference this issue and can be reviewed and merged independently. Repository-local agent setup files are outside these changes.

Acceptance and evidence

  • Changing the skill catalog or session ID does not rewrite stable environment instructions. The first request after history compaction still advertises available skills.
  • Changing agent/task/team state leaves the corresponding system guidance unchanged; hidden and primary-only agents stay out of the visible catalog.
  • A tool call with long old_string and new_string values retains the short path between them, plus the two values' head/tail markers. Raw-only arguments remain visible; short raw JSON retains its numeric representation exactly.
  • Error results remain identifiable, trailing result text reaches the summary model, and generated summaries retain the native history lookup only when it exists.
  • Spawn wording distinguishes parent context from a persistent child's own history; follow-ups can steer/continue the task. File descriptions match ASJ's create-only writes, zero-based read offset and exact text replacement after line-ending normalization.

The parameter preview deliberately spends more space when necessary to preserve separate fields. In one constructed two-long-values case it uses 1,334 characters rather than a 629-character whole-object clipping prototype, while preserving the middle path and both values' head/tail markers. This is an information-retention check, not a token-savings benchmark.

Alternatives and boundaries

Use the existing context placement, synthetic-message metadata, required flag and pruning helper. A new snapshot store, event replay scheme or generic post-compaction reinsertion mechanism is unnecessary for these changes.

Related: #2671. This work moves date/session facts and skill catalogs, but leaves workspace environment paths in the configured system environment. It therefore does not fully solve the cross-session workspace-path case in that issue and does not claim its provider-cache measurements as results of this implementation.

Related: #3575 tracks a different compaction/memory series; this issue concerns summary input/prompt shape and runtime context placement.

Pull requests

PR links and independent validation:

These are four independent one-commit branches based on origin/main. GitHub CI is running on each PR; the first PR's build jobs are in progress, while license/module-sync/validation checks already report success where completed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions